Search in sources :

Example 1 with RelationshipType

use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.

the class DefaultProgramService method getAllRelationshipTypes.

@Override
public List<org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType> getAllRelationshipTypes() {
    try {
        List<RelationshipType> relationshipTypes = new ArrayList<>(relationshipTypeService.getAllRelationshipTypes());
        List<org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType> mobileRelationshipTypes = new ArrayList<>();
        for (RelationshipType relType : relationshipTypes) {
            org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType mobileRelType = new org.hisp.dhis.api.mobile.model.LWUITmodel.RelationshipType();
            mobileRelType.setId(relType.getId());
            mobileRelType.setName(relType.getName());
            mobileRelType.setAIsToB(relType.getaIsToB());
            mobileRelType.setBIsToA(relType.getbIsToA());
            mobileRelationshipTypes.add(mobileRelType);
        }
        return mobileRelationshipTypes;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 2 with RelationshipType

use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.

the class AbstractTrackedEntityInstanceService method checkRelationships.

private List<ImportConflict> checkRelationships(TrackedEntityInstance trackedEntityInstance) {
    List<ImportConflict> importConflicts = new ArrayList<>();
    for (org.hisp.dhis.dxf2.events.trackedentity.Relationship relationship : trackedEntityInstance.getRelationships()) {
        RelationshipType relationshipType = manager.get(RelationshipType.class, relationship.getRelationship());
        if (relationshipType == null) {
            importConflicts.add(new ImportConflict("Relationship.type", "Invalid type " + relationship.getRelationship()));
        }
        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceA = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceA());
        if (entityInstanceA == null) {
            importConflicts.add(new ImportConflict("Relationship.trackedEntityInstance", "Invalid trackedEntityInstance " + relationship.getTrackedEntityInstanceA()));
        }
        org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceB = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceB());
        if (entityInstanceB == null) {
            importConflicts.add(new ImportConflict("Relationship.trackedEntityInstance", "Invalid trackedEntityInstance " + relationship.getTrackedEntityInstanceB()));
        }
    }
    return importConflicts;
}
Also used : ArrayList(java.util.ArrayList) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ImportConflict(org.hisp.dhis.dxf2.importsummary.ImportConflict)

Example 3 with RelationshipType

use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.

the class DhisConvenienceTest method createRelationshipType.

/**
     * @param uniqueChar A unique character to identify the object.
     * @return RelationshipType
     */
public static RelationshipType createRelationshipType(char uniqueChar) {
    RelationshipType relationshipType = new RelationshipType();
    relationshipType.setAutoFields();
    relationshipType.setaIsToB("aIsToB");
    relationshipType.setbIsToA("bIsToA");
    relationshipType.setName("RelationshipType" + uniqueChar);
    return relationshipType;
}
Also used : RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 4 with RelationshipType

use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.

the class DefaultTrackedEntityInstanceService method updateTrackedEntityInstance.

@Override
public void updateTrackedEntityInstance(TrackedEntityInstance instance, String representativeId, Integer relationshipTypeId, List<TrackedEntityAttributeValue> valuesForSave, List<TrackedEntityAttributeValue> valuesForUpdate, Collection<TrackedEntityAttributeValue> valuesForDelete) {
    trackedEntityInstanceStore.update(instance);
    valuesForSave.forEach(attributeValueService::addTrackedEntityAttributeValue);
    valuesForUpdate.forEach(attributeValueService::updateTrackedEntityAttributeValue);
    valuesForDelete.forEach(attributeValueService::deleteTrackedEntityAttributeValue);
    if (shouldSaveRepresentativeInformation(instance, representativeId)) {
        TrackedEntityInstance representative = trackedEntityInstanceStore.getByUid(representativeId);
        if (representative != null) {
            instance.setRepresentative(representative);
            Relationship rel = new Relationship();
            rel.setEntityInstanceA(representative);
            rel.setEntityInstanceB(instance);
            if (relationshipTypeId != null) {
                RelationshipType relType = relationshipTypeService.getRelationshipType(relationshipTypeId);
                if (relType != null) {
                    rel.setRelationshipType(relType);
                    relationshipService.addRelationship(rel);
                }
            }
        }
    }
}
Also used : Relationship(org.hisp.dhis.relationship.Relationship) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 5 with RelationshipType

use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.

the class TrackedEntityInstanceServiceTest method testCreateTrackedEntityInstanceAndRelative.

@Test
public void testCreateTrackedEntityInstanceAndRelative() {
    entityInstanceService.addTrackedEntityInstance(entityInstanceB1);
    RelationshipType relationshipType = createRelationshipType('A');
    int relationshipTypeId = relationshipTypeService.addRelationshipType(relationshipType);
    TrackedEntityAttributeValue attributeValue = createTrackedEntityAttributeValue('A', entityInstanceA1, entityInstanceAttribute);
    Set<TrackedEntityAttributeValue> entityInstanceAttributeValues = new HashSet<>();
    entityInstanceAttributeValues.add(attributeValue);
    int idA = entityInstanceService.createTrackedEntityInstance(entityInstanceA1, entityInstanceB1.getUid(), relationshipTypeId, entityInstanceAttributeValues);
    assertNotNull(entityInstanceService.getTrackedEntityInstance(idA));
}
Also used : TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) RelationshipType(org.hisp.dhis.relationship.RelationshipType) HashSet(java.util.HashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

RelationshipType (org.hisp.dhis.relationship.RelationshipType)11 Relationship (org.hisp.dhis.relationship.Relationship)4 ArrayList (java.util.ArrayList)3 TrackedEntityAttributeValue (org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue)3 HashSet (java.util.HashSet)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 PeriodType (org.hisp.dhis.period.PeriodType)2 Program (org.hisp.dhis.program.Program)2 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)2 TrackedEntity (org.hisp.dhis.trackedentity.TrackedEntity)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 Test (org.junit.Test)2 Date (java.util.Date)1 NotAllowedException (org.hisp.dhis.api.mobile.NotAllowedException)1 ImportConflict (org.hisp.dhis.dxf2.importsummary.ImportConflict)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1