# Fetched custom field value from $_REQUEST $name_prefix = "custom_" . $custom_field->id; if ($custom_field->fieldTypeId == CustomField::$FIELD_FREETEXT || $custom_field->fieldTypeId == CustomField::$FIELD_OPTIONS || $custom_field->fieldTypeId == CustomField::$FIELD_MULTISELECT || $custom_field->fieldTypeId == CustomField::$FIELD_NUMERIC) { return $_REQUEST[$name_prefix]; } else { if ($custom_field->fieldTypeId == CustomField::$FIELD_DATE) { $value_yyyy = $name_prefix . "_yyyy"; $value_mm = $name_prefix . "_mm"; $value_dd = $name_prefix . "_dd"; $date_value = $_REQUEST[$value_yyyy] . "-" . $_REQUEST[$value_mm] . "-" . $_REQUEST[$value_dd]; return $date_value; } } } //$session_num = get_session_number(); $specimen_id = bcadd(get_max_specimen_id(), $_REQUEST['specimen_id']); $dnum = $_REQUEST['dnum']; $dnum = preg_replace("/[^a-zA-Z0-9\\/\\s]/", "", $dnum); $prefixed_dnum = date("Ymd") . "-" . $dnum; $addl_id = $_REQUEST['addl_id']; $addl_id = preg_replace("/[^a-zA-Z0-9\\/\\s]/", "", $addl_id); $date_recvd = $_REQUEST['receipt_yyyy'] . "-" . $_REQUEST['receipt_mm'] . "-" . $_REQUEST['receipt_dd']; if (trim($_REQUEST['collect_yyyy']) == "" && trim($_REQUEST['collect_mm']) == "" && trim($_REQUEST['collect_dd']) == "") { # date_collected not entered. Copy value from date_received $date_collected = $date_received; } else { $date_collected = $_REQUEST['collect_yyyy'] . "-" . $_REQUEST['collect_mm'] . "-" . $_REQUEST['collect_dd']; } $time_collected = $_REQUEST['ctime_hh'] . ":" . $_REQUEST['ctime_mm']; $patient_id = $_REQUEST['pid']; $specimen_type_id = $_REQUEST['stype'];
function autoImportPatientEntry($importPatient, $patientName) { $query_string = "SELECT * FROM patient " . "WHERE name LIKE '{$patientName}'"; $record = query_associative_one($query_string); if ($record) { $saved_db = DbUtil::switchToGlobal(); $userId = $_SESSION['user_id']; $query = "SELECT * FROM lab_config_access where user_id = {$userId}"; $record = query_associative_one($query); $labConfigId = $record['lab_config_id']; $currentLabPatient = Patient::getObject($record); $globalPatientId = $importPatient->patientId; $importLabConfigId = substr($globalPatientId, 0, 3); if ($importLabConfigId == $labConfigId) { return; } $subValue = $importLabConfigId . "00000000000"; $importPatientIdStr = bcsub($globalPatientId, $subValue); $importPatientId = intval($importPatientIdStr); $saved_db = DbUtil::switchToLabConfig($importLabConfigId); $querySelect = "SELECT * FROM specimen " . "WHERE patient_id={$importPatientId}"; $resultset = query_associative_all($querySelect, $rowCount); if ($resultset) { foreach ($resultset as $record) { $specimenRecords[] = Specimen::getObject($record); } foreach ($specimenRecords as $specimenRecord) { $querySelect = "SELECT * FROM test " . "WHERE specimen_id={$specimenRecord->specimenId}"; $resultset = query_associative_all($querySelect, $rowCount); foreach ($resultset as $record) { $testRecords[] = Test::getObject($record); } } } DbUtil::switchRestore($saved_db); /* Build a mapping of Specimens from the Global Table & make appropriate substitutions */ $saved_db = DbUtil::switchToGlobal(); $querySelect = "SELECT * FROM specimen_mapping"; $resultset = query_associative_all($querySelect, $rowCount); if ($resultset) { $specimenIds = array(); foreach ($resultset as $record) { $labIdSpecimenIds = explode(";", $record['lab_id_specimen_id']); foreach ($labIdSpecimenIds as $labIdSpecimenId) { $labIdSpecimenIdsSeparated = explode(":", $labIdSpecimenId); $labId = $labIdSpecimenIdsSeparated[0]; $specimenId = $labIdSpecimenIdsSeparated[1]; $specimenIds[$labId] = $specimenId; } foreach ($specimenRecords as $specimenRecord) { if ($specimenIds[$labConfigId] == $specimenRecord->specimenTypeId) { $specimenRecord->specimenTypeId = $specimenIds[$importLabConfigId]; } } } } /* Build a mapping of Tests from the Global Table & make appropriate substitutions */ $querySelect = "SELECT * FROM test_mapping"; $resultset = query_associative_all($querySelect, $rowCount); if ($resultset) { $testIds = array(); foreach ($resultset as $record) { $labIdTestIds = explode(";", $record['lab_id_test_id']); foreach ($labIdTestIds as $labIdTestId) { $labIdTestIdsSeparated = explode(":", $labIdTestId); $labId = $labIdTestIdsSeparated[0]; $testId = $labIdTestIdsSeparated[1]; $testIds[$labId] = $testId; } foreach ($testRecords as $testRecord) { if ($testIds[$labConfigId] == $testRecord->testTypeId) { $testRecord->testTypeId = $testIds[$importLabConfigId]; } } } } DbUtil::switchRestore($saved_db); $i = 0; if ($specimenRecords) { foreach ($specimenRecords as $specimenRecord) { $saved_db = DbUtil::switchToLabConfig($importLabConfigId); $querySelect = "SELECT * FROM test " . "WHERE specimen_id={$specimenRecord->specimenId}"; $resultset = query_associative_all($querySelect, $rowcount); DbUtil::switchRestore($saved_db); $specimenRecord->specimenId = get_max_specimen_id() + 1; $specimenRecord->patientId = $currentLabPatient->patientId; $specimenRecord->userId = $_SESSION['user_id']; $specimenRecord->doctor = ''; add_specimen($specimenRecord); for ($j = 0; $j < count($resultset); $j++) { $testRecord = $testRecords[$i]; $testRecord->specimenId = $specimenRecord->specimenId; $testRecord->userId = $_SESSION['user_id']; $i++; add_test($testRecord); } } } DbUtil::switchRestore($saved_db); } }
$patientName = $record['name']; $patient = Patient::getObject($record); $patient->createdBy = $_SESSION['user_id']; DbUtil::switchRestore($saved_db); add_patient($patient); $querySelect = "SELECT patient_id FROM patient " . "WHERE name like '{$patientName}' "; $record = query_associative_one($querySelect); $newPatientId = $record['patient_id']; /* Create New Specimen & Test Records */ $i = 0; foreach ($specimenRecords as $specimenRecord) { $saved_db = DbUtil::switchToLabConfig($importLabConfigId); $querySelect = "SELECT * FROM test " . "WHERE specimen_id={$specimenRecord->specimenId}"; $resultset = query_associative_all($querySelect, $rowcount); DbUtil::switchRestore($saved_db); $specimenRecord->specimenId = get_max_specimen_id() + 1; $specimenRecord->patientId = $newPatientId; $specimenRecord->userId = $_SESSION['user_id']; $specimenRecord->doctor = ''; add_specimen($specimenRecord); for ($j = 0; $j < count($resultset); $j++) { $testRecord = $testRecords[$i]; $testRecord->specimenId = $specimenRecord->specimenId; $testRecord->userId = $_SESSION['user_id']; $i++; add_test($testRecord); } } DbUtil::switchRestore($saved_db); ?> <script type="text/javascript">