public static function generatePID($patient) { if (!$patient instanceof Patient) { $patientId = (int) $patient; $patient = new Patient(); $patient->personId = (int) $patientId; $patient->populate(); } $patientId = (int) $patient->personId; $person = $patient->person; $statistics = PatientStatisticsDefinition::getPatientStatistics($patientId); $raceCode = ''; $race = 'Unknown'; if (isset($statistics['Race'])) { $race = $statistics['Race']; } if (isset($statistics['race'])) { $race = $statistics['race']; } if (strlen($statistics['Race']) > 0) { $race = $statistics['Race']; foreach (PatientStatisticsDefinition::listRaceCodes() as $key => $value) { if (strtolower($value) == strtolower($race)) { $raceCode = $key; break; } } } $addr = new Address(); foreach ($addr->getIteratorByPersonId($patient->personId) as $address) { break; } $phoneHome = ''; $phoneBusiness = ''; $phoneNumber = new PhoneNumber(); $phoneNumber->personId = $patient->personId; foreach ($phoneNumber->phoneNumbers as $phone) { if ($phoneHome == '' && $phone['type'] == 'HP') { $phoneHome = $phone['number']; } if ($phoneBusiness == '' && $phone['type'] == 'TE') { $phoneBusiness = $phone['number']; } } if ($phoneHome) { $phone = $phoneHome; } if ($phoneBusiness) { $phone = $phoneBusiness; } if (is_array($phone)) { $phone = $phone['number']; } if (substr($phone, 0, 1) == 1) { $phone = substr($phone, 1); } $areaCode = substr($phone, 0, 3); $localNumber = substr($phone, 3); $ethnic = 'Unknown'; if (isset($statistics['Ethnicity'])) { $ethnic = $statistics['Ethnicity']; } if (isset($statistics['ethnicity'])) { $ethnic = $statistics['ethnicity']; } $ethnicId = strtoupper(substr($ethnic, 0, 1)); if ($ethnicId != 'H' && $ethnicId != 'N' && $ethnicId != 'U') { $ethnicId = 'U'; } return 'PID|||' . $patient->recordNumber . '^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR||' . $person->lastName . '^' . $person->firstName . '||' . date('Ymd', strtotime($person->dateOfBirth)) . '|' . $person->gender . '||' . $raceCode . '^' . $race . '^HL70005|' . $address->line1 . '^^' . $address->city . '^' . $address->state . '^' . $address->zipCode . '^USA^M||^PRN^^^^' . $areaCode . '^' . $localNumber . '|||||||||' . $ethnicId . '^' . $ethnic . '^HL70189'; }