use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method updateRelationships.
private void updateRelationships(TrackedEntityInstance trackedEntityInstance, org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstance) {
for (org.hisp.dhis.dxf2.events.trackedentity.Relationship relationship : trackedEntityInstance.getRelationships()) {
org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceA = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceA());
org.hisp.dhis.trackedentity.TrackedEntityInstance entityInstanceB = manager.get(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, relationship.getTrackedEntityInstanceB());
RelationshipType relationshipType = manager.get(RelationshipType.class, relationship.getRelationship());
Relationship entityRelationship = new Relationship();
entityRelationship.setEntityInstanceA(entityInstanceA);
entityRelationship.setEntityInstanceB(entityInstanceB);
entityRelationship.setRelationshipType(relationshipType);
relationshipService.addRelationship(entityRelationship);
}
}
use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.
the class UpdateProgramAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
displayProvidedOtherFacility = (displayProvidedOtherFacility == null) ? false : displayProvidedOtherFacility;
displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
generateBydEnrollmentDate = (generateBydEnrollmentDate == null) ? false : generateBydEnrollmentDate;
ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
blockEntryForm = (blockEntryForm == null) ? false : blockEntryForm;
remindCompleted = (remindCompleted == null) ? false : remindCompleted;
selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
Program program = programService.getProgram(id);
program.setName(StringUtils.trimToNull(name));
program.setShortName(StringUtils.trimToNull(shortName));
program.setDescription(StringUtils.trimToNull(description));
program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
program.setProgramType(programType);
program.setDisplayIncidentDate(displayIncidentDate);
program.setOnlyEnrollOnce(onlyEnrollOnce);
program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
program.setSkipOffline(skipOffline);
program.setDisplayFrontPageList(displayFrontPageList);
program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
program.setCaptureCoordinates(captureCoordinates);
program.setExpiryDays(expiryDays);
program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
if (program.isRegistration()) {
program.setIgnoreOverdueEvents(ignoreOverdueEvents);
} else {
program.setIgnoreOverdueEvents(false);
}
periodTypeName = StringUtils.trimToNull(periodTypeName);
if (periodTypeName != null) {
PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
} else {
program.setExpiryPeriodType(null);
}
if (relationshipTypeId != null) {
RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
program.setRelationshipType(relationshipType);
program.setRelationshipFromA(relationshipFromA);
program.setRelationshipText(relationshipText);
Program relatedProgram = programService.getProgram(relatedProgramId);
program.setRelatedProgram(relatedProgram);
} else {
program.setRelationshipType(null);
program.setRelationshipFromA(null);
program.setRelationshipText(null);
program.setRelatedProgram(null);
}
if (trackedEntityId != null) {
TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
program.setTrackedEntity(trackedEntity);
} else if (program.getTrackedEntity() != null) {
program.setTrackedEntity(null);
}
if (program.getProgramAttributes() != null) {
program.getProgramAttributes().clear();
}
int index = 0;
for (String selectedPropertyId : selectedPropertyIds) {
String[] ids = selectedPropertyId.split("_");
if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
programAttribute.setAutoFields();
program.getProgramAttributes().add(programAttribute);
}
index++;
}
//TODO make more fine-grained
program.increaseVersion();
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(program, jsonAttributeValues);
}
if (categoryComboId != null) {
program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
}
if (workflowId != null && workflowId > 0) {
program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
} else {
program.setWorkflow(null);
}
programService.updateProgram(program);
return SUCCESS;
}
use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.
the class AddProgramAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
onlyEnrollOnce = (onlyEnrollOnce == null) ? false : onlyEnrollOnce;
selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
Program program = new Program();
program.setName(StringUtils.trimToNull(name));
program.setShortName(StringUtils.trimToNull(shortName));
program.setDescription(StringUtils.trimToNull(description));
program.setVersion(1);
program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
program.setProgramType(programType);
program.setDisplayIncidentDate(displayIncidentDate);
program.setOnlyEnrollOnce(onlyEnrollOnce);
program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
program.setSkipOffline(skipOffline);
program.setDisplayFrontPageList(displayFrontPageList);
program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
program.setCaptureCoordinates(captureCoordinates);
program.setExpiryDays(expiryDays);
program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
if (programType == ProgramType.WITH_REGISTRATION) {
program.setIgnoreOverdueEvents(ignoreOverdueEvents);
} else {
program.setIgnoreOverdueEvents(false);
}
periodTypeName = StringUtils.trimToNull(periodTypeName);
if (periodTypeName != null) {
PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
} else {
program.setExpiryPeriodType(null);
}
if (relationshipTypeId != null) {
RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
program.setRelationshipType(relationshipType);
program.setRelationshipFromA(relationshipFromA);
program.setRelationshipText(relationshipText);
Program relatedProgram = programService.getProgram(relatedProgramId);
program.setRelatedProgram(relatedProgram);
} else {
program.setRelationshipType(null);
program.setRelationshipFromA(null);
program.setRelationshipText(null);
program.setRelatedProgram(null);
}
if (trackedEntityId != null) {
TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
program.setTrackedEntity(trackedEntity);
}
if (categoryComboId != null) {
program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
}
if (workflowId != null && workflowId > 0) {
program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
}
programService.addProgram(program);
int index = 0;
for (String selectedPropertyId : selectedPropertyIds) {
String[] ids = selectedPropertyId.split("_");
if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
programAttribute.setAutoFields();
program.getProgramAttributes().add(programAttribute);
}
index++;
}
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(program, jsonAttributeValues);
}
programService.updateProgram(program);
if (program.isWithoutRegistration()) {
ProgramStage programStage = new ProgramStage();
programStage.setName(name);
programStage.setDescription(description);
programStage.setProgram(program);
programStage.setMinDaysFromStart(0);
programStage.setAutoGenerateEvent(true);
programStage.setExecutionDateLabel(REPORT_DATE_DESCRIPTION);
programStageService.saveProgramStage(programStage);
}
if (program.isWithoutRegistration()) {
// Add a new program-instance
ProgramInstance programInstance = new ProgramInstance();
programInstance.setEnrollmentDate(new Date());
programInstance.setIncidentDate(new Date());
programInstance.setProgram(program);
programInstance.setStatus(ProgramStatus.ACTIVE);
programInstanceService.addProgramInstance(programInstance);
}
return SUCCESS;
}
use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.
the class TrackedEntityInstanceServiceTest method testUpdateTrackedEntityInstanceAndRelative.
@Test
public void testUpdateTrackedEntityInstanceAndRelative() {
entityInstanceService.addTrackedEntityInstance(entityInstanceB1);
RelationshipType relationshipType = createRelationshipType('A');
int relationshipTypeId = relationshipTypeService.addRelationshipType(relationshipType);
entityInstanceA3.setName("B");
TrackedEntityAttributeValue attributeValue = createTrackedEntityAttributeValue('A', entityInstanceA3, entityInstanceAttribute);
Set<TrackedEntityAttributeValue> entityInstanceAttributeValues = new HashSet<>();
entityInstanceAttributeValues.add(attributeValue);
int idA = entityInstanceService.createTrackedEntityInstance(entityInstanceA3, entityInstanceB1.getUid(), relationshipTypeId, entityInstanceAttributeValues);
assertNotNull(entityInstanceService.getTrackedEntityInstance(idA));
attributeValue.setValue("AttributeB");
List<TrackedEntityAttributeValue> attributeValues = new ArrayList<>();
attributeValues.add(attributeValue);
entityInstanceService.updateTrackedEntityInstance(entityInstanceA3, entityInstanceB1.getUid(), relationshipTypeId, attributeValues, new ArrayList<>(), new ArrayList<>());
assertEquals("B", entityInstanceService.getTrackedEntityInstance(idA).getName());
}
use of org.hisp.dhis.relationship.RelationshipType in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method addRelationship.
@Override
public org.hisp.dhis.api.mobile.model.LWUITmodel.Patient addRelationship(org.hisp.dhis.api.mobile.model.LWUITmodel.Relationship enrollmentRelationship, int orgUnitId) throws NotAllowedException {
TrackedEntityInstance patientB;
if (enrollmentRelationship.getPersonBId() != 0) {
patientB = entityInstanceService.getTrackedEntityInstance(enrollmentRelationship.getPersonBId());
} else {
String instanceInfo = findPatientInAdvanced(enrollmentRelationship.getPersonBName(), orgUnitId, 0);
if (instanceInfo == null || instanceInfo.trim().length() == 0) {
throw NotAllowedException.NO_BENEFICIARY_FOUND;
} else {
throw new NotAllowedException(instanceInfo);
}
}
TrackedEntityInstance patientA = entityInstanceService.getTrackedEntityInstance(enrollmentRelationship.getPersonAId());
RelationshipType relationshipType = relationshipTypeService.getRelationshipType(enrollmentRelationship.getId());
Relationship relationship = new Relationship();
relationship.setRelationshipType(relationshipType);
if (enrollmentRelationship.getChosenRelationship().equals(relationshipType.getaIsToB())) {
relationship.setEntityInstanceA(patientA);
relationship.setEntityInstanceB(patientB);
} else {
relationship.setEntityInstanceA(patientB);
relationship.setEntityInstanceB(patientA);
}
relationshipService.addRelationship(relationship);
// return getPatientModel( orgUnitId, patientA );
return getPatientModel(patientA);
}
Aggregations