|
1 | | -DELETE FROM global_property |
2 | | -WHERE property IN ( |
3 | | - 'emrapi.sqlSearch.activePatients', |
4 | | - 'emrapi.sqlSearch.activePatientsByProvider', |
5 | | - 'emrapi.sqlSearch.patientsToAdmit', |
6 | | - 'emrapi.sqlSearch.admittedPatients', |
7 | | - 'emrapi.sqlSearch.patientsToDischarge', |
8 | | - 'emrapi.sqlSearch.activePatientsByLocation', |
9 | | - 'emrapi.sqlSearch.highRiskPatients', |
10 | | - 'emrapi.sqlSearch.patientsHasPendingOrders' |
11 | | -); |
12 | | - |
13 | | -INSERT INTO global_property (`property`, `property_value`, `description`, `uuid`) |
14 | | -VALUES ('emrapi.sqlSearch.activePatients', |
15 | | - 'select distinct |
16 | | - concat(pn.given_name,\' \', pn.family_name) as name, |
| 1 | +UPDATE global_property SET property_value = "select distinct |
| 2 | + concat(pn.given_name,' ', pn.family_name) as name, |
17 | 3 | pi.identifier as identifier, |
18 | | - concat("",p.uuid) as uuid, |
19 | | - IF(va.value_reference = "Admitted", "true", "false") as hasBeenAdmitted |
| 4 | + concat('',p.uuid) as uuid, |
| 5 | + IF(va.value_reference = \"Admitted\", \"true\", \"false\") as hasBeenAdmitted |
20 | 6 | from visit v |
21 | 7 | join person_name pn on v.patient_id = pn.person_id and pn.voided = 0 and pn.preferred = 1 |
22 | 8 | join patient_identifier pi on v.patient_id = pi.patient_id and pi.voided=0 and pi.preferred = 1 |
23 | 9 | join patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id |
24 | | - join global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid |
| 10 | + join global_property gp on gp.property=\"bahmni.primaryIdentifierType\" and gp.property_value=pit.uuid |
25 | 11 | join person p on p.person_id = v.patient_id and p.voided = 0 |
26 | 12 | join location l on l.uuid = ${visit_location_uuid} and v.location_id = l.location_id |
27 | 13 | left outer join visit_attribute va on va.visit_id = v.visit_id and va.attribute_type_id = ( |
28 | | - select visit_attribute_type_id from visit_attribute_type where name="Admission Status" |
| 14 | + select visit_attribute_type_id from visit_attribute_type where name=\"Admission Status\" |
29 | 15 | ) and va.voided = 0 |
30 | | - where v.date_stopped is null AND v.voided = 0', |
31 | | - 'Sql query to get list of active patients', |
32 | | - uuid() |
33 | | -); |
34 | | - |
35 | | -insert into global_property (`property`, `property_value`, `description`, `uuid`) |
36 | | -values ('emrapi.sqlSearch.activePatientsByProvider',' |
37 | | - select distinct concat(pn.given_name," ", pn.family_name) as name, |
38 | | - pi.identifier as identifier, |
39 | | - concat("",p.uuid) as uuid, |
40 | | - concat("",v.uuid) as activeVisitUuid, |
41 | | - IF(va.value_reference = "Admitted", "true", "false") as hasBeenAdmitted |
42 | | - from |
43 | | - visit v join person_name pn on v.patient_id = pn.person_id and pn.voided = 0 and v.voided=0 |
44 | | - join patient_identifier pi on v.patient_id = pi.patient_id and pi.voided=0 |
45 | | - join patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id |
46 | | - join global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid |
47 | | - join person p on p.person_id = v.patient_id and p.voided=0 |
48 | | - join encounter en on en.visit_id = v.visit_id and en.voided=0 |
49 | | - join encounter_provider ep on ep.encounter_id = en.encounter_id and ep.voided=0 |
50 | | - join provider pr on ep.provider_id=pr.provider_id and pr.retired=0 |
51 | | - join person per on pr.person_id=per.person_id and per.voided=0 |
52 | | - join location l on l.uuid=${visit_location_uuid} and l.location_id = v.location_id |
53 | | - left outer join visit_attribute va on va.visit_id = v.visit_id and va.voided = 0 and va.attribute_type_id = ( |
54 | | - select visit_attribute_type_id from visit_attribute_type where name="Admission Status" |
55 | | - ) |
56 | | - where |
57 | | - v.date_stopped is null and |
58 | | - pr.uuid=${provider_uuid} |
59 | | - order by en.encounter_datetime desc', |
60 | | - 'Sql query to get list of active patients by provider uuid', |
61 | | - uuid() |
62 | | -); |
63 | | - |
64 | | -INSERT INTO global_property (`property`, `property_value`, `description`, `uuid`) |
65 | | -VALUES ('emrapi.sqlSearch.patientsToAdmit', |
66 | | - 'select distinct concat(pn.given_name,\' \', pn.family_name) as name, |
67 | | - pi.identifier as identifier, |
68 | | - concat("",p.uuid) as uuid, |
69 | | - concat("",v.uuid) as activeVisitUuid |
70 | | - from visit v |
71 | | - join person_name pn on v.patient_id = pn.person_id and pn.voided = 0 AND v.voided = 0 |
72 | | - join patient_identifier pi on v.patient_id = pi.patient_id |
73 | | - join patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id |
74 | | - join global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid |
75 | | - join person p on v.patient_id = p.person_id |
76 | | - join encounter e on v.visit_id = e.visit_id |
77 | | - join obs o on e.encounter_id = o.encounter_id and o.voided = 0 |
78 | | - join concept c on o.value_coded = c.concept_id |
79 | | - join concept_name cn on c.concept_id = cn.concept_id |
80 | | - join location l on l.uuid=${visit_location_uuid} and v.location_id = l.location_id |
81 | | - where v.date_stopped is null and cn.name = \'Admit Patient\' and v.visit_id not in (select visit_id |
82 | | - from encounter ie join encounter_type iet |
83 | | - on iet.encounter_type_id = ie.encounter_type |
84 | | - where iet.name = \'ADMISSION\')', |
85 | | - 'Sql query to get list of patients to be admitted', |
86 | | - uuid() |
87 | | -); |
88 | | - |
89 | | -INSERT INTO global_property (`property`, `property_value`, `description`, `uuid`) |
90 | | -VALUES ('emrapi.sqlSearch.admittedPatients', |
91 | | - 'select distinct |
92 | | - concat(pn.given_name," ", pn.family_name) as name, |
93 | | - pi.identifier as identifier, |
94 | | - concat("",p.uuid) as uuid, |
95 | | - concat("",v.uuid) as activeVisitUuid, |
96 | | - IF(va.value_reference = "Admitted", "true", "false") as hasBeenAdmitted |
97 | | - from visit v |
98 | | - join person_name pn on v.patient_id = pn.person_id and pn.voided = 0 |
99 | | - join patient_identifier pi on v.patient_id = pi.patient_id |
100 | | - join patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id |
101 | | - join global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid |
102 | | - join person p on v.patient_id = p.person_id |
103 | | - join visit_attribute va on v.visit_id = va.visit_id and va.value_reference = "Admitted" and va.voided = 0 |
104 | | - join visit_attribute_type vat on vat.visit_attribute_type_id = va.attribute_type_id and vat.name = "Admission Status" |
105 | | - join location l on l.uuid=${visit_location_uuid} and v.location_id = l.location_id |
106 | | - where v.date_stopped is null AND v.voided = 0', |
107 | | - 'Sql query to get list of admitted patients', |
108 | | - uuid() |
109 | | -); |
110 | | - |
111 | | -INSERT INTO global_property (`property`, `property_value`, `description`, `uuid`) |
112 | | -VALUES ('emrapi.sqlSearch.patientsToDischarge', |
113 | | - 'SELECT DISTINCT |
114 | | - concat(pn.given_name, \' \', pn.family_name) AS name, |
115 | | - pi.identifier AS identifier, |
116 | | - concat("", p.uuid) AS uuid, |
117 | | - concat("", v.uuid) AS activeVisitUuid, |
118 | | - IF(va.value_reference = "Admitted", "true", "false") as hasBeenAdmitted |
119 | | - FROM visit v |
120 | | - INNER JOIN person_name pn ON v.patient_id = pn.person_id and pn.voided is FALSE |
121 | | - INNER JOIN patient_identifier pi ON v.patient_id = pi.patient_id and pi.voided is FALSE |
122 | | - INNER JOIN patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id |
123 | | - INNER JOIN global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid |
124 | | - INNER JOIN person p ON v.patient_id = p.person_id |
125 | | - Inner Join (SELECT DISTINCT v.visit_id |
126 | | - FROM encounter en |
127 | | - INNER JOIN visit v ON v.visit_id = en.visit_id AND en.encounter_type = |
128 | | - (SELECT encounter_type_id |
129 | | - FROM encounter_type |
130 | | - WHERE name = "ADMISSION")) v1 on v1.visit_id = v.visit_id |
131 | | - INNER JOIN encounter e ON v.visit_id = e.visit_id |
132 | | - INNER JOIN obs o ON e.encounter_id = o.encounter_id |
133 | | - INNER JOIN concept_name cn ON o.value_coded = cn.concept_id AND cn.concept_name_type = "FULLY_SPECIFIED" AND cn.voided is FALSE |
134 | | - JOIN location l on l.uuid=${visit_location_uuid} and v.location_id = l.location_id |
135 | | - left outer join visit_attribute va on va.visit_id = v.visit_id and va.attribute_type_id = |
136 | | - (select visit_attribute_type_id from visit_attribute_type where name="Admission Status") |
137 | | - LEFT OUTER JOIN encounter e1 ON e1.visit_id = v.visit_id AND e1.encounter_type = ( |
138 | | - SELECT encounter_type_id |
139 | | - FROM encounter_type |
140 | | - WHERE name = "DISCHARGE") AND e1.voided is FALSE |
141 | | - WHERE v.date_stopped IS NULL AND v.voided = 0 AND o.voided = 0 AND cn.name = "Discharge Patient" AND e1.encounter_id IS NULL', |
142 | | - 'Sql query to get list of patients to discharge', |
143 | | - uuid() |
144 | | -); |
145 | | - |
146 | | -INSERT INTO global_property (`property`, `property_value`, `description`, `uuid`) |
147 | | -VALUES ('emrapi.sqlSearch.activePatientsByLocation', |
148 | | - 'select distinct concat(pn.given_name," ", pn.family_name) as name, |
149 | | - pi.identifier as identifier, |
150 | | - concat("",p.uuid) as uuid, |
151 | | - concat("",v.uuid) as activeVisitUuid, |
152 | | - IF(va.value_reference = "Admitted", "true", "false") as hasBeenAdmitted |
153 | | - from |
154 | | - visit v join person_name pn on v.patient_id = pn.person_id and pn.voided = 0 and v.voided=0 |
155 | | - join patient_identifier pi on v.patient_id = pi.patient_id and pi.voided=0 |
156 | | - join patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id |
157 | | - join global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid |
158 | | - join person p on p.person_id = v.patient_id and p.voided=0 |
159 | | - join encounter en on en.visit_id = v.visit_id and en.voided=0 |
160 | | - left outer join location loc on en.location_id = loc.location_id |
161 | | - join encounter_provider ep on ep.encounter_id = en.encounter_id and ep.voided=0 |
162 | | - join provider pr on ep.provider_id=pr.provider_id and pr.retired=0 |
163 | | - join person per on pr.person_id=per.person_id and per.voided=0 |
164 | | - left outer join visit_attribute va on va.visit_id = v.visit_id and va.attribute_type_id = ( |
165 | | - select visit_attribute_type_id from visit_attribute_type where name="Admission Status" |
166 | | - ) |
167 | | - where |
168 | | - v.date_stopped is null and |
169 | | - loc.uuid=${location_uuid} |
170 | | - order by en.encounter_datetime desc', |
171 | | - 'SQL query to get list of active patients by location', |
172 | | - uuid() |
173 | | -); |
174 | | - |
175 | | -INSERT INTO global_property (`property`, `property_value`, `description`, `uuid`) |
176 | | -VALUES ('emrapi.sqlSearch.highRiskPatients', |
177 | | - 'SELECT DISTINCT |
178 | | - concat(pn.given_name, " ", pn.family_name) AS name, |
179 | | - pi.identifier AS identifier, |
180 | | - concat("", p.uuid) AS uuid, |
181 | | - concat("", v.uuid) AS activeVisitUuid, |
182 | | - IF(va.value_reference = "Admitted", "true", "false") AS hasBeenAdmitted |
183 | | -FROM person p |
184 | | - INNER JOIN person_name pn ON pn.person_id = p.person_id |
185 | | - INNER JOIN patient_identifier pi ON pn.person_id = pi.patient_id |
186 | | - INNER JOIN patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id |
187 | | - INNER JOIN global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid |
188 | | - INNER JOIN visit v ON v.patient_id = p.person_id AND v.date_stopped IS NULL AND v.voided = 0 |
189 | | - INNER JOIN (SELECT |
190 | | - max(test_obs.obs_group_id) AS max_id, |
191 | | - test_obs.concept_id, |
192 | | - test_obs.person_id |
193 | | - FROM obs test_obs |
194 | | - INNER JOIN concept c ON c.concept_id = test_obs.concept_id AND test_obs.voided = 0 |
195 | | - INNER JOIN concept_name cn |
196 | | - ON c.concept_id = cn.concept_id AND cn.concept_name_type = "FULLY_SPECIFIED" AND |
197 | | - cn.name IN (${testName}) |
198 | | - GROUP BY test_obs.person_id, test_obs.concept_id) AS tests ON tests.person_id = v.patient_id |
199 | | - INNER JOIN obs abnormal_obs |
200 | | - ON abnormal_obs.obs_group_id = tests.max_id AND abnormal_obs.value_coded = 1 AND abnormal_obs.voided = 0 |
201 | | - INNER JOIN concept abnormal_concept ON abnormal_concept.concept_id = abnormal_obs.concept_id |
202 | | - INNER JOIN concept_name abnormal_concept_name |
203 | | - ON abnormal_concept.concept_id = abnormal_concept_name.concept_id AND |
204 | | - abnormal_concept_name.concept_name_type = "FULLY_SPECIFIED" AND |
205 | | - abnormal_concept_name.name IN ("LAB_ABNORMAL") |
206 | | - LEFT OUTER JOIN visit_attribute va ON va.visit_id = v.visit_id AND va.attribute_type_id = |
207 | | - (SELECT visit_attribute_type_id |
208 | | - FROM visit_attribute_type |
209 | | - WHERE name = "Admission Status")', |
210 | | - 'SQL QUERY TO get LIST of patients with high risk', |
211 | | - uuid() |
212 | | -); |
213 | | - |
214 | | - |
215 | | -INSERT INTO global_property (`property`, `property_value`, `description`, `uuid`) |
216 | | -VALUES ('emrapi.sqlSearch.patientsHasPendingOrders', |
217 | | - 'select distinct |
218 | | - concat(pn.given_name, " ", pn.family_name) as name, |
219 | | - pi.identifier as identifier, |
220 | | - concat("",p.uuid) as uuid, |
221 | | - concat("",v.uuid) as activeVisitUuid, |
222 | | - IF(va.value_reference = "Admitted", "true", "false") as hasBeenAdmitted |
223 | | - from visit v |
224 | | - join person_name pn on v.patient_id = pn.person_id and pn.voided = 0 |
225 | | - join patient_identifier pi on v.patient_id = pi.patient_id |
226 | | - join patient_identifier_type pit on pi.identifier_type = pit.patient_identifier_type_id |
227 | | - join global_property gp on gp.property="bahmni.primaryIdentifierType" and gp.property_value=pit.uuid |
228 | | - join person p on p.person_id = v.patient_id |
229 | | - join orders on orders.patient_id = v.patient_id |
230 | | - join order_type on orders.order_type_id = order_type.order_type_id and order_type.name != "Order" and order_type.name != "Drug Order" |
231 | | - left outer join visit_attribute va on va.visit_id = v.visit_id and va.voided = 0 and va.attribute_type_id = |
232 | | - (select visit_attribute_type_id from visit_attribute_type where name="Admission Status") |
233 | | - where v.date_stopped is null AND v.voided = 0 and order_id not in |
234 | | - (select obs.order_id |
235 | | - from obs |
236 | | - where person_id = pn.person_id and order_id = orders.order_id)', |
237 | | - 'Sql query to get list of patients who has pending orders', |
238 | | - uuid() |
239 | | -); |
240 | | - |
| 16 | + where v.date_stopped is null AND v.voided = 0;" |
| 17 | +where property = "emrapi.sqlSearch.activePatients"; |
241 | 18 |
|
0 commit comments