Skip to content

Commit d573e61

Browse files
committed
scanning more tables for updates
1 parent 6ace7c8 commit d573e61

20 files changed

Lines changed: 223 additions & 67 deletions

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.openmrs.module</groupId>
66
<artifactId>nigeriaemr</artifactId>
7-
<version>1.6.0-SNAPSHOT</version>
7+
<version>1.6.1-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>nigeriaemr-api</artifactId>

api/src/main/java/org/openmrs/module/nigeriaemr/api/dao/NigeriaEncounterDAO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public interface NigeriaEncounterDAO extends EncounterDAO {
1818

1919
List<Encounter> getEncountersByEncounterTypeIds(Patient patient, Date fromDate, Date toDate,
2020
List<Integer> encounterTypeIds, boolean asc, int size) throws DAOException;
21+
22+
List<Encounter> getEncountersByEncounterIds(List<Integer> encounterIds) throws DAOException;
2123
}

api/src/main/java/org/openmrs/module/nigeriaemr/api/dao/NigeriaObsDAO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ Obs getHighestObsByConcept(Person person, Concept concept, Date from, Date to, b
3434
List<Obs> getObsByConcept(List<Concept> concept, List<Integer> obsList) throws DAOException;
3535

3636
List<Concept> getConcepts(List<Integer> conceptIds, boolean includeVoided) throws DAOException;
37+
38+
List<Integer> getPatientsByObsDate(Date from, Date to, List<String> patientIds, boolean includeVoided)
39+
throws DAOException;
40+
41+
List<Integer> getPatientEncounterIdsByDate(Integer id, Date fromDate, Date toDate) throws DAOException;
3742
}

api/src/main/java/org/openmrs/module/nigeriaemr/api/dao/NigeriaPatientDAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ List<Integer> getPatientsFromStringIds(List<String> patientIds, Date fromDate, D
2323

2424
List<Integer> getPatientIdsByEncounterDate(Date fromDate, Date toDate, boolean includeVoided) throws DAOException;
2525

26-
List<Integer> getPatientIdsByIdentifiers(List<String> identifiers, Date fromDate, Date toDate) throws DAOException;
26+
List<String> getPatientIdsByIdentifiers(List<String> identifiers, Date fromDate, Date toDate) throws DAOException;
2727

2828
List<Patient> getPatientsByEncounterDate(int startIndex, int endIndex, Date lastEncounterDate, boolean includeVoided)
2929
throws DAOException;

api/src/main/java/org/openmrs/module/nigeriaemr/api/dao/impl/NigeriaEncounterDAOImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,10 @@ public List<Encounter> getEncountersByEncounterTypeIds(Patient patient, Date fro
120120
return criteria.list();
121121
}
122122

123+
@Override
124+
public List<Encounter> getEncountersByEncounterIds(List<Integer> encounterIds) throws DAOException {
125+
Criteria criteria = getSession().createCriteria(Encounter.class);
126+
criteria.add(Restrictions.in("encounterId", encounterIds));
127+
return criteria.list();
128+
}
123129
}

api/src/main/java/org/openmrs/module/nigeriaemr/api/dao/impl/NigeriaObsDAOImpl.java

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.ArrayList;
1717
import java.util.Date;
1818
import java.util.List;
19+
import java.util.stream.Collectors;
1920

2021
public class NigeriaObsDAOImpl extends HibernateObsDAO implements NigeriaObsDAO {
2122

@@ -235,4 +236,104 @@ public List<Concept> getConcepts(List<Integer> conceptIds, boolean includeVoided
235236
criteria.add(Restrictions.in("conceptId", conceptIds));
236237
return criteria.list();
237238
}
239+
240+
@Override
241+
public List<Integer> getPatientsByObsDate(Date from, Date to, List<String> patientIds, boolean includeVoided)
242+
throws DAOException {
243+
244+
String query = getQueryString(from, to, patientIds, includeVoided, "patient", "patient_id", false) + " UNION ALL "
245+
+ getQueryString(from, to, patientIds, includeVoided, "person", "person_id", false) + " UNION ALL "
246+
+ getQueryString(from, to, patientIds, includeVoided, "person_address", "person_id", false) + " UNION ALL "
247+
+ getQueryString(from, to, patientIds, includeVoided, "patient_identifier", "patient_id", false)
248+
+ " UNION ALL "
249+
+ getQueryString(from, to, patientIds, includeVoided, "patient_program", "patient_id", false)
250+
+ " UNION ALL "
251+
+ getQueryString(from, to, patientIds, includeVoided, "person_attribute", "person_id", false)
252+
+ " UNION ALL " + getQueryString(from, to, patientIds, includeVoided, "person_name", "person_id", false)
253+
+ " UNION ALL " + getQueryString(from, to, patientIds, includeVoided, "obs", "person_id", true)
254+
+ " UNION ALL " + getQueryString(from, to, patientIds, includeVoided, "encounter", "patient_id", false)
255+
+ " UNION ALL " + getQueryString(from, to, patientIds, includeVoided, "visit", "patient_id", false);
256+
257+
SQLQuery sql = getSession().createSQLQuery(query);
258+
if (from != null)
259+
sql.setDate("from", from);
260+
if (to != null)
261+
sql.setDate("to", to);
262+
if (patientIds != null && patientIds.size() > 0)
263+
sql.setParameterList("patientIds", patientIds);
264+
265+
List<Integer> ret = sql.list();
266+
267+
return ret.stream().distinct().collect(Collectors.toList());
268+
}
269+
270+
private String getQueryString(Date from, Date to, List<String> patientIds, boolean includeVoided, String tableName,
271+
String fieldName, boolean noDateChanged) {
272+
StringBuilder query = new StringBuilder();
273+
if (noDateChanged) {
274+
query.append(" SELECT ").append(tableName).append(".").append(fieldName).append(" AS patient_id FROM ")
275+
.append(tableName).append(" WHERE TRUE");
276+
if (from != null)
277+
query.append(" AND ").append(tableName).append(".date_created >= :from ");
278+
if (to != null)
279+
query.append(" AND ").append(tableName).append(".date_created <= :to ");
280+
} else {
281+
query.append(" SELECT ").append(tableName).append(".").append(fieldName).append(" AS patient_id FROM ")
282+
.append(tableName).append(" WHERE TRUE");
283+
if (from != null)
284+
query.append(" AND (").append(tableName).append(".date_created >= :from OR ").append(tableName)
285+
.append(".date_created >= :from) ");
286+
if (to != null)
287+
query.append(" AND (").append(tableName).append(".date_changed <= :to OR ").append(tableName)
288+
.append(".date_changed <= :to) ");
289+
}
290+
if (!includeVoided)
291+
query.append(" AND ").append(tableName).append(".voided = FALSE ");
292+
if (patientIds != null && patientIds.size() > 0)
293+
query.append(" AND ").append(tableName).append(".").append(fieldName).append(" IN (:patientIds) ");
294+
return query.toString();
295+
}
296+
297+
@Override
298+
public List<Integer> getPatientEncounterIdsByDate(Integer id, Date fromDate, Date toDate) throws DAOException {
299+
String query = "SELECT encounter_id FROM obs WHERE voided = false ";
300+
if (id != null)
301+
query += " AND person_id = :person_id";
302+
if (fromDate != null)
303+
query += " AND date_created >= :fromDate";
304+
if (toDate != null)
305+
query += " AND date_created <= :toDate";
306+
307+
query += " UNION ALL ";
308+
309+
query += "SELECT encounter_id FROM encounter WHERE voided = false ";
310+
if (id != null)
311+
query += " AND patient_id = :person_id";
312+
if (fromDate != null)
313+
query += " AND (date_created >= :fromDate or date_changed >= :fromDate)";
314+
if (toDate != null)
315+
query += " AND (date_created <= :toDate or date_changed >= :toDate)";
316+
317+
query += " UNION ALL ";
318+
319+
query += "SELECT encounter.encounter_id from encounter, visit WHERE visit.visit_id = encounter.visit_id AND visit.voided = FALSE AND encounter.voided = FALSE ";
320+
if (id != null)
321+
query += " AND encounter.patient_id = :person_id";
322+
if (fromDate != null)
323+
query += " AND (visit.date_created >= :fromDate OR visit.date_changed >= :fromDate)";
324+
if (toDate != null)
325+
query += " AND (visit.date_created <= :toDate OR visit.date_changed >= :toDate)";
326+
327+
SQLQuery sql = getSession().createSQLQuery(query);
328+
if (fromDate != null)
329+
sql.setDate("fromDate", fromDate);
330+
if (toDate != null)
331+
sql.setDate("toDate", toDate);
332+
if (id != null)
333+
sql.setInteger("person_id", id);
334+
335+
List<Integer> ret = sql.list();
336+
337+
return ret.stream().distinct().collect(Collectors.toList());
338+
}
238339
}

api/src/main/java/org/openmrs/module/nigeriaemr/api/dao/impl/NigeriaPatientDAOImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ public List<Integer> getPatientIdsByEncounterDate(Date fromDate, Date toDate, bo
134134
}
135135

136136
@Override
137-
public List<Integer> getPatientIdsByIdentifiers(List<String> identifiers, Date fromDate, Date toDate)
138-
throws DAOException {
137+
public List<String> getPatientIdsByIdentifiers(List<String> identifiers, Date fromDate, Date toDate) throws DAOException {
139138
String query = "SELECT patient_identifier.patient_id FROM patient_identifier ";
140139
if (fromDate != null || toDate != null)
141140
query += " LEFT JOIN patient ON patient.patient_id = patient_identifier.patient_id";

api/src/main/java/org/openmrs/module/nigeriaemr/api/service/NigeriaEncounterService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ List<Encounter> getEncountersByEncounterTypeIds(Patient patient, Date fromDate,
2727
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
2828
Encounter getLastEncounterByEncounterTypeIds(Patient patient, Date fromDate, Date toDate, List<Integer> encounterTypeIds)
2929
throws APIException;
30+
31+
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
32+
List<Encounter> getEncountersByEncounterIds(List<Integer> encounterIds) throws APIException;
3033
}

api/src/main/java/org/openmrs/module/nigeriaemr/api/service/NigeriaObsService.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,38 @@ List<Obs> getObsByEncounterTypes(List<Integer> ObsIds, List<Integer> encounterTy
2626
throws APIException;
2727

2828
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
29-
public Obs getLastObsByConceptId(Person person, Concept concept, Date from, Date to, boolean includeVoided)
30-
throws APIException;
29+
Obs getLastObsByConceptId(Person person, Concept concept, Date from, Date to, boolean includeVoided) throws APIException;
3130

3231
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
33-
public Obs getFirstObsByConceptId(Person person, Concept concept, Date from, Date to, boolean includeVoided)
32+
Obs getFirstObsByConceptId(Person person, Concept concept, Date from, Date to, boolean includeVoided)
3433
throws APIException;
3534

3635
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
37-
public Obs getHighestObsByConcept(Person person, Concept concept, Date from, Date to, boolean includeVoided)
36+
Obs getHighestObsByConcept(Person person, Concept concept, Date from, Date to, boolean includeVoided)
3837
throws APIException;
3938

4039
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
41-
public Obs getObsbyValueCoded(Concept concept, Concept valueCoded, List<Integer> obsList) throws APIException;
40+
Obs getObsbyValueCoded(Concept concept, Concept valueCoded, List<Integer> obsList) throws APIException;
41+
42+
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
43+
Obs getLastObsByConcept(Concept concept, List<Integer> obsList) throws APIException;
4244

4345
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
44-
public Obs getLastObsByConcept(Concept concept, List<Integer> obsList) throws APIException;
46+
List<Obs> getObsByConcept(Concept concept, List<Integer> obsList) throws APIException;
4547

4648
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
47-
public List<Obs> getObsByConcept(Concept concept, List<Integer> obsList) throws APIException;
49+
List<Obs> getObsByConcept(List<Concept> concept, List<Integer> obsList) throws APIException;
4850

4951
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
50-
public List<Obs> getObsByConcept(List<Concept> concept, List<Integer> obsList) throws APIException;
52+
List<Obs> getObsByVisitDate(Date visitDate, List<Integer> obsIds, boolean includeVoided) throws APIException;
5153

5254
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
53-
public List<Obs> getObsByVisitDate(Date visitDate, List<Integer> obsIds, boolean includeVoided) throws APIException;
55+
List<Concept> getConcepts(List<Integer> conceptIds, boolean includeVoided) throws APIException;
56+
57+
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
58+
List<Integer> getPatientsByObsDate(Date from, Date to, List<String> patientIds, boolean includeVoided)
59+
throws APIException;
5460

5561
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
56-
public List<Concept> getConcepts(List<Integer> conceptIds, boolean includeVoided) throws APIException;
62+
List<Integer> getPatientEncounterIdsByDate(Integer id, Date fromDate, Date toDate) throws APIException;
5763
}

api/src/main/java/org/openmrs/module/nigeriaemr/api/service/NigeriaPatientService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ public interface NigeriaPatientService extends PatientService {
3737
String getPatientIdentifier(Patient patient, PatientIdentifierType patientIdentifierType) throws APIException;
3838

3939
@Authorized(NigeriaemrConfig.MODULE_PRIVILEGE)
40-
List<Integer> getPatientIdsByIdentifiers(List<String> identifiers, Date fromDate, Date toDate) throws APIException;
40+
List<String> getPatientIdsByIdentifiers(List<String> identifiers, Date fromDate, Date toDate) throws APIException;
4141

4242
}

0 commit comments

Comments
 (0)