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
32 private $sentAllergyIds = array();
33 private $sentMedicationIds = array();
34 private $sentPrescriptionIds = array();
36 private $fieldEmptyMessages = array();
37 private $demographicsCheckMessages = array();
38 private $warningMessages = array();
40 public function __construct($globals = null, $store = null) {
42 $this->setGlobals($globals);
46 $this->setStore($store);
51 * Set Globals for retrieving eRx global configurations
52 * @param object $globals The eRx Globals object to use for processing
53 * @return eRxPage This object is returned for method chaining
55 public function setGlobals($globals) {
56 $this->globals
= $globals;
62 * Get Globals for retrieving eRx global configurations
63 * @return object The eRx Globals object to use for processing
65 public function getGlobals() {
66 return $this->globals
;
70 * Set Store to handle eRx cashed data
71 * @param object $store The eRx Store object to use for processing
72 * @return eRxPage This object is returned for method chaining
74 public function setStore($store) {
75 $this->store
= $store;
81 * Get Store for handling eRx cashed data
82 * @return object The eRx Store object to use for processing
84 public function getStore() {
88 protected function trimData($string, $length) {
89 return substr($string, 0, $length - 1);
92 protected function stripSpecialCharacter($string) {
93 return preg_replace('/[^a-zA-Z0-9 \'().,#:\/\-@_%]/', '', $string);
96 public function checkError($xml) {
97 $curlHandler = curl_init($xml);
98 $sitePath = $this->getGlobals()->getOpenEMRSiteDirectory();
99 $data = array('RxInput' => $xml);
101 curl_setopt($curlHandler, CURLOPT_URL
, $this->getGlobals()->getPath());
102 curl_setopt($curlHandler, CURLOPT_POST
, 1);
103 curl_setopt($curlHandler, CURLOPT_POSTFIELDS
, 'RxInput='.$xml);
104 curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER
, 0);
105 curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION
, 1);
106 curl_setopt($curlHandler, CURLOPT_COOKIESESSION
, TRUE);
107 curl_setopt($curlHandler, CURLOPT_COOKIEFILE
, $sitePath.'/newcrop-cookiefile');
108 curl_setopt($curlHandler, CURLOPT_COOKIEJAR
, $sitePath.'/newcrop-cookiefile');
109 curl_setopt($curlHandler, CURLOPT_COOKIE
, session_name().'='.session_id());
110 curl_setopt($curlHandler, CURLOPT_USERAGENT
, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
111 curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER
, true);
113 $result = curl_exec($curlHandler) OR die(curl_error($curlHandler));
115 curl_close($curlHandler);
120 public function addSentAllergyIds($allergyIds) {
121 if(is_array($allergyIds)) {
122 foreach($allergyIds as $allergyId) {
123 $this->sentAllergyIds
[] = $allergyId;
126 $this->sentAllergyIds
[] = $allergyIds;
130 public function getSentAllergyIds() {
131 return $this->sentAllergyIds
;
134 public function addSentMedicationIds($medicationIds) {
135 if(is_array($medicationIds)) {
136 foreach($medicationIds as $medicationId) {
137 $this->sentMedicationIds
[] = $medicationId;
140 $this->sentMedicationIds
[] = $medicationIds;
144 public function getSentMedicationIds() {
145 return $this->sentMedicationIds
;
148 public function addSentPrescriptionId($prescriptionIds) {
149 if(is_array($prescriptionIds)) {
150 foreach($prescriptionIds as $prescriptionId) {
151 $this->sentPrescriptionIds
[] = $prescriptionId;
154 $this->sentPrescriptionIds
[] = $prescriptionIds;
158 public function getSentPrescriptionIds() {
159 return $this->sentPrescriptionIds
;
162 public function fieldEmpty($value, $message) {
164 $this->fieldEmptyMessages
[] = $message;
168 public function getFieldEmptyMessages() {
169 return $this->fieldEmptyMessages
;
172 public function demographicsCheck($value, $message) {
174 $this->demographicsCheckMessages
[] = $message;
178 public function getDemographicsCheckMessages() {
179 return $this->demographicsCheckMessages
;
182 public function warningMessage($value, $message) {
184 $this->warningMessages
[] = $message;
188 public function getWarningMessages() {
189 return $this->warningMessages
;
192 public function createElementText($name, $value) {
193 $element = $this->getDocument()->createElement($name);
194 $element->appendChild($this->getDocument()->createTextNode($value));
199 public function createElementTextFieldEmpty($name, $value, $validationText) {
200 $this->fieldEmpty($value, $validationText);
202 return $this->createElementText($name, $value);
205 public function createElementTextDemographicsCheck($name, $value, $validationText) {
206 $this->demographicsCheck($value, $validationText);
208 return $this->createElementText($name, $value);
211 public function appendChildren($element, &$children) {
212 if(is_a($element, 'DOMNode') && is_array($children) && count($children)) {
213 foreach($children as $child) {
214 // if(is_array($child)) {
215 // $this->appendChildren($element, $child);
217 $element->appendChild($child);
222 public function getDocument() {
223 if($this->document
=== null) {
224 $this->document
= new DOMDocument();
225 $this->document
->formatOutput
= true;
228 return $this->document
;
231 public function getNCScript() {
232 if($this->ncScript
=== null) {
233 $document = $this->getDocument();
235 $this->ncScript
= $document->createElement('NCScript');
236 $this->ncScript
->setAttribute('xmlns', 'http://secure.newcropaccounts.com/interfaceV7');
237 $this->ncScript
->setAttribute('xmlns:NCStandard', 'http://secure.newcropaccounts.com/interfaceV7:NCStandard');
238 $this->ncScript
->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
240 $document->appendChild($this->ncScript
);
243 return $this->ncScript
;
246 public function getCredentials() {
247 $eRxCredentials = $this->getGlobals()
250 $elemenet = $this->getDocument()->createElement('Credentials');
251 $elemenet->appendChild($this->createElementTextFieldEmpty('partnerName', $eRxCredentials['0'], xl('NewCrop eRx Partner Name')));
252 $elemenet->appendChild($this->createElementTextFieldEmpty('name', $eRxCredentials['1'], xl('NewCrop eRx Account Name')));
253 $elemenet->appendChild($this->createElementTextFieldEmpty('password', $eRxCredentials['2'], xl('NewCrop eRx Password')));
254 $elemenet->appendChild($this->createElementText('productName', 'OpenEMR'));
255 $elemenet->appendChild($this->createElementText('productVersion', $this->getGlobals()->getOpenEMRVersion()));
260 public function getUserRole($authUserId) {
261 $eRxUserRole = $this->getStore()
262 ->getUserById($authUserId);
264 $eRxUserRole = $eRxUserRole['newcrop_user_role'];
266 $this->fieldEmpty($eRxUserRole, xl('NewCrop eRx User Role'));
268 echo xlt('Unauthorized access to ePrescription');
272 $eRxUserRole = preg_replace('/erx/', '', $eRxUserRole);
274 switch ($eRxUserRole) {
277 case 'nurse': $newCropUser = 'Staff'; break;
278 case 'doctor': $newCropUser = 'LicensedPrescriber'; break;
279 case 'supervisingDoctor': $newCropUser = 'SupervisingDoctor'; break;
280 case 'midlevelPrescriber': $newCropUser = 'MidlevelPrescriber'; break;
281 default: $newCropUser = '';
284 $element = $this->getDocument()->createElement('UserRole');
285 $element->appendChild($this->createElementTextFieldEmpty('user', $newCropUser, xl('NewCrop eRx User Role * invalid selection *')));
286 $element->appendChild($this->createElementText('role', $eRxUserRole));
291 public function getDestination($authUserId, $page = null) {
292 $eRxUserRole = $this->getStore()
293 ->getUserById($authUserId);
295 $eRxUserRole = $eRxUserRole['newcrop_user_role'];
297 $eRxUserRole = preg_replace('/erx/', '', $eRxUserRole);
300 if($eRxUserRole == 'admin') {
302 } elseif($eRxUserRole == 'manager') {
309 $element = $this->getDocument()->createElement('Destination');
310 $element->appendChild($this->createElementText('requestedPage', $page));
315 public function getAccountAddress($facility) {
316 $postalCode = preg_replace('/[^0-9]/', '', $facility['postal_code']);
317 $postalCodePostfix = substr($postalCode, 5, 4);
318 $postalCode = substr($postalCode, 0, 5);
320 if(strlen($postalCode) < 5) {
321 $this->fieldEmpty('', xl('Primary Facility Zip Code'));
324 $element = $this->getDocument()->createElement('AccountAddress');
325 $element->appendChild($this->createElementTextFieldEmpty('address1', $this->trimData($this->stripSpecialCharacter($facility['street']), 35), xl('Primary Facility Street Address')));
326 $element->appendChild($this->createElementTextFieldEmpty('city', $facility['city'], xl('Primary Facility City')));
327 $element->appendChild($this->createElementTextFieldEmpty('state', $facility['state'], xl('Primary Facility State')));
328 $element->appendChild($this->createElementText('zip', $postalCode));
329 if(strlen($postalCodePostfix) == 4) $element->appendChild($this->createElementText('zip4', $postalCodePostfix));
330 $element->appendChild($this->createElementTextFieldEmpty('country', substr($facility['country_code'], 0, 2), xl('Primary Facility Country code')));
335 public function getAccount() {
336 $facility = $this->getStore()
337 ->getFacilityPrimary();
339 if(!$facility['federal_ein']) {
340 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.');
344 $element = $this->getDocument()->createElement('Account');
345 $element->setAttribute('ID', $this->getGlobals()->getAccountId());
346 $element->appendChild($this->createElementTextFieldEmpty('accountName', $this->trimData($this->stripSpecialCharacter($facility['name']), 35), xl('Facility Name')));
347 $element->appendChild($this->createElementText('siteID', $facility['federal_ein'], 'Site ID'));
348 $element->appendChild($this->getAccountAddress($facility));
349 $element->appendChild($this->createElementTextFieldEmpty('accountPrimaryPhoneNumber', preg_replace('/[^0-9]/', '', $facility['phone']), xl('Facility Phone')));
350 $element->appendChild($this->createElementTextFieldEmpty('accountPrimaryFaxNumber', preg_replace('/[^0-9]/', '', $facility['fax']), xl('Facility Fax')));
355 public function getLocationAddress($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('Facility Zip Code'));
364 $element = $this->getDocument()->createElement('LocationAddress');
365 if($facility['street']) $element->appendChild($this->createElementText('address1', $this->trimData($this->stripSpecialCharacter($facility['street']), 35)));
366 if($facility['city']) $element->appendChild($this->createElementText('city', $facility['city']));
367 if($facility['state']) $element->appendChild($this->createElementText('state', $facility['state']));
368 $element->appendChild($this->createElementText('zip', $postalCode));
369 if(strlen($postalCodePostfix) == 4) $element->appendChild($this->createElementText('zip4', $postalCodePostfix));
370 if($facility['country_code']) $element->appendChild($this->createElementText('country', substr($facility['country_code'], 0, 2)));
375 public function getLocation($authUserId) {
376 $userFacility = $this->getStore()
377 ->getUserFacility($authUserId);
379 $element = $this->getDocument()->createElement('Location');
380 $element->setAttribute('ID', $userFacility['id']);
381 $element->appendChild($this->createElementText('locationName', $this->trimData($this->stripSpecialCharacter($userFacility['name']), 35)));
382 $element->appendChild($this->getLocationAddress($userFacility));
383 if($userFacility['phone']) $element->appendChild($this->createElementText('primaryPhoneNumber', preg_replace('/[^0-9]/', '', $userFacility['phone'])));
384 if($userFacility['fax']) $element->appendChild($this->createElementText('primaryFaxNumber', preg_replace('/[^0-9]/', '', $userFacility['fax'])));
385 if($userFacility['phone']) $element->appendChild($this->createElementText('pharmacyContactNumber', preg_replace('/[^0-9]/', '', $userFacility['phone'])));
390 public function getLicensedPrescriber($authUserId) {
391 $userDetails = $this->getStore()
392 ->getUserById($authUserId);
394 $element = $this->getDocument()->createElement('LicensedPrescriber');
395 $element->setAttribute('ID', $userDetails['npi']);
396 $element->appendChild($this->getLicensedPrescriberName($userDetails));
397 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], 'Licensed Prescriber DEA'));
398 if($userDetails['upin']) $element->appendChild($this->createElementText('upin', $userDetails['upin']));
399 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
400 $element->appendChild($this->createElementTextFieldEmpty('npi', $userDetails['npi'], xl('Licensed Prescriber NPI')));
405 public function getStaffName($user) {
406 $element = $this->getDocument()->createElement('StaffName');
407 $element->appendChild($this->createElementText('last', $this->stripSpecialCharacter($user['lname'])));
408 $element->appendChild($this->createElementText('first', $this->stripSpecialCharacter($user['fname'])));
409 $element->appendChild($this->createElementText('middle', $this->stripSpecialCharacter($user['mname'])));
414 public function getStaff($authUserId) {
415 $userDetails = $this->getStore()
416 ->getUserById($authUserId);
418 $element = $this->getDocument()->createElement('Staff');
419 $element->setAttribute('ID', $userDetails['username']);
420 $element->appendChild($this->getStaffName($userDetails));
421 $element->appendChild($this->createElementText('license', $userDetails['state_license_number']));
426 public function getLicensedPrescriberName($user, $prescriberType, $prefix = false) {
427 $element = $this->getDocument()->createElement('LicensedPrescriberName');
428 $element->appendChild($this->createElementTextFieldEmpty('last', $this->stripSpecialCharacter($user['lname']), $prescriberType.' '.xl('Licensed Prescriber Last Name')));
429 $element->appendChild($this->createElementTextFieldEmpty('first', $this->stripSpecialCharacter($user['fname']), $prescriberType.' '.xl('Licensed Prescriber First Name')));
430 $element->appendChild($this->createElementText('middle', $this->stripSpecialCharacter($user['mname'])));
431 if($prefix && $user['title']) $element->appendChild($this->createElementTextFieldEmpty('prefix', $user['title'], $prescriberType.' '.xl('Licensed Prescriber Title (Prefix)')));
436 public function getSupervisingDoctor($authUserId) {
437 $userDetails = $this->getStore()
438 ->getUserById($authUserId);
440 $element = $this->getDocument()->createElement('SupervisingDoctor');
441 $element->setAttribute('ID', $userDetails['npi']);
442 $element->appendChild($this->getLicensedPrescriberName($userDetails, xl('Supervising Doctor')));
443 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], xl('Supervising Doctor DEA')));
444 if($userDetails['upin']) $element->appendChild($this->createElementText('upin', $userDetails['upin']));
445 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
446 $element->appendChild($this->createElementTextFieldEmpty('npi', $userDetails['npi'], xl('Supervising Doctor NPI')));
451 public function getMidlevelPrescriber($authUserId) {
452 $userDetails = $this->getStore()
453 ->getUserById($authUserId);
455 $element = $this->getDocument()->createElement('MidlevelPrescriber');
456 $element->setAttribute('ID', $userDetails['npi']);
457 $element->appendChild($this->getLicensedPrescriberName($userDetails, xl('Midlevel Prescriber'), true));
458 $element->appendChild($this->createElementTextFieldEmpty('dea', $userDetails['federaldrugid'], xl('Midlevel Prescriber DEA')));
459 if($userDetails['upin']) $element->appendChild($this->createElementText('upin', $userDetails['upin']));
460 $element->appendChild($this->createElementText('licenseNumber', $userDetails['state_license_number']));
465 public function getStaffElements($authUserId, $destination) {
466 $userRole = $this->getStore()->getUserById($authUserId);
467 $userRole = preg_replace('/erx/', '', $userRole['newcrop_user_role']);
471 if($userRole != 'manager') {
472 $elements[] = $this->getLocation($authUserId);
475 if($userRole == 'doctor' ||
$destination == 'renewal') {
476 $elements[] = $this->getLicensedPrescriber($authUserId);
479 if($userRole == 'manager' ||
$userRole == 'admin' ||
$userRole == 'nurse') {
480 $elements[] = $this->getStaff($authUserId);
481 } elseif($userRole == 'supervisingDoctor') {
482 $elements[] = $this->getSupervisingDoctor($authUserId);
483 } elseif($userRole == 'midlevelPrescriber') {
484 $elements[] = $this->getMidlevelPrescriber($authUserId);
490 public function getPatientName($patient) {
491 $element = $this->getDocument()->createElement('PatientName');
492 $element->appendChild($this->createElementTextDemographicsCheck('last', $this->trimData($this->stripSpecialCharacter($patient['lname']), 35), xl('Patient Last Name')));
493 $element->appendChild($this->createElementTextDemographicsCheck('first', $this->trimData($this->stripSpecialCharacter($patient['fname']), 35), xl('Patient First Name')));
494 $element->appendChild($this->createElementText('middle', $this->trimData($this->stripSpecialCharacter($patient['mname']), 35)));
499 public function getPatientAddress($patient) {
500 $patient['street'] = $this->trimData($this->stripSpecialCharacter($patient['street']), 35);
501 $this->warningMessage($patient['street'], xl('Patient Street Address'));
504 if(trim($patient['country_code']) == '') {
505 $eRxDefaultPatientCountry = $this->getGlobals()->getDefaultPatientCountry();
507 if($eRxDefaultPatientCountry == '') {
508 $this->demographicsCheck('', xl('Global Default Patient Country'));
510 $patient['country_code'] = $eRxDefaultPatientCountry;
512 $this->demographicsCheck('', xl('Patient Country'));
515 $element = $this->getDocument()->createElement('PatientAddress');
516 $element->appendChild($this->createElementTextFieldEmpty('address1', $patient['street'], xl('Patient Street Address')));
517 $element->appendChild($this->createElementTextDemographicsCheck('city', $patient['city'], xl('Patient City')));
518 if($patient['state']) $element->appendChild($this->createElementText('state', $patient['state']));
519 if($patient['postal_code']) $element->appendChild($this->createElementText('zip', $patient['postal_code']));
520 $element->appendChild($this->createElementText('country', substr($patient['country_code'], 0, 2)));
525 public function getPatientContact($patient) {
526 $element = $this->getDocument()->createElement('PatientContact');
527 if($patient['phone_home']) $element->appendChild($this->createElementText('homeTelephone', preg_replace('/-/', '', $patient['phone_home'])));
532 public function getPatientCharacteristics($patient) {
533 if(trim($patient['date_of_birth']) == '' ||
$patient['date_of_birth'] == '00000000') {
534 $this->warningMessage('', xl('Patient Date Of Birth'));
536 $this->warningMessage(trim($patient['sex']), xl('Patient Gender'));
538 $element = $this->getDocument()->createElement('PatientCharacteristics');
539 if($patient['date_of_birth'] && $patient['date_of_birth'] != '00000000') $element->appendChild($this->createElementText('dob', $patient['date_of_birth']));
540 if($patient['sex']) $element->appendChild($this->createElementText('gender', substr($patient['sex'], 0, 1)));
545 public function getPatientFreeformHealthplans($patientId) {
546 $healthplans = $this->getStore()
547 ->getPatientHealthplansByPatientId($patientId);
551 while($healthplan = sqlFetchArray($healthplans)) {
552 $element = $this->getDocument()->createElement('PatientFreeformHealthplans');
553 $element->appendChild($this->createElementText('healthplanName', $this->trimData($this->stripSpecialCharacter($healthplan['name'], 35))));
555 $elements[] = $element;
561 public function getPatientFreeformAllergy($patientId) {
562 $allergyData = $this->getStore()
563 ->getPatientAllergiesByPatientId($patientId);
567 while($allergy = sqlFetchArray($allergyData)) {
568 $element = $this->getDocument()->createElement('PatientFreeformAllergy');
569 $element->setAttribute('ID', $allergy['id']);
571 if($allergy['title1']) $element->appendChild($this->createElementText('allergyName', $this->trimData($this->stripSpecialCharacter($allergy['title1']), 70)));
572 if($allergy['title2']=='Mild' ||
$allergy['title2']=='Moderate' ||
$allergy['title2']=='Severe') $element->appendChild($this->createElementText('allergySeverityTypeID', $allergy['title2']));
573 if($allergy['comments']) $element->appendChild($this->createElementText('allergyComment', $this->trimData($this->stripSpecialCharacter($allergy['comments']), 200)));
575 $elements[] = $element;
577 $this->addSentAllergyIds($allergy['id']);
583 public function getPatient($patientId) {
584 $patientData = $this->getStore()
585 ->getPatientByPatientId($patientId);
587 $element = $this->getDocument()->createElement('Patient');
588 $element->setAttribute('ID', $patientData['pid']);
589 $element->appendChild($this->getPatientName($patientData));
590 $element->appendChild($this->getPatientAddress($patientData));
591 $element->appendChild($this->getPatientContact($patientData));
592 $element->appendChild($this->getPatientCharacteristics($patientData));
593 $this->appendChildren($element, $this->getPatientFreeformHealthplans($patientId));
594 $this->appendChildren($element, $this->getPatientFreeformAllergy($patientId));
599 public function getOutsidePrescription($prescription) {
600 $element = $this->getDocument()->createElement('OutsidePrescription');
601 $element->appendChild($this->createElementText('externalId', $prescription['externalId']));
602 $element->appendChild($this->createElementText('date', $prescription['date']));
603 $element->appendChild($this->createElementText('doctorName', $prescription['doctorName']));
604 $element->appendChild($this->createElementText('drug', $prescription['drug']));
605 $element->appendChild($this->createElementText('dispenseNumber', $prescription['dispenseNumber']));
606 $element->appendChild($this->createElementText('sig', $prescription['sig']));
607 $element->appendChild($this->createElementText('refillCount', $prescription['refillCount']));
608 $element->appendChild($this->createElementText('prescriptionType', $prescription['prescriptionType']));
613 public function getPatientPrescriptions($prescriptionIds) {
616 foreach($prescriptionIds as $prescriptionId) {
617 if($prescriptionId) {
618 $prescription = $this->getStore()
619 ->getPrescriptionById($prescriptionId);
621 $element = $this->getOutsidePrescription(array(
622 'externalId' => $prescription['prescid'],
623 'date' => $prescription['date_added'],
624 'doctorName' => $prescription['docname'],
625 'drug' => $this->trimData($this->stripSpecialCharacter($prescription['drug']), 80),
626 'dispenseNumber' => intval($prescription['quantity']),
627 'sig' => $this->trimData($this->stripSpecialCharacter($prescription['quantity'][1].$prescription['size'].' '.$prescription['title4'].' '.$prescription['dosage'].' In '.$prescription['title1'].' '.$prescription['title2'].' '.$prescription['title3'], 140)),
628 'refillCount' => intval($prescription['per_refill']),
629 'prescriptionType' => 'reconcile'
632 $this->addSentPrescriptionId($prescriptionId);
634 $elements[] = $element;
641 public function getPatientMedication($patientId, $uploadActive, $count) {
642 $medications = $this->getStore()
643 ->selectMedicationsNotUploadedByPatientId($patientId, $uploadActive, $count);
647 while($medication = sqlFetchArray($medications)) {
648 $elements[] = $this->getOutsidePrescription(array(
649 'externalId' => $medication['id'],
650 'date' => $medication['begdate'],
652 'drug' => $this->trimData($medication['title'], 80),
653 'dispenseNumber' => '',
656 'prescriptionType' => 'reconcile'
659 $this->addSentMedicationIds($medication['id']);
665 public function getPatientElements($patientId, $totalCount, $requestedPrescriptionIds) {
669 $uploadActive = $this->getGlobals()->getUploadActive();
671 $elements[] = $this->getPatient($patientId);
673 $selectPrescriptionIds = $this->getStore()
674 ->selectPrescriptionIdsNotUploadedByPatientId(
680 $selectPrescriptionIdsCount = sqlNumRows($selectPrescriptionIds);
682 $prescriptionIds = array();
684 while($selectPrescriptionId = sqlFetchArray($selectPrescriptionIds)) {
685 $prescriptionIds[] = $selectPrescriptionId['id'];
688 if(count($requestedPrescriptionIds) > 0) {
689 $elements = array_merge($elements, $this->getPatientPrescriptions($requestedPrescriptionIds));
690 } elseif(count($prescriptionIds) > 0) {
691 $elements = array_merge($elements, $this->getPatientPrescriptions($prescriptionIds));
693 $this->getPatientPrescriptions(array(0));
696 if($selectPrescriptionIdsCount < $totalCount) {
697 $elements = array_merge($elements, $this->getPatientMedication($patientId, $uploadActive, $totalCount - $selectPrescriptionIdsCount));