use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class EventSecurityImportValidationTest method setupMetadata.
private void setupMetadata() {
organisationUnitA = createOrganisationUnit('A');
organisationUnitB = createOrganisationUnit('B');
manager.save(organisationUnitA);
manager.save(organisationUnitB);
organisationUnitA.setPublicAccess(AccessStringHelper.FULL);
manager.update(organisationUnitA);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementA.setValueType(ValueType.INTEGER);
dataElementB.setValueType(ValueType.INTEGER);
manager.save(dataElementA);
manager.save(dataElementB);
programStageA = createProgramStage('A', 0);
programStageB = createProgramStage('B', 0);
programStageB.setRepeatable(true);
manager.save(programStageA);
manager.save(programStageB);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
trackedEntityType = createTrackedEntityType('A');
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
TrackedEntityType trackedEntityTypeFromProgram = createTrackedEntityType('C');
trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeFromProgram);
manager.save(programA);
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementA);
programStageDataElement.setProgramStage(programStageA);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageA.getProgramStageDataElements().add(programStageDataElement);
programStageA.setProgram(programA);
programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementB);
programStageDataElement.setProgramStage(programStageB);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageB.getProgramStageDataElements().add(programStageDataElement);
programStageB.setProgram(programA);
programStageB.setMinDaysFromStart(2);
programA.getProgramStages().add(programStageA);
programA.getProgramStages().add(programStageB);
programA.setTrackedEntityType(trackedEntityType);
trackedEntityType.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
manager.update(programStageA);
manager.update(programStageB);
manager.update(programA);
maleA = createTrackedEntityInstance('A', organisationUnitA);
maleB = createTrackedEntityInstance(organisationUnitB);
femaleA = createTrackedEntityInstance(organisationUnitA);
femaleB = createTrackedEntityInstance(organisationUnitB);
maleA.setTrackedEntityType(trackedEntityType);
maleB.setTrackedEntityType(trackedEntityType);
femaleA.setTrackedEntityType(trackedEntityType);
femaleB.setTrackedEntityType(trackedEntityType);
manager.save(maleA);
manager.save(maleB);
manager.save(femaleA);
manager.save(femaleB);
int testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
Date dateMar20 = getDate(testYear, 3, 20);
Date dateApr10 = getDate(testYear, 4, 10);
ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(maleA, programA, dateMar20, dateApr10, organisationUnitA, "MNWZ6hnuhSX");
programInstanceService.addProgramInstance(programInstance);
trackedEntityProgramOwnerService.updateTrackedEntityProgramOwner(maleA.getUid(), programA.getUid(), organisationUnitA.getUid());
manager.update(programA);
User user = userService.getUser(USER_5);
OrganisationUnit qfUVllTs6cS = organisationUnitService.getOrganisationUnit("QfUVllTs6cS");
user.addOrganisationUnit(qfUVllTs6cS);
user.addOrganisationUnit(organisationUnitA);
User adminUser = userService.getUser(ADMIN_USER_UID);
adminUser.addOrganisationUnit(organisationUnitA);
Program p = programService.getProgram("prabcdefghA");
p.addOrganisationUnit(qfUVllTs6cS);
programService.updateProgram(p);
manager.update(user);
manager.update(adminUser);
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method succeedsWhenMandatoryDataElementIsNotPresentButMandatoryValidationIsNotNeeded.
@Test
void succeedsWhenMandatoryDataElementIsNotPresentButMandatoryValidationIsNotNeeded() {
setUpIdentifiers();
DataElement dataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
ProgramStage programStage = new ProgramStage();
ProgramStageDataElement mandatoryStageElement1 = new ProgramStageDataElement();
DataElement mandatoryElement1 = new DataElement();
mandatoryElement1.setUid("MANDATORY_DE");
mandatoryStageElement1.setDataElement(mandatoryElement1);
mandatoryStageElement1.setCompulsory(true);
ProgramStageDataElement mandatoryStageElement2 = new ProgramStageDataElement();
DataElement mandatoryElement2 = new DataElement();
mandatoryElement2.setUid(dataValue().getDataElement());
mandatoryStageElement2.setDataElement(mandatoryElement2);
mandatoryStageElement2.setCompulsory(true);
programStage.setProgramStageDataElements(Set.of(mandatoryStageElement1, mandatoryStageElement2));
when(context.getProgramStage("PROGRAM_STAGE")).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
Event event = Event.builder().programStage("PROGRAM_STAGE").status(EventStatus.ACTIVE).dataValues(Set.of(dataValue())).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method getProgramStageDataElements.
private Set<ProgramStageDataElement> getProgramStageDataElements(DataElement dataElement, ProgramStage programStage, boolean compulsory) {
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement(programStage, dataElement);
programStageDataElement.setCompulsory(compulsory);
return Set.of(programStageDataElement);
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failValidationWhenAMandatoryDataElementIsMissing.
@Test
void failValidationWhenAMandatoryDataElementIsMissing() {
setUpIdentifiers();
DataElement dataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
ProgramStage programStage = new ProgramStage();
ProgramStageDataElement mandatoryStageElement1 = new ProgramStageDataElement();
DataElement mandatoryElement1 = new DataElement();
mandatoryElement1.setUid("MANDATORY_DE");
mandatoryStageElement1.setDataElement(mandatoryElement1);
mandatoryStageElement1.setCompulsory(true);
ProgramStageDataElement mandatoryStageElement2 = new ProgramStageDataElement();
DataElement mandatoryElement2 = new DataElement();
mandatoryElement2.setUid(dataValue().getDataElement());
mandatoryStageElement2.setDataElement(mandatoryElement2);
mandatoryStageElement2.setCompulsory(true);
programStage.setProgramStageDataElements(Set.of(mandatoryStageElement1, mandatoryStageElement2));
when(context.getProgramStage("PROGRAM_STAGE")).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
Event event = Event.builder().programStage("PROGRAM_STAGE").status(EventStatus.COMPLETED).dataValues(Set.of(dataValue())).build();
hook.validateEvent(reporter, event);
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(TrackerErrorCode.E1303, reporter.getReportList().get(0).getErrorCode());
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class EventDataValuesValidationHookTest method failValidationWhenDataElementIsNotPresentInProgramStage.
@Test
void failValidationWhenDataElementIsNotPresentInProgramStage() {
setUpIdentifiers();
DataElement dataElement = dataElement();
when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
DataElement notPresentDataElement = dataElement();
notPresentDataElement.setUid("de_not_present_in_program_stage");
when(context.getDataElement("de_not_present_in_program_stage")).thenReturn(notPresentDataElement);
ProgramStage programStage = new ProgramStage();
ProgramStageDataElement mandatoryStageElement1 = new ProgramStageDataElement();
DataElement mandatoryElement1 = new DataElement();
mandatoryElement1.setUid(dataValue().getDataElement());
mandatoryStageElement1.setDataElement(mandatoryElement1);
mandatoryStageElement1.setCompulsory(true);
programStage.setProgramStageDataElements(Set.of(mandatoryStageElement1));
when(context.getProgramStage("PROGRAM_STAGE")).thenReturn(programStage);
ValidationErrorReporter reporter = new ValidationErrorReporter(context);
DataValue notPresentDataValue = dataValue();
notPresentDataValue.setDataElement("de_not_present_in_program_stage");
Event event = Event.builder().programStage("PROGRAM_STAGE").status(EventStatus.ACTIVE).dataValues(Set.of(dataValue(), notPresentDataValue)).build();
hook.validateEvent(reporter, event);
assertThat(reporter.getReportList(), hasSize(1));
assertEquals(TrackerErrorCode.E1305, reporter.getReportList().get(0).getErrorCode());
}
Aggregations