Permalink
Browse files

PTM-88 : Functionality to exclude non-matching patients

  • Loading branch information...
Lahiru-J committed Aug 22, 2017
1 parent a327c3e commit b1f3fccf5151ee10f4d2282e62c88fa8b93dcca4
Showing with 1,728 additions and 105 deletions.
  1. +369 −80 api/src/main/java/org/openmrs/module/patientmatching/MatchingReportUtils.java
  2. +77 −0 api/src/main/java/org/openmrs/module/patientmatching/RejectedPatientPair.java
  3. +63 −0 api/src/main/java/org/openmrs/module/patientmatching/RejectedPatientPairUtils.java
  4. +8 −0 api/src/main/java/org/openmrs/module/patientmatching/Report.java
  5. +32 −0 api/src/main/java/org/openmrs/module/patientmatching/db/RejectedPatientPairDAO.java
  6. +78 −0 ...rc/main/java/org/openmrs/module/patientmatching/db/hibernate/HibernateRejectedPatientPairDAO.java
  7. +39 −13 api/src/main/java/org/regenstrief/linkage/io/OpenMRSReader.java
  8. +1 −1 api/src/main/java/org/regenstrief/linkage/io/ReaderProvider.java
  9. +21 −0 api/src/main/resources/ConfigurationEntry.hbm.xml
  10. +18 −0 api/src/main/resources/MatchingRecord.hbm.xml
  11. +14 −0 api/src/main/resources/MatchingRecordAttribute.hbm.xml
  12. +23 −0 api/src/main/resources/PatientMatchingConfiguration.hbm.xml
  13. +11 −0 api/src/main/resources/RejectedPatientPair.hbm.xml
  14. +33 −0 api/src/main/resources/Report.hbm.xml
  15. +18 −0 api/src/main/resources/ReportGenerationStep.hbm.xml
  16. +16 −0 api/src/main/resources/patient-matching-hibernate.cfg.xml
  17. +375 −0 api/src/test/java/org/openmrs/module/patientmatching/MatchingReportUtilsTest.java
  18. +68 −0 api/src/test/java/org/regenstrief/linkage/io/OpenMRSReaderTest.java
  19. +146 −0 api/src/test/resources/PatientMatchingTestDataSet.xml
  20. +59 −0 api/src/test/resources/TestingApplicationContext.xml
  21. +15 −0 api/src/test/resources/patient-matching-hibernate.cfg.xml
  22. +5 −0 omod/pom.xml
  23. +63 −1 omod/src/main/java/org/openmrs/module/patientmatching/web/dwr/DWRMatchingConfigUtilities.java
  24. +11 −0 omod/src/main/resources/RejectedPatientPair.hbm.xml
  25. +6 −1 omod/src/main/resources/config.xml
  26. +6 −0 omod/src/main/resources/moduleApplicationContext.xml
  27. +31 −0 omod/src/main/resources/sqldiff.xml
  28. +5 −2 omod/src/main/webapp/dupesList.jsp
  29. +37 −7 omod/src/main/webapp/reportForm.jsp
  30. +42 −0 omod/src/test/java/org/openmrs/module/patientmatching/web/dwr/DWRMatchingConfigUtilitiesTest.java
  31. +38 −0 omod/src/test/resources/PatientTestDataSet.xml

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,77 @@
package org.openmrs.module.patientmatching;
import org.openmrs.Patient;
import java.io.Serializable;
/**
* This class holds the non-matching patient pairs which were stated by the reviewer
*/
public class RejectedPatientPair implements Serializable {
private Patient patient1;
private Patient patient2;
/**
* Creates a RejectedPatientPair with given patients.
* @param patient1 Patient 1
* @param patient2 Patient 2
*/
public RejectedPatientPair(Patient patient1, Patient patient2) {
// Always assign the patient having minimum id to the the variable patient1 as a convention.
if (patient1.getPatientId() < patient2.getPatientId()) {
this.patient1 = patient1;
this.patient2 = patient2;
} else {
this.patient1 = patient2;
this.patient2 = patient1;
}
}
public RejectedPatientPair() {
}
public Patient getPatient1() {
return patient1;
}
public Patient getPatient2() {
return patient2;
}
public void setPatient1(Patient patient1) {
this.patient1 = patient1;
}
public void setPatient2(Patient patient2) {
this.patient2 = patient2;
}
@Override
public int hashCode() {
int result = 1;
result = 31 * result + patient1.getPatientId();
result = 31 * result + patient2.getPatientId();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof RejectedPatientPair)) {
return false;
}
RejectedPatientPair rp = (RejectedPatientPair) obj;
return (rp.patient1 == patient1 && rp.patient2 == patient2)
|| (rp.patient1 == patient2 && rp.patient2 == patient1);
}
}
@@ -0,0 +1,63 @@
package org.openmrs.module.patientmatching;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Utility class to perform various task related to the {@link RejectedPatientPair}
*/
public class RejectedPatientPairUtils {
/**
* This method will create a Set<Long> of patient IDs.
* For example if there are non-matching pairs like (20,30), (20,45), (20, 89), and (76,56)
* This method will create set(20,30,45,89) and set(76,56)
*
* @param pairs list of non-matching patient pairs
* @return a List of patient ID sets
*/
public static List<Set<Long>> getRejectedPatientPairSets(List<RejectedPatientPair> pairs) {
if (pairs == null || pairs.isEmpty()) {
return null;
}
Set<Set<Long>> setRejectedPatientPairs = new HashSet<Set<Long>>();
for (int i = 0; i < pairs.size(); i++) {
Set<Long> setPairs = new HashSet<Long>();
// Add the first appearing RejectedPatientPair's ids to the set
RejectedPatientPair rp = pairs.get(i);
setPairs.add(new Long(rp.getPatient1().getPatientId()));
setPairs.add(new Long(rp.getPatient2().getPatientId()));
for (int j = i + 1; j < pairs.size(); j++) {
// From the two RejectedPatientPairs if there is at least one common patient
if (pairs.get(i).getPatient1() == pairs.get(j).getPatient1()
|| pairs.get(i).getPatient1() == pairs.get(j).getPatient2()
|| pairs.get(i).getPatient2() == pairs.get(j).getPatient1()
|| pairs.get(i).getPatient2() == pairs.get(j).getPatient2()) {
setPairs.add(new Long(pairs.get(j).getPatient1().getPatientId()));
setPairs.add(new Long(pairs.get(j).getPatient2().getPatientId()));
}
}
boolean isASubset = false;
for (Set<Long> existingSet : setRejectedPatientPairs) {
if (isASubset = existingSet.containsAll(setPairs)) {
break;
}
}
if (!isASubset) {
setRejectedPatientPairs.add(setPairs);
}
}
return new ArrayList<Set<Long>>(setRejectedPatientPairs);
}
}
@@ -73,4 +73,12 @@ public void setUsedConfigurationList(Set<PatientMatchingConfiguration> usedConfi
public void setReportGenerationSteps(Set<ReportGenerationStep> reportGenerationSteps){
this.reportGenerationSteps = reportGenerationSteps;
}
public void addMatchingRecord(MatchingRecord matchingRecord){this.matchingRecordSet.add(matchingRecord);}
public void clearReportGenerationSteps(){this.reportGenerationSteps.clear();}
public void addReportGenerationStep(ReportGenerationStep reportGenerationStep){
this.reportGenerationSteps.add(reportGenerationStep);
}
}
@@ -0,0 +1,32 @@
package org.openmrs.module.patientmatching.db;
import org.openmrs.module.patientmatching.RejectedPatientPair;
import java.util.List;
/**
* The DAO class to access database objects
*/
public interface RejectedPatientPairDAO {
/**
* Persists the patient pair to the database
*
* @param pair {@link RejectedPatientPair} which should be excluded from report generation process
*/
void saveRejectedPatientPair(RejectedPatientPair pair);
/**
* Persists list of {@link RejectedPatientPair} to the database
*
* @param pairs list of {@link RejectedPatientPair}
*/
void saveRejectedPatientPairList(List<RejectedPatientPair> pairs);
/**
* Retrieve the {@link RejectedPatientPair} list
*
* @return a list of {@link RejectedPatientPair}
*/
List<RejectedPatientPair> getRejectedPatientPairs();
}
@@ -0,0 +1,78 @@
package org.openmrs.module.patientmatching.db.hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.openmrs.module.patientmatching.RejectedPatientPair;
import org.openmrs.module.patientmatching.db.RejectedPatientPairDAO;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
/**
* Implementation of the {@link RejectedPatientPairDAO}
*/
public class HibernateRejectedPatientPairDAO implements RejectedPatientPairDAO {
private static SessionFactory sessionFactory;
public HibernateRejectedPatientPairDAO() {}
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
HibernateRejectedPatientPairDAO.sessionFactory = sessionFactory;
}
@Override
public void saveRejectedPatientPair(RejectedPatientPair pair) {
Session session = getCurrentSession();
Transaction transaction = session.beginTransaction();
session.saveOrUpdate(pair);
transaction.commit();
session.flush();
}
@Override
public void saveRejectedPatientPairList(List<RejectedPatientPair> pairs) {
Session session = getCurrentSession();
Transaction transaction = session.beginTransaction();
for (RejectedPatientPair p : pairs) {
session.saveOrUpdate(p);
}
transaction.commit();
session.flush();
}
@Override
public List<RejectedPatientPair> getRejectedPatientPairs() {
List list = getCurrentSession().createCriteria(RejectedPatientPair.class).list();
ArrayList<RejectedPatientPair> rejectedPatientPairs = new ArrayList<RejectedPatientPair>();
for (Object obj : list) {
rejectedPatientPairs.add((RejectedPatientPair) obj);
}
return rejectedPatientPairs;
}
private Session getCurrentSession() {
if (sessionFactory != null) {
return sessionFactory.openSession();
} else {
try {
Method method = sessionFactory.getClass().getMethod("getCurrentSession", null);
return (org.hibernate.Session) method.invoke(sessionFactory, null);
} catch (Exception e) {
throw new RuntimeException("Failed to get the current hibernate session", e);
}
}
}
}
@@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -19,6 +20,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.criterion.ProjectionList;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.type.StandardBasicTypes;
import org.openmrs.Patient;
import org.openmrs.PatientIdentifierType;
@@ -62,26 +64,32 @@
private Collection<String> projections;
/**
*
*/
private Date reportCreatedOn;
private List<Patient> addedUpdatedPatients;
public OpenMRSReader() {
this(null);
this(null,null);
}
public OpenMRSReader(Collection<String> projections) {
public OpenMRSReader(Collection<String> projections, Date reportCreatedOn) {
pageNumber = 0;
resultMode = MODE_PATIENT;
expand_patient = true;
if (projections != null && !projections.contains("org.openmrs.Patient.patientId")) {
projections.add("org.openmrs.Patient.patientId");
}
this.projections = projections;
log.info("Getting all patient records ...");
updatePatientList();
log.info("Finish intialization ...");
this.projections = null;
this.reportCreatedOn = reportCreatedOn;
}
public void init(){
addedUpdatedPatients = new ArrayList<Patient>();
log.info("Getting all patient records ...");
updatePatientList();
log.info("Finished initialization ...");
}
public void setExpandPatient(boolean expand){
@@ -92,7 +100,14 @@ private Criteria createCriteria(){
createHibernateSession().clear();
criteria = createHibernateSession().createCriteria(Patient.class)
.setMaxResults(PAGING_SIZE)
.setFirstResult(pageNumber * PAGING_SIZE);
.setFirstResult(pageNumber * PAGING_SIZE)
.add(Restrictions.eq("personVoided", false));
// Add restriction to fetch the patients based on the date report created on
if(reportCreatedOn != null)
criteria.add(Restrictions.or(Restrictions.gt("dateCreated",reportCreatedOn),
Restrictions.gt("dateChanged",reportCreatedOn)));
if (projections != null) {
resultMode = MODE_PROJECTION;
ProjectionList projectionList = Projections.projectionList();
@@ -122,7 +137,7 @@ private Criteria createCriteria(){
}
return criteria;
}
private Session createHibernateSession() {
HibernateConnection connection = new HibernateConnection();
SessionFactory sessionFactory = connection.getSessionFactory();
@@ -228,6 +243,13 @@ private void updatePatientList() {
}
}
}
if(list.size() > 0) {
for (Object patient : list) {
addedUpdatedPatients.add((Patient) patient);
}
}
patients = list.iterator();
}
@@ -347,4 +369,8 @@ public boolean reset() {
return (patients != null);
}
public List<Patient> getAddedUpdatedPatients() {
return addedUpdatedPatients;
}
}
@@ -112,7 +112,7 @@ private Connection getConnection(LinkDataSource lds){
private DataSource getDataSource(LinkDataSource lds){
try{
String driver, url, user, passwd;
String[] access = lds.getAccess().split(",");
String[] access = lds.getAccess().split(",",-1);
driver = access[0];
url = access[1];
user = access[2];
Oops, something went wrong.

0 comments on commit b1f3fcc

Please sign in to comment.