Search in sources :

Example 6 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class SetMandatoryFieldValidatorTest method setUpTest.

@BeforeEach
void setUpTest() {
    firstProgramStage = createProgramStage('A', 0);
    firstProgramStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    dataElementA = createDataElement('A');
    dataElementA.setUid(DATA_ELEMENT_ID);
    ProgramStageDataElement programStageDataElementA = createProgramStageDataElement(firstProgramStage, dataElementA, 0);
    firstProgramStage.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA));
    secondProgramStage = createProgramStage('B', 0);
    secondProgramStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    dataElementB = createDataElement('B');
    ProgramStageDataElement programStageDataElementB = createProgramStageDataElement(secondProgramStage, dataElementB, 0);
    secondProgramStage.setProgramStageDataElements(Sets.newHashSet(programStageDataElementB));
    when(preheat.get(ProgramStage.class, firstProgramStage.getUid())).thenReturn(firstProgramStage);
    when(preheat.get(ProgramStage.class, secondProgramStage.getUid())).thenReturn(secondProgramStage);
    bundle = TrackerBundle.builder().build();
    bundle.setRuleEffects(getRuleEventAndEnrollmentEffects());
    bundle.setPreheat(preheat);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class ProgramStageDataElementMapper method map.

@Override
public DimensionResponse map(BaseIdentifiableObject dimension, String prefix) {
    ProgramStageDataElement programStageDataElement = (ProgramStageDataElement) dimension;
    final DimensionResponse mapped = super.map(programStageDataElement.getDataElement(), prefix).withValueType(programStageDataElement.getDataElement().getValueType().name()).withId(getProgramStageDataElementUid(programStageDataElement));
    return Optional.of(programStageDataElement).map(ProgramStageDataElement::getDataElement).map(DataElement::getOptionSet).map(BaseIdentifiableObject::getUid).map(mapped::withOptionSet).orElse(mapped);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) DimensionResponse(org.hisp.dhis.analytics.dimension.DimensionResponse)

Example 8 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class ProgramStageDataElementMapperTest method setDataElement.

private void setDataElement(ProgramStageDataElement programStageDataElement) {
    DataElement dataElement = new DataElement();
    dataElement.setUid(DATA_ELEMENT_UID);
    dataElement.setValueType(VALUE_TYPE);
    programStageDataElement.setDataElement(dataElement);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement)

Example 9 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class ObjectBundleServiceProgramTest method testCreateSimpleProgramWithSectionsNoReg.

@Test
void testCreateSimpleProgramWithSectionsNoReg() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_noreg_sections.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.hasErrorReports());
    objectBundleService.commit(bundle);
    List<DataSet> dataSets = manager.getAll(DataSet.class);
    List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    List<User> users = manager.getAll(User.class);
    List<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
    List<Program> programs = manager.getAll(Program.class);
    List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
    List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
    List<ProgramStageSection> programStageSections = manager.getAll(ProgramStageSection.class);
    assertFalse(dataSets.isEmpty());
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, validationRules.size());
    assertEquals(1, programs.size());
    assertEquals(1, programStages.size());
    assertEquals(3, programStageDataElements.size());
    assertEquals(2, programStageSections.size());
    ProgramStage programStage = programStages.get(0);
    assertEquals(3, programStage.getProgramStageDataElements().size());
    assertEquals(2, programStage.getProgramStageSections().size());
}
Also used : User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) Program(org.hisp.dhis.program.Program) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) ValidationRule(org.hisp.dhis.validation.ValidationRule) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) ProgramStage(org.hisp.dhis.program.ProgramStage) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with ProgramStageDataElement

use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.

the class ObjectBundleServiceProgramTest method testCreateSimpleProgramReg.

@Test
void testCreateSimpleProgramReg() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_reg1.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    validate.forEachErrorReport(System.out::println);
    assertFalse(validate.hasErrorReports());
    objectBundleService.commit(bundle);
    List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    List<User> users = manager.getAll(User.class);
    List<Program> programs = manager.getAll(Program.class);
    List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
    List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
    List<ProgramTrackedEntityAttribute> programTrackedEntityAttributes = manager.getAll(ProgramTrackedEntityAttribute.class);
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, programs.size());
    assertEquals(2, programStages.size());
    assertEquals(4, programStageDataElements.size());
    assertEquals(2, programTrackedEntityAttributes.size());
}
Also used : User(org.hisp.dhis.user.User) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramStage(org.hisp.dhis.program.ProgramStage) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) 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