3 * interface/eRxXMLBuilder.php Functions for building NewCrop XML.
6 * @link http://www.open-emr.org
7 * @author Sam Likins <sam.likins@wsi-services.com>
8 * @copyright Copyright (c) 2015 Sam Likins <sam.likins@wsi-services.com>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
22 private $sentAllergyIds = array();
23 private $sentMedicationIds = array();
24 private $sentPrescriptionIds = array();
26 private $fieldEmptyMessages = array();
27 private $demographicsCheckMessages = array();
28 private $warningMessages = array();
30 public function __construct($globals = null, $store = null)
33 $this->setGlobals($globals);
37 $this->setStore($store);
42 * Set Globals for retrieving eRx global configurations
43 * @param object $globals The eRx Globals object to use for processing
44 * @return eRxPage This object is returned for method chaining
46 public function setGlobals($globals)
48 $this->globals
= $globals;
54 * Get Globals for retrieving eRx global configurations
55 * @return object The eRx Globals object to use for processing
57 public function getGlobals()
59 return $this->globals
;
63 * Set Store to handle eRx cashed data
64 * @param object $store The eRx Store object to use for processing
65 * @return eRxPage This object is returned for method chaining
67 public function setStore($store)
69 $this->store
= $store;
75 * Get Store for handling eRx cashed data
76 * @return object The eRx Store object to use for processing
78 public function getStore()
83 protected function trimData($string, $length)
85 return substr($string, 0, $length - 1);
88 protected function stripSpecialCharacter($string)
90 return preg_replace('/[^a-zA-Z0-9 \'().,#:\/\-@_%]/', '', $string);
93 public function checkError($xml)
95 $curlHandler = curl_init($xml);
96 $sitePath = $this->getGlobals()->getOpenEMRSiteDirectory();
97 $data = array('RxInput' => $xml);
99 curl_setopt($curlHandler, CURLOPT_URL
, $this->getGlobals()->getPath());
100 curl_setopt($curlHandler, CURLOPT_POST
, 1);
101 curl_setopt($curlHandler, CURLOPT_POSTFIELDS
, 'RxInput='.$xml);
102 curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER
, 0);
103 curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION
, 1);
104 curl_setopt($curlHandler, CURLOPT_COOKIESESSION
, true);
105 curl_setopt($curlHandler, CURLOPT_COOKIEFILE
, $sitePath.'/newcrop-cookiefile');
106 curl_setopt($curlHandler, CURLOPT_COOKIEJAR
, $sitePath.'/newcrop-cookiefile');
107 curl_setopt($curlHandler, CURLOPT_COOKIE
, session_name().'='.session_id());
108 curl_setopt($curlHandler, CURLOPT_USERAGENT
, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
109 curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER
, true);
111 $result = curl_exec($curlHandler) or die(curl_error($curlHandler));
113 curl_close($curlHandler);
118 public function addSentAllergyIds($allergyIds)
120 if (is_array($allergyIds)) {
121 foreach ($allergyIds as $allergyId) {
122 $this->sentAllergyIds
[] = $allergyId;
125 $this->sentAllergyIds
[] = $allergyIds;
129 public function getSentAllergyIds()
131 return $this->sentAllergyIds
;
134 public function addSentMedicationIds($medicationIds)
136 if (is_array($medicationIds)) {
137 foreach ($medicationIds as $medicationId) {
138 $this->sentMedicationIds
[] = $medicationId;
141 $this->sentMedicationIds
[] = $medicationIds;
145 public function getSentMedicationIds()
147 return $this->sentMedicationIds
;
150 public function addSentPrescriptionId($prescriptionIds)
152 if (is_array($prescriptionIds)) {
153 foreach ($prescriptionIds as $prescriptionId) {
154 $this->sentPrescriptionIds
[] = $prescriptionId;
157 $this->sentPrescriptionIds
[] = $prescriptionIds;
161 public function getSentPrescriptionIds()
163 return $this->sentPrescriptionIds
;
166 public function fieldEmpty($value, $message)
169 $this->fieldEmptyMessages
[] = $message;
173 public function getFieldEmptyMessages()
175 return $this->fieldEmptyMessages
;
178 public function demographicsCheck($value, $message)
181 $this->demographicsCheckMessages
[] = $message;
185 public function getDemographicsCheckMessages()
187 return $this->demographicsCheckMessages
;
190 public function warningMessage($value, $message)
193 $this->warningMessages
[] = $message;
197 public function getWarningMessages()
199 return $this->warningMessages
;
202 public function createElementText($name, $value)
204 $element = $this->getDocument()->createElement($name);
205 $element->appendChild($this->getDocument()->createTextNode($value));
210 public function createElementTextFieldEmpty($name, $value, $validationText)
212 $this->fieldEmpty($value, $validationText);
214 return $this->createElementText($name, $value);
217 public function createElementTextDemographicsCheck($name, $value, $validationText)
219 $this->demographicsCheck($value, $validationText);
221 return $this->createElementText($name, $value);
224 public function appendChildren($element, &$children)
226 if (is_a($element, 'DOMNode') && is_array($children) && count($children)) {
227 foreach ($children as $child) {
228 // if(is_array($child)) {
229 // $this->appendChildren($element, $child);
231 $element->appendChild($child);
236 public function getDocument()
238 if ($this->document
=== null) {
239 $this->document
= new DOMDocument();
240 $this->document
->formatOutput
= true;
243 return $this->document
;
246 public function getNCScript()
248 if ($this->ncScript
=== null) {
249 $document = $this->getDocument();
251 $this->ncScript
= $document->createElement('NCScript');
252 $this->ncScript
->setAttribute('xmlns', 'http://secure.newcropaccounts.com/interfaceV7');
253 $this->ncScript
->setAttribute('xmlns:NCStandard', 'http://secure.newcropaccounts.com/interfaceV7:NCStandard');
254 $this->ncScript
->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
256 $document->appendChild($this->ncScript
);
259 return $this->ncScript
;
262 public function getCredentials()
264 $eRxCredentials = $this->getGlobals()
267 $elemenet = $this->getDocument()->createElement('Credentials');
268 $elemenet->appendChild($this->createElementTextFieldEmpty('partnerName', $eRxCredentials['0'], xl('NewCrop eRx Partner Name')));
269 $elemenet->appendChild($this->createElementTextFieldEmpty('name', $eRxCredentials['1'], xl('NewCrop eRx Account Name')));
270 $elemenet->appendChild($this->createElementTextFieldEmpty('password', $eRxCredentials['2'], xl('NewCrop eRx Password')));
271 $elemenet->appendChild($this->createElementText('productName', 'OpenEMR'));
272 $elemenet->appendChild($this->createElementText('productVersion', $this->getGlobals()->getOpenEMRVersion()));
277 public function getUserRole($authUserId)
279 $eRxUserRole = $this->getStore()
280 ->getUserById($authUserId);
282 $eRxUserRole = $eRxUserRole['newcrop_user_role'];
284 $this->fieldEmpty($eRxUserRole, xl('NewCrop eRx User Role'));
286 echo xlt('Unauthorized access to ePrescription');
290 $eRxUserRole = preg_replace('/erx/', '', $eRxUserRole);
292 switch ($eRxUserRole) {
296 $newCropUser = 'Staff';
299 $newCropUser = 'LicensedPrescriber';
301 case 'supervisingDoctor':
302 $newCropUser = 'SupervisingDoctor';
304 case 'midlevelPrescriber':
305 $newCropUser = 'MidlevelPrescriber';
311 $element = $this->getDocument()->createElement('UserRole');
312 $element->appendChild($this->createElementTextFieldEmpty('user', $newCropUser, xl('NewCrop eRx User Role * invalid selection *')));
313 $element->appendChild($this->createElementText('role', $eRxUserRole));
318 public function getDestination($authUserId, $page = null)
320 $eRxUserRole = $this->getStore()
321 ->getUserById($authUserId);
323 $eRxUserRole = $eRxUserRole['newcrop_user_role'];
325 $eRxUserRole = preg_replace('/erx/', '', $eRxUserRole);
328 if ($eRxUserRole == 'admin') {
330 } elseif ($eRxUserRole == 'manager') {
337 $element = $this->getDocument()->createElement('Destination');
338 $element->appendChild($this->createElementText('requestedPage', $page));
343 public function getAccountAddress($facility)
345 $postalCode = preg_replace('/[^0-9]/', '', $facility['postal_code']);
346 $postalCodePostfix = substr($postalCode, 5, 4);
347 $postalCode = substr($postalCode, 0, 5);
349 if (strlen($postalCode) < 5) {
350 $this->fieldEmpty('', xl('Primary Facility Zip Code'));
353 $element = $this->getDocument()->createElement('AccountAddress');
354 $element->appendChild($this->createElementTextFieldEmpty('address1', $this->trimData($this->stripSpecialCharacter($facility['street']), 35), xl('Primary Facility Street Address')));
355 $element->appendChild($this->createElementTextFieldEmpty('city', $facility['city'], xl('Primary Facility City')));
356 $element->appendChild($this->createElementTextFieldEmpty('state', $facility['state'], xl('Primary Facility State')));
357 $element->appendChild($this->createElementText('zip', $postalCode));
358 if (strlen($postalCodePostfix) == 4) {
359 $element->appendChild($this->createElementText('zip4', $postalCodePostfix));
362 $element->appendChild($this->createElementTextFieldEmpty('country', substr($facility['country_code'], 0, 2), xl('Primary Facility Country code')));
367 public function getAccount()
369 $facility = $this->getStore()
370 ->getFacilityPrimary();
372 if (!$facility['federal_ein']) {
373 echo xlt('Please select a Primary Business Entity facility with \'Tax ID\' as your facility Tax ID. If you are an individual practitioner, use your tax id. This is used for identifying you in the NewCrop system.');
377 $element = $this->getDocument()->createElement('Account');
378 $element->setAttribute('ID', $this->getGlobals()->getAccountId());
379 $element->appendChild($this->createElementTextFieldEmpty('accountName', $this->trimData($this->stripSpecialCharacter($facility['name']), 35), xl('Facility Name')));
380 $element->appendChild($this->createElementText('siteID', $facility['federal_ein'], 'Site ID'));
381 $element->appendChild($this->getAccountAddress($facility));
382 $element->appendChild($this->createElementTextFieldEmpty('accountPrimaryPhoneNumber', preg_replace('/[^0-9]/', '', $facility['phone']), xl('Facility Phone')));
383 $element->appendChild($this->createElementTextFieldEmpty('accountPrimaryFaxNumber', preg_replace('/[^0-9]/', '', $facility['fax']), xl('Facility Fax')));
388 public function getLocationAddress($facility)
390 $postalCode = preg_replace('/[^0-9]/', '', $facility['postal_code']);
391 $postalCodePostfix = substr($postalCode, 5, 4);
392 $postalCode = substr($postalCode, 0, 5);
394 if (strlen($postalCode) < 5) {
395 $this->fieldEmpty('', xl('Facility Zip Code'));
398 $element = $this->getDocument()->createElement('LocationAddress');
399 if ($facility['street']) {
400 $element->appendChild($this->createElementText('address1', $this->trimData($this->stripSpecialCharacter($facility['street']), 35)));
403 if ($facility['city']) {
404 $element->appendChild($this->createElementText('city', $facility['city']));
407 if ($facility['state']) {
408 $element->appendChild($this->createElementText('state', $facility['state']));
411 $element->appendChild($this->createElementText('zip', $postalCode));
412 if (strlen($postalCodePostfix) == 4) {
413 $element->appendChild($this->createElementText('zip4', $postalCodePostfix));
416 if ($facility['country_code']) {
417 $element->appendChild($this->createElementText('country', substr($facility['country_code'], 0, 2)));
423 public function getLocation($authUserId)
425 $userFacility = $this->getStore()
426 ->getUserFacility($authUserId);
428 $element = $this->getDocument()->createElement('Location');
429 $element->setAttribute('ID', $userFacility['id']);
430 $element->appendChild($this->createElementText('locationName', $this->trimData($this->stripSpecialCharacter($userFacility['name']), 35)));
431 $element->appendChild($this->getLocationAddress($userFacility));
432 if ($userFacility['phone']) {
433 $element->appendChild($this->createElementText('primaryPhoneNumber', preg_replace('/[^0-9]/', '', $userFacility['phone'])));
436 if ($userFacility['fax']) {
437 $element->appendChild($this->createElementText('primaryFaxNumber', preg_replace('/[^0-9]/', '', $userFacility['fax'])));
440 if ($userFacility['phone']) {
441 $element->appendChild($this->createElementText('pharmacyContactNumber', preg_replace('/[^0-9]/', '', $userFacility['phone'])));
447 public function getLicensedPrescriber($authUserId)
449 $userDetails = $this->getStore()
450 ->getUserById($authUserId);
452 $element = $this->getDocument()->createElement('LicensedPrescriber');
453 $element->setAttribute('ID', $userDetails['npi']);
454 $element->appendChild($this->getLicensedPrescriberName($userDetails, xl('Licensed Prescriber')));
455 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], 'Licensed Prescriber DEA'));
456 if ($userDetails['upin']) {
457 $element->appendChild($this->createElementText('upin', $userDetails['upin']));
460 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
461 $element->appendChild($this->createElementTextFieldEmpty('npi', $userDetails['npi'], xl('Licensed Prescriber NPI')));
466 public function getStaffName($user)
468 $element = $this->getDocument()->createElement('StaffName');
469 $element->appendChild($this->createElementText('last', $this->stripSpecialCharacter($user['lname'])));
470 $element->appendChild($this->createElementText('first', $this->stripSpecialCharacter($user['fname'])));
471 $element->appendChild($this->createElementText('middle', $this->stripSpecialCharacter($user['mname'])));
476 public function getStaff($authUserId)
478 $userDetails = $this->getStore()
479 ->getUserById($authUserId);
481 $element = $this->getDocument()->createElement('Staff');
482 $element->setAttribute('ID', $userDetails['username']);
483 $element->appendChild($this->getStaffName($userDetails));
484 $element->appendChild($this->createElementText('license', $userDetails['state_license_number']));
489 public function getLicensedPrescriberName($user, $prescriberType, $prefix = false)
491 $element = $this->getDocument()->createElement('LicensedPrescriberName');
492 $element->appendChild($this->createElementTextFieldEmpty('last', $this->stripSpecialCharacter($user['lname']), $prescriberType.' '.xl('Licensed Prescriber Last Name')));
493 $element->appendChild($this->createElementTextFieldEmpty('first', $this->stripSpecialCharacter($user['fname']), $prescriberType.' '.xl('Licensed Prescriber First Name')));
494 $element->appendChild($this->createElementText('middle', $this->stripSpecialCharacter($user['mname'])));
495 if ($prefix && $user['title']) {
496 $element->appendChild($this->createElementTextFieldEmpty('prefix', $user['title'], $prescriberType.' '.xl('Licensed Prescriber Title (Prefix)')));
502 public function getSupervisingDoctor($authUserId)
504 $userDetails = $this->getStore()
505 ->getUserById($authUserId);
507 $element = $this->getDocument()->createElement('SupervisingDoctor');
508 $element->setAttribute('ID', $userDetails['npi']);
509 $element->appendChild($this->getLicensedPrescriberName($userDetails, xl('Supervising Doctor')));
510 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], xl('Supervising Doctor DEA')));
511 if ($userDetails['upin']) {
512 $element->appendChild($this->createElementText('upin', $userDetails['upin']));
515 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
516 $element->appendChild($this->createElementTextFieldEmpty('npi', $userDetails['npi'], xl('Supervising Doctor NPI')));
521 public function getMidlevelPrescriber($authUserId)
523 $userDetails = $this->getStore()
524 ->getUserById($authUserId);
526 $element = $this->getDocument()->createElement('MidlevelPrescriber');
527 $element->setAttribute('ID', $userDetails['npi']);
528 $element->appendChild($this->getLicensedPrescriberName($userDetails, xl('Midlevel Prescriber'), true));
529 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], xl('Midlevel Prescriber DEA')));
530 if ($userDetails['upin']) {
531 $element->appendChild($this->createElementText('upin', $userDetails['upin']));
534 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
535 $element->appendChild($this->createElementTextFieldEmpty('npi', $userDetails['npi'], xl('Midlevel Prescriber NPI')));
540 public function getStaffElements($authUserId, $destination)
542 $userRole = $this->getStore()->getUserById($authUserId);
543 $userRole = preg_replace('/erx/', '', $userRole['newcrop_user_role']);
547 if ($userRole != 'manager') {
548 $elements[] = $this->getLocation($authUserId);
551 if ($userRole == 'doctor' ||
$destination == 'renewal') {
552 $elements[] = $this->getLicensedPrescriber($authUserId);
555 if ($userRole == 'manager' ||
$userRole == 'admin' ||
$userRole == 'nurse') {
556 $elements[] = $this->getStaff($authUserId);
557 } elseif ($userRole == 'supervisingDoctor') {
558 $elements[] = $this->getSupervisingDoctor($authUserId);
559 } elseif ($userRole == 'midlevelPrescriber') {
560 $elements[] = $this->getMidlevelPrescriber($authUserId);
566 public function getPatientName($patient)
568 $element = $this->getDocument()->createElement('PatientName');
569 $element->appendChild($this->createElementTextDemographicsCheck('last', $this->trimData($this->stripSpecialCharacter($patient['lname']), 35), xl('Patient Last Name')));
570 $element->appendChild($this->createElementTextDemographicsCheck('first', $this->trimData($this->stripSpecialCharacter($patient['fname']), 35), xl('Patient First Name')));
571 $element->appendChild($this->createElementText('middle', $this->trimData($this->stripSpecialCharacter($patient['mname']), 35)));
576 public function getPatientAddress($patient)
578 $patient['street'] = $this->trimData($this->stripSpecialCharacter($patient['street']), 35);
579 $this->warningMessage($patient['street'], xl('Patient Street Address'));
582 if (trim($patient['country_code']) == '') {
583 $eRxDefaultPatientCountry = $this->getGlobals()->getDefaultPatientCountry();
585 if ($eRxDefaultPatientCountry == '') {
586 $this->demographicsCheck('', xl('Global Default Patient Country'));
588 $patient['country_code'] = $eRxDefaultPatientCountry;
591 $this->demographicsCheck('', xl('Patient Country'));
594 $element = $this->getDocument()->createElement('PatientAddress');
595 $element->appendChild($this->createElementTextFieldEmpty('address1', $patient['street'], xl('Patient Street Address')));
596 $element->appendChild($this->createElementTextDemographicsCheck('city', $patient['city'], xl('Patient City')));
597 if ($patient['state']) {
598 $element->appendChild($this->createElementText('state', $patient['state']));
601 if ($patient['postal_code']) {
602 $element->appendChild($this->createElementText('zip', $patient['postal_code']));
605 $element->appendChild($this->createElementText('country', substr($patient['country_code'], 0, 2)));
610 public function getPatientContact($patient)
612 $element = $this->getDocument()->createElement('PatientContact');
613 if ($patient['phone_home']) {
614 $element->appendChild($this->createElementText('homeTelephone', preg_replace('/-/', '', $patient['phone_home'])));
620 public function getPatientCharacteristics($patient)
622 if (trim($patient['date_of_birth']) == '' ||
$patient['date_of_birth'] == '00000000') {
623 $this->warningMessage('', xl('Patient Date Of Birth'));
626 $this->warningMessage(trim($patient['sex']), xl('Patient Gender'));
628 $element = $this->getDocument()->createElement('PatientCharacteristics');
629 if ($patient['date_of_birth'] && $patient['date_of_birth'] != '00000000') {
630 $element->appendChild($this->createElementText('dob', $patient['date_of_birth']));
633 if ($patient['sex']) {
634 $element->appendChild($this->createElementText('gender', substr($patient['sex'], 0, 1)));
640 public function getPatientFreeformHealthplans($patientId)
642 $healthplans = $this->getStore()
643 ->getPatientHealthplansByPatientId($patientId);
647 while ($healthplan = sqlFetchArray($healthplans)) {
648 $element = $this->getDocument()->createElement('PatientFreeformHealthplans');
649 $element->appendChild($this->createElementText('healthplanName', $this->trimData($this->stripSpecialCharacter($healthplan['name']), 35)));
651 $elements[] = $element;
657 public function getPatientFreeformAllergy($patientId)
659 $allergyData = $this->getStore()
660 ->getPatientAllergiesByPatientId($patientId);
664 while ($allergy = sqlFetchArray($allergyData)) {
665 $element = $this->getDocument()->createElement('PatientFreeformAllergy');
666 $element->setAttribute('ID', $allergy['id']);
668 if ($allergy['title1']) {
669 $element->appendChild($this->createElementText('allergyName', $this->trimData($this->stripSpecialCharacter($allergy['title1']), 70)));
672 if ($allergy['title2']=='Mild' ||
$allergy['title2']=='Moderate' ||
$allergy['title2']=='Severe') {
673 $element->appendChild($this->createElementText('allergySeverityTypeID', $allergy['title2']));
676 if ($allergy['comments']) {
677 $element->appendChild($this->createElementText('allergyComment', $this->trimData($this->stripSpecialCharacter($allergy['comments']), 200)));
680 $elements[] = $element;
682 $this->addSentAllergyIds($allergy['id']);
688 public function getPatient($patientId)
690 $patientData = $this->getStore()
691 ->getPatientByPatientId($patientId);
693 $element = $this->getDocument()->createElement('Patient');
694 $element->setAttribute('ID', $patientData['pid']);
695 $element->appendChild($this->getPatientName($patientData));
696 $element->appendChild($this->getPatientAddress($patientData));
697 $element->appendChild($this->getPatientContact($patientData));
698 $element->appendChild($this->getPatientCharacteristics($patientData));
699 $this->appendChildren($element, $this->getPatientFreeformHealthplans($patientId));
700 $this->appendChildren($element, $this->getPatientFreeformAllergy($patientId));
705 public function getOutsidePrescription($prescription)
707 $element = $this->getDocument()->createElement('OutsidePrescription');
708 $element->appendChild($this->createElementText('externalId', $prescription['externalId']));
709 $element->appendChild($this->createElementText('date', $prescription['date']));
710 $element->appendChild($this->createElementText('doctorName', $prescription['doctorName']));
711 $element->appendChild($this->createElementText('drug', $prescription['drug']));
712 $element->appendChild($this->createElementText('dispenseNumber', $prescription['dispenseNumber']));
713 $element->appendChild($this->createElementText('sig', $prescription['sig']));
714 $element->appendChild($this->createElementText('refillCount', $prescription['refillCount']));
715 $element->appendChild($this->createElementText('prescriptionType', $prescription['prescriptionType']));
720 public function getPatientPrescriptions($prescriptionIds)
724 foreach ($prescriptionIds as $prescriptionId) {
725 if ($prescriptionId) {
726 $prescription = $this->getStore()
727 ->getPrescriptionById($prescriptionId);
729 $element = $this->getOutsidePrescription(array(
730 'externalId' => $prescription['prescid'],
731 'date' => $prescription['date_added'],
732 'doctorName' => $prescription['docname'],
733 'drug' => $this->trimData($this->stripSpecialCharacter($prescription['drug']), 80),
734 'dispenseNumber' => intval($prescription['quantity']),
735 'sig' => $this->trimData($this->stripSpecialCharacter($prescription['quantity'][1].$prescription['size'].' '.$prescription['title4'].' '.$prescription['dosage'].' In '.$prescription['title1'].' '.$prescription['title2'].' '.$prescription['title3'], 140)),
736 'refillCount' => intval($prescription['per_refill']),
737 'prescriptionType' => 'reconcile'
740 $this->addSentPrescriptionId($prescriptionId);
742 $elements[] = $element;
749 public function getPatientMedication($patientId, $uploadActive, $count)
751 $medications = $this->getStore()
752 ->selectMedicationsNotUploadedByPatientId($patientId, $uploadActive, $count);
756 while ($medication = sqlFetchArray($medications)) {
757 $elements[] = $this->getOutsidePrescription(array(
758 'externalId' => $medication['id'],
759 'date' => $medication['begdate'],
761 'drug' => $this->trimData($medication['title'], 80),
762 'dispenseNumber' => '',
765 'prescriptionType' => 'reconcile'
768 $this->addSentMedicationIds($medication['id']);
774 public function getPatientElements($patientId, $totalCount, $requestedPrescriptionIds)
779 $uploadActive = $this->getGlobals()->getUploadActive();
781 $elements[] = $this->getPatient($patientId);
783 $selectPrescriptionIds = $this->getStore()
784 ->selectPrescriptionIdsNotUploadedByPatientId(
790 $selectPrescriptionIdsCount = sqlNumRows($selectPrescriptionIds);
792 $prescriptionIds = array();
794 while ($selectPrescriptionId = sqlFetchArray($selectPrescriptionIds)) {
795 $prescriptionIds[] = $selectPrescriptionId['id'];
798 if (count($requestedPrescriptionIds) > 0) {
799 $elements = array_merge($elements, $this->getPatientPrescriptions($requestedPrescriptionIds));
800 } elseif (count($prescriptionIds) > 0) {
801 $elements = array_merge($elements, $this->getPatientPrescriptions($prescriptionIds));
803 $this->getPatientPrescriptions(array(0));
806 if ($selectPrescriptionIdsCount < $totalCount) {
807 $elements = array_merge($elements, $this->getPatientMedication($patientId, $uploadActive, $totalCount - $selectPrescriptionIdsCount));