Highway to PSR2
[openemr.git] / interface / modules / zend_modules / module / Carecoordination / src / Carecoordination / Controller / CarecoordinationController.php
blobb420ec2aa18d0edfdcee6220ed643903ee0552ee
1 <?php
2 /* +-----------------------------------------------------------------------------+
3 * OpenEMR - Open Source Electronic Medical Record
4 * Copyright (C) 2014 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author Vinish K <vinish@zhservices.com>
20 * @author Chandni Babu <chandnib@zhservices.com>
21 * @author Riju KP <rijukp@zhservices.com>
22 * +------------------------------------------------------------------------------+
24 namespace Carecoordination\Controller;
26 use Zend\Mvc\Controller\AbstractActionController;
27 use Zend\View\Model\ViewModel;
28 use Zend\View\Model\JsonModel;
29 use Application\Listener\Listener;
30 use Documents\Controller\DocumentsController;
32 use C_Document;
33 use Document;
34 use CouchDB;
35 use xmltoarray_parser_htmlfix;
37 class CarecoordinationController extends AbstractActionController
40 public function __construct($sm)
42 $this->listenerObject = new Listener;
43 $this->date_format = \Application\Model\ApplicationTable::dateFormat($GLOBALS['date_display_format']);
46 /**
47 * Index Page
48 * @param int $id menu id
49 * $param array $data menu details
50 * @param string $slug controller name
51 * @return \Zend\View\Model\ViewModel
53 public function indexAction()
55 $this->redirect()->toRoute('encountermanager', array('action' => 'index'));
59 * Upload CCDA file
61 public function uploadAction()
63 $request = $this->getRequest();
64 $action = $request->getPost('action');
65 $am_id = $request->getPost('am_id');
66 $document_id = $request->getPost('document_id');
68 if ($action == 'add_new_patient') {
69 $this->getCarecoordinationTable()->insert_patient($am_id, $document_id);
72 $upload = $request->getPost('upload');
73 $category_details = $this->getCarecoordinationTable()->fetch_cat_id('CCDA');
75 if ($upload == 1) {
76 $time_start = date('Y-m-d H:i:s');
77 $cdoc = \Documents\Controller\DocumentsController::uploadAction();
78 $uploaded_documents = array();
79 $uploaded_documents = $this->getCarecoordinationTable()->fetch_uploaded_documents(array('user' => $_SESSION['authId'], 'time_start' => $time_start, 'time_end' => date('Y-m-d H:i:s')));
80 if ($uploaded_documents[0]['id'] > 0) {
81 $_REQUEST["document_id"] = $uploaded_documents[0]['id'];
82 $_REQUEST["batch_import"] = 'YES';
83 $this->importAction();
85 } else {
86 $result = \Documents\Plugin\Documents::fetchXmlDocuments();
87 foreach ($result as $row) {
88 if ($row['doc_type'] == 'CCDA') {
89 $_REQUEST["document_id"] = $row['doc_id'];
90 $this->importAction();
91 \Documents\Model\DocumentsTable::updateDocumentCategoryUsingCatname($row['doc_type'], $row['doc_id']);
96 $records = $this->getCarecoordinationTable()->document_fetch(array('cat_title' => 'CCDA', 'type' => '12'));
97 $view = new ViewModel(array(
98 'records' => $records,
99 'category_id' => $category_details[0]['id'],
100 'file_location' => basename($_FILES['file']['name']),
101 'patient_id' => '00',
102 'listenerObject' => $this->listenerObject
104 return $view;
108 * Function to import the data CCDA file to audit tables.
110 * @param document_id integer value
111 * @return none
113 public function importAction()
115 $request = $this->getRequest();
116 if ($request->getQuery('document_id')) {
117 $_REQUEST["document_id"] = $request->getQuery('document_id');
118 $category_details = $this->getCarecoordinationTable()->fetch_cat_id('CCDA');
119 \Documents\Controller\DocumentsController::getDocumentsTable()->updateDocumentCategory($category_details[0]['id'], $_REQUEST["document_id"]);
122 $document_id = $_REQUEST["document_id"];
123 $xml_content = $this->getCarecoordinationTable()->getDocument($document_id);
124 $xml_content_new = preg_replace('#<br />#', '', $xml_content);
125 $xml_content_new = preg_replace('#<br/>#', '', $xml_content_new);
127 $xmltoarray = new \Zend\Config\Reader\Xml();
128 $array = $xmltoarray->fromString((string) $xml_content_new);
130 $patient_role = $array['recordTarget']['patientRole'];
131 $patient_pub_pid = $patient_role['id'][0]['extension'];
132 $patient_ssn = $patient_role['id'][1]['extension'];
133 $patient_address = $patient_role['addr']['streetAddressLine'];
134 $patient_city = $patient_role['addr']['city'];
135 $patient_state = $patient_role['addr']['state'];
136 $patient_postalcode = $patient_role['addr']['postalCode'];
137 $patient_country = $patient_role['addr']['country'];
138 $patient_phone_type = $patient_role['telecom']['use'];
139 $patient_phone_no = $patient_role['telecom']['value'];
140 $patient_fname = $patient_role['patient']['name']['given'][0];
141 $patient_lname = $patient_role['patient']['name']['given'][1];
142 $patient_family_name = $patient_role['patient']['name']['family'];
143 $patient_gender_code = $patient_role['patient']['administrativeGenderCode']['code'];
144 $patient_gender_name = $patient_role['patient']['administrativeGenderCode']['displayName'];
145 $patient_dob = $patient_role['patient']['birthTime']['value'];
146 $patient_marital_status = $patient_role['patient']['religiousAffiliationCode']['code'];
147 $patient_marital_status_display = $patient_role['patient']['religiousAffiliationCode']['displayName'];
148 $patient_race = $patient_role['patient']['raceCode']['code'];
149 $patient_race_display = $patient_role['patient']['raceCode']['displayName'];
150 $patient_ethnicity = $patient_role['patient']['ethnicGroupCode']['code'];
151 $patient_ethnicity_display = $patient_role['patient']['ethnicGroupCode']['displayName'];
152 $patient_language = $patient_role['patient']['languageCommunication']['languageCode']['code'];
154 $author = $array['recordTarget']['author']['assignedAuthor'];
155 $author_id = $author['id']['extension'];
156 $author_address = $author['addr']['streetAddressLine'];
157 $author_city = $author['addr']['city'];
158 $author_state = $author['addr']['state'];
159 $author_postalCode = $author['addr']['postalCode'];
160 $author_country = $author['addr']['country'];
161 $author_phone_use = $author['telecom']['use'];
162 $author_phone = $author['telecom']['value'];
163 $author_name_given = $author['assignedPerson']['name']['given'];
164 $author_name_family = $author['assignedPerson']['name']['family'];
166 $data_enterer = $array['recordTarget']['dataEnterer']['assignedEntity'];
167 $data_enterer_id = $data_enterer['id']['extension'];
168 $data_enterer_address = $data_enterer['addr']['streetAddressLine'];
169 $data_enterer_city = $data_enterer['addr']['city'];
170 $data_enterer_state = $data_enterer['addr']['state'];
171 $data_enterer_postalCode = $data_enterer['addr']['postalCode'];
172 $data_enterer_country = $data_enterer['addr']['country'];
173 $data_enterer_phone_use = $data_enterer['telecom']['use'];
174 $data_enterer_phone = $data_enterer['telecom']['value'];
175 $data_enterer_name_given = $data_enterer['assignedPerson']['name']['given'];
176 $data_enterer_name_family = $data_enterer['assignedPerson']['name']['family'];
178 $informant = $array['recordTarget']['informant'][0]['assignedEntity'];
179 $informant_id = $informant['id']['extension'];
180 $informant_address = $informant['addr']['streetAddressLine'];
181 $informant_city = $informant['addr']['city'];
182 $informant_state = $informant['addr']['state'];
183 $informant_postalCode = $informant['addr']['postalCode'];
184 $informant_country = $informant['addr']['country'];
185 $informant_phone_use = $informant['telecom']['use'];
186 $informant_phone = $informant['telecom']['value'];
187 $informant_name_given = $informant['assignedPerson']['name']['given'];
188 $informant_name_family = $informant['assignedPerson']['name']['family'];
190 $personal_informant = $array['recordTarget']['informant'][1]['relatedEntity'];
191 $personal_informant_name = $personal_informant['relatedPerson']['name']['given'];
192 $personal_informant_family = $personal_informant['relatedPerson']['name']['family'];
194 $custodian = $array['recordTarget']['custodian']['assignedCustodian']['representedCustodianOrganization'];
195 $custodian_name = $custodian['name'];
196 $custodian_address = $custodian['addr']['streetAddressLine'];
197 $custodian_city = $custodian['addr']['city'];
198 $custodian_state = $custodian['addr']['state'];
199 $custodian_postalCode = $custodian['addr']['postalCode'];
200 $custodian_country = $custodian['addr']['country'];
201 $custodian_phone = $custodian['telecom']['value'];
202 $custodian_phone_use = $custodian['telecom']['use'];
204 $informationRecipient = $array['recordTarget']['informationRecipient']['intendedRecipient'];
205 $informationRecipient_name = $informationRecipient['informationRecipient']['name']['given'];
206 $informationRecipient_name = $informationRecipient['informationRecipient']['name']['family'];
207 $informationRecipient_org = $informationRecipient['receivedOrganization']['name'];
209 $legalAuthenticator = $array['recordTarget']['legalAuthenticator'];
210 $legalAuthenticator_signatureCode = $legalAuthenticator['signatureCode']['code'];
211 $legalAuthenticator_id = $legalAuthenticator['assignedEntity']['id']['extension'];
212 $legalAuthenticator_address = $legalAuthenticator['assignedEntity']['addr']['streetAddressLine'];
213 $legalAuthenticator_city = $legalAuthenticator['assignedEntity']['addr']['city'];
214 $legalAuthenticator_state = $legalAuthenticator['assignedEntity']['addr']['state'];
215 $legalAuthenticator_postalCode = $legalAuthenticator['assignedEntity']['addr']['postalCode'];
216 $legalAuthenticator_country = $legalAuthenticator['assignedEntity']['addr']['country'];
217 $legalAuthenticator_phone = $legalAuthenticator['assignedEntity']['telecom']['value'];
218 $legalAuthenticator_phone_use = $legalAuthenticator['assignedEntity']['telecom']['use'];
219 $legalAuthenticator_name_given = $legalAuthenticator['assignedEntity']['assignedPerson']['name']['given'];
220 $legalAuthenticator_name_family = $legalAuthenticator['assignedEntity']['assignedPerson']['name']['family'];
222 $authenticator = $array['recordTarget']['authenticator'];
223 $authenticator_signatureCode = $authenticator['signatureCode']['code'];
224 $authenticator_id = $authenticator['assignedEntity']['id']['extension'];
225 $authenticator_address = $authenticator['assignedEntity']['addr']['streetAddressLine'];
226 $authenticator_city = $authenticator['assignedEntity']['addr']['city'];
227 $authenticator_state = $authenticator['assignedEntity']['addr']['state'];
228 $authenticator_postalCode = $authenticator['assignedEntity']['addr']['postalCode'];
229 $authenticator_country = $authenticator['assignedEntity']['addr']['country'];
230 $authenticator_phone = $authenticator['assignedEntity']['telecom']['value'];
231 $authenticator_phone_use = $authenticator['assignedEntity']['telecom']['use'];
232 $authenticator_name_given = $authenticator['assignedEntity']['assignedPerson']['name']['given'];
233 $authenticator_name_family = $authenticator['assignedEntity']['assignedPerson']['name']['family'];
235 $this->getCarecoordinationTable()->import($array, $document_id);
237 $view = new ViewModel();
238 $view->setTerminal(true);
239 return $view;
242 public function revandapproveAction()
244 $request = $this->getRequest();
245 $document_id = $request->getQuery('document_id') ? $request->getQuery('document_id') : $request->getPost('document_id', null);
246 $audit_master_id = $request->getQuery('amid') ? $request->getQuery('amid') : $request->getPost('amid', null);
247 $pid = $request->getQuery('pid') ? $request->getQuery('pid') : $request->getPost('pid', null);
249 if ($request->getPost('setval') == 'approve') {
250 $this->getCarecoordinationTable()->insertApprovedData($request->getPost());
251 return $this->redirect()->toRoute('carecoordination', array(
252 'controller' => 'Carecoordination',
253 'action' => 'upload'));
254 } else if ($request->getPost('setval') == 'discard') {
255 $this->getCarecoordinationTable()->discardCCDAData(array('audit_master_id' => $audit_master_id));
256 return $this->redirect()->toRoute('carecoordination', array(
257 'controller' => 'Carecoordination',
258 'action' => 'upload'));
261 $documentationOf = $this->getCarecoordinationTable()->getdocumentationOf($audit_master_id);
262 $demographics = $this->getCarecoordinationTable()->getDemographics(array('audit_master_id' => $audit_master_id));
263 $demographics_old = $this->getCarecoordinationTable()->getDemographicsOld(array('pid' => $pid));
265 $problems = $this->getCarecoordinationTable()->getProblems(array('pid' => $pid));
266 $problems_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'lists1');
268 $allergies = $this->getCarecoordinationTable()->getAllergies(array('pid' => $pid));
269 $allergies_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'lists2');
271 $medications = $this->getCarecoordinationTable()->getMedications(array('pid' => $pid));
272 $medications_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'lists3');
274 $immunizations = $this->getCarecoordinationTable()->getImmunizations(array('pid' => $pid));
275 $immunizations_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'immunization');
277 $lab_results = $this->getCarecoordinationTable()->getLabResults(array('pid' => $pid));
278 $lab_results_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'procedure_result');
280 $vitals = $this->getCarecoordinationTable()->getVitals(array('pid' => $pid));
281 $vitals_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'vital_sign');
283 $social_history = $this->getCarecoordinationTable()->getSocialHistory(array('pid' => $pid));
284 $social_history_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'social_history');
286 $encounter = $this->getCarecoordinationTable()->getEncounterData(array('pid' => $pid));
287 $encounter_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'encounter');
289 $procedure = $this->getCarecoordinationTable()->getProcedure(array('pid' => $pid));
290 $procedure_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'procedure');
292 $care_plan = $this->getCarecoordinationTable()->getCarePlan(array('pid' => $pid));
293 $care_plan_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'care_plan');
295 $functional_cognitive_status = $this->getCarecoordinationTable()->getFunctionalCognitiveStatus(array('pid' => $pid));
296 $functional_cognitive_status_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'functional_cognitive_status');
298 $referral = $this->getCarecoordinationTable()->getReferralReason(array('pid' => $pid));
299 $referral_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'referral');
301 $discharge_medication_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'discharge_medication');
303 $discharge_summary = array();
304 $discharge_summary_audit = $this->getCarecoordinationTable()->createAuditArray($audit_master_id, 'discharge_summary');
306 $gender_list = $this->getCarecoordinationTable()->getList('sex');
307 $country_list = $this->getCarecoordinationTable()->getList('country');
308 $marital_status_list = $this->getCarecoordinationTable()->getList('marital');
309 $religion_list = $this->getCarecoordinationTable()->getList('religious_affiliation');
310 $race_list = $this->getCarecoordinationTable()->getList('race');
311 $ethnicity_list = $this->getCarecoordinationTable()->getList('ethnicity');
312 $state_list = $this->getCarecoordinationTable()->getList('state');
313 $tobacco = $this->getCarecoordinationTable()->getList('smoking_status');
315 $demographics_old[0]['sex'] = $this->getCarecoordinationTable()->getListTitle($demographics_old[0]['sex'], 'sex', '');
316 $demographics_old[0]['country_code'] = $this->getCarecoordinationTable()->getListTitle($demographics_old[0]['country_code'], 'country', '');
317 $demographics_old[0]['status'] = $this->getCarecoordinationTable()->getListTitle($demographics_old[0]['status'], 'marital', '');
318 $demographics_old[0]['religion'] = $this->getCarecoordinationTable()->getListTitle($demographics_old[0]['religion'], 'religious_affiliation', '');
319 $demographics_old[0]['race'] = $this->getCarecoordinationTable()->getListTitle($demographics_old[0]['race'], 'race', '');
320 $demographics_old[0]['ethnicity'] = $this->getCarecoordinationTable()->getListTitle($demographics_old[0]['ethnicity'], 'ethnicity', '');
321 $demographics_old[0]['state'] = $this->getCarecoordinationTable()->getListTitle($demographics_old[0]['state'], 'state', '');
323 $view = new ViewModel(array(
324 'demographics' => $demographics,
325 'demographics_old' => $demographics_old,
326 'problems' => $problems,
327 'problems_audit' => $problems_audit,
328 'allergies' => $allergies,
329 'allergies_audit' => $allergies_audit,
330 'medications' => $medications,
331 'medications_audit' => $medications_audit,
332 'immunizations' => $immunizations,
333 'immunizations_audit' => $immunizations_audit,
334 'lab_results' => $lab_results,
335 'lab_results_audit' => $lab_results_audit,
336 'vitals' => $vitals,
337 'vitals_audit' => $vitals_audit,
338 'social_history' => $social_history,
339 'social_history_audit' => $social_history_audit,
340 'encounter' => $encounter,
341 'encounter_audit' => $encounter_audit,
342 'procedure' => $procedure,
343 'procedure_audit' =>$procedure_audit,
344 'care_plan' => $care_plan,
345 'care_plan_audit' => $care_plan_audit,
346 'functional_cognitive_status' => $functional_cognitive_status,
347 'functional_cognitive_status_audit' => $functional_cognitive_status_audit,
348 'referral' => $referral,
349 'referral_audit' => $referral_audit,
350 'discharge_medication_audit' => $discharge_medication_audit,
351 'discharge_summary' => $discharge_summary,
352 'discharge_summary_audit' => $discharge_summary_audit,
353 'amid' => $audit_master_id,
354 'pid' => $pid,
355 'document_id' => $document_id,
356 'gender_list' => $gender_list,
357 'country_list' => $country_list,
358 'marital_status_list' => $marital_status_list,
359 'religion_list' => $religion_list,
360 'race_list' => $race_list,
361 'ethnicity_list' => $ethnicity_list,
362 'tobacco' => $tobacco,
363 'state_list' => $state_list,
364 'listenerObject' => $this->listenerObject,
365 'documentationOf' => $documentationOf,
367 return $view;
370 public function getCCDAComponentsAction()
372 $request = $this->getRequest();
373 $id = $request->getQuery('id');
374 $arr = explode("-", $id);
375 $amid = $arr[0];
376 $pid = $arr[1];
377 $components = $this->getCarecoordinationTable()->getCCDAComponents(1);
378 $discharge_medication_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'discharge_medication');
379 $discharge_summary_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'discharge_summary');
380 if (count($discharge_medication_audit)>0) {
381 $components['discharge_medication'] = 'Dishcharge Medications';
384 if (count($discharge_summary_audit)>0) {
385 $components['discharge_summary'] = 'Dishcharge Summary';
388 $components = array_diff($components, array('instructions' => 'Instructions'));
390 $temp = '<table>';
391 foreach ($components as $key => $value) {
392 $temp .='<tr class="se_in_9">
393 <th colspan="1" id="expandCompDetails-'.\Application\Plugin\CommonPlugin::escape($key.$amid.$pid).'" class="expandCompDetails se_in_23" component="'.\Application\Plugin\CommonPlugin::escape($key).'" amid="'.\Application\Plugin\CommonPlugin::escape($amid).'" style="padding: 0px 5px!important;"></th>
394 <th colspan="8" style="padding: 0px 0px!important;"><label>'.\Application\Plugin\CommonPlugin::escape($value).'</th>
395 </tr>
396 <tr>
397 <td colspan="9" id="hideComp-'.\Application\Plugin\CommonPlugin::escape($key.$amid.$pid).'" class="imported_ccdaComp_details" style="display: none;"></td>
398 </tr>';
401 $temp .= '</table>';
402 echo $temp;
403 exit;
406 public function getEachCCDAComponentDetailsAction()
408 $request = $this->getRequest();
409 $id = $request->getQuery('id');
410 $component = $request->getQuery('component');
411 $amid = $request->getQuery('amid');
412 $temp = '';
414 switch ($component) {
415 case 'allergies':
416 $allergies_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'lists2');
417 if (count($allergies_audit)>0) {
418 $temp .='<div><table class="narr_table" border="1" width="100%!important;">
419 <thead><tr class="narr_tr">
420 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Substance').'</th>
421 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Reaction').'</th>
422 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Severity').'</th>
423 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Status').'</th>
424 </tr></thead>
425 <tbody>';
426 foreach ($allergies_audit['lists2'] as $key => $val) {
427 $severity_option_id = $this->getCarecoordinationTable()->getOptionId('severity_ccda', '', 'SNOMED-CT:' . $val['severity_al']);
428 $severity_text = $this->getCarecoordinationTable()->getListTitle($severity_option_id, 'severity_ccda', 'SNOMED-CT:' . $val['severity_al']);
429 if ($val['enddate'] != 0 && $val['enddate'] != '') {
430 $status = 'completed';
431 } else {
432 $status = 'active';
435 $temp .='<tr class="narr_tr">
436 <td>'.\Application\Plugin\CommonPlugin::escape($val['list_code_text']).'</td>
437 <td>'.\Application\Listener\Listener::z_xlt($val['reaction_text']).'</td>
438 <td>'.\Application\Listener\Listener::z_xlt($severity_text).'</td>
439 <td>'.\Application\Listener\Listener::z_xlt($status).'</td>
440 </tr>';
443 $temp .='</tbody></table></div>';
444 } else {
445 $temp .= \Application\Listener\Listener::z_xlt('No Known Allergies');
447 break;
448 case 'medications':
449 $medications_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'lists3');
450 if (count($medications_audit)>0) {
451 $temp .='<div><table class="narr_table" border="1" width="100%">
452 <thead><tr class="narr_tr">
453 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Medication').'</th>
454 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Directions').'</th>
455 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Start Date').'</th>
456 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Status').'</th>
457 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Indications').'</th>
458 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Fill Instructions').'</th>
459 </tr></thead>
460 <tbody>';
461 foreach ($medications_audit['lists3'] as $key => $val) {
462 if ($val['enddate'] && $val['enddate'] != 0) {
463 $active = 'completed';
464 } else {
465 $active = 'active';
468 $temp .='<tr class="narr_tr">
469 <td>'.\Application\Plugin\CommonPlugin::escape($val['drug_text']).'</td>
470 <td>'.\Application\Plugin\CommonPlugin::escape($val['rate']." ".$val['rate_unit']." ".$val['route_display']." ".$val['dose']." ".$val['dose_unit']).'</td>
471 <td>'.\Application\Model\ApplicationTable::fixDate(substr($val['begdate'], 0, 4) . "-" . substr($val['begdate'], 4, 2) . "-" . substr($val['begdate'], 6, 2), $this->date_format, 'yyyy-mm-dd').'</td>
472 <td>'.\Application\Listener\Listener::z_xlt($active).'</td>
473 <td>'.\Application\Plugin\CommonPlugin::escape($val['indication']).'</td>
474 <td>'.\Application\Plugin\CommonPlugin::escape($val['note']).'</td>
475 </tr>';
478 $temp .='</tbody></table></div>';
479 } else {
480 $temp .= \Application\Listener\Listener::z_xlt('No Known Medications');
482 break;
483 case 'problems':
484 $problems_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'lists1');
485 if (count($problems_audit)>0) {
486 $temp .='<div><ul>';
487 $i = 1;
488 foreach ($problems_audit['lists1'] as $key => $val) {
489 if ($val['enddate'] != 0 && $val['enddate'] != '') {
490 $status = 'Resolved';
491 } else {
492 $status = 'Active';
495 $temp .='<li>'.$i.'. '.\Application\Plugin\CommonPlugin::escape($val['list_code_text']).','.substr($val['begdate'], 0, 4) . "-" . substr($val['begdate'], 4, 2) . "-" . substr($val['begdate'], 6, 2).', '.\Application\Listener\Listener::z_xlt('Status').' :'.\Application\Listener\Listener::z_xlt($status).'</li>';
496 $i++;
499 $temp .='</ul></div>';
500 } else {
501 $temp .= \Application\Listener\Listener::z_xlt('No Known Problems');
503 break;
504 case 'immunizations':
505 $immunizations_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'immunization');
506 if (count($immunizations_audit)>0) {
507 $temp .='<div><table class="narr_table" border="1" width="100%">
508 <thead><tr class="narr_tr">
509 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Vaccine').'</th>
510 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Date').'</th>
511 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Status').'</th>
512 </tr></thead>
513 <tbody>';
514 foreach ($immunizations_audit['immunization'] as $key => $val) {
515 $temp .='<tr class="narr_tr">
516 <td>'.\Application\Plugin\CommonPlugin::escape($val['cvx_code_text']).'</td>
517 <td>'.$this->getCarecoordinationTable()->getMonthString(substr($val['administered_date'], 4, 2)).' '.substr($val['administered_date'], 0, 4).'</td>
518 <td>'.\Application\Listener\Listener::z_xlt('Completed').'</td>
519 </tr>';
522 $temp .='</tbody></table></div>';
523 } else {
524 $temp .= \Application\Listener\Listener::z_xlt('No Known Immunizations');
526 break;
527 case 'procedures':
528 $procedure_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'procedure');
529 if (count($procedure_audit)>0) {
530 $temp .='<div><table class="narr_table" border="1" width="100%">
531 <thead><tr class="narr_tr">
532 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Procedure').'</th>
533 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Date').'</th>
534 </tr></thead>
535 <tbody>';
536 foreach ($procedure_audit['procedure'] as $key => $val) {
537 $temp .='<tr class="narr_tr">
538 <td>'.\Application\Plugin\CommonPlugin::escape($val['code_text']).'</td>
539 <td>'.\Application\Model\ApplicationTable::fixDate(substr($val['date'], 0, 4) . "-" . substr($val['date'], 4, 2) . "-" . substr($val['date'], 6, 2), $this->date_format, 'yyyy-mm-dd').'</td>
540 </tr>';
543 $temp .='</tbody></table></div>';
544 } else {
545 $temp .= \Application\Listener\Listener::z_xlt('No Known Procedures');
547 break;
548 case 'results':
549 $lab_results_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'procedure_result');
550 if (count($lab_results_audit)>0) {
551 $temp .='<div>
552 <table class="narr_table" border="1">
553 <thead><tr class="narr_tr">
554 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Laboratory Information').'</th>
555 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Result').'</th>
556 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Date').'</th>
557 </tr></thead>
558 <tbody>';
559 foreach ($lab_results_audit['procedure_result'] as $key => $val) {
560 if ($val['results_text']) {
561 $temp .='<tr class="narr_tr">
562 <td>'.\Application\Plugin\CommonPlugin::escape($val['results_text']) . ($val['results_range'] != "-" ? "(" . \Application\Plugin\CommonPlugin::escape($val['results_range']) . ")" : "").'</td>
563 <td>'.\Application\Plugin\CommonPlugin::escape($val['results_value']) . " " . \Application\Plugin\CommonPlugin::escape($val['results_unit']).'</td>
564 <td>'.\Application\Model\ApplicationTable::fixDate(substr($val['date'], 0, 4) . "-" . substr($val['date'], 4, 2) . "-" . substr($val['date'], 6, 2), $this->date_format, 'yyyy-mm-dd').'</td>
565 </tr>';
569 $temp .='</tbody></table></div>';
570 } else {
571 $temp .= \Application\Listener\Listener::z_xlt('No Known Lab Results');
573 break;
574 case 'plan_of_care':
575 $care_plan_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'care_plan');
576 if (count($care_plan_audit)>0) {
577 $temp .='<div><table class="narr_table" border="1" width="100%">
578 <head><tr class="narr_tr">
579 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Planned Activity').'</th>
580 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Planned Date').'</th>
581 </tr></thead>
582 <tbody>';
583 foreach ($care_plan_audit['care_plan'] as $key => $val) {
584 $temp .='<tr class="narr_tr">
585 <td>'.\Application\Plugin\CommonPlugin::escape($val['code_text']).'</td>
586 <td>'.\Application\Model\ApplicationTable::fixDate(substr($val['date'], 0, 4) . "-" . substr($val['date'], 4, 2) . "-" . substr($val['date'], 6, 2), $this->date_format, 'yyyy-mm-dd').'</td>
587 </tr>';
590 $temp .='</tbody></table></div>';
591 } else {
592 $temp .= \Application\Listener\Listener::z_xlt('No Known Plan of Care');
594 break;
595 case 'vitals':
596 $vitals_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'vital_sign');
597 if (count($vitals_audit)>0) {
598 $temp .= '<div><table class="narr_table" border="1" width="100%">
599 <thead><tr class="narr_tr">
600 <th class="narr_th" align="right">'.\Application\Listener\Listener::z_xlt('Date / Time').': </th>';
601 foreach ($vitals_audit['vital_sign'] as $key => $val) {
602 $temp .= '<th class="narr_th">'.\Application\Model\ApplicationTable::fixDate(substr($val['date'], 0, 4) . "-" . substr($val['date'], 4, 2) . "-" . substr($val['date'], 6, 2), $this->date_format, 'yyyy-mm-dd').'</th>';
605 $temp .= '</tr></thead><tbody>
606 <tr class="narr_tr">
607 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Temperature').'</th>';
608 foreach ($vitals_audit['vital_sign'] as $key => $val) {
609 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['temperature']).'</td>';
612 $temp .= '</tr>
613 <tr class="narr_tr">
614 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Diastolic').'</th>';
615 foreach ($vitals_audit['vital_sign'] as $key => $val) {
616 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['bpd']).'</td>';
619 $temp .= '</tr>
620 <tr class="narr_tr">
621 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Systolic').'</th>';
622 foreach ($vitals_audit['vital_sign'] as $key => $val) {
623 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['bps']).'</td>';
626 $temp .= '</tr>
627 <tr class="narr_tr">
628 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Head Circumference').'</th>';
629 foreach ($vitals_audit['vital_sign'] as $key => $val) {
630 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['head_circ']).'</td>';
633 $temp .= '</tr>
634 <tr class="narr_tr">
635 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Pulse').'</th>';
636 foreach ($vitals_audit['vital_sign'] as $key => $val) {
637 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['pulse']).'</td>';
640 $temp .= '</tr>
641 <tr class="narr_tr">
642 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Height').'</th>';
643 foreach ($vitals_audit['vital_sign'] as $key => $val) {
644 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['height']).'</td>';
647 $temp .= '</tr>
648 <tr class="narr_tr">
649 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Oxygen Saturation').'</th>';
650 foreach ($vitals_audit['vital_sign'] as $key => $val) {
651 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['oxygen_saturation']).'</td>';
654 $temp .= '</tr>
655 <tr class="narr_tr">
656 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Breath').'</th>';
657 foreach ($vitals_audit['vital_sign'] as $key => $val) {
658 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['breath']).'</td>';
661 $temp .= '</tr>
662 <tr class="narr_tr">
663 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('Weight').'</th>';
664 foreach ($vitals_audit['vital_sign'] as $key => $val) {
665 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['weight']).'</td>';
668 $temp .= '</tr>
669 <tr class="narr_tr">
670 <th class="narr_th" align="left">'.\Application\Listener\Listener::z_xlt('BMI').'</th>';
671 foreach ($vitals_audit['vital_sign'] as $key => $val) {
672 $temp .= '<td>'.\Application\Plugin\CommonPlugin::escape($val['BMI']).'</td>';
675 $temp .= '</tr></tbody></table></div>';
676 } else {
677 $temp .= \Application\Listener\Listener::z_xlt('No Known Vitals');
679 break;
680 case 'social_history':
681 $social_history_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'social_history');
682 if (count($social_history_audit)>0) {
683 $temp .='<div><table class="narr_table" border="1" width="100%">
684 <thead><tr class="narr_tr">
685 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Social History Element').'</th>
686 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Description').'</th>
687 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Effective Dates').'</th>
688 </tr></thead>
689 <tbody>';
690 foreach ($social_history_audit['social_history'] as $key => $val) {
691 $array_his_tobacco = explode("|", $val['smoking']);
692 if ($array_his_tobacco[2] != 0 && $array_his_tobacco[2] != '') {
693 $his_tob_date = substr($array_his_tobacco[2], 0, 4). "-" .substr($array_his_tobacco[2], 4, 2). "-" .substr($array_his_tobacco[2], 6, 2);
696 $temp .='<tr class="narr_tr">
697 <td>'.\Application\Listener\Listener::z_xlt('Smoking').'</td>
698 <td>'.\Application\Plugin\CommonPlugin::escape($array_his_tobacco[0]).'</td>
699 <td>'.\Application\Model\ApplicationTable::fixDate($his_tob_date, $this->date_format, 'yyyy-mm-dd').'</td>
700 </tr>';
703 $temp .='</tbody></table></div>';
704 } else {
705 $temp .= \Application\Listener\Listener::z_xlt('No Known Social History');
707 break;
708 case 'encounters':
709 $encounter_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'encounter');
710 if (count($encounter_audit)>0) {
711 $temp .='<div><table class="narr_table" border="1" width="100%">
712 <thead><tr class="narr_tr">
713 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Encounter').'</th>
714 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Performer').'</th>
715 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Location').'</th>
716 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Date').'</th>
717 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Encounter Diagnosis').'</th>
718 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Status').'</th>
719 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Reason for Visit').'</th>
720 </tr></thead>
721 <tbody>';
722 foreach ($encounter_audit['encounter'] as $key => $val) {
723 if ($val['code_text'] != 'NULL') {
724 $encounter_activity = 'Active';
725 } else {
726 $encounter_activity = '';
729 $enc_date = substr($val['date'], 0, 4). "-" .substr($val['date'], 4, 2). "-" .substr($val['date'], 6, 2);
730 $temp .='<tr class="narr_tr">
731 <td>'.\Application\Plugin\CommonPlugin::escape($val['pc_catname']).'</td>
732 <td>'.\Application\Plugin\CommonPlugin::escape($val['provider_name']).'</td>
733 <td>'.\Application\Plugin\CommonPlugin::escape($val['represented_organization_name']).'</td>
734 <td>'.\Application\Model\ApplicationTable::fixDate($enc_date, $this->date_format, 'yyyy-mm-dd').'</td>
735 <td>'.($val['code_text'] != 'NULL' ? \Application\Plugin\CommonPlugin::escape($val['code_text']) : '').'</td>
736 <td>'.\Application\Listener\Listener::z_xlt($encounter_activity).'</td>
737 <td></td>
738 </tr>';
741 $temp .='</tbody></table></div>';
742 } else {
743 $temp .= \Application\Listener\Listener::z_xlt('No Known Encounters');
745 break;
746 case 'functional_status':
747 $functional_cognitive_status_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'functional_cognitive_status');
748 if (count($functional_cognitive_status_audit)>0) {
749 $temp .='<div><table class="narr_table" border="1" width="100%">
750 <thead><tr class="narr_tr">
751 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Functional Condition').'</th>
752 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Effective Dates').'</th>
753 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Condition Status').'</th>
754 </tr></thead>
755 <tbody>';
756 foreach ($functional_cognitive_status_audit['functional_cognitive_status'] as $key => $val) {
757 $temp .='<tr class="narr_tr">
758 <td>'.\Application\Plugin\CommonPlugin::escape($val['description']).'</td>
759 <td>'.\Application\Model\ApplicationTable::fixDate(substr($val['date'], 0, 4) . "-" . substr($val['date'], 4, 2) . "-" . substr($val['date'], 6, 2), $this->date_format, 'yyyy-mm-dd').'</td>
760 <td>'.\Application\Listener\Listener::z_xlt('Active').'</td>
761 </tr>';
764 $temp .='</tbody></table></div>';
765 } else {
766 $temp .= \Application\Listener\Listener::z_xlt('No Known Social Functional Status');
768 break;
769 case 'referral':
770 $referral_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'referral');
771 if (count($referral_audit)>0) {
772 $temp .='<div>';
773 foreach ($referral_audit['referral'] as $key => $val) {
774 $referal_data = explode("#$%^&*", $val['body']);
775 foreach ($referal_data as $k => $v) {
776 $temp .='<p>'.\Application\Plugin\CommonPlugin::escape($v).'</p>';
780 $temp .='</div>';
781 } else {
782 $temp .= \Application\Listener\Listener::z_xlt('No Known Referrals');
784 break;
785 case 'instructions':
786 $temp .= \Application\Listener\Listener::z_xlt('No Known Clinical Instructions');
787 break;
788 case 'discharge_medication':
789 $discharge_medication_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'discharge_medication');
790 $temp .='<div><table class="narr_table" border="1" width="100%">
791 <thead><tr class="narr_tr">
792 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Medication').'</th>
793 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Directions').'</th>
794 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Start Date').'</th>
795 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Status').'</th>
796 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Indications').'</th>
797 <th class="narr_th">'.\Application\Listener\Listener::z_xlt('Fill Instructions').'</th>
798 </tr></thead>
799 <tbody>';
800 foreach ($discharge_medication_audit['discharge_medication'] as $key => $val) {
801 if ($val['enddate'] && $val['enddate'] != 0) {
802 $active = 'completed';
803 } else {
804 $active = 'active';
807 $temp .='<tr class="narr_tr">
808 <td>'.\Application\Plugin\CommonPlugin::escape($val['drug_text']).'</td>
809 <td>'.\Application\Plugin\CommonPlugin::escape($val['rate']." ".$val['rate_unit']." ".$val['route_display']." ".$val['dose']." ".$val['dose_unit']).'</td>
810 <td>'.\Application\Model\ApplicationTable::fixDate(substr($val['begdate'], 0, 4) . "-" . substr($val['begdate'], 4, 2) . "-" . substr($val['begdate'], 6, 2), $this->date_format, 'yyyy-mm-dd').'</td>
811 <td>'.\Application\Listener\Listener::z_xlt($active).'</td>
812 <td>'.\Application\Plugin\CommonPlugin::escape($val['indication']).'</td>
813 <td>'.\Application\Plugin\CommonPlugin::escape($val['note']).'</td>
814 </tr>';
817 $temp .='</tbody></table></div>';
818 break;
819 case 'discharge_summary':
820 $discharge_summary_audit = $this->getCarecoordinationTable()->createAuditArray($amid, 'discharge_summary');
821 $temp .='<div>';
822 foreach ($discharge_summary_audit['discharge_summary'] as $key => $val) {
823 $text = str_replace("#$%", "<br>", \Application\Plugin\CommonPlugin::escape($val['text']));
824 $temp .=$text;
827 $temp .='</div>';
828 break;
831 echo $temp;
832 exit;
835 * Table gateway
836 * @return object
838 public function getCarecoordinationTable()
840 if (!$this->carecoordinationTable) {
841 $sm = $this->getServiceLocator();
842 $this->carecoordinationTable = $sm->get('Carecoordination\Model\CarecoordinationTable');
845 return $this->carecoordinationTable;