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