2 // Import of XML data from XML files created by "MEDICS" offine EMR application
3 // development by mi-squared.com -2010 licences under GPL v2 or greater
5 // Provided as an example of how to import complete medical records into OpenEMR
6 // from an XML formatted file
8 // This is intended to be run by a automated command line process/cron job not a web request
9 // Based on OpenEMR 3.1 release
10 // See import_mi2xml-xpaths.txt for a field structure details
13 include_once("../interface/globals.php");
14 include_once("$srcdir/patient.inc");
15 include_once("$srcdir/forms.inc");
16 include_once("$srcdir/acl.inc");
18 // set name of XML file
20 echo "No XML file path provided.\n";
28 $medics = simplexml_load_file($file) or die ("Unable to load XML file!");
30 ////////////////////////////////////////////////////////////////////
31 process_medics( $medics );
32 ////////////////////////////////////////////////////////////////////
34 ////////////////////////////////////////////////////////////////////
36 ////////////////////////////////////////////////////////////////////
38 function process_medics ( $medics ) {
42 // - family/social history
45 $msg = create_patient( $medics, $errors );
46 $has_errors = sizeof($errors) > 0;
48 render_errors( $errors );
60 $msg = add_encounter( $medics, $errors );
61 $has_errors = sizeof($errors) > 0;
63 render_errors( $errors );
72 function render_errors( &$errors ) {
74 foreach( $errors as $error ) {
83 function create_patient( &$medics, &$errors ) {
86 $patient_pid = get_patientid($medics);
88 $pubpid = trim( $medics->pubpid
);
90 // ID must be valid or 'NEWPATIENT'
92 array_push( $errors, "Patient ID '$pubpid' missing, patient skipped! ");
96 if ( $pubpid != 'NEWPATIENT') {
98 // 1. validate patient
100 $query = "SELECT pid FROM patient_data WHERE pubpid LIKE '$pubpid'";
101 $res = sqlStatement($query);
102 $row = sqlFetchArray($res);
105 $patient_pid = $row['pid'];
106 if (sqlFetchArray($res)) {
107 array_push( $errors, "Patient ID '$pubpid' is ambiguous, patient skipped! ");
110 // array_push( $errors, "Patient ID '$pubpid' exists, updates/new encounters only. ");
115 // 2. validate insurance provider - REMOVED
117 // 3. validate billing provider
120 $tmp = fetchProviderInfo($medics);
122 array_push( $errors, "Provider '$tmp' not found, patient skipped!");
126 $patient_provider_id = $tmp['id'];
127 $patient_provider_name = $tmp['username'];
128 $patient_provider_facility = $tmp['facility_id'];
130 // 4. get facility from // Move to function
131 $row = sqlQuery("SELECT id, name, pos_code FROM facility WHERE id = '$patient_provider_facility'" );
134 array_push( $errors, "Facility '$tmp' not found, patient skipped! ");
137 $patient_facility_id = $row['id'];
138 $patient_facility_name = $row['name'];
139 $patient_facility_pos = $row['pos_code'];
141 // 5. insert patient data
144 // Insert into patient_data.
146 $row = sqlQuery("SELECT max(pid)+1 AS pid FROM patient_data");
147 $patient_pid = $row['pid'] ?
$row['pid'] : 1;
149 // Combine street lines
150 $patient_street = $medics->street
. ' ' . $medics->street2
;
155 form2db($medics->fname
), // fname
156 form2db($medics->lname
), // lname
157 form2db($medics->mname
), // mname
158 sex($medics->sex
), // sex
159 form2db($medics->dob
), // dob
160 form2db($patient_street), // street
161 '', // Dutch: nstreet
164 form2db($medics->zip
), // zip
165 form2db($medics->city
), // city
166 form2db($medics->state
), // state
170 form2db($medics->phone_home
), // phone_home
171 form2db($medics->phone_alternate
), // phone_biz
174 '', // contact_relationship
179 form2db($medics->ethnicity
), // ethnoracial
181 '', // migrantseasonal
183 '', // monthly_income
185 '0000-00-00 00:00:00', // financial_review
186 $patient_pid, // pubpid - use PID when NEWPATIENT
194 form2db($medics->hippa_notice
), // hipaa_mail
195 form2db($medics->hippa_notice
), // hipaa_voice
198 '', // drivers_license
199 form2db($medics->hippa_notice
), // hipaa_notice
200 '', // $hipaa_message
201 $dos = fixDate($medics->fromdate
) // regdate
204 // Insert dummy row for employer_data.
205 newEmployerData($patient_pid);
207 // Update or Instest subscriber ins data
208 if( ($medics->pubpid
== 'NEWPATIENT') ||
(!empty($medics->policy_id
) ) ) {
212 $insurance_company_id, // (insurance) provider
213 form2db($medics->policy_id
), // policy_number - same as pt identifier?
214 '', // group_number - anything special here?
215 '', // plan_name - anything special here?
216 form2db($medics->lname
), // subscriber_lname
217 form2db($medics->mname
), // subscriber_mname
218 form2db($medics->fname
), // subscriber_fname
219 'self', // subscriber_relationship
221 fixDate($medics->dob
), // subscriber_DOB
222 form2db($medics->street
), // subscriber_street
223 form2db($medics->zip
), // subscriber_postal_code
224 form2db($medics->city
), // subscriber_city
225 form2db($medics->state
), // subscriber_state
226 '', // subscriber_country
227 form2db($medics->phone_home
), // subscriber_phone
228 '', // subscriber_employer
229 '', // subscriber_employer_street
230 '', // subscriber_employer_city
231 '', // subscriber_employer_postal_code
232 '', // subscriber_employer_state
233 '', // subscriber_employer_country
235 sex($medics->sex
), // subscriber_sex
236 fixDate($medics->eff_date
) // effective date
240 $tmp = $medics->lname
. ',' . $medics->fname
;
241 $alertmsg .= "New Patient Added: '$patient_pid' / '$tmp' <br>\n";
244 $medics->pid
= $patient_pid;
247 'history_father' => form2db($medics->familyinformation
->father
),
248 'history_mother' => form2db($medics->familyinformation
->mother
),
249 'history_spouse' => form2db($medics->familyinformation
->spouse
),
250 'history_siblings' => form2db($medics->familyinformation
->siblings
),
251 'history_offspring' => form2db($medics->familyinformation
->offspring
),
252 'relatives_cancer' => form2db($medics->medical
->relativesexperience
->cancer
),
253 'relatives_tuberculosis' => form2db($medics->medical
->relativesexperience
->tuberculosis
),
254 'relatives_diabetes' => form2db($medics->medical
->relativesexperience
->diabetes
),
255 'relatives_high_blood_pressure' => form2db($medics->medical
->relativesexperience
->highbloodpressure
),
256 'relatives_heart_problems' => form2db($medics->medical
->relativesexperience
->heartproblems
),
257 'relatives_stroke' => form2db($medics->medical
->relativesexperience
->stroke
),
258 'relatives_epilepsy' => form2db($medics->medical
->relativesexperience
->epilepsy
),
259 'relatives_mental_illness' => form2db($medics->medical
->relativesexperience
->mentalillness
),
260 'relatives_suicide' => form2db($medics->medical
->relativesexperience
->suicide
),
261 'usertext12' => form2db($medics->medical
->relativesexperience
->other
),
262 'coffee' => form2db($medics->medical
->lifestyleusage
->coffee
),
263 'tobacco' => form2db($medics->medical
->lifestyleusage
->tobacco
),
264 'alcohol' => form2db($medics->medical
->lifestyleusage
->alcohol
),
265 'sleep_patterns' => form2db($medics->medical
->lifestyleusage
->sleep
),
266 'exercise_patterns' => form2db($medics->medical
->lifestyleusage
->exercise
),
267 'seatbelt_use' => form2db($medics->medical
->lifestyleusage
->seatbelt
),
268 'counseling' => form2db($medics->medical
->lifestyleusage
->counseling
),
269 'hazardous_activities' => form2db($medics->medical
->lifestyleusage
->hazardactivities
),
270 'usertext13' => form2db($medics->medical
->lifestyleusage
->urinaryincontinence
),
271 'usertext14' => form2db($medics->medical
->lifestyleusage
->fallhistory
),
272 'additional_history' => form2db($medics->medical
->lifestyleusage
->other
) . " " .
273 form2db($medics->medical
->lifestyleusage
->generalnotes
)
276 // Insert/Update into history_data.
277 if ($medics->pubpid
== 'NEWPATIENT') {
278 newHistoryData($patient_pid, $history);
280 updateHistoryData($patient_pid, $history);
283 // Add or Update History data
284 add_update_history($medics, $patient_pid, $errors);
286 // Create or update an issue for each historical medication.
288 foreach ($medics->medical
->medications
->medication
as $medication) {
290 if (isempty($medication->name
)) continue;
293 $meds['title'] = form2db($medication->name
);
294 $meds['dosage'] = form2db($medication->dosage
);
295 $meds['frequency'] = form2db($medication->frequency
);
296 $meds['duration'] = form2db($medication->duration
); // TBD does not exsist in MEDICS
297 $meds['id'] = form2db($medication->id
);
299 if ( !isempty($meds['id']) ) {
300 $row = sqlQuery("SELECT id FROM lists WHERE id = " . $meds['id'] );
302 create_issue($patient_pid, 'medication', $meds );
304 update_issue($patient_pid, 'medication', $meds );
307 create_issue($patient_pid, 'medication', $meds );
314 // Create a new issue in the lists table.
316 function create_issue($pid, $type, $fields) {
318 if ( !isempty( $fields['title'] ) ) {
319 echo "\nAdding new issue '" . $fields['title'] . "'";
321 sqlInsert("INSERT INTO lists SET " .
325 "title = '" . $fields['title'] . "', " .
327 "user = '" . $
$_SESSION['authUser'] . "', " .
328 "groupname = '" . $
$_SESSION['authProvider'] . "', " .
330 "destination = '', " .
331 "frequency = '" . $fields['frequency'] . "', " .
332 "dosage = '" . $fields['dosage'] . "', " .
333 "duration = '" . $fields['duration'] . "'"
336 echo "Skipping field creation with empty title.";
342 // update issue in the lists table.
344 function update_issue($pid, $type, $fields) {
346 echo "\nUpdating issue id " . $fields['id'] . " ('" . $fields['title'] . "')";
348 sqlInsert("update lists SET " .
352 "title = '" . $fields['title'] . "', " .
354 "user = '" . $
$_SESSION['authUser'] . "', " .
355 "groupname = '" . $
$_SESSION['authProvider'] . "', " .
357 "destination = '', " .
358 "frequency = '" . $fields['frequency'] . "', " .
359 "dosage = '" . $fields['dosage'] . "', " .
360 "duration = '" . $fields['duration'] . "' " .
361 "WHERE id = " . $fields['id']
366 function add_update_history ($medics, $patient_pid, &$errors) {
368 $dos = fixDate($medics->fromdate
);
370 if (!isempty($medics->medical
->medicalhistory
->medicationnotes
) ||
371 !isempty($medics->medical
->medicalhistory
->allergies
) ||
372 !isempty($medics->medical
->medicalhistory
->history
) ||
373 !isempty($medics->medical
->medicalhistory
->surgicalhistory
) ||
374 !isempty($medics->medical
->medicalhistory
->preventative
)) {
376 $row = sqlQuery("SELECT pid FROM aperio_medical_history WHERE pid = '$patient_pid'");
378 sqlInsert("INSERT INTO aperio_medical_history SET " .
379 "pid = '$patient_pid', " .
380 "medication = '" . $medics->medical
->medicalhistory
->medicationnotes
."', " .
381 "allergies = '" . $medics->medical
->medicalhistory
->allergies
."', " .
382 "medical = '" . $medics->medical
->medicalhistory
->history
."', " .
383 "surgical = '" . $medics->medical
->medicalhistory
->surgicalhistory
."', " .
384 "preventative = '" . $medics->medical
->medicalhistory
->preventative
."' "
385 // . "updated = '$dos'"
387 // return( "Created history form for Patient ID:" . $patient_pid);
389 sqlStatement("UPDATE aperio_medical_history SET " .
390 "medication = '" . $medics->medical
->medicalhistory
->medicationnotes
."', " .
391 "allergies = '" . $medics->medical
->medicalhistory
->allergies
."', " .
392 "medical = '" . $medics->medical
->medicalhistory
->history
."', " .
393 "surgical = '" . $medics->medical
->medicalhistory
->surgicalhistory
."', " .
394 "preventative = '" . $medics->medical
->medicalhistory
->preventative
."' " .
395 // "updated = '$dos'" .
396 " WHERE pid = '$patient_pid'"
398 // return("Updated history form for Patient ID:" . $patient_pid);
402 // return("No History form created for Patient ID:" . $patient_pid);
406 function add_encounter( $medics, &$errors ) {
409 $patient_pid = $medics->pid
;
410 $dos = fixDate($medics->fromdate
);
411 $encounter_id = $GLOBALS['adodb']['db']->GenID('sequences');
412 $encounter_reason = form2db($medics->chiefcomplaint
);
413 addForm($encounter_id, "New Patient Encounter",
414 sqlInsert("INSERT INTO form_encounter SET " .
416 "onset_date = '$dos', " .
417 "reason = '$encounter_reason', " .
418 "facility = '$patient_facility_name', " .
419 "facility_id = '$patient_facility_id', " .
420 "sensitivity = 'normal', " .
421 "pid = '$patient_pid', " .
422 "encounter = '$encounter_id'"
424 "newpatient", $patient_pid, 1, $dos
427 $msg .= "Created new encounter for " . $medics->pubpid
. ".<br>\n";
431 $msg .= add_ros_subj ( $patient_pid, $dos, $encounter_id, $medics, $errors ); //ROS
432 $msg .= add_phyexam_obj( $patient_pid, $dos, $encounter_id, $medics, $errors ); //PE
433 $msg .= add_assessment_plan( $patient_pid, $dos, $encounter_id, $medics, $errors ); //Assessment/Plan
434 $msg .= add_vitals( $patient_pid, $dos, $encounter_id, $medics, $errors ); //
435 $msg .= add_other_dx( $patient_pid, $dos, $encounter_id, $medics, $errors ); //Other DX
438 $msg .= add_billing_records( $patient_pid, $dos, $encounter_id, $medics, $errors );
444 function isempty( $str ) {
445 return $str == null ||
empty($str);
447 function add_ros_subj( $patient_pid, $dos, $encounter_id, $medics, &$errors ) {
450 !isempty($medics->medical
->subjective
->general
) ||
451 !isempty($medics->medical
->subjective
->neurological
) ||
452 !isempty($medics->medical
->subjective
->heent
) ||
453 !isempty($medics->medical
->subjective
->respiratory
) ||
454 !isempty($medics->medical
->subjective
->cardio
) ||
455 !isempty($medics->medical
->subjective
->gastro
) ||
456 !isempty($medics->medical
->subjective
->skin
) ||
457 !isempty($medics->medical
->subjective
->extremities
) ||
458 !isempty($medics->medical
->subjective
->subjective
)
461 $row = fetchProviderInfo($medics);
463 if ($row['id']) { // TBD array error check NEEDED
464 $patient_provider_name = $row['username'];
467 addForm($encounter_id, "ROS",
468 sqlInsert("INSERT INTO form_aperio_ros SET " .
470 "pid = '$patient_pid', " .
473 "general = '" . form2db($medics->medical
->subjective
->general
) . "', " .
474 "neurological = '" . form2db($medics->medical
->subjective
->neurological
) . "', " .
475 "heent = '" . form2db($medics->medical
->subjective
->heent
) . "', " .
476 "respiratory = '" . form2db($medics->medical
->subjective
->respiratory
) . "', " .
477 "cardio = '" . form2db($medics->medical
->subjective
->cardio
) . "', " .
478 "gastro = '" . form2db($medics->medical
->subjective
->gastro
) . "', " .
479 "skin = '" . form2db($medics->medical
->subjective
->skin
) . "', " .
480 "extremities = '" . form2db($medics->medical
->subjective
->extremities
) . "', " .
481 "subjective = '" . form2db($medics->medical
->subjective
->subjective
) . "'"
483 "aperio_ros", $patient_pid, 1, $dos, $patient_provider_name
486 return "Added ROS for Patient ID " . $patient_pid . ".";
490 function add_phyexam_obj( $patient_pid, $dos, $encounter_id, $medics, &$errors ) {
492 if (!isempty($medics->medical
->objective
->general
) ||
493 !isempty($medics->medical
->objective
->neurological
) ||
494 !isempty($medics->medical
->objective
->heent
) ||
495 !isempty($medics->medical
->objective
->respiratory
) ||
496 !isempty($medics->medical
->objective
->cardio
) ||
497 !isempty($medics->medical
->objective
->gastro
) ||
498 !isempty($medics->medical
->objective
->skin
) ||
499 !isempty($medics->medical
->objective
->extremities
) ||
500 !isempty($medics->medical
->objective
->objective
))
503 $row = fetchProviderInfo($medics);
504 if ($row['id']) { // TBD array error check NEEDED
505 $patient_provider_name = $row['username'];
508 addForm($encounter_id, "Physical Exam",
509 sqlInsert("INSERT INTO form_aperio_pe SET " .
511 "pid = '$patient_pid', " .
514 "general = '" . form2db($medics->medical
->objective
->general
) . "', " .
515 "neurological = '" . form2db($medics->medical
->objective
->neurological
) . "', " .
516 "heent = '" . form2db($medics->medical
->objective
->heent
) . "', " .
517 "respiratory = '" . form2db($medics->medical
->objective
->respiratory
) . "', " .
518 "cardio = '" . form2db($medics->medical
->objective
->cardio
) . "', " .
519 "gastro = '" . form2db($medics->medical
->objective
->gastro
) . "', " .
520 "skin = '" . form2db($medics->medical
->objective
->skin
) . "', " .
521 "extremities = '" . form2db($medics->medical
->objective
->extremities
) . "', " .
522 "objective = '" . form2db($medics->medical
->objective
->objective
) . "'"
524 "aperio_pe", $patient_pid, 1, $dos, $patient_provider_name
527 return "Added PE for Patient ID " . $patient_pid . ".";
532 function add_assessment_plan( $patient_pid, $dos, $encounter_id, $medics, &$errors ) {
534 if (!isempty($medics->medical
->systems
->assessment
) ||
535 !isempty($medics->medical
->systems
->plan
))
537 $row = fetchProviderInfo($medics);
538 if ($row['id']) { // TBD array error check NEEDED
539 $patient_provider_name = $row['username'];
542 addForm($encounter_id, "Assessment-Plan",
543 sqlInsert("INSERT INTO form_aperio_ap SET " .
545 "pid = '$patient_pid', " .
548 "assessment = '" . form2db($medics->medical
->systems
->assessment
) . "', " .
549 "plan = '" . form2db($medics->medical
->systems
->plan
) . "'"
551 "aperio_ap", $patient_pid, 1, $dos, $patient_provider_name
554 return "Added Assessment for Patient ID " . $patient_pid . ".";
558 function add_other_dx( $patient_pid, $dos, $encounter_id, $medics, &$errors ) {
560 if (!isempty($medics->medical
->systems
->otherdx
)) {
561 $row = fetchProviderInfo($medics);
562 if ($row['id']) { // TBD array error check NEEDED
563 $patient_provider_name = $row['username'];
566 addForm($encounter_id, "Other DX",
567 sqlInsert("INSERT INTO form_aperio_opd SET " .
569 "pid = '$patient_pid', " .
572 "opd = '" . form2db($medics->medical
->systems
->otherdx
) . "'"
574 "aperio_opd", $patient_pid, 1, $dos, $patient_provider_name
577 return "Added OtherDX for Patient ID " . $patient_pid . ".";
582 function add_vitals( $patient_pid, $dos, $encounter_id, $medics, &$errors ) {
586 // Create Vitals form.
587 if (!empty($medics->medical
->physicalexamsvitals
->bps
)) {
590 // Calculate BMI_status
591 if ($medics->medical->physicalexamsvitals->weight > 0 &&
592 $medics->medical->physicalexamsvitals->height > 0) {
593 $bmi = ($weight/$height/$height)*703;
594 if ( $bmi > 42 ) $bmi_status = 'Obesity III';
595 elseif ( $bmi > 34 ) $bmi_status = 'Obesity II';
596 elseif ( $bmi > 30 ) $bmi_status = 'Obesity I';
597 elseif ( $bmi > 27 ) $bmi_status = 'Overweight';
598 elseif ( $bmi > 25 ) $bmi_status = 'Normal BL';
599 elseif ( $bmi > 18.5 ) $bmi_status = 'Normal';
600 elseif ( $bmi > 10 ) $bmi_status = 'Underweight';
603 addForm($encounter_id, "Vitals",
604 sqlInsert("INSERT INTO form_vitals SET " .
606 "pid = '$patient_pid', " .
607 "user = '" . form2db($patient_provider_name) . "', " .
611 "mentalstate = '" . form2db($medics->medical
->physicalexamsvitals
->mentalstatus
) . "', " .
612 "bps = '" . form2db($medics->medical
->physicalexamsvitals
->bps
) . "', " .
613 "bpd = '" . form2db($medics->medical
->physicalexamsvitals
->bpd
) . "', " .
614 "weight = '" . form2db($medics->medical
->physicalexamsvitals
->weight
) . "', " .
615 "height = '" . form2db($medics->medical
->physicalexamsvitals
->height
) . "', " .
616 "temperature = '" . form2db($medics->medical
->physicalexamsvitals
->temperature
). "', " .
617 "temp_method = '" . form2db($medics->medical
->physicalexamsvitals
->tempmethods
). "', " .
618 "pulse = '" . form2db($medics->medical
->physicalexamsvitals
->pulse
) . "', " .
619 "respiration = '" . form2db($medics->medical
->physicalexamsvitals
->respiration
). "', " .
620 "BMI = '" . form2db($medics->medical
->physicalexamsvitals
->bmi
) . "', " .
621 "BMI_status = '$bmi_status', " .
622 "waist_circ = '" . form2db($medics->medical
->physicalexamsvitals
->waistcirc
) . "', " .
623 "head_circ = '" . form2db($medics->medical
->physicalexamsvitals
->headcirc
) . "', " .
624 "oxygen_saturation = '" . form2db($medics->medical
->physicalexamsvitals
->o2
) . "'"
626 "vitals", $patient_pid, 1, $dos
629 return "Created vitals form for Patient ID " . $patient_pid . ".\n";
632 return "No vitals form created for Patient ID " . $patient_pid . ".\n";
635 function add_billing_records( $patient_pid, $dos, $encounter_id, $medics, &$errors ) {
637 $row = fetchProviderInfo($medics);
638 $patient_provider_id = $row['id'];
642 for ( $diag = 0; $diag < 15; $diag++
) {
644 $_code = trim($medics->medical
->systems
->diagnosis
[$diag]->code
);
645 $_codenote = trim($medics->medical
->systems
->diagnosis
[$diag]->codenote
);
646 $_codestatus = trim($medics->medical
->systems
->diagnosis
[$diag]->codestatus
);
648 if (empty($_code)) { continue; }
651 echo "\n---> ::: $_code $_codenote $_codestatus\n";
655 $patient_provider_id,
658 $_codenote . ' (' . $_codestatus . ')'
663 if (!empty($medics->medical
->billable
)) {
665 $cptCode = $medics->medical
->billable
->service
[0]->code
;
666 $codeNote= $medics->medical
->billable
->service
[0]->codenote
;
668 for ($justify = '', $j = 0; $j < 4 && $j < count($diags); ++
$j) {
669 $justify .= $diags[$j] . ':';
672 add_billing($patient_pid, $encounter_id, $patient_provider_id,
673 'CPT4', $cptCode, $codeNote, $justify);
677 // Write a row to the billing table.
679 function add_billing($pid, $encounter, $provider, $codetype, $code,
680 $description, $justify='', $modifier='', $units=1) {
682 // echo "\n ADD BILLING: ---> $pid $encounter $provider $codetype $code $description $justify $modifier $units\n";
684 // Get the fee from the codes table.
686 if ($codetype == 'CPT4') {
687 $query = "SELECT fee FROM codes WHERE code_type = 1 AND code = '$code' AND ";
688 if (empty($modifier))
689 $query .= "( modifier IS NULL OR modifier = '')";
691 $query .= "modifier = '$modifier'";
692 $row = sqlQuery($query);
693 if ($row['fee']) $fee = $row['fee'] * $units;
696 sqlInsert("INSERT INTO billing ( " .
697 "date, code_type, code, pid, provider_id, user, groupname, authorized, " .
698 "encounter, code_text, billed, activity, payer_id, modifier, units, " .
706 "'" . $
$_SESSION['authUser'] . "', " .
707 "'" . $
$_SESSION['authProvider'] . "', " .
713 "'$insurance_company_id'," .
723 function get_patientid( $medics ) {
725 $pubpid = trim( $medics->pubpid
);
727 $query = "SELECT pid FROM patient_data WHERE pubpid LIKE '$pubpid'";
728 $res = sqlStatement($query);
729 $row = sqlFetchArray($res);
731 $patient_pid = $row['pid'];
738 // Encode a string from a form field for database writing.
740 function form2db($fldval) {
741 $fldval = trim($fldval);
742 if (!get_magic_quotes_gpc()) $fldval = addslashes($fldval);
746 // Encode sex for OpenEMR compatibility.
748 function sex($insex) {
749 if (!empty($insex)) {
750 $insex = strtoupper(substr($insex, 0, 1));
751 if ($insex == 'M') return 'Male';
752 if ($insex == 'F') return 'Female';
757 function fetchProviderInfo($medics) {
758 $query = "SELECT id, username, facility_id FROM users WHERE npi = '" . $medics->provider_npi
. "'";
759 $row = sqlQuery($query);
761 array_push( $errors, "Provider '" . $medics->provider_npi
. "' not found");
769 # XPATHS used by import_mi2xml.php scripts
770 # Includes customized encounter forms (see the code) provided for example
772 # Some xpaths can be repeated many times, see comments below
774 # Provided by Medical Information Integration, LLC
793 patient/phone_alternate
796 patient/provider_name
798 patient/chiefcomplaint
800 patient/familyinformation/father
801 patient/familyinformation/mother
802 patient/familyinformation/spouse
803 patient/familyinformation/siblings
804 patient/familyinformation/offspring
806 patient/medical/relativesexperience/cancer
807 patient/medical/relativesexperience/tuberculosis
808 patient/medical/relativesexperience/diabetes
809 patient/medical/relativesexperience/highbloodpressure
810 patient/medical/relativesexperience/heartproblems
811 patient/medical/relativesexperience/stroke
812 patient/medical/relativesexperience/epilepsy
813 patient/medical/relativesexperience/mentalillness
814 patient/medical/relativesexperience/suicide
815 patient/medical/relativesexperience/other
816 patient/medical/lifestyleusage/coffee
817 patient/medical/lifestyleusage/tobacco
818 patient/medical/lifestyleusage/alcohol
819 patient/medical/lifestyleusage/sleep
820 patient/medical/lifestyleusage/exercise
821 patient/medical/lifestyleusage/seatbelt
822 patient/medical/lifestyleusage/counseling
823 patient/medical/lifestyleusage/hazardactivities
824 patient/medical/lifestyleusage/urinaryincontinence
825 patient/medical/lifestyleusage/fallhistory
826 patient/medical/lifestyleusage/other
827 patient/medical/lifestyleusage/generalnotes
829 patient/medical/medicalhistory/medicationnotes
830 patient/medical/medicalhistory/allergies
831 patient/medical/medicalhistory/history
832 patient/medical/medicalhistory/surgicalhistory
833 patient/medical/medicalhistory/preventative
835 # Multiple segments supported in current script
837 patient/medical/medications/medication/name
838 patient/medical/medications/medication/dosage
839 patient/medical/medications/medication/frequency
840 patient/medical/medications/medication/id
843 patient/medical/subjective/general
844 patient/medical/subjective/neurological
845 patient/medical/subjective/heent
846 patient/medical/subjective/respiratory
847 patient/medical/subjective/cardio
848 patient/medical/subjective/gastro
849 patient/medical/subjective/skin
850 patient/medical/subjective/extremities
851 patient/medical/subjective/subjective
854 patient/medical/objective/general
855 patient/medical/objective/neurological
856 patient/medical/objective/heent
857 patient/medical/objective/respiratory
858 patient/medical/objective/cardio
859 patient/medical/objective/gastro
860 patient/medical/objective/skin
861 patient/medical/objective/extremities
862 patient/medical/objective/objective
865 patient/medical/physicalexamsvitals/mentalstatus
866 patient/medical/physicalexamsvitals/bps
867 patient/medical/physicalexamsvitals/bpd
868 patient/medical/physicalexamsvitals/weight
869 patient/medical/physicalexamsvitals/height
870 patient/medical/physicalexamsvitals/temperature
871 patient/medical/physicalexamsvitals/tempmethods
872 patient/medical/physicalexamsvitals/pulse
873 patient/medical/physicalexamsvitals/respiration
874 patient/medical/physicalexamsvitals/bmi
875 patient/medical/physicalexamsvitals/waistcirc
876 patient/medical/physicalexamsvitals/headcirc
877 patient/medical/physicalexamsvitals/o2
880 patient/medical/systems/assessment
881 patient/medical/systems/plan
883 # Multiple segments supported in current script
884 patient/medical/systems/diagnosis/code
885 patient/medical/systems/diagnosis/codenote
886 patient/medical/systems/diagnosis/codestatus
889 patient/medical/systems/otherdx
891 # Multiple segments supported in current script
892 patient/medical/billable/service[1]/code
893 patient/medical/billable/service[1]/codenote
894 patient/medical/billable/service[1]/modifier