4 * interface/eRxXMLBuilder.php Functions for building NewCrop XML.
6 * Copyright (C) 2015 Sam Likins <sam.likins@wsi-services.com>
8 * LICENSE: This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 3 of the License, or (at your option) any
11 * later version. This program is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 * Public License for more details. You should have received a copy of the GNU
15 * General Public License along with this program.
16 * If not, see <http://opensource.org/licenses/gpl-license.php>.
20 * @author Sam Likins <sam.likins@wsi-services.com>
21 * @link http://www.open-emr.org
33 private $sentAllergyIds = array();
34 private $sentMedicationIds = array();
35 private $sentPrescriptionIds = array();
37 private $fieldEmptyMessages = array();
38 private $demographicsCheckMessages = array();
39 private $warningMessages = array();
41 public function __construct($globals = null, $store = null)
44 $this->setGlobals($globals);
48 $this->setStore($store);
53 * Set Globals for retrieving eRx global configurations
54 * @param object $globals The eRx Globals object to use for processing
55 * @return eRxPage This object is returned for method chaining
57 public function setGlobals($globals)
59 $this->globals
= $globals;
65 * Get Globals for retrieving eRx global configurations
66 * @return object The eRx Globals object to use for processing
68 public function getGlobals()
70 return $this->globals
;
74 * Set Store to handle eRx cashed data
75 * @param object $store The eRx Store object to use for processing
76 * @return eRxPage This object is returned for method chaining
78 public function setStore($store)
80 $this->store
= $store;
86 * Get Store for handling eRx cashed data
87 * @return object The eRx Store object to use for processing
89 public function getStore()
94 protected function trimData($string, $length)
96 return substr($string, 0, $length - 1);
99 protected function stripSpecialCharacter($string)
101 return preg_replace('/[^a-zA-Z0-9 \'().,#:\/\-@_%]/', '', $string);
104 public function checkError($xml)
106 $curlHandler = curl_init($xml);
107 $sitePath = $this->getGlobals()->getOpenEMRSiteDirectory();
108 $data = array('RxInput' => $xml);
110 curl_setopt($curlHandler, CURLOPT_URL
, $this->getGlobals()->getPath());
111 curl_setopt($curlHandler, CURLOPT_POST
, 1);
112 curl_setopt($curlHandler, CURLOPT_POSTFIELDS
, 'RxInput='.$xml);
113 curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER
, 0);
114 curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION
, 1);
115 curl_setopt($curlHandler, CURLOPT_COOKIESESSION
, true);
116 curl_setopt($curlHandler, CURLOPT_COOKIEFILE
, $sitePath.'/newcrop-cookiefile');
117 curl_setopt($curlHandler, CURLOPT_COOKIEJAR
, $sitePath.'/newcrop-cookiefile');
118 curl_setopt($curlHandler, CURLOPT_COOKIE
, session_name().'='.session_id());
119 curl_setopt($curlHandler, CURLOPT_USERAGENT
, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
120 curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER
, true);
122 $result = curl_exec($curlHandler) or die(curl_error($curlHandler));
124 curl_close($curlHandler);
129 public function addSentAllergyIds($allergyIds)
131 if (is_array($allergyIds)) {
132 foreach ($allergyIds as $allergyId) {
133 $this->sentAllergyIds
[] = $allergyId;
136 $this->sentAllergyIds
[] = $allergyIds;
140 public function getSentAllergyIds()
142 return $this->sentAllergyIds
;
145 public function addSentMedicationIds($medicationIds)
147 if (is_array($medicationIds)) {
148 foreach ($medicationIds as $medicationId) {
149 $this->sentMedicationIds
[] = $medicationId;
152 $this->sentMedicationIds
[] = $medicationIds;
156 public function getSentMedicationIds()
158 return $this->sentMedicationIds
;
161 public function addSentPrescriptionId($prescriptionIds)
163 if (is_array($prescriptionIds)) {
164 foreach ($prescriptionIds as $prescriptionId) {
165 $this->sentPrescriptionIds
[] = $prescriptionId;
168 $this->sentPrescriptionIds
[] = $prescriptionIds;
172 public function getSentPrescriptionIds()
174 return $this->sentPrescriptionIds
;
177 public function fieldEmpty($value, $message)
180 $this->fieldEmptyMessages
[] = $message;
184 public function getFieldEmptyMessages()
186 return $this->fieldEmptyMessages
;
189 public function demographicsCheck($value, $message)
192 $this->demographicsCheckMessages
[] = $message;
196 public function getDemographicsCheckMessages()
198 return $this->demographicsCheckMessages
;
201 public function warningMessage($value, $message)
204 $this->warningMessages
[] = $message;
208 public function getWarningMessages()
210 return $this->warningMessages
;
213 public function createElementText($name, $value)
215 $element = $this->getDocument()->createElement($name);
216 $element->appendChild($this->getDocument()->createTextNode($value));
221 public function createElementTextFieldEmpty($name, $value, $validationText)
223 $this->fieldEmpty($value, $validationText);
225 return $this->createElementText($name, $value);
228 public function createElementTextDemographicsCheck($name, $value, $validationText)
230 $this->demographicsCheck($value, $validationText);
232 return $this->createElementText($name, $value);
235 public function appendChildren($element, &$children)
237 if (is_a($element, 'DOMNode') && is_array($children) && count($children)) {
238 foreach ($children as $child) {
239 // if(is_array($child)) {
240 // $this->appendChildren($element, $child);
242 $element->appendChild($child);
247 public function getDocument()
249 if ($this->document
=== null) {
250 $this->document
= new DOMDocument();
251 $this->document
->formatOutput
= true;
254 return $this->document
;
257 public function getNCScript()
259 if ($this->ncScript
=== null) {
260 $document = $this->getDocument();
262 $this->ncScript
= $document->createElement('NCScript');
263 $this->ncScript
->setAttribute('xmlns', 'http://secure.newcropaccounts.com/interfaceV7');
264 $this->ncScript
->setAttribute('xmlns:NCStandard', 'http://secure.newcropaccounts.com/interfaceV7:NCStandard');
265 $this->ncScript
->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
267 $document->appendChild($this->ncScript
);
270 return $this->ncScript
;
273 public function getCredentials()
275 $eRxCredentials = $this->getGlobals()
278 $elemenet = $this->getDocument()->createElement('Credentials');
279 $elemenet->appendChild($this->createElementTextFieldEmpty('partnerName', $eRxCredentials['0'], xl('NewCrop eRx Partner Name')));
280 $elemenet->appendChild($this->createElementTextFieldEmpty('name', $eRxCredentials['1'], xl('NewCrop eRx Account Name')));
281 $elemenet->appendChild($this->createElementTextFieldEmpty('password', $eRxCredentials['2'], xl('NewCrop eRx Password')));
282 $elemenet->appendChild($this->createElementText('productName', 'OpenEMR'));
283 $elemenet->appendChild($this->createElementText('productVersion', $this->getGlobals()->getOpenEMRVersion()));
288 public function getUserRole($authUserId)
290 $eRxUserRole = $this->getStore()
291 ->getUserById($authUserId);
293 $eRxUserRole = $eRxUserRole['newcrop_user_role'];
295 $this->fieldEmpty($eRxUserRole, xl('NewCrop eRx User Role'));
297 echo xlt('Unauthorized access to ePrescription');
301 $eRxUserRole = preg_replace('/erx/', '', $eRxUserRole);
303 switch ($eRxUserRole) {
307 $newCropUser = 'Staff';
310 $newCropUser = 'LicensedPrescriber';
312 case 'supervisingDoctor':
313 $newCropUser = 'SupervisingDoctor';
315 case 'midlevelPrescriber':
316 $newCropUser = 'MidlevelPrescriber';
322 $element = $this->getDocument()->createElement('UserRole');
323 $element->appendChild($this->createElementTextFieldEmpty('user', $newCropUser, xl('NewCrop eRx User Role * invalid selection *')));
324 $element->appendChild($this->createElementText('role', $eRxUserRole));
329 public function getDestination($authUserId, $page = null)
331 $eRxUserRole = $this->getStore()
332 ->getUserById($authUserId);
334 $eRxUserRole = $eRxUserRole['newcrop_user_role'];
336 $eRxUserRole = preg_replace('/erx/', '', $eRxUserRole);
339 if ($eRxUserRole == 'admin') {
341 } elseif ($eRxUserRole == 'manager') {
348 $element = $this->getDocument()->createElement('Destination');
349 $element->appendChild($this->createElementText('requestedPage', $page));
354 public function getAccountAddress($facility)
356 $postalCode = preg_replace('/[^0-9]/', '', $facility['postal_code']);
357 $postalCodePostfix = substr($postalCode, 5, 4);
358 $postalCode = substr($postalCode, 0, 5);
360 if (strlen($postalCode) < 5) {
361 $this->fieldEmpty('', xl('Primary Facility Zip Code'));
364 $element = $this->getDocument()->createElement('AccountAddress');
365 $element->appendChild($this->createElementTextFieldEmpty('address1', $this->trimData($this->stripSpecialCharacter($facility['street']), 35), xl('Primary Facility Street Address')));
366 $element->appendChild($this->createElementTextFieldEmpty('city', $facility['city'], xl('Primary Facility City')));
367 $element->appendChild($this->createElementTextFieldEmpty('state', $facility['state'], xl('Primary Facility State')));
368 $element->appendChild($this->createElementText('zip', $postalCode));
369 if (strlen($postalCodePostfix) == 4) {
370 $element->appendChild($this->createElementText('zip4', $postalCodePostfix));
373 $element->appendChild($this->createElementTextFieldEmpty('country', substr($facility['country_code'], 0, 2), xl('Primary Facility Country code')));
378 public function getAccount()
380 $facility = $this->getStore()
381 ->getFacilityPrimary();
383 if (!$facility['federal_ein']) {
384 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.');
388 $element = $this->getDocument()->createElement('Account');
389 $element->setAttribute('ID', $this->getGlobals()->getAccountId());
390 $element->appendChild($this->createElementTextFieldEmpty('accountName', $this->trimData($this->stripSpecialCharacter($facility['name']), 35), xl('Facility Name')));
391 $element->appendChild($this->createElementText('siteID', $facility['federal_ein'], 'Site ID'));
392 $element->appendChild($this->getAccountAddress($facility));
393 $element->appendChild($this->createElementTextFieldEmpty('accountPrimaryPhoneNumber', preg_replace('/[^0-9]/', '', $facility['phone']), xl('Facility Phone')));
394 $element->appendChild($this->createElementTextFieldEmpty('accountPrimaryFaxNumber', preg_replace('/[^0-9]/', '', $facility['fax']), xl('Facility Fax')));
399 public function getLocationAddress($facility)
401 $postalCode = preg_replace('/[^0-9]/', '', $facility['postal_code']);
402 $postalCodePostfix = substr($postalCode, 5, 4);
403 $postalCode = substr($postalCode, 0, 5);
405 if (strlen($postalCode) < 5) {
406 $this->fieldEmpty('', xl('Facility Zip Code'));
409 $element = $this->getDocument()->createElement('LocationAddress');
410 if ($facility['street']) {
411 $element->appendChild($this->createElementText('address1', $this->trimData($this->stripSpecialCharacter($facility['street']), 35)));
414 if ($facility['city']) {
415 $element->appendChild($this->createElementText('city', $facility['city']));
418 if ($facility['state']) {
419 $element->appendChild($this->createElementText('state', $facility['state']));
422 $element->appendChild($this->createElementText('zip', $postalCode));
423 if (strlen($postalCodePostfix) == 4) {
424 $element->appendChild($this->createElementText('zip4', $postalCodePostfix));
427 if ($facility['country_code']) {
428 $element->appendChild($this->createElementText('country', substr($facility['country_code'], 0, 2)));
434 public function getLocation($authUserId)
436 $userFacility = $this->getStore()
437 ->getUserFacility($authUserId);
439 $element = $this->getDocument()->createElement('Location');
440 $element->setAttribute('ID', $userFacility['id']);
441 $element->appendChild($this->createElementText('locationName', $this->trimData($this->stripSpecialCharacter($userFacility['name']), 35)));
442 $element->appendChild($this->getLocationAddress($userFacility));
443 if ($userFacility['phone']) {
444 $element->appendChild($this->createElementText('primaryPhoneNumber', preg_replace('/[^0-9]/', '', $userFacility['phone'])));
447 if ($userFacility['fax']) {
448 $element->appendChild($this->createElementText('primaryFaxNumber', preg_replace('/[^0-9]/', '', $userFacility['fax'])));
451 if ($userFacility['phone']) {
452 $element->appendChild($this->createElementText('pharmacyContactNumber', preg_replace('/[^0-9]/', '', $userFacility['phone'])));
458 public function getLicensedPrescriber($authUserId)
460 $userDetails = $this->getStore()
461 ->getUserById($authUserId);
463 $element = $this->getDocument()->createElement('LicensedPrescriber');
464 $element->setAttribute('ID', $userDetails['npi']);
465 $element->appendChild($this->getLicensedPrescriberName($userDetails));
466 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], 'Licensed Prescriber DEA'));
467 if ($userDetails['upin']) {
468 $element->appendChild($this->createElementText('upin', $userDetails['upin']));
471 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
472 $element->appendChild($this->createElementTextFieldEmpty('npi', $userDetails['npi'], xl('Licensed Prescriber NPI')));
477 public function getStaffName($user)
479 $element = $this->getDocument()->createElement('StaffName');
480 $element->appendChild($this->createElementText('last', $this->stripSpecialCharacter($user['lname'])));
481 $element->appendChild($this->createElementText('first', $this->stripSpecialCharacter($user['fname'])));
482 $element->appendChild($this->createElementText('middle', $this->stripSpecialCharacter($user['mname'])));
487 public function getStaff($authUserId)
489 $userDetails = $this->getStore()
490 ->getUserById($authUserId);
492 $element = $this->getDocument()->createElement('Staff');
493 $element->setAttribute('ID', $userDetails['username']);
494 $element->appendChild($this->getStaffName($userDetails));
495 $element->appendChild($this->createElementText('license', $userDetails['state_license_number']));
500 public function getLicensedPrescriberName($user, $prescriberType, $prefix = false)
502 $element = $this->getDocument()->createElement('LicensedPrescriberName');
503 $element->appendChild($this->createElementTextFieldEmpty('last', $this->stripSpecialCharacter($user['lname']), $prescriberType.' '.xl('Licensed Prescriber Last Name')));
504 $element->appendChild($this->createElementTextFieldEmpty('first', $this->stripSpecialCharacter($user['fname']), $prescriberType.' '.xl('Licensed Prescriber First Name')));
505 $element->appendChild($this->createElementText('middle', $this->stripSpecialCharacter($user['mname'])));
506 if ($prefix && $user['title']) {
507 $element->appendChild($this->createElementTextFieldEmpty('prefix', $user['title'], $prescriberType.' '.xl('Licensed Prescriber Title (Prefix)')));
513 public function getSupervisingDoctor($authUserId)
515 $userDetails = $this->getStore()
516 ->getUserById($authUserId);
518 $element = $this->getDocument()->createElement('SupervisingDoctor');
519 $element->setAttribute('ID', $userDetails['npi']);
520 $element->appendChild($this->getLicensedPrescriberName($userDetails, xl('Supervising Doctor')));
521 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], xl('Supervising Doctor DEA')));
522 if ($userDetails['upin']) {
523 $element->appendChild($this->createElementText('upin', $userDetails['upin']));
526 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
527 $element->appendChild($this->createElementTextFieldEmpty('npi', $userDetails['npi'], xl('Supervising Doctor NPI')));
532 public function getMidlevelPrescriber($authUserId)
534 $userDetails = $this->getStore()
535 ->getUserById($authUserId);
537 $element = $this->getDocument()->createElement('MidlevelPrescriber');
538 $element->setAttribute('ID', $userDetails['npi']);
539 $element->appendChild($this->getLicensedPrescriberName($userDetails, xl('Midlevel Prescriber'), true));
540 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], xl('Midlevel Prescriber DEA')));
541 if ($userDetails['upin']) {
542 $element->appendChild($this->createElementText('upin', $userDetails['upin']));
545 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
550 public function getStaffElements($authUserId, $destination)
552 $userRole = $this->getStore()->getUserById($authUserId);
553 $userRole = preg_replace('/erx/', '', $userRole['newcrop_user_role']);
557 if ($userRole != 'manager') {
558 $elements[] = $this->getLocation($authUserId);
561 if ($userRole == 'doctor' ||
$destination == 'renewal') {
562 $elements[] = $this->getLicensedPrescriber($authUserId);
565 if ($userRole == 'manager' ||
$userRole == 'admin' ||
$userRole == 'nurse') {
566 $elements[] = $this->getStaff($authUserId);
567 } elseif ($userRole == 'supervisingDoctor') {
568 $elements[] = $this->getSupervisingDoctor($authUserId);
569 } elseif ($userRole == 'midlevelPrescriber') {
570 $elements[] = $this->getMidlevelPrescriber($authUserId);
576 public function getPatientName($patient)
578 $element = $this->getDocument()->createElement('PatientName');
579 $element->appendChild($this->createElementTextDemographicsCheck('last', $this->trimData($this->stripSpecialCharacter($patient['lname']), 35), xl('Patient Last Name')));
580 $element->appendChild($this->createElementTextDemographicsCheck('first', $this->trimData($this->stripSpecialCharacter($patient['fname']), 35), xl('Patient First Name')));
581 $element->appendChild($this->createElementText('middle', $this->trimData($this->stripSpecialCharacter($patient['mname']), 35)));
586 public function getPatientAddress($patient)
588 $patient['street'] = $this->trimData($this->stripSpecialCharacter($patient['street']), 35);
589 $this->warningMessage($patient['street'], xl('Patient Street Address'));
592 if (trim($patient['country_code']) == '') {
593 $eRxDefaultPatientCountry = $this->getGlobals()->getDefaultPatientCountry();
595 if ($eRxDefaultPatientCountry == '') {
596 $this->demographicsCheck('', xl('Global Default Patient Country'));
598 $patient['country_code'] = $eRxDefaultPatientCountry;
601 $this->demographicsCheck('', xl('Patient Country'));
604 $element = $this->getDocument()->createElement('PatientAddress');
605 $element->appendChild($this->createElementTextFieldEmpty('address1', $patient['street'], xl('Patient Street Address')));
606 $element->appendChild($this->createElementTextDemographicsCheck('city', $patient['city'], xl('Patient City')));
607 if ($patient['state']) {
608 $element->appendChild($this->createElementText('state', $patient['state']));
611 if ($patient['postal_code']) {
612 $element->appendChild($this->createElementText('zip', $patient['postal_code']));
615 $element->appendChild($this->createElementText('country', substr($patient['country_code'], 0, 2)));
620 public function getPatientContact($patient)
622 $element = $this->getDocument()->createElement('PatientContact');
623 if ($patient['phone_home']) {
624 $element->appendChild($this->createElementText('homeTelephone', preg_replace('/-/', '', $patient['phone_home'])));
630 public function getPatientCharacteristics($patient)
632 if (trim($patient['date_of_birth']) == '' ||
$patient['date_of_birth'] == '00000000') {
633 $this->warningMessage('', xl('Patient Date Of Birth'));
636 $this->warningMessage(trim($patient['sex']), xl('Patient Gender'));
638 $element = $this->getDocument()->createElement('PatientCharacteristics');
639 if ($patient['date_of_birth'] && $patient['date_of_birth'] != '00000000') {
640 $element->appendChild($this->createElementText('dob', $patient['date_of_birth']));
643 if ($patient['sex']) {
644 $element->appendChild($this->createElementText('gender', substr($patient['sex'], 0, 1)));
650 public function getPatientFreeformHealthplans($patientId)
652 $healthplans = $this->getStore()
653 ->getPatientHealthplansByPatientId($patientId);
657 while ($healthplan = sqlFetchArray($healthplans)) {
658 $element = $this->getDocument()->createElement('PatientFreeformHealthplans');
659 $element->appendChild($this->createElementText('healthplanName', $this->trimData($this->stripSpecialCharacter($healthplan['name'], 35))));
661 $elements[] = $element;
667 public function getPatientFreeformAllergy($patientId)
669 $allergyData = $this->getStore()
670 ->getPatientAllergiesByPatientId($patientId);
674 while ($allergy = sqlFetchArray($allergyData)) {
675 $element = $this->getDocument()->createElement('PatientFreeformAllergy');
676 $element->setAttribute('ID', $allergy['id']);
678 if ($allergy['title1']) {
679 $element->appendChild($this->createElementText('allergyName', $this->trimData($this->stripSpecialCharacter($allergy['title1']), 70)));
682 if ($allergy['title2']=='Mild' ||
$allergy['title2']=='Moderate' ||
$allergy['title2']=='Severe') {
683 $element->appendChild($this->createElementText('allergySeverityTypeID', $allergy['title2']));
686 if ($allergy['comments']) {
687 $element->appendChild($this->createElementText('allergyComment', $this->trimData($this->stripSpecialCharacter($allergy['comments']), 200)));
690 $elements[] = $element;
692 $this->addSentAllergyIds($allergy['id']);
698 public function getPatient($patientId)
700 $patientData = $this->getStore()
701 ->getPatientByPatientId($patientId);
703 $element = $this->getDocument()->createElement('Patient');
704 $element->setAttribute('ID', $patientData['pid']);
705 $element->appendChild($this->getPatientName($patientData));
706 $element->appendChild($this->getPatientAddress($patientData));
707 $element->appendChild($this->getPatientContact($patientData));
708 $element->appendChild($this->getPatientCharacteristics($patientData));
709 $this->appendChildren($element, $this->getPatientFreeformHealthplans($patientId));
710 $this->appendChildren($element, $this->getPatientFreeformAllergy($patientId));
715 public function getOutsidePrescription($prescription)
717 $element = $this->getDocument()->createElement('OutsidePrescription');
718 $element->appendChild($this->createElementText('externalId', $prescription['externalId']));
719 $element->appendChild($this->createElementText('date', $prescription['date']));
720 $element->appendChild($this->createElementText('doctorName', $prescription['doctorName']));
721 $element->appendChild($this->createElementText('drug', $prescription['drug']));
722 $element->appendChild($this->createElementText('dispenseNumber', $prescription['dispenseNumber']));
723 $element->appendChild($this->createElementText('sig', $prescription['sig']));
724 $element->appendChild($this->createElementText('refillCount', $prescription['refillCount']));
725 $element->appendChild($this->createElementText('prescriptionType', $prescription['prescriptionType']));
730 public function getPatientPrescriptions($prescriptionIds)
734 foreach ($prescriptionIds as $prescriptionId) {
735 if ($prescriptionId) {
736 $prescription = $this->getStore()
737 ->getPrescriptionById($prescriptionId);
739 $element = $this->getOutsidePrescription(array(
740 'externalId' => $prescription['prescid'],
741 'date' => $prescription['date_added'],
742 'doctorName' => $prescription['docname'],
743 'drug' => $this->trimData($this->stripSpecialCharacter($prescription['drug']), 80),
744 'dispenseNumber' => intval($prescription['quantity']),
745 'sig' => $this->trimData($this->stripSpecialCharacter($prescription['quantity'][1].$prescription['size'].' '.$prescription['title4'].' '.$prescription['dosage'].' In '.$prescription['title1'].' '.$prescription['title2'].' '.$prescription['title3'], 140)),
746 'refillCount' => intval($prescription['per_refill']),
747 'prescriptionType' => 'reconcile'
750 $this->addSentPrescriptionId($prescriptionId);
752 $elements[] = $element;
759 public function getPatientMedication($patientId, $uploadActive, $count)
761 $medications = $this->getStore()
762 ->selectMedicationsNotUploadedByPatientId($patientId, $uploadActive, $count);
766 while ($medication = sqlFetchArray($medications)) {
767 $elements[] = $this->getOutsidePrescription(array(
768 'externalId' => $medication['id'],
769 'date' => $medication['begdate'],
771 'drug' => $this->trimData($medication['title'], 80),
772 'dispenseNumber' => '',
775 'prescriptionType' => 'reconcile'
778 $this->addSentMedicationIds($medication['id']);
784 public function getPatientElements($patientId, $totalCount, $requestedPrescriptionIds)
789 $uploadActive = $this->getGlobals()->getUploadActive();
791 $elements[] = $this->getPatient($patientId);
793 $selectPrescriptionIds = $this->getStore()
794 ->selectPrescriptionIdsNotUploadedByPatientId(
800 $selectPrescriptionIdsCount = sqlNumRows($selectPrescriptionIds);
802 $prescriptionIds = array();
804 while ($selectPrescriptionId = sqlFetchArray($selectPrescriptionIds)) {
805 $prescriptionIds[] = $selectPrescriptionId['id'];
808 if (count($requestedPrescriptionIds) > 0) {
809 $elements = array_merge($elements, $this->getPatientPrescriptions($requestedPrescriptionIds));
810 } elseif (count($prescriptionIds) > 0) {
811 $elements = array_merge($elements, $this->getPatientPrescriptions($prescriptionIds));
813 $this->getPatientPrescriptions(array(0));
816 if ($selectPrescriptionIdsCount < $totalCount) {
817 $elements = array_merge($elements, $this->getPatientMedication($patientId, $uploadActive, $totalCount - $selectPrescriptionIdsCount));