dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39348
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19927: use ValueType in MinMaxOutlierAnalysisService
------------------------------------------------------------
revno: 19927
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-02 12:31:37 +0700
message:
use ValueType in MinMaxOutlierAnalysisService
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/MinMaxOutlierAnalysisService.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java
dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java
--
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-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/MinMaxOutlierAnalysisService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/MinMaxOutlierAnalysisService.java 2015-07-03 01:33:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataanalysis/MinMaxOutlierAnalysisService.java 2015-09-02 05:31:37 +0000
@@ -28,23 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_NEGATIVE_INT;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_POSITIVE_INT;
-import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.amplecode.quick.BatchHandler;
import org.amplecode.quick.BatchHandlerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.common.IdentifiableObjectUtils;
+import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.commons.filter.Filter;
import org.hisp.dhis.commons.filter.FilterUtils;
import org.hisp.dhis.dataelement.DataElement;
@@ -59,6 +48,13 @@
import org.hisp.dhis.system.util.MathUtils;
import org.joda.time.DateTime;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* @author Lars Helge Overland
*/
@@ -66,27 +62,27 @@
implements MinMaxDataAnalysisService
{
private static final Log log = LogFactory.getLog( MinMaxOutlierAnalysisService.class );
-
+
private static final Filter<DataElement> DATALEMENT_INT_FILTER = new DataElementTypeFilter( DataElement.VALUE_TYPE_INT );
-
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
-
+
private DataAnalysisStore dataAnalysisStore;
public void setDataAnalysisStore( DataAnalysisStore dataAnalysisStore )
{
this.dataAnalysisStore = dataAnalysisStore;
}
-
+
private MinMaxDataElementService minMaxDataElementService;
public void setMinMaxDataElementService( MinMaxDataElementService minMaxDataElementService )
{
this.minMaxDataElementService = minMaxDataElementService;
}
-
+
private BatchHandlerFactory batchHandlerFactory;
public void setBatchHandlerFactory( BatchHandlerFactory batchHandlerFactory )
@@ -103,21 +99,21 @@
Collection<DataElement> dataElements, Collection<Period> periods, Double stdDevFactor, Date from )
{
Set<DataElement> elements = new HashSet<>( dataElements );
-
+
FilterUtils.filter( elements, DATALEMENT_INT_FILTER );
-
+
Set<DataElementCategoryOptionCombo> categoryOptionCombos = new HashSet<>();
-
+
for ( DataElement dataElement : elements )
{
categoryOptionCombos.addAll( dataElement.getCategoryCombo().getOptionCombos() );
}
log.debug( "Starting min-max analysis, no of data elements: " + elements.size() + ", no of org units: " + organisationUnits.size() );
-
+
return dataAnalysisStore.getMinMaxViolations( elements, categoryOptionCombos, periods, organisationUnits, MAX_OUTLIERS );
}
-
+
@Override
public void generateMinMaxValues( Collection<OrganisationUnit> organisationUnits,
Collection<DataElement> dataElements, Double stdDevFactor )
@@ -127,57 +123,59 @@
Set<Integer> orgUnitIds = new HashSet<>( IdentifiableObjectUtils.getIdentifiers( organisationUnits ) );
Date from = new DateTime( 1, 1, 1, 1, 1 ).toDate();
-
+
minMaxDataElementService.removeMinMaxDataElements( dataElements, organisationUnits );
log.debug( "Deleted existing min-max values" );
BatchHandler<MinMaxDataElement> batchHandler = batchHandlerFactory.createBatchHandler( MinMaxDataElementBatchHandler.class ).init();
-
+
for ( DataElement dataElement : dataElements )
{
- if ( VALUE_TYPE_INT.equals( dataElement.getType() ) )
+ ValueType valueType = dataElement.getValueType();
+
+ if ( valueType.isNumeric() )
{
Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo().getOptionCombos();
for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryOptionCombos )
{
Map<Integer, Double> standardDeviations = dataAnalysisStore.getStandardDeviation( dataElement, categoryOptionCombo, orgUnitIds, from );
-
+
Map<Integer, Double> averages = dataAnalysisStore.getAverage( dataElement, categoryOptionCombo, standardDeviations.keySet(), from );
-
+
for ( Integer unit : averages.keySet() )
{
Double stdDev = standardDeviations.get( unit );
Double avg = averages.get( unit );
-
+
if ( stdDev != null && avg != null )
{
int min = (int) MathUtils.getLowBound( stdDev, stdDevFactor, avg );
int max = (int) MathUtils.getHighBound( stdDev, stdDevFactor, avg );
-
- if ( VALUE_TYPE_POSITIVE_INT.equals( dataElement.getNumberType() ) || VALUE_TYPE_ZERO_OR_POSITIVE_INT.equals( dataElement.getNumberType() ) )
+
+ if ( ValueType.INTEGER_POSITIVE == valueType || ValueType.INTEGER_ZERO_OR_POSITIVE == valueType )
{
min = Math.max( 0, min ); // Cannot be < 0
}
-
- if ( VALUE_TYPE_NEGATIVE_INT.equals( dataElement.getNumberType() ) )
+
+ if ( ValueType.INTEGER_NEGATIVE == valueType )
{
max = Math.min( 0, max ); // Cannot be > 0
}
-
+
OrganisationUnit source = new OrganisationUnit();
source.setId( unit );
-
+
batchHandler.addObject( new MinMaxDataElement( source, dataElement, categoryOptionCombo, min, max, true ) );
}
- }
+ }
}
}
}
-
+
log.info( "Min-max value generation done" );
-
+
batchHandler.flush();
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java 2015-08-30 14:51:28 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ActivityReportingServiceImpl.java 2015-09-02 05:31:37 +0000
@@ -28,20 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.hisp.dhis.api.mobile.ActivityReportingService;
import org.hisp.dhis.api.mobile.NotAllowedException;
import org.hisp.dhis.api.mobile.model.Activity;
@@ -51,14 +37,14 @@
import org.hisp.dhis.api.mobile.model.DataValue;
import org.hisp.dhis.api.mobile.model.Interpretation;
import org.hisp.dhis.api.mobile.model.InterpretationComment;
-import org.hisp.dhis.api.mobile.model.OptionSet;
-import org.hisp.dhis.api.mobile.model.PatientAttribute;
-import org.hisp.dhis.api.mobile.model.Task;
import org.hisp.dhis.api.mobile.model.LWUITmodel.LostEvent;
import org.hisp.dhis.api.mobile.model.LWUITmodel.Notification;
import org.hisp.dhis.api.mobile.model.LWUITmodel.Patient;
import org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList;
import org.hisp.dhis.api.mobile.model.LWUITmodel.Section;
+import org.hisp.dhis.api.mobile.model.OptionSet;
+import org.hisp.dhis.api.mobile.model.PatientAttribute;
+import org.hisp.dhis.api.mobile.model.Task;
import org.hisp.dhis.api.mobile.model.comparator.ActivityComparator;
import org.hisp.dhis.api.mobile.model.comparator.TrackedEntityAttributeValueSortOrderComparator;
import org.hisp.dhis.chart.Chart;
@@ -121,6 +107,20 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
public class ActivityReportingServiceImpl
implements ActivityReportingService
{
@@ -814,7 +814,7 @@
{
org.hisp.dhis.api.mobile.model.PatientAttribute patientAttribute = new org.hisp.dhis.api.mobile.model.PatientAttribute(
value.getAttribute().getName(), value.getValue(), value.getAttribute().getValueType(), false, value
- .getAttribute().getDisplayInListNoProgram(), new OptionSet() );
+ .getAttribute().getDisplayInListNoProgram(), new OptionSet() );
patientAtts.add( patientAttribute );
}
@@ -871,14 +871,14 @@
relationshipMobile.setbIsToA( eachRelationship.getRelationshipType().getaIsToB() );
relationshipMobile.setPersonBId( eachRelationship.getEntityInstanceA().getId() );
}
-
+
// get relative's name
TrackedEntityInstance relative = entityInstanceService.getTrackedEntityInstance( relationshipMobile
.getPersonBId() );
List<TrackedEntityAttributeValue> attributes = new ArrayList<TrackedEntityAttributeValue>(
relative.getAttributeValues() );
List<TrackedEntityAttributeValue> attributesInList = new ArrayList<TrackedEntityAttributeValue>();
-
+
for ( TrackedEntityAttributeValue value : attributes )
{
if ( value != null && value.getAttribute().getDisplayInListNoProgram() )
@@ -898,7 +898,7 @@
}
}
relationshipMobile.setPersonBName( relativeName );
-
+
relationshipList.add( relationshipMobile );
}
patientModel.setRelationships( relationshipList );
@@ -1065,6 +1065,7 @@
// Value
TrackedEntityDataValue patientDataValue = dataValueService.getTrackedEntityDataValue( programStageInstance,
programStageDataElement.getDataElement() );
+
if ( patientDataValue != null )
{
// Convert to standard date format before send to client
@@ -1175,7 +1176,7 @@
List<Program> tempPrograms = null;
ProgramType programType = ProgramType.fromValue( type );
-
+
if ( programType == ProgramType.WITHOUT_REGISTRATION )
{
tempPrograms = new ArrayList<>(
@@ -1252,7 +1253,7 @@
// side, we only need name and id
private org.hisp.dhis.api.mobile.model.LWUITmodel.Program getMobileProgramWithoutData( Program program )
{
- Comparator<ProgramStageDataElement> orderBySortOrder =
+ Comparator<ProgramStageDataElement> orderBySortOrder =
( ProgramStageDataElement i1, ProgramStageDataElement i2 ) -> i1.getSortOrder().compareTo( i2.getSortOrder() );
org.hisp.dhis.api.mobile.model.LWUITmodel.Program anonymousProgramMobile = new org.hisp.dhis.api.mobile.model.LWUITmodel.Program();
@@ -1429,7 +1430,7 @@
public List<org.hisp.dhis.api.mobile.model.PatientAttribute> getPatientAttributesForMobile( String programId )
{
List<org.hisp.dhis.api.mobile.model.PatientAttribute> list = new ArrayList<>();
-
+
for ( TrackedEntityAttribute pa : getPatientAtts( programId ) )
{
PatientAttribute patientAttribute = new PatientAttribute();
@@ -1441,7 +1442,7 @@
list.add( patientAttribute );
}
-
+
return list;
}
@@ -1500,7 +1501,7 @@
TrackedEntityInstance newTrackedEntityInstance = entityInstanceService
.getTrackedEntityInstance( this.patientId );
String errorMsg = null;
-
+
try
{
for ( org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramInstance mobileProgramInstance : patient
@@ -1510,7 +1511,7 @@
enrollProgram( patientId + "-" + mobileProgramInstance.getProgramId(),
mobileProgramInstance.getProgramStageInstances(), incidentDate );
}
-
+
Program program = programService.getProgram( Integer.parseInt( programIdText ) );
String[] errorCode = entityInstanceService.validateTrackedEntityInstance( newTrackedEntityInstance,
program, format ).split( "_" );
@@ -1533,8 +1534,8 @@
{
e.printStackTrace();
}
-
- if(errorMsg!=null)
+
+ if ( errorMsg != null )
{
throw new NotAllowedException( errorMsg );
}
@@ -1954,7 +1955,7 @@
public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient generateRepeatableEvent( int orgUnitId, String eventInfo )
throws NotAllowedException
{
- //OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( orgUnitId );
+ //OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( orgUnitId );
String[] keys = eventInfo.split( "_" );
ProgramStage programStage = programStageService.getProgramStage( Integer.parseInt( keys[4] ) );
@@ -2113,7 +2114,7 @@
}
UserQueryParams params = new UserQueryParams();
- params.setQuery( keyword );
+ params.setQuery( keyword );
users = userService.getUsers( params );
for ( User userCore : users )
@@ -2569,7 +2570,7 @@
{
errorMsg = "Duplicate value of "
+ attributeService.getTrackedEntityAttribute( Integer.parseInt( errorCode[1] ) )
- .getDisplayName();
+ .getDisplayName();
}
else
{
=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java 2015-08-31 08:17:08 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/DefaultProgramService.java 2015-09-02 05:31:37 +0000
@@ -28,12 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.hisp.dhis.api.mobile.IProgramService;
import org.hisp.dhis.api.mobile.model.DataElement;
import org.hisp.dhis.api.mobile.model.Model;
@@ -51,6 +45,12 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
public class DefaultProgramService
implements IProgramService
{
@@ -201,7 +201,7 @@
pr.setVersion( program.getVersion() );
pr.setDateOfEnrollmentDescription( program.getDateOfEnrollmentDescription() );
pr.setDateOfIncidentDescription( program.getDateOfIncidentDescription() );
- if( program.getTrackedEntity() != null && program.getTrackedEntity().getName() != null)
+ if ( program.getTrackedEntity() != null && program.getTrackedEntity().getName() != null )
{
pr.setTrackedEntityName( program.getTrackedEntity().getName() );
}
@@ -219,7 +219,7 @@
prStg.setReportDate( "" );
prStg.setReportDateDescription( programStage.getReportDateDescription() );
-
+
prStg.setDueDate( "" );
prStg.setId( programStage.getId() );
@@ -248,12 +248,9 @@
for ( ProgramStageDataElement programStageDataElement : programStageDataElements )
{
org.hisp.dhis.dataelement.DataElement dataElement = programStageDataElement.getDataElement();
-
- org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement de = ModelMapping
- .getDataElementLWUIT( dataElement );
+ org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement de = ModelMapping.getDataElementLWUIT( dataElement );
de.setCompulsory( programStageDataElement.isCompulsory() );
-
de.setNumberType( programStageDataElement.getDataElement().getNumberType() );
des.add( de );
@@ -263,6 +260,7 @@
// Set all program sections
List<org.hisp.dhis.api.mobile.model.LWUITmodel.Section> mobileSections = new ArrayList<>();
+
if ( programStage.getProgramStageSections().size() > 0 )
{
for ( ProgramStageSection eachSection : programStage.getProgramStageSections() )
@@ -274,11 +272,12 @@
// Set all data elements' id, then we could have full from
// data element list of program stage
List<Integer> dataElementIds = new ArrayList<>();
- for ( ProgramStageDataElement eachPogramStageDataElement : eachSection
- .getProgramStageDataElements() )
+
+ for ( ProgramStageDataElement eachPogramStageDataElement : eachSection.getProgramStageDataElements() )
{
dataElementIds.add( eachPogramStageDataElement.getDataElement().getId() );
}
+
mobileSection.setDataElementIds( dataElementIds );
mobileSections.add( mobileSection );
}
@@ -326,7 +325,7 @@
{
mobileAttribute.setDisplayedInList( false );
}
-
+
mobileAttribute.setMandatory( ppa.isMandatory() );
if ( pa.getValueType().equals( TrackedEntityAttribute.TYPE_OPTION_SET ) )