Permalink
Browse files

PTM-82: Functionality to load patient records considering date_create…

…d and date_changed

For the incremental patient matching, records of the patients are
loaded considering the date of a particular report created against with
the patient’s date_created or date_changed
  • Loading branch information...
Lahiru-J committed Jun 18, 2017
1 parent a327c3e commit d94b12d7413bd2c8c961546ce716b159be346fbb
@@ -75,6 +75,11 @@
public static String status = NO_PROCESS;
public static int i;

/**
* Constant name is given for a report in the incremental patient matching process
*/
private static final String REPORT_NAME = "dedup-incremental-report-";

/**
*
* Get the list of steps (statuses) that the analysis has to go through
@@ -149,7 +154,8 @@
public static Map<String, Object> InitScratchTable(Map<String,Object> objects){
Connection databaseConnection=(Connection) objects.get("databaseConnection");
RecMatchConfig recMatchConfig=(RecMatchConfig) objects.get("recMatchConfig");
MatchingConfig matchingConfig = ((List<MatchingConfig>)objects.get("matchingConfigLists")).get(0);
List<MatchingConfig> matchingConfigList = (List<MatchingConfig>)objects.get("matchingConfigLists");
MatchingConfig matchingConfig = matchingConfigList.get(0);
String driver=(String) objects.get("driver");
String url = (String) objects.get("url");
String user = (String) objects.get("user");
@@ -166,7 +172,14 @@
databaseConnection, recMatchConfig.getLinkDataSource1(),
driver, url, user, passwd);
recordStore.clearRecords();
OpenMRSReader reader = new OpenMRSReader(globalIncludeColumns);

// If only a single strategy has been selected
Report report = null;
if(matchingConfigList.size() == 1){
String reportName = REPORT_NAME + matchingConfig.getName();
report = Context.getService(PatientMatchingReportMetadataService.class).getReportByName(reportName);
}
OpenMRSReader reader = new OpenMRSReader(globalIncludeColumns, report != null ? report.getCreatedOn() : null);
while (reader.hasNextRecord()) {
recordStore.storeRecord(reader.nextRecord());
}
@@ -309,7 +322,7 @@
throw new RuntimeException(e);
}

String reportName = "dedup-report-"+configString+dateString;
String reportName = REPORT_NAME + configString+dateString;
DedupMatchResultList handler = (DedupMatchResultList)objects.get("handler");

handler.flattenPairIdList();
@@ -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,21 +64,24 @@

private Collection<String> projections;

private Date reportCreatedOn;

/**
*
*/
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;
this.reportCreatedOn = reportCreatedOn;

log.info("Getting all patient records ...");
updatePatientList();
@@ -93,6 +98,12 @@ private Criteria createCriteria(){
criteria = createHibernateSession().createCriteria(Patient.class)
.setMaxResults(PAGING_SIZE)
.setFirstResult(pageNumber * PAGING_SIZE);

// 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();

0 comments on commit d94b12d

Please sign in to comment.