Search in sources :

Example 36 with ProgramStageDataElement

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);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Date(java.util.Date) HashSet(java.util.HashSet)

Example 37 with ProgramStageDataElement

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());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 38 with ProgramStageDataElement

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);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement)

Example 39 with 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());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 40 with ProgramStageDataElement

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());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Aggregations

ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)43 DataElement (org.hisp.dhis.dataelement.DataElement)21 ProgramStage (org.hisp.dhis.program.ProgramStage)15 HashSet (java.util.HashSet)12 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)7 User (org.hisp.dhis.user.User)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 Program (org.hisp.dhis.program.Program)6 Test (org.junit.jupiter.api.Test)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 List (java.util.List)4 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)4 Event (org.hisp.dhis.tracker.domain.Event)4 HashMap (java.util.HashMap)3 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 PeriodType (org.hisp.dhis.period.PeriodType)3