use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class TrackedEntityAttributeStoreIntegrationTest method setUpTest.
@Override
public void setUpTest() {
attributeW = createTrackedEntityAttribute('W');
attributeW.setUnique(true);
attributeY = createTrackedEntityAttribute('Y');
attributeY.setUnique(true);
attributeZ = createTrackedEntityAttribute('Z', ValueType.NUMBER);
Program program = createProgram('A');
programService.addProgram(program);
TrackedEntityType trackedEntityTypeA = createTrackedEntityType('A');
trackedEntityTypeA.setPublicAccess(AccessStringHelper.FULL);
trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeA);
TrackedEntityType trackedEntityTypeB = createTrackedEntityType('B');
trackedEntityTypeB.setPublicAccess(AccessStringHelper.FULL);
trackedEntityTypeService.addTrackedEntityType(trackedEntityTypeB);
// Create 20 Tracked Entity Attributes (named A .. O)
IntStream.range(A, T).mapToObj(i -> Character.toString((char) i)).forEach(c -> attributeService.addTrackedEntityAttribute(createTrackedEntityAttribute(c.charAt(0), ValueType.TEXT)));
// Transform the Tracked Entity Attributes into a List of
// TrackedEntityTypeAttribute
List<TrackedEntityTypeAttribute> teatList = IntStream.range(A, T).mapToObj(i -> Character.toString((char) i)).map(s -> new TrackedEntityTypeAttribute(trackedEntityTypeA, attributeService.getTrackedEntityAttributeByName("Attribute" + s))).collect(Collectors.toList());
// Setting searchable to true for 5 random tracked entity type
// attributes
TrackedEntityTypeAttribute teta = teatList.get(0);
teta.setSearchable(true);
teta = teatList.get(4);
teta.setSearchable(true);
teta = teatList.get(9);
teta.setSearchable(true);
teta = teatList.get(14);
teta.setSearchable(true);
teta = teatList.get(19);
teta.setSearchable(true);
// Assign 10 TrackedEntityTypeAttribute to Tracked Entity Type A
trackedEntityTypeA.getTrackedEntityTypeAttributes().addAll(teatList.subList(0, 10));
trackedEntityTypeService.updateTrackedEntityType(trackedEntityTypeA);
// Assign 10 TrackedEntityTypeAttribute to Tracked Entity Type B
trackedEntityTypeB.getTrackedEntityTypeAttributes().addAll(teatList.subList(10, 20));
trackedEntityTypeService.updateTrackedEntityType(trackedEntityTypeB);
programB = createProgram('B');
programService.addProgram(programB);
List<ProgramTrackedEntityAttribute> pteaList = IntStream.range(A, T).mapToObj(i -> Character.toString((char) i)).map(s -> new ProgramTrackedEntityAttribute(programB, attributeService.getTrackedEntityAttributeByName("Attribute" + s))).collect(Collectors.toList());
// Setting searchable to true for 5 random program tracked entity
// attributes
ProgramTrackedEntityAttribute ptea = pteaList.get(0);
ptea.setSearchable(true);
ptea = pteaList.get(4);
ptea.setSearchable(true);
ptea = pteaList.get(9);
ptea.setSearchable(true);
ptea = pteaList.get(13);
ptea.setSearchable(true);
ptea = pteaList.get(18);
ptea.setSearchable(true);
programB.getProgramAttributes().addAll(pteaList);
programService.updateProgram(programB);
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class RelationshipUtilsTest method setup.
@BeforeEach
void setup() {
OrganisationUnit ou = createOrganisationUnit('A');
teiA = createTrackedEntityInstance('A', ou);
teiB = createTrackedEntityInstance('B', ou);
Program p = createProgram('A');
piA = createProgramInstance(p, teiA, ou);
ProgramStage ps = createProgramStage('A', p);
psiA = createProgramStageInstance(ps, piA, ou);
relationshipType = createRelationshipType('A');
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class RelationshipTypeObjectBundleHook method handleRelationshipConstraintReferences.
/**
* Handles the references for RelationshipConstraint, persisting any bject
* that might end up in a transient state.
*/
private void handleRelationshipConstraintReferences(RelationshipConstraint relationshipConstraint) {
TrackedEntityType trackedEntityType = relationshipConstraint.getTrackedEntityType();
Program program = relationshipConstraint.getProgram();
ProgramStage programStage = relationshipConstraint.getProgramStage();
if (trackedEntityType != null) {
trackedEntityType = trackedEntityTypeService.getTrackedEntityType(trackedEntityType.getUid());
relationshipConstraint.setTrackedEntityType(trackedEntityType);
}
if (program != null) {
program = programService.getProgram(program.getUid());
relationshipConstraint.setProgram(program);
}
if (programStage != null) {
programStage = programStageService.getProgramStage(programStage.getUid());
relationshipConstraint.setProgramStage(programStage);
}
sessionFactory.getCurrentSession().save(relationshipConstraint);
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class MetadataOrgUnitMergeHandlerTest method testMergePrograms.
@Test
void testMergePrograms() {
Program prA = createProgram('A');
prA.addOrganisationUnit(ouA);
prA.addOrganisationUnit(ouB);
Program prB = createProgram('B');
prB.addOrganisationUnit(ouA);
OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
assertEquals(2, ouA.getPrograms().size());
assertEquals(1, ouB.getPrograms().size());
assertEquals(0, ouC.getPrograms().size());
handler.mergePrograms(request);
assertEquals(0, ouA.getPrograms().size());
assertEquals(0, ouB.getPrograms().size());
assertEquals(2, ouC.getPrograms().size());
}
use of org.hisp.dhis.program.Program in project dhis2-core by dhis2.
the class DataDimensionExtractor method getBaseDimensionalItemObject.
private BaseDimensionalItemObject getBaseDimensionalItemObject(final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects, final DimensionalItemId id) {
BaseDimensionalItemObject dimensionalItemObject = null;
switch(id.getDimensionItemType()) {
case DATA_ELEMENT:
DataElement dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
if (dataElement != null) {
dimensionalItemObject = cloneIfNeeded(dataElement, id);
}
break;
case INDICATOR:
final Indicator indicator = (Indicator) atomicObjects.getValue(Indicator.class, id.getId0());
if (indicator != null) {
dimensionalItemObject = cloneIfNeeded(indicator, id);
}
break;
case DATA_ELEMENT_OPERAND:
dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId0());
final CategoryOptionCombo categoryOptionCombo = id.getId1() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId1());
final CategoryOptionCombo attributeOptionCombo = id.getId2() == null ? null : (CategoryOptionCombo) atomicObjects.getValue(CategoryOptionCombo.class, id.getId2());
if (dataElement != null && (id.getId1() != null) == (categoryOptionCombo != null) && (id.getId2() != null) == (attributeOptionCombo != null)) {
dimensionalItemObject = new DataElementOperand(dataElement, categoryOptionCombo, attributeOptionCombo);
}
break;
case REPORTING_RATE:
final DataSet dataSet = (DataSet) atomicObjects.getValue(DataSet.class, id.getId0());
if (dataSet != null) {
dimensionalItemObject = new ReportingRate(dataSet, ReportingRateMetric.valueOf(id.getId1()));
}
break;
case PROGRAM_DATA_ELEMENT:
Program program = (Program) atomicObjects.getValue(Program.class, id.getId0());
dataElement = (DataElement) atomicObjects.getValue(DataElement.class, id.getId1());
if (program != null && dataElement != null) {
dimensionalItemObject = new ProgramDataElementDimensionItem(program, dataElement);
}
break;
case PROGRAM_ATTRIBUTE:
program = (Program) atomicObjects.getValue(Program.class, id.getId0());
final TrackedEntityAttribute attribute = (TrackedEntityAttribute) atomicObjects.getValue(TrackedEntityAttribute.class, id.getId1());
if (program != null && attribute != null) {
dimensionalItemObject = new ProgramTrackedEntityAttributeDimensionItem(program, attribute);
}
break;
case PROGRAM_INDICATOR:
final ProgramIndicator programIndicator = (ProgramIndicator) atomicObjects.getValue(ProgramIndicator.class, id.getId0());
if (programIndicator != null) {
dimensionalItemObject = cloneIfNeeded(programIndicator, id);
}
break;
default:
log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getItemObjectMap");
break;
}
return dimensionalItemObject;
}
Aggregations