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;
}
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;
}
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;
}
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);
}
}
}
}
}
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));
}
Aggregations