Search in sources :

Example 46 with ProgramStage

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

the class RelationshipStoreTest method getByProgramStageInstance.

@Test
void getByProgramStageInstance() {
    Program programA = createProgram('A', new HashSet<>(), organisationUnit);
    programService.addProgram(programA);
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setProgram(programA);
    programInstance.setAutoFields();
    programInstance.setEnrollmentDate(new Date());
    programInstance.setIncidentDate(new Date());
    programInstance.setStatus(ProgramStatus.ACTIVE);
    programInstanceService.addProgramInstance(programInstance);
    ProgramStage programStageA = createProgramStage('S', programA);
    programStageA.setProgram(programA);
    programStageService.saveProgramStage(programStageA);
    programA.getProgramStages().add(programStageA);
    ProgramStageInstance programStageInstance = new ProgramStageInstance();
    programStageInstance.setOrganisationUnit(organisationUnit);
    programStageInstance.setProgramStage(programStageA);
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setAutoFields();
    programStageInstanceService.addProgramStageInstance(programStageInstance);
    RelationshipItem relationshipItemFrom = new RelationshipItem();
    relationshipItemFrom.setTrackedEntityInstance(trackedEntityInstanceA);
    RelationshipItem relationshipItemTo = new RelationshipItem();
    relationshipItemTo.setProgramStageInstance(programStageInstance);
    Relationship relationshipA = new Relationship();
    relationshipA.setRelationshipType(relationshipType);
    relationshipA.setFrom(relationshipItemFrom);
    relationshipA.setTo(relationshipItemTo);
    relationshipA.setKey(RelationshipUtils.generateRelationshipKey(relationshipA));
    relationshipA.setInvertedKey(RelationshipUtils.generateRelationshipInvertedKey(relationshipA));
    relationshipService.addRelationship(relationshipA);
    List<Relationship> relationshipList = relationshipService.getRelationshipsByProgramStageInstance(programStageInstance, true);
    assertEquals(1, relationshipList.size());
    assertTrue(relationshipList.contains(relationshipA));
    assertTrue(relationshipService.getRelationshipByRelationship(relationshipA).isPresent());
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Relationship(org.hisp.dhis.relationship.Relationship) ProgramStage(org.hisp.dhis.program.ProgramStage) Date(java.util.Date) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 47 with ProgramStage

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

the class DefaultPdfDataEntryFormService method setProgramStage_DocumentContent.

private void setProgramStage_DocumentContent(Document document, PdfWriter writer, String programStageUid) throws Exception {
    ProgramStage programStage = programStageService.getProgramStage(programStageUid);
    if (programStage == null) {
        throw new RuntimeException("Error - ProgramStage not found for UID " + programStageUid);
    } else {
        // Get Rectangle with TextBox Width to be used
        Rectangle rectangle = new Rectangle(0, 0, TEXTBOXWIDTH, PdfDataEntryFormUtil.CONTENT_HEIGHT_DEFAULT);
        // Create Main Layout table and set the properties
        PdfPTable mainTable = getProgramStageMainTable();
        // Generate Period List for ProgramStage
        List<Period> periods = getProgramStagePeriodList();
        // Add Org Unit, Period, Hidden ProgramStageID Field
        insertTable_OrgAndPeriod(mainTable, writer, periods);
        insertTable_TextRow(writer, mainTable, TEXT_BLANK);
        // Add ProgramStage Field - programStage.getId();
        insertTable_HiddenValue(mainTable, rectangle, writer, PdfDataEntryFormUtil.LABELCODE_PROGRAMSTAGEIDTEXTBOX, String.valueOf(programStage.getId()));
        // Add ProgramStage Content to PDF - [The Main Section]
        insertTable_ProgramStage(mainTable, writer, programStage);
        // Add the mainTable to document
        document.add(mainTable);
    }
}
Also used : PdfPTable(com.lowagie.text.pdf.PdfPTable) Rectangle(com.lowagie.text.Rectangle) Period(org.hisp.dhis.period.Period) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 48 with ProgramStage

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

the class EventStatusPreProcessorTest method testVisitedStatusIsConvertedToActive.

@Test
void testVisitedStatusIsConvertedToActive() {
    // Given
    Event event = new Event();
    event.setStatus(EventStatus.VISITED);
    event.setProgramStage("programStageUid");
    TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setUid("programInstanceUid");
    Program program = new Program();
    program.setUid("programUid");
    ProgramStage programStage = new ProgramStage();
    programStage.setUid("programStageUid");
    programStage.setProgram(program);
    TrackerPreheat preheat = new TrackerPreheat();
    preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
    preheat.put(TrackerIdentifier.UID, programStage);
    bundle.setPreheat(preheat);
    // When
    preProcessorToTest.process(bundle);
    // Then
    assertEquals(EventStatus.ACTIVE, bundle.getEvents().get(0).getStatus());
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 49 with ProgramStage

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

the class ProgramRuleIntegrationTest method setUpTest.

@Override
public void setUpTest() throws Exception {
    renderService = _renderService;
    userService = _userService;
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("tracker/simple_metadata.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 validationReport = objectBundleValidationService.validate(bundle);
    assertFalse(validationReport.hasErrorReports());
    objectBundleService.commit(bundle);
    Program program = bundle.getPreheat().get(PreheatIdentifier.UID, Program.class, "BFcipDERJnf");
    Program programWithoutRegistration = bundle.getPreheat().get(PreheatIdentifier.UID, Program.class, "BFcipDERJne");
    DataElement dataElement1 = bundle.getPreheat().get(PreheatIdentifier.UID, DataElement.class, "DATAEL00001");
    DataElement dataElement2 = bundle.getPreheat().get(PreheatIdentifier.UID, DataElement.class, "DATAEL00002");
    ProgramStage programStage = bundle.getPreheat().get(PreheatIdentifier.UID, ProgramStage.class, "NpsdDv6kKSO");
    ProgramRuleVariable programRuleVariable = createProgramRuleVariableWithDataElement('A', program, dataElement2);
    programRuleVariableService.addProgramRuleVariable(programRuleVariable);
    ProgramRule programRuleA = createProgramRule('A', program);
    programRuleA.setUid("ProgramRule");
    programRuleService.addProgramRule(programRuleA);
    ProgramRule programRuleWithoutRegistration = createProgramRule('W', programWithoutRegistration);
    programRuleService.addProgramRule(programRuleWithoutRegistration);
    ProgramRule programRuleB = createProgramRule('B', program);
    programRuleB.setProgramStage(programStage);
    programRuleService.addProgramRule(programRuleB);
    ProgramRuleAction programRuleActionShowWarning = createProgramRuleAction('A', programRuleA);
    programRuleActionShowWarning.setProgramRuleActionType(ProgramRuleActionType.SHOWWARNING);
    programRuleActionShowWarning.setContent("WARNING");
    programRuleActionService.addProgramRuleAction(programRuleActionShowWarning);
    ProgramRuleAction programRuleActionAssign = createProgramRuleAction('C', programRuleA);
    programRuleActionAssign.setProgramRuleActionType(ProgramRuleActionType.ASSIGN);
    programRuleActionAssign.setData("#{ProgramRuleVariableA}");
    programRuleActionAssign.setDataElement(dataElement1);
    programRuleActionService.addProgramRuleAction(programRuleActionAssign);
    ProgramRuleAction programRuleActionShowWarningForProgramStage = createProgramRuleAction('B', programRuleB);
    programRuleActionShowWarningForProgramStage.setProgramRuleActionType(ProgramRuleActionType.SHOWWARNING);
    programRuleActionShowWarningForProgramStage.setContent("PROGRAM STAGE WARNING");
    programRuleActionService.addProgramRuleAction(programRuleActionShowWarningForProgramStage);
    programRuleA.getProgramRuleActions().add(programRuleActionShowWarning);
    programRuleA.getProgramRuleActions().add(programRuleActionAssign);
    programRuleWithoutRegistration.getProgramRuleActions().add(programRuleActionShowWarning);
    programRuleService.updateProgramRule(programRuleWithoutRegistration);
    programRuleB.getProgramRuleActions().add(programRuleActionShowWarningForProgramStage);
    programRuleService.updateProgramRule(programRuleB);
    userA = userService.getUser("M5zQapPyTZI");
    injectSecurityContext(userA);
}
Also used : ProgramRuleVariable(org.hisp.dhis.programrule.ProgramRuleVariable) ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) Program(org.hisp.dhis.program.Program) ProgramRule(org.hisp.dhis.programrule.ProgramRule) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramRuleAction(org.hisp.dhis.programrule.ProgramRuleAction) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) List(java.util.List) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 50 with ProgramStage

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

the class EventProgramPreProcessorTest method programStageWithRegistration.

private ProgramStage programStageWithRegistration() {
    ProgramStage programStage = createProgramStage('A', 1, false);
    programStage.setUid(PROGRAM_STAGE_WITH_REGISTRATION);
    programStage.setProgram(programWithRegistration());
    return programStage;
}
Also used : ProgramStage(org.hisp.dhis.program.ProgramStage) DhisConvenienceTest.createProgramStage(org.hisp.dhis.DhisConvenienceTest.createProgramStage)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)209 Test (org.junit.jupiter.api.Test)86 Program (org.hisp.dhis.program.Program)82 DataElement (org.hisp.dhis.dataelement.DataElement)67 Event (org.hisp.dhis.tracker.domain.Event)47 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)40 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)39 ProgramInstance (org.hisp.dhis.program.ProgramInstance)38 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)26 DhisConvenienceTest.createProgramStage (org.hisp.dhis.DhisConvenienceTest.createProgramStage)22 DataValue (org.hisp.dhis.tracker.domain.DataValue)22 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 User (org.hisp.dhis.user.User)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)17 ArrayList (java.util.ArrayList)16 Date (java.util.Date)16 List (java.util.List)16 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)16 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)16