Search in sources :

Example 1 with TrackedEntityInstance

use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class ProgramExpressionServiceTest method setUpTest.

@Override
public void setUpTest() {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(organisationUnit);
    Program program = createProgram('A', new HashSet<>(), organisationUnit);
    programService.addProgram(program);
    stageA = new ProgramStage("StageA", program);
    stageA.setSortOrder(1);
    programStageService.saveProgramStage(stageA);
    stageB = new ProgramStage("StageB", program);
    stageB.setSortOrder(2);
    programStageService.saveProgramStage(stageB);
    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add(stageA);
    programStages.add(stageB);
    program.setProgramStages(programStages);
    programService.updateProgram(program);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    TrackedEntityInstance entityInstance = createTrackedEntityInstance('A', organisationUnit);
    entityInstanceService.addTrackedEntityInstance(entityInstance);
    ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, program, new Date(), new Date(), organisationUnit);
    ProgramStageInstance stageInstance = programStageInstanceService.createProgramStageInstance(programInstance, stageA, new Date(), new Date(), organisationUnit);
    TrackedEntityDataValue dataValueA = new TrackedEntityDataValue(stageInstance, dataElementA, "1");
    TrackedEntityDataValue dataValueB = new TrackedEntityDataValue(stageInstance, dataElementB, "2");
    dataValueService.saveTrackedEntityDataValue(dataValueA);
    dataValueService.saveTrackedEntityDataValue(dataValueB);
    programExpressionA = new ProgramExpression("[" + ProgramExpression.OBJECT_PROGRAM_STAGE_DATAELEMENT + ProgramExpression.SEPARATOR_OBJECT + stageA.getUid() + "." + dataElementA.getUid() + "]", "A");
    programExpressionB = new ProgramExpression("[" + ProgramExpression.OBJECT_PROGRAM_STAGE_DATAELEMENT + ProgramExpression.SEPARATOR_OBJECT + stageA.getUid() + "." + dataElementB.getUid() + "]", "B");
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityDataValue(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) HashSet(java.util.HashSet)

Example 2 with TrackedEntityInstance

use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class ProgramIndicatorServiceTest method setUpTest.

@Override
public void setUpTest() {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(organisationUnit);
    // ---------------------------------------------------------------------
    // Program
    // ---------------------------------------------------------------------
    programA = createProgram('A', new HashSet<>(), organisationUnit);
    programService.addProgram(programA);
    psA = new ProgramStage("StageA", programA);
    psA.setSortOrder(1);
    programStageService.saveProgramStage(psA);
    psB = new ProgramStage("StageB", programA);
    psB.setSortOrder(2);
    programStageService.saveProgramStage(psB);
    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add(psA);
    programStages.add(psB);
    programA.setProgramStages(programStages);
    programService.updateProgram(programA);
    programB = createProgram('B', new HashSet<>(), organisationUnit);
    programService.addProgram(programB);
    // ---------------------------------------------------------------------
    // Program Stage DE
    // ---------------------------------------------------------------------
    deA = createDataElement('A');
    deA.setDomainType(DataElementDomain.TRACKER);
    deB = createDataElement('B');
    deB.setDomainType(DataElementDomain.TRACKER);
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    ProgramStageDataElement stageDataElementA = new ProgramStageDataElement(psA, deA, false, 1);
    ProgramStageDataElement stageDataElementB = new ProgramStageDataElement(psA, deB, false, 2);
    ProgramStageDataElement stageDataElementC = new ProgramStageDataElement(psB, deA, false, 1);
    ProgramStageDataElement stageDataElementD = new ProgramStageDataElement(psB, deB, false, 2);
    programStageDataElementService.addProgramStageDataElement(stageDataElementA);
    programStageDataElementService.addProgramStageDataElement(stageDataElementB);
    programStageDataElementService.addProgramStageDataElement(stageDataElementC);
    programStageDataElementService.addProgramStageDataElement(stageDataElementD);
    // ---------------------------------------------------------------------
    // TrackedEntityInstance & Enrollment
    // ---------------------------------------------------------------------
    TrackedEntityInstance entityInstance = createTrackedEntityInstance('A', organisationUnit);
    entityInstanceService.addTrackedEntityInstance(entityInstance);
    incidentDate = DateUtils.getMediumDate("2014-10-22");
    enrollmentDate = DateUtils.getMediumDate("2014-12-31");
    programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, programA, enrollmentDate, incidentDate, organisationUnit);
    incidentDate = DateUtils.getMediumDate("2014-10-22");
    enrollmentDate = DateUtils.getMediumDate("2014-12-31");
    programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, programA, enrollmentDate, incidentDate, organisationUnit);
    // TODO enroll twice?
    // ---------------------------------------------------------------------
    // TrackedEntityAttribute
    // ---------------------------------------------------------------------
    atA = createTrackedEntityAttribute('A', ValueType.NUMBER);
    atB = createTrackedEntityAttribute('B', ValueType.NUMBER);
    attributeService.addTrackedEntityAttribute(atA);
    attributeService.addTrackedEntityAttribute(atB);
    TrackedEntityAttributeValue attributeValueA = new TrackedEntityAttributeValue(atA, entityInstance, "1");
    TrackedEntityAttributeValue attributeValueB = new TrackedEntityAttributeValue(atB, entityInstance, "2");
    attributeValueService.addTrackedEntityAttributeValue(attributeValueA);
    attributeValueService.addTrackedEntityAttributeValue(attributeValueB);
    // ---------------------------------------------------------------------
    // TrackedEntityDataValue
    // ---------------------------------------------------------------------
    ProgramStageInstance stageInstanceA = programStageInstanceService.createProgramStageInstance(programInstance, psA, enrollmentDate, incidentDate, organisationUnit);
    ProgramStageInstance stageInstanceB = programStageInstanceService.createProgramStageInstance(programInstance, psB, enrollmentDate, incidentDate, organisationUnit);
    Set<ProgramStageInstance> programStageInstances = new HashSet<>();
    programStageInstances.add(stageInstanceA);
    programStageInstances.add(stageInstanceB);
    programInstance.setProgramStageInstances(programStageInstances);
    programInstance.setProgram(programA);
    TrackedEntityDataValue dataValueA = new TrackedEntityDataValue(stageInstanceA, deA, "3");
    TrackedEntityDataValue dataValueB = new TrackedEntityDataValue(stageInstanceA, deB, "1");
    TrackedEntityDataValue dataValueC = new TrackedEntityDataValue(stageInstanceB, deA, "5");
    TrackedEntityDataValue dataValueD = new TrackedEntityDataValue(stageInstanceB, deB, "7");
    dataValueService.saveTrackedEntityDataValue(dataValueA);
    dataValueService.saveTrackedEntityDataValue(dataValueB);
    dataValueService.saveTrackedEntityDataValue(dataValueC);
    dataValueService.saveTrackedEntityDataValue(dataValueD);
    // ---------------------------------------------------------------------
    // Constant
    // ---------------------------------------------------------------------
    Constant constantA = createConstant('A', 7.0);
    constantService.saveConstant(constantA);
    // ---------------------------------------------------------------------
    // ProgramIndicator
    // ---------------------------------------------------------------------
    String expressionA = "( d2:daysBetween(" + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_ENROLLMENT_DATE + "}, " + KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "}) )  / " + ProgramIndicator.KEY_CONSTANT + "{" + constantA.getUid() + "}";
    indicatorA = createProgramIndicator('A', programA, expressionA, null);
    programA.getProgramIndicators().add(indicatorA);
    indicatorB = createProgramIndicator('B', programA, "70", null);
    programA.getProgramIndicators().add(indicatorB);
    indicatorC = createProgramIndicator('C', programA, "0", null);
    programA.getProgramIndicators().add(indicatorC);
    String expressionD = "0 + A + 4 + " + ProgramIndicator.KEY_PROGRAM_VARIABLE + "{" + ProgramIndicator.VAR_INCIDENT_DATE + "}";
    indicatorD = createProgramIndicator('D', programB, expressionD, null);
    String expressionE = KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid() + "} + " + KEY_DATAELEMENT + "{" + psB.getUid() + "." + deA.getUid() + "} - " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} + " + KEY_ATTRIBUTE + "{" + atB.getUid() + "}";
    String filterE = KEY_DATAELEMENT + "{" + psA.getUid() + "." + deA.getUid() + "} + " + KEY_ATTRIBUTE + "{" + atA.getUid() + "} > 10";
    indicatorE = createProgramIndicator('E', programB, expressionE, filterE);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Constant(org.hisp.dhis.constant.Constant) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityDataValue(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) HashSet(java.util.HashSet)

Example 3 with TrackedEntityInstance

use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class ProgramInstanceServiceTest method setUpTest.

@Override
public void setUpTest() {
    organisationUnitA = createOrganisationUnit('A');
    int idA = organisationUnitService.addOrganisationUnit(organisationUnitA);
    organisationUnitB = createOrganisationUnit('B');
    int idB = organisationUnitService.addOrganisationUnit(organisationUnitB);
    orgunitIds = new HashSet<>();
    orgunitIds.add(idA);
    orgunitIds.add(idB);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programService.addProgram(programA);
    ProgramStage stageA = createProgramStage('A', programA);
    stageA.setSortOrder(1);
    programStageService.saveProgramStage(stageA);
    ProgramStage stageB = createProgramStage('B', programA);
    stageB.setSortOrder(2);
    programStageService.saveProgramStage(stageB);
    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add(stageA);
    programStages.add(stageB);
    programA.setProgramStages(programStages);
    programService.updateProgram(programA);
    programB = createProgram('B', new HashSet<>(), organisationUnitA);
    programService.addProgram(programB);
    programC = createProgram('C', new HashSet<>(), organisationUnitA);
    programService.addProgram(programC);
    entityInstanceA = createTrackedEntityInstance('A', organisationUnitA);
    entityInstanceService.addTrackedEntityInstance(entityInstanceA);
    TrackedEntityInstance entityInstanceB = createTrackedEntityInstance('B', organisationUnitB);
    entityInstanceService.addTrackedEntityInstance(entityInstanceB);
    DateTime testDate1 = DateTime.now();
    testDate1.withTimeAtStartOfDay();
    testDate1 = testDate1.minusDays(70);
    incidenDate = testDate1.toDate();
    DateTime testDate2 = DateTime.now();
    testDate2.withTimeAtStartOfDay();
    enrollmentDate = testDate2.toDate();
    programInstanceA = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceA, programA);
    programInstanceA.setUid("UID-A");
    programInstanceA.setOrganisationUnit(organisationUnitA);
    programInstanceB = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceA, programB);
    programInstanceB.setUid("UID-B");
    programInstanceB.setStatus(ProgramStatus.CANCELLED);
    programInstanceB.setOrganisationUnit(organisationUnitB);
    programInstanceC = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceA, programC);
    programInstanceC.setUid("UID-C");
    programInstanceC.setStatus(ProgramStatus.COMPLETED);
    programInstanceC.setOrganisationUnit(organisationUnitA);
    programInstanceD = new ProgramInstance(enrollmentDate, incidenDate, entityInstanceB, programA);
    programInstanceD.setUid("UID-D");
    programInstanceD.setOrganisationUnit(organisationUnitB);
}
Also used : TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet)

Example 4 with TrackedEntityInstance

use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class DhisConvenienceTest method createTrackedEntityInstance.

public static TrackedEntityInstance createTrackedEntityInstance(char uniqueChar, OrganisationUnit organisationUnit, TrackedEntityAttribute attribute) {
    TrackedEntityInstance entityInstance = new TrackedEntityInstance();
    entityInstance.setAutoFields();
    entityInstance.setOrganisationUnit(organisationUnit);
    TrackedEntityAttributeValue attributeValue = new TrackedEntityAttributeValue();
    attributeValue.setAttribute(attribute);
    attributeValue.setEntityInstance(entityInstance);
    attributeValue.setValue("Attribute" + uniqueChar);
    entityInstance.getTrackedEntityAttributeValues().add(attributeValue);
    return entityInstance;
}
Also used : TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 5 with TrackedEntityInstance

use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.

the class DhisConvenienceTest method createTrackedEntityInstance.

public static TrackedEntityInstance createTrackedEntityInstance(char uniqueChar, OrganisationUnit organisationUnit) {
    TrackedEntityInstance entityInstance = new TrackedEntityInstance();
    entityInstance.setAutoFields();
    entityInstance.setOrganisationUnit(organisationUnit);
    return entityInstance;
}
Also used : TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Aggregations

TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)11 Date (java.util.Date)10 HashSet (java.util.HashSet)9 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)8 ArrayList (java.util.ArrayList)7 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 Program (org.hisp.dhis.program.Program)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)6 List (java.util.List)5 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)5 PatientList (org.hisp.dhis.api.mobile.model.LWUITmodel.PatientList)5 PatientAttribute (org.hisp.dhis.api.mobile.model.PatientAttribute)4 Grid (org.hisp.dhis.common.Grid)4 TrackedEntityInstanceQueryParams (org.hisp.dhis.trackedentity.TrackedEntityInstanceQueryParams)4 Activity (org.hisp.dhis.api.mobile.model.Activity)3 Patient (org.hisp.dhis.api.mobile.model.LWUITmodel.Patient)3 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)3 QueryItem (org.hisp.dhis.common.QueryItem)3