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");
}
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);
}
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);
}
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;
}
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;
}
Aggregations