Skip to content

Commit

Permalink
PTM-84: Functionality to support two datasources
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirujayathilake committed Jul 16, 2017
1 parent a327c3e commit b8adb68
Show file tree
Hide file tree
Showing 14 changed files with 828 additions and 47 deletions.

Large diffs are not rendered by default.

Expand Up @@ -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);
}
}
35 changes: 23 additions & 12 deletions api/src/main/java/org/regenstrief/linkage/io/OpenMRSReader.java
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -62,26 +64,29 @@ public class OpenMRSReader implements DataSourceReader {

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;

log.info("Getting all patient records ...");
updatePatientList();

log.info("Finish intialization ...");
this.projections = null;
this.reportCreatedOn = reportCreatedOn;
}

public void init(){
log.info("Getting all patient records ...");

updatePatientList();

log.info("Finished initialization ...");
}

public void setExpandPatient(boolean expand){
Expand All @@ -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();
Expand Down Expand Up @@ -122,7 +133,7 @@ private Criteria createCriteria(){
}
return criteria;
}

private Session createHibernateSession() {
HibernateConnection connection = new HibernateConnection();
SessionFactory sessionFactory = connection.getSessionFactory();
Expand Down
21 changes: 21 additions & 0 deletions api/src/main/resources/ConfigurationEntry.hbm.xml
@@ -0,0 +1,21 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.openmrs.module.patientmatching.ConfigurationEntry" table="patientmatching_configurationEntries">

<id name="entryId" column="entry_id"
unsaved-value="0">
<generator class="identity" />
</id>
<discriminator column="entry_id" insert="false" />

<many-to-one name="patientMatchingConfiguration" class="org.openmrs.module.patientmatching.PatientMatchingConfiguration" not-null="true">
<column name="configuration_id" />
</many-to-one>

<property name="fieldViewName" column="field_view_name" length="255" unique="true" />
<property name="fieldName" column="field_name" not-null="true" />
<property name="inclusion" column="inclusion" not-null="false" />
<property name="blockOrder" column="block_order" not-null="false" />
<property name="flag" column="flag" not-null="false" />
</class>
</hibernate-mapping>
18 changes: 18 additions & 0 deletions api/src/main/resources/MatchingRecord.hbm.xml
@@ -0,0 +1,18 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.openmrs.module.patientmatching.MatchingRecord" table="patientmatching_matchingset">
<id name="setId" column="set_id" unsaved-value="0">
<generator class="identity" />
</id>
<property name="groupId" type="java.lang.Integer" column="group_id" not-null="true" />
<many-to-one name="report" class="org.openmrs.module.patientmatching.Report" not-null="true">
<column name="report_id" />
</many-to-one>
<many-to-one name="patient" column="patient_id" class="org.openmrs.Patient"/>
<property name="state" type="java.lang.String" column="state" not-null="true"/>
<set name="matchingRecordAttributeSet" lazy="true" inverse="true" cascade="all-delete-orphan" sort="natural">
<key column="matching_record_id" not-null="true"/>
<one-to-many class="org.openmrs.module.patientmatching.MatchingRecordAttribute"/>
</set>
</class>
</hibernate-mapping>
14 changes: 14 additions & 0 deletions api/src/main/resources/MatchingRecordAttribute.hbm.xml
@@ -0,0 +1,14 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false">
<class name="org.openmrs.module.patientmatching.MatchingRecordAttribute" table="patientmatching_matching_attribute">
<id name="recordAttributeId" column="record_attribute_id"
unsaved-value="0">
<generator class="identity" />
</id>
<many-to-one name="matchingRecord" class="org.openmrs.module.patientmatching.MatchingRecord" not-null="true">
<column name="matching_record_id" />
</many-to-one>
<property name="fieldName" column="field_name" length="128" />
<property name="fieldValue" column="field_value" not-null="true" length="128"/>
</class>
</hibernate-mapping>
23 changes: 23 additions & 0 deletions api/src/main/resources/PatientMatchingConfiguration.hbm.xml
@@ -0,0 +1,23 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.openmrs.module.patientmatching">
<class name="PatientMatchingConfiguration" table="patientmatching_configuration">

<id name="configurationId" column="configuration_id" unsaved-value="0">
<generator class="identity" />
</id>

<property name="configurationName" column="configuration_name" length="255" unique="true" />
<property name="randomSampleSize" column="random_sample_size" not-null="true" />
<property name="usingRandomSample" column="using_random_sample" not-null="true"/>
<property name="estimatedPairs" column="estimated_pairs" not-null="true"/>
<property name="estimatedTime" column="estimated_time" not-null="true"/>
<property name="totalRecords" column="total_records" not-null="true"/>

<!-- bi-directional one-to-many association -->
<set name="configurationEntries" lazy="true" inverse="true" cascade="all-delete-orphan" sort="natural">
<key column="configuration_id" not-null="true" />
<one-to-many class="org.openmrs.module.patientmatching.ConfigurationEntry" />
</set>

</class>
</hibernate-mapping>
33 changes: 33 additions & 0 deletions api/src/main/resources/Report.hbm.xml
@@ -0,0 +1,33 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping auto-import="false">
<class name="org.openmrs.module.patientmatching.Report" table="patientmatching_report">
<id name="reportId" column="report_id"
unsaved-value="0">
<generator class="identity" />
</id>

<property name="reportName" column="report_name" length="255" />
<property name="createdOn" type="java.util.Date" column="created_on" not-null="true" length="19"/>

<many-to-one name="createdBy" class="org.openmrs.User">
<column name="created_by" />
</many-to-one>

<set name="matchingRecordSet" lazy="true" inverse="true" cascade="all-delete-orphan" sort="natural">
<key column="report_id" not-null="true"/>
<one-to-many class="org.openmrs.module.patientmatching.MatchingRecord"/>
</set>

<set name="reportGenerationSteps" lazy="true" inverse="true" cascade="all-delete-orphan" sort="natural">
<key column="report_id" not-null="true"/>
<one-to-many class="org.openmrs.module.patientmatching.ReportGenerationStep"/>
</set>

<set name="usedConfigurationList" table="patientmatching_report_configuration" cascade="none">
<key column="report_id"/>
<many-to-many column="configuration_id"
class="org.openmrs.module.patientmatching.PatientMatchingConfiguration"/>
</set>

</class>
</hibernate-mapping>
18 changes: 18 additions & 0 deletions api/src/main/resources/ReportGenerationStep.hbm.xml
@@ -0,0 +1,18 @@
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.openmrs.module.patientmatching.ReportGenerationStep" table=" patientmatching_report_generation_step">

<id name="stepId" type="int" column="step_id"
unsaved-value="0">
<generator class="identity" />
</id>

<many-to-one name="report" class="org.openmrs.module.patientmatching.Report" not-null="true">
<column name="report_id" />
</many-to-one>

<property name="processName" type="java.lang.String" column="process_name" length="50" />
<property name="sequenceNo" type="java.lang.Integer" column="sequence_number" not-null="true" />
<property name="timeTaken" type="java.lang.Integer" column="time_taken" not-null="false" />
</class>
</hibernate-mapping>

0 comments on commit b8adb68

Please sign in to comment.