rsammy Posted July 16, 2007 Share Posted July 16, 2007 i have a screen where there is a field called patient #. this is a text write in field. this field should already display a number(can be anything - alphanumeric) when page loads. user can either retain the same number or type in another number on top of it and hit submit to retain whatever was chosen. is there a way we can auto-generate a number( a function or something like that) that i can use to populate this field? at this time, user can only enter a number(all numerics) in this field. i should let them either write in their number or keep the system generated number. thanx Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 16, 2007 Share Posted July 16, 2007 Yes...but your question was pretty open-ended and vague. Or maybe I'm not understanding what you're asking? Do you want to generate a number? Or just populate a field with a number? If it's just a question of generating a unique number...you can possibly do... <?php session_start(); $_SESSION['patid'] = rand(100,999).'-'.time(); echo'Your patient id is: <input type="text" class="patientinfo" name="patid" value="'.$_SESSION['patid'].'">'; ?> Quote Link to comment Share on other sites More sharing options...
rsammy Posted July 16, 2007 Author Share Posted July 16, 2007 wow! thanx for your reply. actually, i need to both generate and put this number in teh field on form load. if user chooses, this can be overwritten with a proper number. for example, this is the patient number field with is very similar to the patient ssn. but at the time of registration, the office manager may not have all info of the patient available to enter it. so just chooses to enter the name and other info with a temp patient #. h/she can later change this part by editing the info with the correct patient #(which is 9 digits long). to make it more clear, i am pasting my code here - so it can be more clear to you on what im doing... <?PHP //File for database information //require_once ("phpInclude/config.php"); require_once ("../config.php"); //File to verify authenticated user include ("phpInclude/cookie.php"); $ClientName=$_GET["Client_Name"]; $ClientName='Group'; $month = date("M"); $month_number = date("n"); $year = date("Y"); $numberofdays = date("t"); $month_day = date("j"); $date = "$year-$month_number-$month_day"; $today="$month_number/$month_day/$year"; function option_select($month_year_day, $t) { if($month_year_day == $t) { print "<option value=$t selected>$t</option>"; } else { print "<option value=$t>$t</option>"; } } if (isset($USER_NAME)) { list($user_fname, $user_lname) = explode (' ', $USER_NAME); //$pat_ID=$_POST["pat_ID"]; if ($USER_NAME == ' Office Manager') { $query= "SELECT grp_name FROM group_details"; } else { $query= "SELECT grp_name FROM group_details, user_mgr WHERE user_mgr.user_fname='$user_fname' AND user_mgr.user_lname='$user_lname' AND user_mgr.user_grp_id=group_details.grp_id"; } $result=mysql_query($query); $row = mysql_fetch_array($result); $group_name = $row["grp_name"]; } $message = ""; $goodMessage = ""; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>INSTICOMM</title> <link rel='stylesheet' type='text/css' href='css/styleSheet.css'> <SCRIPT language="JavaScript" src="js/tree.js"></script> <SCRIPT language="JavaScript" src="js/validateSSN.js"></SCRIPT> <SCRIPT language="JavaScript" src="date-picker.js"></SCRIPT> <SCRIPT language="JavaScript"> function trim(inputString) { // Removes leading and trailing spaces from the passed string. Also // removes consecutive spaces and replaces it with one space. var retValue = inputString; var ch = retValue.substring(0, 1); while (ch == " ") { // Check for spaces at the beginning of the string retValue = retValue.substring(1, retValue.length); ch = retValue.substring(0, 1); } ch = retValue.substring(retValue.length-1, retValue.length); while (ch == " ") { // Check for spaces at the end of the string retValue = retValue.substring(0, retValue.length-1); ch = retValue.substring(retValue.length-1, retValue.length); } while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings } return retValue; // Return the trimmed string back to the user } // Ends the "trim" function function validate() { var err_msg = new Array(); var i=0; var j=0; var bigstring = "Please correct the following errors:\n"; var loginID = ""; var pass = ""; var count = 0; var aMatch = false; var aBlank = false; PatientFirstName = document.admitpat.PatientFirstName.value; PatientLastName = document.admitpat.PatientLastName.value; PatientDOB = document.admitpat.PatientDOB.value; //PatientSex = document.admitpat.PatientSex.value; PatientSSN = document.admitpat.PatientSSN.value; InsuranceProvider = document.admitpat.InsuranceProvider.value; InsuranceID = document.admitpat.InsuranceID.value; //alert (PatientSSN); //return false; if (trim(PatientFirstName).length < 1) { err_msg[i] = "First name cannot be blank."; i++; } if (trim(PatientLastName).length < 1) { err_msg[i] = "Last name cannot be blank."; i++; } if (trim(PatientDOB).length < 1) { err_msg[i] = "Date of Birth cannot be blank."; i++; } if (admitpat.PatientSex.value == "") { err_msg[i] = "Patient Sex cannot be blank."; i++; } if(!(isDate(PatientDOB))) { err_msg[i] = "Date of Birth is not valid. It must be in this format: mm/dd/yyyy."; i++; } if (trim(PatientSSN).length < 1) { err_msg[i] = "Patient Number cannot be blank."; i++; } if(!(SSNValidation(PatientSSN))) { err_msg[i] = "Patient # is not valid."; i++; } if (admitpat.physician.value == "") { err_msg[i] = "Preferred Provider cannot be blank."; i++; } if (i>0) { for (j=0; j<err_msg.length; j++) { count = j + 1; bigstring = bigstring + "\n" + count +". " + err_msg[j]; } alert (bigstring); return false; } else { return true; } } </Script> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function changeCase(frmObj) { var index; var tmpStr; var tmpChar; var preString; var postString; var strlen; //**********Changes made by RM on 07/11/2006 to retain what user types in field - if typed in Upper Case or change first character of each word from lower case to upper case********** //tmpStr = frmObj.value.toLowerCase(); tmpStr = frmObj.value; //**********End Changes by RM********** strLen = tmpStr.length; if (strLen > 0) { for (index = 0; index < strLen; index++) { if (index == 0) { tmpChar = tmpStr.substring(0,1).toUpperCase(); postString = tmpStr.substring(1,strLen); tmpStr = tmpChar + postString; } else { tmpChar = tmpStr.substring(index, index+1); if (tmpChar == " " && index < (strLen-1)) { tmpChar = tmpStr.substring(index+1, index+2).toUpperCase(); preString = tmpStr.substring(0, index+1); postString = tmpStr.substring(index+2,strLen); tmpStr = preString + tmpChar + postString; } } } } frmObj.value = tmpStr; } // End --> </SCRIPT> <SCRIPT language="JavaScript"> <?PHP //Navigation File //require_once ("phpInclude/nav.php"); require_once ("../nav.php"); ?> </SCRIPT> </head> <BODY onload="window.scroll(0,yoffset)"> <table width="900" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="4" bgcolor="#FFFFFF"> <div align="left"><font color="#FFFFFF"></font></div> <div align="right"><font color="#FFFFFF"><img src="images/title_barom.jpg" width="900" height="69"></font></div></td> </tr> <tr> <td align="left" valign="top" width="276"> <table width="276" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" valign="top"><div align="center"><img src="../images/clear.gif" height="15" width="1"><font color="#006699"><img src="images/clear.gif" height="15" width="1"><b><?PHP print($group_name); ?><br> User: </b><?PHP print($USER_NAME); ?> </font></div></td> </tr> <tr> <td align="left" valign="top"> <SCRIPT language="JavaScript"> tree.loadState() tree.display() </SCRIPT> </td> </tr> </table> <p align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><? print("<b>$copyright1</b>"); ?></p> </td> <td colspan="3" align="left" valign="top" width="624"> <div align="right"><a href=javascript:window.history.back(-1)><strong><br></strong> </a><br> <br> </div> <table width="614" border="1" cellspacing="0" cellpadding="0" align="center" bordercolor="#006699"> <tr> <td bgcolor="#006699"> <b><font color="#FFFFFF">New Patient Registration</font></b> </td> </tr> <tr> <td> <table width="608" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="3"><img src="../images/clear.gif" width="1" height="15"></td> </tr> <tr> <td width="15"> </td> <td width="578" rowspan="3" align="left" valign="top"> <form name="admitpat" method="post" action="newPatientAdded.php" onSubmit="return validate()"> <table width="563" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="283"> <div align="right"><font class="inputLbl"> <input type="hidden" name="pat_ID" value="<? print ("$pat_ID"); ?>"> </font></div></td> <td colspan="2"> </td> </tr> <table width="563" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="283"> <div align="right"><font class="inputLbl">First Name: </font></div></td> <td colspan="2"> <input class="txtboxLarge" type="text" name="PatientFirstName" value="<? print ("$pat_first_name"); ?>" onBlur="javascript:changeCase(document.admitpat.PatientFirstName);"> <font class="redTxt">*</font> </td> </tr> <tr> <td width="283"> <div align="right"><font class="inputLbl">Middle Initial: </font></div></td> <td colspan="2"> <input class="txtbox" type="text" name="PatientMiddleInitial" value="<? print("$pat_mid_init"); ?>" onBlur="javascript:changeCase(document.admitpat.PatientMiddleInitial);"> </td> </tr> <tr> <td width="283"> <div align="right"><font class="inputLbl">Last Name: </font></div></td> <td colspan="2"> <input class="txtboxLarge" type="text" name="PatientLastName" value="<? print("$pat_last_name"); ?>" onBlur="javascript:changeCase(document.admitpat.PatientLastName);"> <font class="redTxt">*</font> </td> </tr> <tr> <td width="283"> <div align="right"><font class="inputLbl">Date of Birth as mm/dd/yyyy: </font></div></td> <td colspan="2"> <input class="txtboxLarge" type="text" name="PatientDOB" value="<? print("$pat_dob"); ?>" onBlur="validateBDay();"> <script language=javascript> function validateBDay() { var BirthdayDay = document.admitpat.PatientDOB.value; var bDate = BirthdayDay.split("/"); var bMonth = bDate[0]; var bDay = bDate[1]; var bYear = bDate[2]; var BDate = new Date(bYear, (bMonth - 1), bDay); var Today = new Date(); TodayDay = Today.getDate(); TodayMon = Today.getMonth()+1; TodayYear = Today.getYear(); if (TodayYear < 2000) TodayYear += 1900; //var sysdate = new Date(); if (BDate > Today) alert("Birthday cannot be greater than today's date"); } </script> <font class="redTxt">*</font> </td> <tr> <td width="275"> <div align="right"><font class="inputLbl">Sex: </font></div></td> <td colspan="2" align="left" valign="top"><select name="PatientSex" id="pat_sex"> <option value="" selected></option> <option value="Male">Male</option> <option value="Female">Female</option> <?PHP if($pat_ID == $row["pat_ID"]) { print("\" selected>"); } else { print("\">"); } print ("</select>"); ?> <font class="redTxt">*</font> </td> </tr> <tr> <td width="283"> <div align="right"><font class="inputLbl">Patient # (9-digit number): </font></div></td> <td width="172"> <input class="txtboxLarge" type="text" name="PatientSSN" value="<? print("$pat_ssn"); ?>" > <font class="redTxt">*</font> </td> <td width="108"><font class="errTxt"> </font></td> </tr> </table> </table> <table width="563" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="283"> <div align="right"></div></td> <td width="280"> </td> </tr> <tr> <td width="283"> <div align="right"></div></td> <td width="280"> </td> </tr> <tr> <td width="283"> <div align="right"></div></td> <td width="280"> <input class="sbttn" type="submit" name="action" value="Register"> </td> </tr> </form> </tr> <tr> <td width="15"> </td> <td width="15"> </td> </tr> </table></td> </tr> </table> <p> </p></td> </tr> </table> </body> </html> <?PHP mysql_close(); ?> pat_ssn field is what im talking about. it should be a 18 character field with alphanumerics. i would like to generate a unique number here - consisting of full date and time and an alphabet. say something like "Q20070716021418" to denote that thsi is a temporary patient. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.