dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #22369
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10731: Improve Aggregate Query Builder (WIP).
------------------------------------------------------------
revno: 10731
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-05-02 15:41:20 +0700
message:
Improve Aggregate Query Builder (WIP).
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java
dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java 2013-05-02 03:31:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionService.java 2013-05-02 08:41:20 +0000
@@ -35,12 +35,9 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientAttribute;
-import org.hisp.dhis.patientdatavalue.PatientDataValue;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.program.Program;
-import org.hisp.dhis.program.ProgramStageInstance;
/**
* @author Chau Thu Tran
@@ -71,16 +68,7 @@
void insertAggregateValue( CaseAggregationCondition caseAggregationCondition, Collection<Integer> orgunitIds,
Period period );
-
- Collection<PatientDataValue> getPatientDataValues( CaseAggregationCondition aggregationCondition,
- Collection<Integer> orgunitIds, Period period );
-
- Collection<Patient> getPatients( CaseAggregationCondition aggregationCondition, Collection<Integer> orgunitIds,
- Period period );
-
- Collection<ProgramStageInstance> getProgramStageInstances( CaseAggregationCondition aggregationCondition,
- Collection<Integer> orgunitIds, Period period );
-
+
Collection<DataElement> getDataElementsInCondition( String aggregationExpression );
Collection<Program> getProgramsInCondition( String aggregationExpression );
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2013-05-02 03:31:45 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/caseaggregation/DefaultCaseAggregationConditionService.java 2013-05-02 08:41:20 +0000
@@ -27,7 +27,6 @@
package org.hisp.dhis.caseaggregation;
-import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.AGGRERATION_SUM;
import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_ORGUNIT_COMPLETE_PROGRAM_STAGE;
import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT;
import static org.hisp.dhis.caseaggregation.CaseAggregationCondition.OBJECT_PATIENT_ATTRIBUTE;
@@ -54,21 +53,14 @@
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.i18n.I18nService;
-import org.hisp.dhis.patient.Patient;
import org.hisp.dhis.patient.PatientAttribute;
import org.hisp.dhis.patient.PatientAttributeService;
-import org.hisp.dhis.patient.PatientService;
-import org.hisp.dhis.patientdatavalue.PatientDataValue;
-import org.hisp.dhis.patientdatavalue.PatientDataValueService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.program.Program;
import org.hisp.dhis.program.ProgramService;
import org.hisp.dhis.program.ProgramStage;
-import org.hisp.dhis.program.ProgramStageInstance;
-import org.hisp.dhis.program.ProgramStageInstanceService;
import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.system.util.ConcurrentUtils;
-import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.system.util.SystemUtils;
import org.springframework.transaction.annotation.Transactional;
@@ -95,18 +87,12 @@
private DataElementService dataElementService;
- private PatientService patientService;
-
- private PatientDataValueService dataValueService;
-
private ProgramStageService programStageService;
private ProgramService programService;
private PatientAttributeService patientAttributeService;
- private ProgramStageInstanceService programStageInstanceService;
-
private I18nService i18nService;
// -------------------------------------------------------------------------
@@ -122,12 +108,6 @@
{
this.aggregationConditionManager = aggregationConditionManager;
}
-
- public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService )
- {
- this.programStageInstanceService = programStageInstanceService;
- }
-
public void setPatientAttributeService( PatientAttributeService patientAttributeService )
{
this.patientAttributeService = patientAttributeService;
@@ -163,16 +143,6 @@
return aggregationConditionStore.save( caseAggregationCondition );
}
- public void setPatientService( PatientService patientService )
- {
- this.patientService = patientService;
- }
-
- public void setDataValueService( PatientDataValueService dataValueService )
- {
- this.dataValueService = dataValueService;
- }
-
@Override
public void deleteCaseAggregationCondition( CaseAggregationCondition caseAggregationCondition )
{
@@ -222,138 +192,7 @@
public void insertAggregateValue( CaseAggregationCondition caseAggregationCondition,
Collection<Integer> orgunitIds, Period period )
{
- aggregationConditionManager.insertAggregateValue( caseAggregationCondition, orgunitIds, period);
- }
-
- @Override
- public Collection<PatientDataValue> getPatientDataValues( CaseAggregationCondition aggregationCondition,
- Collection<Integer> orgunitIds, Period period )
- {
- // get params
-
- String startDate = DateUtils.getMediumDateString( period.getStartDate() );
- String endDate = DateUtils.getMediumDateString( period.getEndDate() );
- DataElement deSum = aggregationCondition.getDeSum();
- Integer deSumId = (deSum == null) ? null : deSum.getId();
-
- Collection<PatientDataValue> result = new HashSet<PatientDataValue>();
-
-// String sql = aggregationConditionManager.parseExpressionToSql( aggregationCondition.getAggregationExpression(),
-// aggregationCondition.getOperator(), deSumId, orgunitIds, startDate, endDate );
-
- String sql = "";
- Collection<DataElement> dataElements = getDataElementsInCondition( aggregationCondition
- .getAggregationExpression() );
-
- if ( dataElements.size() > 0 )
- {
- Collection<Integer> patientIds = aggregationConditionManager.executeSQL( sql );
-
- for ( Integer patientId : patientIds )
- {
- Patient patient = patientService.getPatient( patientId );
-
- Collection<PatientDataValue> dataValues = dataValueService.getPatientDataValues( patient, dataElements,
- period.getStartDate(), period.getEndDate() );
-
- result.addAll( dataValues );
- }
- }
-
- return result;
- }
-
- public Collection<Patient> getPatients( CaseAggregationCondition aggregationCondition,
- Collection<Integer> orgunitIds, Period period )
- {
- DataElement deSum = aggregationCondition.getDeSum();
- Integer deSumId = (deSum == null) ? null : deSum.getId();
-
-// String sql = aggregationConditionManager
-// .parseExpressionToSql( aggregationCondition.getAggregationExpression(), aggregationCondition.getOperator(),
-// deSumId, orgunitIds, DateUtils.getMediumDateString( period.getStartDate() ),
-// DateUtils.getMediumDateString( period.getEndDate() ) );
-
- String sql = "";
- Collection<Patient> result = new HashSet<Patient>();
-
- Collection<Integer> patientIds = aggregationConditionManager.executeSQL( sql );
-
- if ( patientIds != null )
- {
- for ( Integer patientId : patientIds )
- {
- result.add( patientService.getPatient( patientId ) );
- }
- }
-
- return result;
- }
-
- public Collection<ProgramStageInstance> getProgramStageInstances( CaseAggregationCondition aggregationCondition,
- Collection<Integer> orgunitIds, Period period )
- {
- Collection<ProgramStageInstance> result = new HashSet<ProgramStageInstance>();
-
- // get params
- String startDate = DateUtils.getMediumDateString( period.getStartDate() );
- String endDate = DateUtils.getMediumDateString( period.getEndDate() );
-
- String operator = aggregationCondition.getOperator();
- String sql = "";
- if ( operator.equals( CaseAggregationCondition.AGGRERATION_COUNT )
- || operator.equals( CaseAggregationCondition.AGGRERATION_SUM ) )
- {
- aggregationCondition.setOperator( AGGRERATION_SUM );
-
- // get params
-
- DataElement deSum = aggregationCondition.getDeSum();
- Integer deSumId = (deSum == null) ? null : deSum.getId();
-
-// sql = aggregationConditionManager.parseExpressionToSql( aggregationCondition.getAggregationExpression(),
-// aggregationCondition.getOperator(), deSumId, orgunitIds, startDate, endDate );
- sql = "";
- }
- else
- {
- sql = "SELECT psi.programstageinstanceid ";
- sql += "FROM patientdatavalue pdv ";
- sql += " INNER JOIN programstageinstance psi ";
- sql += " ON psi.programstageinstanceid = pdv.programstageinstanceid ";
- sql += "WHERE executiondate >='" + DateUtils.getMediumDateString( period.getStartDate() ) + "' ";
- sql += " AND executiondate <='" + DateUtils.getMediumDateString( period.getEndDate() )
- + "' AND pdv.dataelementid=" + aggregationCondition.getDeSum().getId();
-
- if ( aggregationCondition.getAggregationExpression() != null
- && !aggregationCondition.getAggregationExpression().isEmpty() )
- {
- sql = sql + " AND pdv.programstageinstanceid in ( ";
-
- // Get params
-
- DataElement deSum = aggregationCondition.getDeSum();
- Integer deSumId = (deSum == null) ? null : deSum.getId();
-
-// String conditionSql = aggregationConditionManager.parseExpressionToSql(
-// aggregationCondition.getAggregationExpression(), aggregationCondition.getOperator(), deSumId,
-// orgunitIds, DateUtils.getMediumDateString( period.getStartDate() ),
-// DateUtils.getMediumDateString( period.getEndDate() ) );
-//
-// sql += conditionSql + " ) ";
-
- sql = "";
- }
- }
-
- Collection<Integer> stageInstanceIds = aggregationConditionManager.executeSQL( sql );
-
- for ( Integer stageInstanceId : stageInstanceIds )
- {
- result.add( programStageInstanceService.getProgramStageInstance( stageInstanceId ) );
- }
-
- return result;
+ aggregationConditionManager.insertAggregateValue( caseAggregationCondition, orgunitIds, period );
}
public String getConditionDescription( String condition )
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-05-02 03:31:45 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2013-05-02 08:41:20 +0000
@@ -180,15 +180,10 @@
<property name="aggregationConditionManager"
ref="org.hisp.dhis.caseaggregation.CaseAggregationConditionManager" />
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
- <property name="patientService" ref="org.hisp.dhis.patient.PatientService" />
- <property name="dataValueService"
- ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
<property name="programStageService" ref="org.hisp.dhis.program.ProgramStageService" />
<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
<property name="patientAttributeService"
ref="org.hisp.dhis.patient.PatientAttributeService" />
- <property name="programStageInstanceService"
- ref="org.hisp.dhis.program.ProgramStageInstanceService" />
<property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
</bean>