Search in sources :

Example 21 with RelationshipItem

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;
}
Also used : RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Example 22 with 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())));
}
Also used : Relationship(org.hisp.dhis.relationship.Relationship) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 23 with RelationshipItem

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));
}
Also used : Relationship(org.hisp.dhis.relationship.Relationship) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 24 with RelationshipItem

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));
}
Also used : RelationshipItem(org.hisp.dhis.relationship.RelationshipItem) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 25 with RelationshipItem

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;
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) RelationshipItem(org.hisp.dhis.relationship.RelationshipItem)

Aggregations

RelationshipItem (org.hisp.dhis.relationship.RelationshipItem)30 Relationship (org.hisp.dhis.relationship.Relationship)16 Test (org.junit.jupiter.api.Test)11 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)9 RelationshipType (org.hisp.dhis.relationship.RelationshipType)8 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)7 ArrayList (java.util.ArrayList)5 ProgramInstance (org.hisp.dhis.program.ProgramInstance)5 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 Date (java.util.Date)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 CodeGenerator (org.hisp.dhis.common.CodeGenerator)2 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)2 ProgramInstanceService (org.hisp.dhis.program.ProgramInstanceService)2 RelationshipService (org.hisp.dhis.relationship.RelationshipService)2