Highway to PSR2
[openemr.git] / interface / modules / zend_modules / module / Immunization / src / Immunization / Controller / ImmunizationController.php
blob4e0e3cad669717a8dd76ce9032164c31fd51bb27
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/>.
18 * @author Bindia Nandakumar <bindia@zhservices.com>
19 * +------------------------------------------------------------------------------+
21 namespace Immunization\Controller;
23 use Zend\Mvc\Controller\AbstractActionController;
24 use Zend\View\Model\ViewModel;
25 use Zend\View\Model\JsonModel;
27 use Immunization\Form\ImmunizationForm;
28 use Application\Listener\Listener;
30 class ImmunizationController extends AbstractActionController
32 protected $immunizationTable;
34 protected $listenerObject;
36 protected $date_format;
38 public function __construct()
40 $this->listenerObject = new Listener;
43 /**
44 * Index Page
45 * @return \Zend\View\Model\ViewModel
47 public function indexAction()
49 $form = new ImmunizationForm();
50 $request = $this->getRequest();
51 $form->setData($request->getPost());
52 $isPost = '';
53 $data = $request->getPost();
54 $isFormRefresh = 'true';
55 $form_code = isset($data['codes']) ? $data['codes'] : array();
56 $from_date = $request->getPost('from_date', null) ? $this->CommonPlugin()->date_format($request->getPost('from_date', null), 'yyyy-mm-dd', $GLOBALS['date_display_format']) : date('Y-m-d', strtotime(date('Ymd')) - (86400*7));
57 $to_date = $request->getPost('to_date', null) ? $this->CommonPlugin()->date_format($request->getPost('to_date', null), 'yyyy-mm-dd', $GLOBALS['date_display_format']) : date('Y-m-d');
58 $form_get_hl7 = '';
59 $patient_id = $request->getPost('patient_id', null);
60 //pagination
61 $results = $request->getPost('form_results', 100);
62 $results = ($results > 0) ? $results : 100;
63 $current_page = $request->getPost('form_current_page', 1);
64 $end = $current_page*$results;
65 $start = ($end - $results);
66 $new_search = $request->getPost('form_new_search', null);
67 //end pagination
69 if (empty($patient_id)) {
70 $query_pids = '';
71 } else {
72 $pid_arr = explode(',', $patient_id);
73 $query_pids = '(';
74 foreach ($pid_arr as $pid_val) {
75 $query_pids .= "p.pid = ( '";
76 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "' ) or ";
77 $query_pids .= "p.fname like ( '%";
78 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
79 $query_pids .= "p.mname like ( '%";
80 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
81 $query_pids .= "p.lname like ( '%";
82 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
85 $query_pids = trim($query_pids);
86 $query_pids = rtrim($query_pids, 'or');
87 $query_pids .= ') and ';
90 if (empty($form_code)) {
91 $query_codes = '';
92 } else {
93 $query_codes = 'c.id in ( ';
94 foreach ($form_code as $code) {
95 $query_codes .= $code . ",";
98 $query_codes = substr($query_codes, 0, -1);
99 $query_codes .= ') and ';
102 $params = array(
103 'form_from_date' => $from_date,
104 'form_to_date' => $to_date,
105 'form_get_hl7' => $form_get_hl7,
106 'query_codes' => $query_codes,
107 'results' => $results,
108 'current_page' => $current_page,
109 'limit_start' => $start,
110 'limit_end' => $end,
111 'query_pids' => $query_pids,
112 'patient_id' => $patient_id,
115 if ($new_search) {
116 $count = $this->getImmunizationTable()->immunizedPatientDetails($params, 1);
117 } else {
118 $count = $request->getPost('form_count');
119 if ($count == '') {
120 $count = $this->getImmunizationTable()->immunizedPatientDetails($params, 1);
124 $totalpages = ceil($count/$results);
125 $details = $this->getImmunizationTable()->immunizedPatientDetails($params);
126 $rows = array();
127 foreach ($details as $row) {
128 $rows[] = $row;
131 $params['res_count'] = $count;
132 $params['total_pages'] = $totalpages;
134 $codes = $this->getAllCodes($data);
135 if ($codes != '') {
136 $form->get('codes')->setValueOptions($codes);
139 $view = new ViewModel(array(
140 'listenerObject' => $this->listenerObject,
141 'form' => $form,
142 'view' => $rows,
143 'isFormRefresh' => $isFormRefresh,
144 'form_data' => $params,
145 'commonplugin' => $this->CommonPlugin(),
147 return $view;
151 * function getAllCodes
152 * List All Codes in the combobox
154 public function getAllCodes($data)
156 $defaultCode = isset($data['codes']) ? $data['codes'] : '';
157 $res = $this->getImmunizationTable()->codeslist();
158 $i = 0;
159 foreach ($res as $value) {
160 if ($value == $defaultCode) {
161 $select = true;
162 } else {
163 $select = false;
166 $rows[$i] = array (
167 'value' => $value['id'],
168 'label' => $value['NAME'],
169 'selected' => $select,
171 $i++;
174 return $rows;
178 * function getHL7
179 * generating HL7 format
181 public function reportAction()
183 $request = $this->getRequest();
184 $data = $request->getPost();
185 if (isset($data['hl7button'])) {
186 $form_code = isset($data['codes']) ? $data['codes'] : array();
187 $from_date = $request->getPost('from_date', null) ? $this->CommonPlugin()->date_format($request->getPost('from_date', null), 'yyyy-mm-dd', $GLOBALS['date_display_format']) : date('Y-m-d', strtotime(date('Ymd')) - (86400*7));
188 $to_date = $request->getPost('to_date', null) ? $this->CommonPlugin()->date_format($request->getPost('to_date', null), 'yyyy-mm-dd', $GLOBALS['date_display_format']) : date('Y-m-d');
189 $form_get_hl7 = 'true';
190 $patient_id = $request->getPost('patient_id', null);
191 //pagination
192 $results = $request->getPost('form_results', 100);
193 $results = ($results > 0) ? $results : 100;
194 $current_page = $request->getPost('form_current_page', 1);
195 $end = $current_page*$results;
196 $start = ($end - $results);
197 $new_search = $request->getPost('form_new_search', null);
198 //endpagination
200 if (empty($form_code)) {
201 $query_codes = '';
202 } else {
203 $query_codes = 'c.id in ( ';
204 foreach ($form_code as $code) {
205 $query_codes .= $code . ",";
208 $query_codes = substr($query_codes, 0, -1);
209 $query_codes .= ') and ';
212 if (empty($patient_id)) {
213 $query_pids = '';
214 } else {
215 $pid_arr = explode(',', $patient_id);
216 $query_pids = '(';
217 foreach ($pid_arr as $pid_val) {
218 $query_pids .= "p.pid = ( '";
219 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "' ) or ";
220 $query_pids .= "p.fname like ( '%";
221 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
222 $query_pids .= "p.mname like ( '%";
223 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
224 $query_pids .= "p.lname like ( '%";
225 $query_pids .= \Application\Model\ApplicationTable::quoteValue($pid_val) . "%' ) or ";
228 $query_pids = trim($query_pids);
229 $query_pids = rtrim($query_pids, 'or');
230 $query_pids .= ') and ';
233 $params = array(
234 'form_from_date' => $from_date,
235 'form_to_date' => $to_date,
236 'form_get_hl7' => $form_get_hl7,
237 'query_codes' => $query_codes,
238 'results' => $results,
239 'current_page' => $current_page,
240 'limit_start' => $start,
241 'limit_end' => $end,
242 'query_pids' => $query_pids,
245 if ($new_search) {
246 $count = $this->getImmunizationTable()->immunizedPatientDetails($params, 1);
247 } else {
248 $count = $request->getPost('form_count');
249 if ($count == '') {
250 $count = $this->getImmunizationTable()->immunizedPatientDetails($params, 1);
254 $totalpages = ceil($count/$results);
256 $details = $this->getImmunizationTable()->immunizedPatientDetails($params);
257 $rows = array();
258 foreach ($details as $row) {
259 $rows[] = $row;
262 $D = "\r";
263 $nowdate = date('YmdHis');
264 $now = date('YmdGi');
265 $now1 = date('Y-m-d G:i');
266 $filename = "imm_reg_". $now . ".hl7";
268 // GENERATE HL7 FILE
269 if ($form_get_hl7==='true') {
270 $content = '';
271 $patient_id = '';
272 foreach ($rows as $r) {
273 $race_code = $administered_unit_title = $administered_route_title = '';
274 $race_title = $ethnicity = $ethnicity_code = $ethnicity_title = '';
275 $administered_site_code = $guardian_relationship_code = $manufacturer_code = '';
276 $immunization_info_source_code = $email = $race = $units = $manufacturer = '';
277 $information_source = $completion_status = $refusal_reason_code = '';
278 $immunization_refusal = $ordering_provider = $entered_by = $publicity_code_val = '';
279 $publicity_code = $imm_registry_status_code = $protection_indicator = '';
280 $guardiansname = '';
282 if ($r['patientid'] != $patient_id) {
283 $content .= "MSH|^~\&|OPENEMR|" .$r['facility_code']."||NIST Test Iz Reg|$nowdate||".
284 "VXU^V04^VXU_V04|OPENEMR-110316102457117|P|2.5.1|||AL|ER" .
285 "$D" ;
286 $race_code = $this->getImmunizationTable()->getNotes($r['race'], 'race');
287 $race_title = $this->CommonPlugin()->getListtitle('race', $r['race']);
288 $ethnicity_code = $this->getImmunizationTable()->getNotes($r['ethnicity'], 'ethnicity');
289 $ethnicity_title = $this->CommonPlugin()->getListtitle('ethnicity', $r['ethnicity']);
290 $guardianarray = explode(' ', $r['guardiansname']);
291 $guardianname = $guardianarray[1].'^'.$guardianarray[0];
292 if ($r['sex']==='Male') {
293 $r['sex'] = 'M';
296 if ($r['sex']==='Female') {
297 $r['sex'] = 'F';
300 if ($r['status']==='married') {
301 $r['status'] = 'M';
304 if ($r['status']==='single') {
305 $r['status'] = 'S';
308 if ($r['status']==='divorced') {
309 $r['status'] = 'D';
312 if ($r['status']==='widowed') {
313 $r['status'] = 'W';
316 if ($r['status']==='separated') {
317 $r['status'] = 'A';
320 if ($r['status']==='domestic partner') {
321 $r['status'] = 'P';
324 if ($r['email']) {
325 $email = '~^NET^Internet^'.$r['email'];
328 if ($r['race']) {
329 $race = $race_code.'^'.$race_title.'^HL70005';
332 if ($r['ethnicity']) {
333 $ethnicity = $ethnicity_code.'^'.$ethnicity_title.'^CDCREC';
336 $r['ss'] = $r['ss'] ? "~".$r['ss']."^^^MAA^SS" : "";
337 $content .= "PID|" . // [[ 3.72 ]]
338 "1|" . // 1. Set id
339 "|" . // 2. (B)Patient id
340 $r['pubpid']. "^^^MPI&2.16.840.1.113883.19.3.2.1&ISO^MR" . $r['ss']. "|". // 3. (R) Patient indentifier list. TODO: Hard-coded the OID from NIST test.
341 "|" . // 4. (B) Alternate PID
342 $r['patientname']."^^^^L|" . // 5.R. Name
343 $guardianname."|" . // 6. Mather Maiden Name
344 $r['DOB']."|" . // 7. Date, time of birth
345 $r['sex']."|" . // 8. Sex
346 "|" . // 9.B Patient Alias
347 $race. "|" . // 10. Race // Ram change
348 $r['address'] . "^L" . "|" . // 11. Address. Default to address type Mailing Address(M)
349 "|" . // 12. county code
350 "^PRN^PH^^^" . $this->format_phone($r['phone_home']) . "^^".$email."|" . // 13. Phone Home. Default to Primary Home Number(PRN)
351 "^WPN^PH^^^" . $this->format_phone($r['phone_biz']) . "^^|" . // 14. Phone Work.
352 $r['language']."|" . // 15. Primary language
353 $r['status']."|" . // 16. Marital status
354 "|" . // 17. Religion
355 "|" . // 18. patient Account Number
356 "|" . // 19.B SSN Number
357 "|" . // 20.B Driver license number
358 "|" . // 21. Mathers Identifier
359 $ethnicity . "|" . // 22. Ethnic Group
360 "|" . // 23. Birth Plase
361 "|" . // 24. Multiple birth indicator
362 "|" . // 25. Birth order
363 "|" . // 26. Citizenship
364 "|" . // 27. Veteran military status
365 "|" . // 28.B Nationality
366 "|" . // 29. Patient Death Date and Time
367 "|" . // 30. Patient Death Indicator
368 "|" . // 31. Identity Unknown Indicator
369 "|" . // 32. Identity Reliability Code
370 "|" . // 33. Last Update Date/Time
371 "|" . // 34. Last Update Facility
372 "|" . // 35. Species Code
373 "|" . // 36. Breed Code
374 "|" . // 37. Breed Code
375 "|" . // 38. Production Class Code
376 "" . // 39. Tribal Citizenship
377 "$D" ;
379 if ($r['publicity_code']) {
380 $publicity_code_val = $this->getImmunizationTable()->getNotes($r['publicity_code'], 'publicity_code');
381 $publicity_code = $publicity_code_val."^".$r['publicity_code']."^HL70215";
384 $imm_registry_status_code = $this->getImmunizationTable()->getNotes($r['imm_reg_status'], 'immunization_registry_status');
385 $protection_indicator = $this->getImmunizationTable()->getNotes($r['protect_indicator'], 'yesno');
386 if ($publicity_code || $protection_indicator || $imm_registry_status_code) {
387 $content .= "PD1|" . // Patient Additional Demographic Segment
388 "|". // 1. Living Dependancy
389 "|". // 2. Living Arrangement
390 $r['fac_name']."|" . // 3. Patient Primary Facility
391 $r['primary_care_provider_details']."|" . // 4. Patient Primary Care Provider NPI and Provider name
392 "|" . // 5. Student Indicator
393 "|" . // 6. Handicap
394 "|" . // 7. Living Will Code
395 "|" . // 8. Organ Donor Code
396 "|" . // 9. Separate Bill
397 "|" . // 10. Duplicate Patient
398 $publicity_code."|" . // 11. Publicity Code
399 $protection_indicator."|" . // 12. Protection Indicator
400 $r['protection_effective_date']."|" . // 13. Protection Indicator Effective Date[If PD1-12(Protection Indicator) is valued)]
401 "|" . // 14. Place of worship
402 "|" . // 15. Advance Directive Code
403 $imm_registry_status_code."|". // 16. Immunization Registry Status
404 $r['immunization_registry_status_effective_date']."|" . // 17. Immunization Registry Status Effective Date [If the PD1-16 (Registry Status)field is valued.]
405 $r['publicity_code_effective_date']."|" . // 18. Publicity Code Effective Date [If the PD1-11 (Publicity Code)field is valued.]
406 "|". // 19. Military Branch
407 "|". // 20. Military Rank/grade
408 "" . //21. Military Status
409 "$D" ;
412 if ($r['guardiansex']==='male') {
413 $r['guardiansex'] = 'M';
416 if ($r['guardiansex']==='female') {
417 $r['guardiansex'] = 'F';
420 $guardian_relationship_code = $this->getImmunizationTable()->getNotes($r['guardianrelationship'], 'next_of_kin_relationship');
421 if ($r['guardiansname'] && $r['guardianrelationship']) {
422 $content .= "NK1|" . // Nearest of kin
423 "1|" . // Set ID
424 $guardianname."^^^^^L|". // 2. Legal Name of next of kin
425 $guardian_relationship_code."^".$r['guardianrelationship']."^HL70063|" . // 3. Relationship of next of kin with patient
426 $r['guardian_address']."|" . // 4. Address of next of kin
427 "^PRN^PH^^^" . $this->format_phone($r['guardianphone']) . "|" . // 5. Phone Home of next of kin. Default to Primary Home Number(PRN)
428 "^WPN^PH^^^" . $this->format_phone($r['guardianworkphone']) . // 6. Phone Business of next of kin.
429 "|" . //7. Contact Role
430 "|" . //8. Start Date
431 "|" . //9. End Date
432 "|" . // 10. Next of kin/Associated parties job title
433 "|" . //11. Next of kin/Associated parties job code/class
434 "|" . //12. Next of kin/Associated parties employee number
435 "|" . //13. Organization name
436 "|" . //14. Marital status
437 $r['guardiansex']."|" . // 15. Administrative Sex of next of kin
438 "|" . // 16. Date, time of birth of next of kin
439 "|" . //17. Living Dependancy
440 "|" . //18. Ambulatory Status
441 "|" . //19. Citizenship
442 "|" . // 20. Primary Language
443 "|" . //21. Living Arrangement
444 "|" . //22. Publicity Code
445 "|" . //23. Protection Indicator
446 "|" . //24. Student Indicator
447 "|" . // 25. Religion
448 "|" . //26. Mother's Maiden Name
449 "|" . //27. Nationality
450 "|" . //28. Ethnic Group
451 "" . //29. Contact Reason
452 "$D" ;
456 if ($r['completion_status'] == 'Refused') {
457 $r['immunizationid'] = '9999';
460 if ($r['administered_by_id'] == 0 && $r['information_source'] == 'hist_inf_src_unspecified') {
461 $ordering_provider = "";
462 } else if ($r['ordering_provider']) {
463 $ordering_provider = $r['ordering_provider']."^".$r['ordering_provider_name']."^^^^^NIST-AA-1^L";
466 if ($r['created_by']) {
467 $entered_by = $r['created_by']."^".$r['entered_by_name']."^^^^^NIST-AA-1";
470 $content .= "ORC" . // ORC mandatory for RXA
471 "|" .
472 "RE|". //1. Order Control
473 "|" . //2. Placer Order Number
474 $r['immunizationid']."^NDA|" . //3. Filler Order Number 9999 for refusal and identifier for historic immunization
475 "|" . //4. Placer Group Number
476 "|" . //5. Order Status
477 "|" . //6. Response Flag
478 "|" . //7. Quantity/Timing
479 "|" . //8. Parent
480 "|" . //9. Date/time of transaction
481 $entered_by."|" . //10. Entered By
482 "|" . //11. Verified By
483 $ordering_provider."|" . //12. Ordering Provider
484 "|" . //13. Enterer's location
485 "|" . //14. Call Back Phone number
486 "|" . //15. Order effective date/time
487 "|" . //16. Order control code reason
488 "|" . //17. Entering organization
489 "|" . //18. Entering device
490 "|" . //19. Action by
491 "|" . //20. Advanced Beneficiary Notice Code
492 "|" . //21. Ordering Facility Name
493 "|" . //22. Ordering Facility Address
494 "|" . //23. Ordering Facility Phone Number
495 "|" . //24. Ordering Provider Address
496 "|" . //25. Order Status Modifier
497 "|" . //26. Advanced Beneficiary Notice Override reason
498 "|" . //27. Filler's Expected Availability date/time
499 "|" . //28. Confidentiality Code
500 "|" . //29. Order Type
501 "|" . //30. Enterer Authorization Mode
502 "" . //31. Parent Universal Service Identifier
503 "$D" ;
504 $administered_unit_title = $this->CommonPlugin()->getListtitle('drug_units', $r['administered_unit']);
505 $manufacturer_code = $this->getImmunizationTable()->getNotes($r['manufacturer'], 'Immunization_Manufacturer');
506 $immunization_info_source_code = $this->getImmunizationTable()->getNotes($r['information_source'], 'immunization_informationsource');
507 if ($administered_unit_title) {
508 $units = $administered_unit_title.'^'.$administered_unit_title.'^UCUM^^^';
511 if ($r['manufacturer']) {
512 $manufacturer = $manufacturer_code . "^" . $r['manufacturer']. "^" . "MVX";
515 if ($r['information_source']) {
516 $information_source = $immunization_info_source_code."^".$r['information_source']."^NIP001";
519 if ($r['providername'] != null && $r['information_source'] == 'new_immunization_record') {
520 $r['providername'] = $r['users_id']."^".$r['providername'];
523 $refusal_reason_code = $this->getImmunizationTable()->getNotes($r['refusal_reason'], 'immunization_refusal_reason');
524 $completion_status = $this->getImmunizationTable()->getNotes($r['completion_status'], 'Immunization_Completion_Status');
525 if ($r['refusal_reason']) {
526 $completion_status = 'RE' ;
527 $immunization_refusal = $refusal_reason_code."^".$r['refusal_reason']."^NIP002";
530 if ($r['code'] == '998') {
531 $completion_status = 'NA';
534 $content .= "RXA|" .
535 "0|" . // 1. Give Sub-ID Counter
536 "1|" . // 2. Administrattion Sub-ID Counter
537 $r['administered_date']."|" . // 3. Date/Time Start of Administration
538 "|" . // 4. Date/Time End of Administration
539 $r['code']. "^" . $r['immunizationtitle'] . "^" . "CVX" ."|" . // 5. Administration Code(CVX)
540 $r['administered_amount']. "|" . // 6. Administered Amount. TODO: Immunization amt currently not captured in database, default to 999(not recorded)
541 $units."|" . // 7. Administered Units
542 "|" . // 8. Administered Dosage Form
543 $information_source."|" . // 9. Administration Notes
544 $r['providername']."|" . // 10. Administering Provider
545 $r['facility_address']."|" . // 11. Administered-at Location
546 "|" . // 12. Administered Per (Time Unit)
547 "|" . // 13. Administered Strength
548 "|" . // 14. Administered Strength Units
549 $r['lot_number']."|" . // 15. Substance Lot Number
550 $r['expiration_date']."|" . // 16. Substance Expiration Date
551 $manufacturer. "|" . // 17. Substance Manufacturer Name
552 $immunization_refusal."|" . // 18. Substance/Treatment Refusal Reason
553 "|" . // 19.Indication
554 $completion_status."|" . // 20.Completion Status
555 "A" . // 21.Action Code - RXA
556 "$D" ;
557 $administered_route_title = $this->CommonPlugin()->getListtitle('drug_route', $r['route']);
558 $administered_site_code = $this->getImmunizationTable()->getNotes($r['administration_site'], 'immunization_administered_site');
559 if ($r['route_code'] || $r['administration_site']) {
560 $content .= "RXR|".
561 $r['route_code']."^".$administered_route_title."^HL70162|" . //1. Route
562 $administered_site_code."^".$r['administration_site']."^HL70163". // 2. Administration Site
563 "|". // 3. Administration Device
564 "|". // 4. Administration Method
565 "|". // 5. Routing Instruction
566 "" . // 6. Administration Site Modifier
567 "$D" ;
570 $imm_obs_res = $this->getImmunizationTable()->getImmunizationObservationResultsData($r['patientid'], $r['immunizationid']);
571 if (count($imm_obs_res > 0)) {
572 $last_key = 1;
573 foreach ($imm_obs_res as $key_obs => $val_obs) {
574 $criteria_code = $criteria_notes = $obs_value_notes = $obs_value = $obs_method = $date_obs = $value_type = $criteria_value = '';
575 $criteria_code = $this->getImmunizationTable()->getCodes($val_obs['imo_criteria'], 'immunization_observation');
576 $criteria_notes = $this->getImmunizationTable()->getNotes($val_obs['imo_criteria'], 'immunization_observation');
577 $obs_value_notes = $this->getImmunizationTable()->getNotes($val_obs['imo_criteria_value'], 'imm_vac_eligibility_results');
578 $criteria_value = $criteria_code."^".$val_obs['imo_criteria']."^".$criteria_notes;
579 $date_obs = preg_replace('/-/', '', substr($val_obs['imo_date_observation'], 0, 10));
580 if ($val_obs['imo_criteria'] == 'funding_program_eligibility') {
581 $obs_value = $obs_value_notes."^".$val_obs['imo_criteria_value']."^HL70064";
582 $obs_method = "VXC40^per immunization^CDCPHINVS";
583 $value_type = "CE";
584 } else if ($val_obs['imo_criteria'] == 'vaccine_type') {
585 $obs_value = $val_obs['imo_code']."^".$val_obs['imo_codetext']."^".$val_obs['imo_codetype'];
586 $value_type = "CE";
587 } else if ($val_obs['imo_criteria'] == 'disease_with_presumed_immunity') {
588 $value_type = "CE";
589 $obs_value = $val_obs['imo_code']."^".$val_obs['imo_codetext']."^SCT";
592 if ($key_obs > 1) {
593 if ($last_key > 4) {
594 $key_val = $last_key + 1;
595 } else {
596 $key_val = $key_val + 1;
598 } else {
599 $key_val = $key_obs+1;
602 $content .= "OBX|".
603 $key_val."|". //1. Set ID
604 $value_type."|". //2. Value Type
605 $criteria_value."|". //3. Observation Identifier
606 $key_val."|" . //4. Observation Sub ID
607 $obs_value."|". //5. Observation Value
608 "|". //6. Units
609 "|".
610 "|".
611 "|".
612 "|".
613 "F|". //11. Observation Result Status
614 "|".
615 "|".
616 $date_obs."|". //14. Date/Time Of Observation
617 "|".
618 "|".
619 $obs_method. //17. Observation Method
620 "$D";
621 $last_key = $key_val;
623 if ($val_obs['imo_vis_date_published'] != 0) {
624 $value_type = "TS";
625 $criteria_value = "29768-9^Date vaccine information statement published^LN";
626 $obs_value = preg_replace('/-/', '', $val_obs['imo_vis_date_published']);
627 if ($key_obs > 1) {
628 if ($last_key == 4) {
629 $key_val = $last_key + 1;
630 } else {
631 $key_val = $key_val + 1;
633 } else {
634 $key_val = $last_key+1;
637 $content .= "OBX|".
638 $key_val."|". //1. Set ID
639 $value_type."|". //2. Value Type
640 $criteria_value."|". //3. Observation Identifier
641 $last_key."|" . //4. Observation Sub ID
642 $obs_value."|". //5. Observation Value
643 "|". //6. Units
644 "|".
645 "|".
646 "|".
647 "|".
648 "F|". //11. Observation Result Status
649 "|".
650 "|".
651 $date_obs."|". //14. Date/Time Of Observation
652 "|".
653 "|".
654 "". //17. Observation Method
655 "$D";
658 $last_key = $key_val;
659 if ($val_obs['imo_vis_date_presented'] != 0) {
660 $value_type = "TS";
661 $criteria_value = "29769-7^Date vaccine information statement presented^LN";
662 $obs_value = preg_replace('/-/', '', $val_obs['imo_vis_date_presented']);
663 if ($key_obs > 1) {
664 if ($last_key == 5) {
665 $key_val = $last_key + 1;
666 } else {
667 $key_val = $key_val + 1;
669 } else {
670 $key_val = $last_key+1;
673 $content .= "OBX|".
674 $key_val."|". //1. Set ID
675 $value_type."|". //2. Value Type
676 $criteria_value."|". //3. Observation Identifier
677 ($last_key-1)."|" . //4. Observation Sub ID
678 $obs_value."|". //5. Observation Value
679 "|". //6. Units
680 "|".
681 "|".
682 "|".
683 "|".
684 "F|". //11. Observation Result Status
685 "|".
686 "|".
687 $date_obs."|". //14. Date/Time Of Observation
688 "|".
689 "|".
690 "". //17. Observation Method
691 "$D";
694 $last_key = $key_val;
698 $patient_id = $r['patientid'];
701 header('Content-type: text/plain');
702 header('Content-Disposition: attachment; filename=' . $filename);
704 // put the content in the file
705 echo($content);
706 exit;
713 * @param type $ethnicity
714 * @return type
716 public function format_ethnicity($ethnicity)
718 switch ($ethnicity) {
719 case "hisp_or_latin":
720 return ("H^Hispanic or Latino^HL70189");
721 case "not_hisp_or_latin":
722 return ("N^not Hispanic or Latino^HL70189");
723 default: // Unknown
724 return ("U^Unknown^HL70189");
730 * @param type $a
731 * @return type
733 public function tr($a)
735 return (str_replace(' ', '^', $a));
740 * @param type $cvx_code
741 * @return type
743 public function format_cvx_code($cvx_code)
745 if ($cvx_code < 10) {
746 return "0$cvx_code";
749 return $cvx_code;
754 * @param $phone String phone number
755 * @return String formatted phone
757 public function format_phone($phone)
759 $phone = preg_replace("/[^0-9]/", "", $phone);
760 switch (strlen($phone)) {
761 case 7:
762 return $this->tr(preg_replace("/([0-9]{3})([0-9]{4})/", "000 $1$2", $phone));
763 case 10:
764 return $this->tr(preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1 $2$3", $phone));
765 default:
766 return $this->tr("000 0000000");
771 * Table Gateway
773 public function getImmunizationTable()
775 if (!$this->immunizationTable) {
776 $sm = $this->getServiceLocator();
777 $this->immunizationTable = $sm->get('Immunization\Model\ImmunizationTable');
780 return $this->immunizationTable;