use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class DeduplicationHelperTest method getRelationshipItem.
private RelationshipItem getRelationshipItem(Relationship relationship, TrackedEntityInstance trackedEntityInstance) {
RelationshipItem relationshipItem = new RelationshipItem();
relationshipItem.setRelationship(relationship);
relationshipItem.setTrackedEntityInstance(trackedEntityInstance);
return relationshipItem;
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class DeduplicationHelperTest method shouldNotFailGetDuplicateRelationshipError.
@Test
void shouldNotFailGetDuplicateRelationshipError() {
TrackedEntityInstance teiA = getTeiA();
TrackedEntityInstance teiB = getTeiB();
TrackedEntityInstance teiC = getTeiC();
// A->C, C->B
RelationshipItem fromA = new RelationshipItem();
RelationshipItem toA = new RelationshipItem();
RelationshipItem fromB = new RelationshipItem();
RelationshipItem toB = new RelationshipItem();
fromA.setTrackedEntityInstance(teiA);
toA.setTrackedEntityInstance(teiC);
fromB.setTrackedEntityInstance(teiB);
toB.setTrackedEntityInstance(teiC);
Relationship relA = new Relationship();
Relationship relB = new Relationship();
relA.setAutoFields();
relB.setAutoFields();
relA.setRelationshipType(relationshipType);
relB.setRelationshipType(relationshipType);
relA.setFrom(fromA);
relA.setTo(toA);
relB.setFrom(fromB);
relB.setTo(toB);
fromA.setRelationship(relA);
toA.setRelationship(relA);
fromB.setRelationship(relB);
toB.setRelationship(relB);
teiA.getRelationshipItems().add(fromA);
teiB.getRelationshipItems().add(fromB);
assertNotNull(deduplicationHelper.getDuplicateRelationshipError(teiA, teiB.getRelationshipItems().stream().map(RelationshipItem::getRelationship).collect(Collectors.toSet())));
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class RelationshipUtilsTest method testGenerateRelationshipKey.
@Test
void testGenerateRelationshipKey() {
RelationshipItem from = new RelationshipItem();
RelationshipItem to = new RelationshipItem();
from.setTrackedEntityInstance(teiA);
to.setTrackedEntityInstance(teiB);
Relationship relationship = new Relationship();
relationship.setRelationshipType(relationshipType);
relationship.setFrom(from);
relationship.setTo(to);
String key = relationshipType.getUid() + "_" + teiA.getUid() + "_" + teiB.getUid();
assertEquals(key, RelationshipUtils.generateRelationshipKey(relationship));
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class RelationshipUtilsTest method testExtractRelationshipItemUid.
@Test
void testExtractRelationshipItemUid() {
RelationshipItem itemA = new RelationshipItem();
RelationshipItem itemB = new RelationshipItem();
RelationshipItem itemC = new RelationshipItem();
itemA.setTrackedEntityInstance(teiA);
itemB.setProgramInstance(piA);
itemC.setProgramStageInstance(psiA);
assertEquals(teiA.getUid(), RelationshipUtils.extractRelationshipItemUid(itemA));
assertEquals(piA.getUid(), RelationshipUtils.extractRelationshipItemUid(itemB));
assertEquals(psiA.getUid(), RelationshipUtils.extractRelationshipItemUid(itemC));
}
use of org.hisp.dhis.relationship.RelationshipItem in project dhis2-core by dhis2.
the class AbstractEnrollmentService method getEnrollment.
@Override
public Enrollment getEnrollment(User user, ProgramInstance programInstance, TrackedEntityInstanceParams params, boolean skipOwnershipCheck) {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(programInstance.getUid());
List<String> errors = trackerAccessManager.canRead(user, programInstance, skipOwnershipCheck);
if (!errors.isEmpty()) {
throw new IllegalQueryException(errors.toString());
}
if (programInstance.getEntityInstance() != null) {
enrollment.setTrackedEntityType(programInstance.getEntityInstance().getTrackedEntityType().getUid());
enrollment.setTrackedEntityInstance(programInstance.getEntityInstance().getUid());
}
if (programInstance.getOrganisationUnit() != null) {
enrollment.setOrgUnit(programInstance.getOrganisationUnit().getUid());
enrollment.setOrgUnitName(programInstance.getOrganisationUnit().getName());
}
if (programInstance.getGeometry() != null) {
enrollment.setGeometry(programInstance.getGeometry());
}
enrollment.setCreated(DateUtils.getIso8601NoTz(programInstance.getCreated()));
enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(programInstance.getCreatedAtClient()));
enrollment.setLastUpdated(DateUtils.getIso8601NoTz(programInstance.getLastUpdated()));
enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(programInstance.getLastUpdatedAtClient()));
enrollment.setProgram(programInstance.getProgram().getUid());
enrollment.setStatus(EnrollmentStatus.fromProgramStatus(programInstance.getStatus()));
enrollment.setEnrollmentDate(programInstance.getEnrollmentDate());
enrollment.setIncidentDate(programInstance.getIncidentDate());
enrollment.setFollowup(programInstance.getFollowup());
enrollment.setCompletedDate(programInstance.getEndDate());
enrollment.setCompletedBy(programInstance.getCompletedBy());
enrollment.setStoredBy(programInstance.getStoredBy());
enrollment.setCreatedByUserInfo(programInstance.getCreatedByUserInfo());
enrollment.setLastUpdatedByUserInfo(programInstance.getLastUpdatedByUserInfo());
enrollment.setDeleted(programInstance.isDeleted());
enrollment.getNotes().addAll(NoteHelper.convertNotes(programInstance.getComments()));
if (params.isIncludeEvents()) {
for (ProgramStageInstance programStageInstance : programInstance.getProgramStageInstances()) {
if ((params.isIncludeDeleted() || !programStageInstance.isDeleted()) && trackerAccessManager.canRead(user, programStageInstance, true).isEmpty()) {
enrollment.getEvents().add(eventService.getEvent(programStageInstance, params.isDataSynchronizationQuery(), true));
}
}
}
if (params.isIncludeRelationships()) {
for (RelationshipItem relationshipItem : programInstance.getRelationshipItems()) {
enrollment.getRelationships().add(relationshipService.getRelationship(relationshipItem.getRelationship(), RelationshipParams.FALSE, user));
}
}
return enrollment;
}
Aggregations