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));
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']));
539 public function getStaffElements($authUserId, $destination)
541 $userRole = $this->getStore()->getUserById($authUserId);
542 $userRole = preg_replace('/erx/', '', $userRole['newcrop_user_role']);
546 if ($userRole != 'manager') {
547 $elements[] = $this->getLocation($authUserId);
550 if ($userRole == 'doctor' ||
$destination == 'renewal') {
551 $elements[] = $this->getLicensedPrescriber($authUserId);
554 if ($userRole == 'manager' ||
$userRole == 'admin' ||
$userRole == 'nurse') {
555 $elements[] = $this->getStaff($authUserId);
556 } elseif ($userRole == 'supervisingDoctor') {
557 $elements[] = $this->getSupervisingDoctor($authUserId);
558 } elseif ($userRole == 'midlevelPrescriber') {
559 $elements[] = $this->getMidlevelPrescriber($authUserId);
565 public function getPatientName($patient)
567 $element = $this->getDocument()->createElement('PatientName');
568 $element->appendChild($this->createElementTextDemographicsCheck('last', $this->trimData($this->stripSpecialCharacter($patient['lname']), 35), xl('Patient Last Name')));
569 $element->appendChild($this->createElementTextDemographicsCheck('first', $this->trimData($this->stripSpecialCharacter($patient['fname']), 35), xl('Patient First Name')));
570 $element->appendChild($this->createElementText('middle', $this->trimData($this->stripSpecialCharacter($patient['mname']), 35)));
575 public function getPatientAddress($patient)
577 $patient['street'] = $this->trimData($this->stripSpecialCharacter($patient['street']), 35);
578 $this->warningMessage($patient['street'], xl('Patient Street Address'));
581 if (trim($patient['country_code']) == '') {
582 $eRxDefaultPatientCountry = $this->getGlobals()->getDefaultPatientCountry();
584 if ($eRxDefaultPatientCountry == '') {
585 $this->demographicsCheck('', xl('Global Default Patient Country'));
587 $patient['country_code'] = $eRxDefaultPatientCountry;
590 $this->demographicsCheck('', xl('Patient Country'));
593 $element = $this->getDocument()->createElement('PatientAddress');
594 $element->appendChild($this->createElementTextFieldEmpty('address1', $patient['street'], xl('Patient Street Address')));
595 $element->appendChild($this->createElementTextDemographicsCheck('city', $patient['city'], xl('Patient City')));
596 if ($patient['state']) {
597 $element->appendChild($this->createElementText('state', $patient['state']));
600 if ($patient['postal_code']) {
601 $element->appendChild($this->createElementText('zip', $patient['postal_code']));
604 $element->appendChild($this->createElementText('country', substr($patient['country_code'], 0, 2)));
609 public function getPatientContact($patient)
611 $element = $this->getDocument()->createElement('PatientContact');
612 if ($patient['phone_home']) {
613 $element->appendChild($this->createElementText('homeTelephone', preg_replace('/-/', '', $patient['phone_home'])));
619 public function getPatientCharacteristics($patient)
621 if (trim($patient['date_of_birth']) == '' ||
$patient['date_of_birth'] == '00000000') {
622 $this->warningMessage('', xl('Patient Date Of Birth'));
625 $this->warningMessage(trim($patient['sex']), xl('Patient Gender'));
627 $element = $this->getDocument()->createElement('PatientCharacteristics');
628 if ($patient['date_of_birth'] && $patient['date_of_birth'] != '00000000') {
629 $element->appendChild($this->createElementText('dob', $patient['date_of_birth']));
632 if ($patient['sex']) {
633 $element->appendChild($this->createElementText('gender', substr($patient['sex'], 0, 1)));
639 public function getPatientFreeformHealthplans($patientId)
641 $healthplans = $this->getStore()
642 ->getPatientHealthplansByPatientId($patientId);
646 while ($healthplan = sqlFetchArray($healthplans)) {
647 $element = $this->getDocument()->createElement('PatientFreeformHealthplans');
648 $element->appendChild($this->createElementText('healthplanName', $this->trimData($this->stripSpecialCharacter($healthplan['name']), 35)));
650 $elements[] = $element;
656 public function getPatientFreeformAllergy($patientId)
658 $allergyData = $this->getStore()
659 ->getPatientAllergiesByPatientId($patientId);
663 while ($allergy = sqlFetchArray($allergyData)) {
664 $element = $this->getDocument()->createElement('PatientFreeformAllergy');
665 $element->setAttribute('ID', $allergy['id']);
667 if ($allergy['title1']) {
668 $element->appendChild($this->createElementText('allergyName', $this->trimData($this->stripSpecialCharacter($allergy['title1']), 70)));
671 if ($allergy['title2']=='Mild' ||
$allergy['title2']=='Moderate' ||
$allergy['title2']=='Severe') {
672 $element->appendChild($this->createElementText('allergySeverityTypeID', $allergy['title2']));
675 if ($allergy['comments']) {
676 $element->appendChild($this->createElementText('allergyComment', $this->trimData($this->stripSpecialCharacter($allergy['comments']), 200)));
679 $elements[] = $element;
681 $this->addSentAllergyIds($allergy['id']);
687 public function getPatient($patientId)
689 $patientData = $this->getStore()
690 ->getPatientByPatientId($patientId);
692 $element = $this->getDocument()->createElement('Patient');
693 $element->setAttribute('ID', $patientData['pid']);
694 $element->appendChild($this->getPatientName($patientData));
695 $element->appendChild($this->getPatientAddress($patientData));
696 $element->appendChild($this->getPatientContact($patientData));
697 $element->appendChild($this->getPatientCharacteristics($patientData));
698 $this->appendChildren($element, $this->getPatientFreeformHealthplans($patientId));
699 $this->appendChildren($element, $this->getPatientFreeformAllergy($patientId));
704 public function getOutsidePrescription($prescription)
706 $element = $this->getDocument()->createElement('OutsidePrescription');
707 $element->appendChild($this->createElementText('externalId', $prescription['externalId']));
708 $element->appendChild($this->createElementText('date', $prescription['date']));
709 $element->appendChild($this->createElementText('doctorName', $prescription['doctorName']));
710 $element->appendChild($this->createElementText('drug', $prescription['drug']));
711 $element->appendChild($this->createElementText('dispenseNumber', $prescription['dispenseNumber']));
712 $element->appendChild($this->createElementText('sig', $prescription['sig']));
713 $element->appendChild($this->createElementText('refillCount', $prescription['refillCount']));
714 $element->appendChild($this->createElementText('prescriptionType', $prescription['prescriptionType']));
719 public function getPatientPrescriptions($prescriptionIds)
723 foreach ($prescriptionIds as $prescriptionId) {
724 if ($prescriptionId) {
725 $prescription = $this->getStore()
726 ->getPrescriptionById($prescriptionId);
728 $element = $this->getOutsidePrescription(array(
729 'externalId' => $prescription['prescid'],
730 'date' => $prescription['date_added'],
731 'doctorName' => $prescription['docname'],
732 'drug' => $this->trimData($this->stripSpecialCharacter($prescription['drug']), 80),
733 'dispenseNumber' => intval($prescription['quantity']),
734 'sig' => $this->trimData($this->stripSpecialCharacter($prescription['quantity'][1].$prescription['size'].' '.$prescription['title4'].' '.$prescription['dosage'].' In '.$prescription['title1'].' '.$prescription['title2'].' '.$prescription['title3'], 140)),
735 'refillCount' => intval($prescription['per_refill']),
736 'prescriptionType' => 'reconcile'
739 $this->addSentPrescriptionId($prescriptionId);
741 $elements[] = $element;
748 public function getPatientMedication($patientId, $uploadActive, $count)
750 $medications = $this->getStore()
751 ->selectMedicationsNotUploadedByPatientId($patientId, $uploadActive, $count);
755 while ($medication = sqlFetchArray($medications)) {
756 $elements[] = $this->getOutsidePrescription(array(
757 'externalId' => $medication['id'],
758 'date' => $medication['begdate'],
760 'drug' => $this->trimData($medication['title'], 80),
761 'dispenseNumber' => '',
764 'prescriptionType' => 'reconcile'
767 $this->addSentMedicationIds($medication['id']);
773 public function getPatientElements($patientId, $totalCount, $requestedPrescriptionIds)
778 $uploadActive = $this->getGlobals()->getUploadActive();
780 $elements[] = $this->getPatient($patientId);
782 $selectPrescriptionIds = $this->getStore()
783 ->selectPrescriptionIdsNotUploadedByPatientId(
789 $selectPrescriptionIdsCount = sqlNumRows($selectPrescriptionIds);
791 $prescriptionIds = array();
793 while ($selectPrescriptionId = sqlFetchArray($selectPrescriptionIds)) {
794 $prescriptionIds[] = $selectPrescriptionId['id'];
797 if (count($requestedPrescriptionIds) > 0) {
798 $elements = array_merge($elements, $this->getPatientPrescriptions($requestedPrescriptionIds));
799 } elseif (count($prescriptionIds) > 0) {
800 $elements = array_merge($elements, $this->getPatientPrescriptions($prescriptionIds));
802 $this->getPatientPrescriptions(array(0));
805 if ($selectPrescriptionIdsCount < $totalCount) {
806 $elements = array_merge($elements, $this->getPatientMedication($patientId, $uploadActive, $totalCount - $selectPrescriptionIdsCount));