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\Model
;
23 use Zend\Db\TableGateway\TableGateway
;
24 use Zend\Db\TableGateway\AbstractTableGateway
;
25 use Zend\Db\Adapter\Adapter
;
26 use Zend\Db\ResultSet\ResultSet
;
27 use Zend\Db\Sql\Select
;
28 use Zend\InputFilter\Factory
as InputFactory
;
29 use Zend\InputFilter\InputFilter
;
30 use Zend\InputFilter\InputFilterAwareInterface
;
31 use Zend\InputFilter\InputFilterInterface
;
33 use \Application\Model\ApplicationTable
;
34 class ImmunizationTable
extends AbstractTableGateway
37 protected $applicationTable;
39 public function __construct(TableGateway
$tableGateway)
41 $this->tableGateway
= $tableGateway;
42 $adapter = \Zend\Db\TableGateway\Feature\GlobalAdapterFeature
::getStaticAdapter();
43 $this->adapter
= $adapter;
44 $this->resultSetPrototype
= new ResultSet();
45 $this->applicationTable
= new ApplicationTable
;
49 * function codeslist()
52 public function codeslist()
54 $sql = "SELECT id, CONCAT('CVX:',CODE) AS NAME FROM codes LEFT JOIN code_types ct ON codes.code_type = ct.ct_id WHERE ct.ct_key='CVX' ORDER BY NAME";
55 $result = $this->applicationTable
->zQuery($sql);
60 * function immunized patient details
61 * @param type $form_data
64 public function immunizedPatientDetails($form_data,$getCount=null)
66 $query_data = array();
67 $query_codes = $form_data['query_codes'];
68 $from_date = $form_data['form_from_date'];
69 $to_date = $form_data['form_to_date'];
70 $form_get_hl7 = $form_data['form_get_hl7'];
71 $query_pids = $form_data['query_pids'];
76 "i.patient_id AS patientid, " .
79 if ($form_get_hl7==='true') {
81 "DATE_FORMAT(p.DOB,'%Y%m%d') AS DOB, ".
83 "CONCAT(IF(p.street IS NULL,'',p.street), '^^', IF(p.city IS NULL,'',p.city), '^', IF(p.state IS NULL,'',p.state), '^', IF(p.postal_code IS NULL,'',p.postal_code) ,'^', IF(l.option_id IS NULL,'',l.notes)) AS address, ".
93 "p.guardianrelationship, ".
96 "p.guardianworkphone, ".
100 "p.protect_indicator, ".
101 "DATE_FORMAT(p.prot_indi_effdate,'%Y%m%d') AS protection_effective_date, ".
102 "DATE_FORMAT(p.publ_code_eff_date,'%Y%m%d') AS publicity_code_effective_date, ".
103 "DATE_FORMAT(p.imm_reg_stat_effdate,'%Y%m%d') AS immunization_registry_status_effective_date, ".
104 "CONCAT(IF(p.guardianaddress IS NULL,'',p.guardianaddress), '^', '','^',IF(p.guardiancity IS NULL,'',p.guardiancity), '^', IF(p.guardianstate IS NULL,'',p.guardianstate), '^', IF(p.guardianpostalcode IS NULL,'',p.guardianpostalcode) ,'^', IF(l.option_id IS NULL,'',l.notes),'^','L', '^', '', '^', '', '^', '') AS guardian_address, ".
109 "DATE_FORMAT(i.vis_date,'%Y%m%d') AS immunizationdate, ".
110 "DATE_FORMAT(i.administered_date,'%Y%m%d') AS administered_date, ".
111 "i.lot_number AS lot_number, ".
112 "i.manufacturer AS manufacturer, ".
113 "i.administration_site, ".
114 "CONCAT(IF(p.lname IS NULL,'',p.lname), '^', p.fname , '^', IF(p.mname IS NULL,'',p.mname)) AS patientname, ".
116 "f.name AS fac_name, ".
118 "i.administered_by_id,".
120 "CONCAT (IF(u.npi IS NULL,'',u.npi),'^',u.lname,'^',u.fname,'^',IF(u.mname IS NULL,'',u.mname)) as primary_care_provider_details, ".
121 "l.notes AS country_code, ".
122 "l1.notes AS route_code, ".
124 "CONCAT(u.lname,'^',u.fname,'^',IF(u.mname IS NULL,'',u.mname),'^','','^',IF(u.title IS NULL,'',u.title),'^','','^','','^','TX','^','L','^','','^','','^','','^','','^','') AS providername, ".
125 "CONCAT(f.id,'^',IF(f.street IS NULL,'',SUBSTRING(f.`street`,1,20)),'^',IF(f.`city` IS NULL,'',f.`city`),'^',IF(f.`state` IS NULL,'',f.`state`),'^',IF(f.`postal_code` IS NULL,'',f.`postal_code`),'^',IF(f.`country_code` IS NULL,'',f.`country_code`)) AS facility_address, ".
126 "u.id AS users_id, ".
128 "i.ordering_provider, ".
129 "CONCAT(u1.lname,'^',u1.fname,'^',IF(u1.mname IS NULL,'',u1.mname)) AS entered_by_name, ".
130 "CONCAT(u2.lname,'^',u2.fname,'^',IF(u2.mname IS NULL,'',u2.mname)) AS ordering_provider_name, ".
131 "i.administered_by_id,i.note,i.information_source,DATE_FORMAT(i.expiration_date,'%Y%m%d') AS expiration_date,i.refusal_reason,i.completion_status,";
133 $query .= "CONCAT(IF(p.fname IS NULL,'',p.fname),' ',IF(p.mname IS NULL,'',p.mname),' ',IF(p.lname IS NULL,'',p.lname)) AS patientname, ".
134 "i.vis_date AS immunizationdate, " ;
137 "i.id AS immunizationid, c.code_text_short AS immunizationtitle, c.code_text,i.amount_administered AS administered_amount, i.amount_administered_unit AS administered_unit ".
138 "FROM (immunizations AS i, patient_data AS p, codes AS c) ".
139 "LEFT JOIN code_types ct ON c.code_type = ct.ct_id ".
140 "LEFT JOIN users AS u ON i.administered_by_id = u.id ".
141 "LEFT JOIN facility AS f ON f.id = u.facility_id ".
142 "LEFT JOIN list_options l ON l.option_id = p.country_code AND l.list_id='country' ".
143 "LEFT JOIN list_options l1 ON l1.option_id = i.route AND l1.list_id='drug_route' ".
144 "LEFT JOIN list_options l2 ON l2.option_id = p.guardiancountry AND l2.list_id='country' ".
145 "LEFT JOIN users AS u1 ON i.created_by = u1.id ".
146 "LEFT JOIN users AS u2 ON i.ordering_provider = u2.id ".
148 "ct.ct_key='CVX' and ";
150 $query .= "i.vis_date >= ? " ;
151 $query_data[] = $from_date;
153 if($from_date!=0 and $to_date!=0) {
157 $query .= "i.vis_date <= ? ";
158 $query_data[] = $to_date;
160 if($from_date!=0 or $to_date!=0) {
163 $query .= "i.patient_id=p.pid and ".
164 add_escape_custom($query_codes) .
166 "i.cvx_code = c.code ORDER BY i.patient_id, i.id";
169 $result = $this->applicationTable
->zQuery($query,$query_data);
170 $resCount = $result->count();
174 $query .= " LIMIT ".\Application\Plugin\CommonPlugin
::escapeLimit($form_data['limit_start']).",".\Application\Plugin\CommonPlugin
::escapeLimit($form_data['results']);
175 $result = $this->applicationTable
->zQuery($query,$query_data);
179 public function getNotes($option_id,$list_id)
189 $result = $this->applicationTable
->zQuery($query,array($list_id,$option_id,1));
190 $res_cur = $result->current();
192 return $res_cur['notes'];
196 * function getImmunizationObservationResultsData function to get immunization observation data
199 * @return type Array $val
201 public function getImmunizationObservationResultsData($pid,$id)
206 immunization_observation
209 $result = $this->applicationTable
->zQuery($sql, array($pid,$id));
210 foreach($result as $row) {
216 public function getCodes($option_id,$list_id)
226 $result = $this->applicationTable
->zQuery($query,array($list_id,$option_id,1));
227 $res_cur = $result->current();
229 $codes = explode(":",$res_cur['codes']);