use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class RegistrationSingleEventServiceTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
userService = _userService;
organisationUnitA = createOrganisationUnit('A');
organisationUnitB = createOrganisationUnit('B');
manager.save(organisationUnitA);
manager.save(organisationUnitB);
TrackedEntityType trackedEntityType = createTrackedEntityType('A');
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
maleA = createTrackedEntityInstance(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);
trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
dataElementA = createDataElement('A');
dataElementA.setValueType(ValueType.INTEGER);
manager.save(dataElementA);
programStageA = createProgramStage('A', 0);
manager.save(programStageA);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
manager.save(programA);
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementA);
programStageDataElement.setProgramStage(programStageA);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageA.getProgramStageDataElements().add(programStageDataElement);
programStageA.setProgram(programA);
programA.getProgramStages().add(programStageA);
manager.update(programStageA);
manager.update(programA);
createUserAndInjectSecurityContext(true);
manager.flush();
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class ProgramStageValidationStrategyTest method setUpTest.
@Override
protected void setUpTest() {
final int testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
userService = _userService;
createUserAndInjectSecurityContext(false, "F_TRACKED_ENTITY_DATAVALUE_ADD", "F_TRACKED_ENTITY_DATAVALUE_DELETE", "F_UNCOMPLETE_EVENT", "F_PROGRAMSTAGE_ADD", "F_PROGRAMSTAGE_DELETE", "F_PROGRAM_PUBLIC_ADD", "F_PROGRAM_PRIVATE_ADD", "F_PROGRAM_DELETE", "F_TRACKED_ENTITY_ADD", "F_TRACKED_ENTITY_UPDATE", "F_TRACKED_ENTITY_DELETE", "F_DATAELEMENT_PUBLIC_ADD", "F_DATAELEMENT_PRIVATE_ADD", "F_DATAELEMENT_DELETE", "F_CATEGORY_COMBO_PUBLIC_ADD", "F_CATEGORY_COMBO_PRIVATE_ADD", "F_CATEGORY_COMBO_DELETE");
User currentUser = currentUserService.getCurrentUser();
UserAccess userAccess1 = new UserAccess(currentUser, "rwrw----");
UserAccess userAccess2 = new UserAccess(currentUser, "rwrw----");
UserAccess userAccess3 = new UserAccess(currentUser, "rwrw----");
organisationUnitA = createOrganisationUnit('A');
organisationUnitA.addUser(currentUser);
organisationUnitA.getSharing().addUserAccess(userAccess1);
currentUser.getTeiSearchOrganisationUnits().add(organisationUnitA);
manager.save(organisationUnitA, false);
userService.updateUser(currentUser);
TrackedEntityType trackedEntityType = createTrackedEntityType('A');
trackedEntityType.getSharing().addUserAccess(userAccess1);
manager.save(trackedEntityType, false);
org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance(organisationUnitA);
maleA.setTrackedEntityType(trackedEntityType);
maleA.getSharing().addUserAccess(userAccess1);
maleA.setCreatedBy(currentUser);
manager.save(maleA, false);
trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
DataElement dataElementA = createDataElement('A');
dataElementA.setValueType(ValueType.INTEGER);
dataElementA.getSharing().addUserAccess(userAccess1);
manager.save(dataElementA, false);
DataElement dataElementB = createDataElement('B');
dataElementB.setValueType(ValueType.TEXT);
dataElementB.getSharing().addUserAccess(userAccess2);
manager.save(dataElementB, false);
DataElement dataElementC = createDataElement('C');
dataElementC.setValueType(ValueType.INTEGER);
dataElementC.getSharing().addUserAccess(userAccess3);
manager.save(dataElementC, false);
programStageA = createProgramStage('A', 0);
programStageA.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
programStageA.getSharing().addUserAccess(userAccess1);
manager.save(programStageA, false);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
programA.getSharing().addUserAccess(userAccess1);
manager.save(programA, false);
// Create a compulsory PSDE
ProgramStageDataElement programStageDataElementA = new ProgramStageDataElement();
programStageDataElementA.setDataElement(dataElementA);
programStageDataElementA.setProgramStage(programStageA);
programStageDataElementA.setCompulsory(true);
programStageDataElementA.getSharing().addUserAccess(userAccess1);
manager.save(programStageDataElementA, false);
// Create a compulsory PSDE
ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement();
programStageDataElementB.setDataElement(dataElementB);
programStageDataElementB.setProgramStage(programStageA);
programStageDataElementB.setCompulsory(true);
programStageDataElementB.getSharing().addUserAccess(userAccess1);
manager.save(programStageDataElementB, false);
// Create a NON-compulsory PSDE
ProgramStageDataElement programStageDataElementC = new ProgramStageDataElement();
programStageDataElementC.setDataElement(dataElementC);
programStageDataElementC.setProgramStage(programStageA);
programStageDataElementC.setCompulsory(false);
programStageDataElementC.getSharing().addUserAccess(userAccess1);
manager.save(programStageDataElementC, false);
// Assign all 3 created PSDEs to created ProgramStage programStageA and
// to
// created Program programA
programStageA.getProgramStageDataElements().add(programStageDataElementA);
programStageA.getProgramStageDataElements().add(programStageDataElementB);
programStageA.getProgramStageDataElements().add(programStageDataElementC);
programStageA.setProgram(programA);
programA.getProgramStages().add(programStageA);
manager.update(programStageA);
manager.update(programA);
ProgramInstance programInstance = new ProgramInstance();
programInstance.setProgram(programA);
programInstance.setIncidentDate(new Date());
programInstance.setEnrollmentDate(new Date());
programInstance.setEntityInstance(maleA);
programInstance.getSharing().addUserAccess(userAccess1);
maleA.getProgramInstances().add(programInstance);
manager.save(programInstance, false);
manager.update(maleA);
Period periodA = createPeriod(testYear + "03");
periodA.getSharing().addUserAccess(userAccess1);
manager.save(periodA, false);
CategoryCombo categoryComboA = createCategoryCombo('A');
CategoryOptionCombo categoryOptionComboA = createCategoryOptionCombo('A');
categoryOptionComboA.setCategoryCombo(categoryComboA);
categoryComboA.getSharing().addUserAccess(userAccess1);
categoryOptionComboA.getSharing().addUserAccess(userAccess1);
manager.save(categoryComboA, false);
manager.save(categoryOptionComboA, false);
dataValueAMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementA.getUid(), "");
dataValueBMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementB.getUid(), "");
dataValueCMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementC.getUid(), "");
dataValueA = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementA.getUid(), "42");
dataValueB = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementB.getUid(), "Ford Prefect");
dataValueC = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementC.getUid(), "84");
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class EventSecurityTest method setUpTest.
@Override
protected void setUpTest() {
userService = _userService;
categoryService = _categoryService;
createAndInjectAdminUser();
organisationUnitA = createOrganisationUnit('A');
manager.save(organisationUnitA);
dataElementA = createDataElement('A');
dataElementA.setValueType(ValueType.INTEGER);
manager.save(dataElementA);
programStageA = createProgramStage('A', 0);
manager.save(programStageA);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITHOUT_REGISTRATION);
manager.save(programA);
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementA);
programStageDataElement.setProgramStage(programStageA);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageA.getProgramStageDataElements().add(programStageDataElement);
programStageA.setProgram(programA);
programA.getProgramStages().add(programStageA);
manager.update(programStageA);
manager.update(programA);
ProgramInstance programInstance = new ProgramInstance();
programInstance.setProgram(programA);
programInstance.setIncidentDate(new Date());
programInstance.setEnrollmentDate(new Date());
programInstanceService.addProgramInstance(programInstance);
manager.update(programA);
manager.flush();
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class ProgramRuleEngineTest method setupEvents.
private void setupEvents() {
organisationUnitA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnitA);
organisationUnitB = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(organisationUnitB);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programS = createProgram('S', new HashSet<>(), organisationUnitB);
programB = createProgram('E', new HashSet<>(), organisationUnitA);
programService.addProgram(programA);
programService.addProgram(programS);
programService.addProgram(programB);
ProgramTrackedEntityAttribute attribute = createProgramTrackedEntityAttribute(programS, attributeB);
attribute.setUid("ATTR-UID");
ProgramTrackedEntityAttribute programAttributeEmail = createProgramTrackedEntityAttribute(programB, attributeEmail);
attribute.setUid("ATTR-UID2");
programTrackedEntityAttributeStore.save(attribute);
programTrackedEntityAttributeStore.save(attribute);
programA.setProgramAttributes(Arrays.asList(attribute));
programS.setProgramAttributes(Arrays.asList(attribute));
programB.setProgramAttributes(Arrays.asList(programAttributeEmail));
programService.updateProgram(programA);
programService.updateProgram(programS);
programService.updateProgram(programB);
ProgramStage programStageA = createProgramStage('A', programA);
ProgramStage programStageAge = createProgramStage('S', programA);
ProgramStage programStageB = createProgramStage('B', programA);
ProgramStage programStageC = createProgramStage('C', programA);
programStageService.saveProgramStage(programStageA);
programStageService.saveProgramStage(programStageAge);
programStageService.saveProgramStage(programStageB);
programStageService.saveProgramStage(programStageC);
ProgramStageDataElement programStageDataElementA = createProgramStageDataElement(programStageA, dataElementA, 1);
ProgramStageDataElement programStageDataElementB = createProgramStageDataElement(programStageB, dataElementB, 2);
ProgramStageDataElement programStageDataElementC = createProgramStageDataElement(programStageC, dataElementC, 3);
ProgramStageDataElement programStageDataElementD = createProgramStageDataElement(programStageC, dataElementD, 4);
ProgramStageDataElement programStageDataElementDate = createProgramStageDataElement(programStageAge, dataElementDate, 5);
ProgramStageDataElement programStageDataElementAge = createProgramStageDataElement(programStageAge, dataElementAge, 6);
programStageDataElementService.addProgramStageDataElement(programStageDataElementA);
programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
programStageDataElementService.addProgramStageDataElement(programStageDataElementC);
programStageDataElementService.addProgramStageDataElement(programStageDataElementD);
programStageDataElementService.addProgramStageDataElement(programStageDataElementDate);
programStageDataElementService.addProgramStageDataElement(programStageDataElementAge);
programStageA.setSortOrder(1);
programStageB.setSortOrder(2);
programStageC.setSortOrder(3);
programStageA.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA, programStageDataElementB, programStageDataElementDate));
programStageAge.setProgramStageDataElements(Sets.newHashSet(programStageDataElementDate));
programStageB.setProgramStageDataElements(Sets.newHashSet(programStageDataElementA, programStageDataElementB));
programStageC.setProgramStageDataElements(Sets.newHashSet(programStageDataElementC, programStageDataElementD));
programStageService.updateProgramStage(programStageA);
programStageService.updateProgramStage(programStageB);
programStageService.updateProgramStage(programStageC);
programStageService.updateProgramStage(programStageAge);
programA.setProgramStages(Sets.newHashSet(programStageA, programStageB, programStageC, programStageAge));
programService.updateProgram(programA);
TrackedEntityInstance entityInstanceA = createTrackedEntityInstance(organisationUnitA);
entityInstanceService.addTrackedEntityInstance(entityInstanceA);
TrackedEntityInstance entityInstanceB = createTrackedEntityInstance(organisationUnitB);
entityInstanceService.addTrackedEntityInstance(entityInstanceB);
TrackedEntityInstance entityInstanceS = createTrackedEntityInstance(organisationUnitB);
entityInstanceService.addTrackedEntityInstance(entityInstanceS);
TrackedEntityInstance entityInstanceE = createTrackedEntityInstance(organisationUnitA);
entityInstanceService.addTrackedEntityInstance(entityInstanceE);
TrackedEntityAttributeValue attributeValue = new TrackedEntityAttributeValue(attributeA, entityInstanceA, "test");
trackedEntityAttributeValueService.addTrackedEntityAttributeValue(attributeValue);
TrackedEntityAttributeValue attributeValueB = new TrackedEntityAttributeValue(attributeB, entityInstanceB, "xmen");
trackedEntityAttributeValueService.addTrackedEntityAttributeValue(attributeValueB);
TrackedEntityAttributeValue attributeValueS = new TrackedEntityAttributeValue(attributeB, entityInstanceS, "xmen");
TrackedEntityAttributeValue attributeValueEmail = new TrackedEntityAttributeValue(attributeEmail, entityInstanceE, "zubair@dhis2.org");
trackedEntityAttributeValueService.addTrackedEntityAttributeValue(attributeValueS);
entityInstanceA.setTrackedEntityAttributeValues(Sets.newHashSet(attributeValue));
entityInstanceService.updateTrackedEntityInstance(entityInstanceA);
entityInstanceB.setTrackedEntityAttributeValues(Sets.newHashSet(attributeValueB));
entityInstanceService.updateTrackedEntityInstance(entityInstanceB);
entityInstanceS.setTrackedEntityAttributeValues(Sets.newHashSet(attributeValueS));
entityInstanceService.updateTrackedEntityInstance(entityInstanceS);
entityInstanceE.setTrackedEntityAttributeValues(Sets.newHashSet(attributeValueEmail));
entityInstanceService.updateTrackedEntityInstance(entityInstanceE);
DateTime testDate1 = DateTime.now();
testDate1.withTimeAtStartOfDay();
testDate1 = testDate1.minusDays(70);
Date incidentDate = testDate1.toDate();
DateTime testDate2 = DateTime.now();
testDate2.withTimeAtStartOfDay();
Date enrollmentDate = testDate2.toDate();
ProgramInstance programInstanceA = programInstanceService.enrollTrackedEntityInstance(entityInstanceA, programA, enrollmentDate, incidentDate, organisationUnitA);
programInstanceA.setUid("UID-P1");
programInstanceService.updateProgramInstance(programInstanceA);
ProgramInstance programInstanceE = programInstanceService.enrollTrackedEntityInstance(entityInstanceE, programB, enrollmentDate, incidentDate, organisationUnitA);
programInstanceE.setUid("UID-P2");
programInstanceService.updateProgramInstance(programInstanceE);
ProgramInstance programInstanceS = programInstanceService.enrollTrackedEntityInstance(entityInstanceS, programS, enrollmentDate, incidentDate, organisationUnitB);
programInstanceS.setUid("UID-PS");
programInstanceService.updateProgramInstance(programInstanceS);
ProgramStageInstance programStageInstanceA = new ProgramStageInstance(programInstanceA, programStageA);
programStageInstanceA.setDueDate(enrollmentDate);
programStageInstanceA.setExecutionDate(new Date());
programStageInstanceA.setUid("UID-PS1");
programStageInstanceService.addProgramStageInstance(programStageInstanceA);
eventDataValueDate = new EventDataValue();
eventDataValueDate.setDataElement(dataElementDate.getUid());
eventDataValueDate.setAutoFields();
eventDataValueDate.setValue(dob);
eventDataValueAge = new EventDataValue();
eventDataValueAge.setDataElement(dataElementAge.getUid());
eventDataValueAge.setAutoFields();
eventDataValueAge.setValue(dob);
ProgramStageInstance programStageInstanceDate = new ProgramStageInstance(programInstanceA, programStageAge);
programStageInstanceDate.setDueDate(enrollmentDate);
programStageInstanceDate.setExecutionDate(psEventDate);
programStageInstanceDate.setUid("UID-PS12");
programStageInstanceDate.setEventDataValues(Sets.newHashSet(eventDataValueDate));
programStageInstanceService.addProgramStageInstance(programStageInstanceDate);
ProgramStageInstance programStageInstanceAge = new ProgramStageInstance(programInstanceA, programStageAge);
programStageInstanceAge.setDueDate(enrollmentDate);
programStageInstanceAge.setExecutionDate(psEventDate);
programStageInstanceAge.setUid("UID-PS13");
programStageInstanceAge.setEventDataValues(Sets.newHashSet(eventDataValueAge));
programStageInstanceService.addProgramStageInstance(programStageInstanceAge);
ProgramStageInstance programStageInstanceB = new ProgramStageInstance(programInstanceA, programStageB);
programStageInstanceB.setDueDate(enrollmentDate);
programStageInstanceB.setExecutionDate(new Date());
programStageInstanceB.setUid("UID-PS2");
programStageInstanceService.addProgramStageInstance(programStageInstanceB);
ProgramStageInstance programStageInstanceC = new ProgramStageInstance(programInstanceA, programStageC);
programStageInstanceC.setDueDate(enrollmentDate);
programStageInstanceC.setExecutionDate(new Date());
programStageInstanceC.setUid("UID-PS3");
programStageInstanceService.addProgramStageInstance(programStageInstanceC);
programInstanceA.getProgramStageInstances().addAll(Sets.newHashSet(programStageInstanceA, programStageInstanceB, programStageInstanceC, programStageInstanceAge));
programInstanceService.updateProgramInstance(programInstanceA);
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class AssignValueImplementerTest method setUpTest.
@BeforeEach
void setUpTest() {
firstProgramStage = createProgramStage('A', 0);
firstProgramStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
attributeA = createTrackedEntityAttribute('A');
attributeA.setUid(ATTRIBUTE_ID);
attributeA.setValueType(ValueType.NUMBER);
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');
dataElementB.setUid(ANOTHER_DATA_ELEMENT_ID);
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);
when(preheat.get(DataElement.class, dataElementA.getUid())).thenReturn(dataElementA);
when(preheat.get(TrackedEntityAttribute.class, attributeA.getUid())).thenReturn(attributeA);
bundle = TrackerBundle.builder().build();
bundle.setPreheat(preheat);
when(systemSettingManager.getBooleanSetting(SettingKey.RULE_ENGINE_ASSIGN_OVERWRITE)).thenReturn(Boolean.FALSE);
}
Aggregations