use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class DefaultProgramNotificationService method resolveProgramMessageRecipients.
private ProgramMessageRecipients resolveProgramMessageRecipients(ProgramNotificationTemplate template, OrganisationUnit organisationUnit, ProgramInstance programInstance) {
ProgramMessageRecipients recipients = new ProgramMessageRecipients();
TrackedEntityInstance trackedEntityInstance = programInstance.getEntityInstance();
ProgramNotificationRecipient recipientType = template.getNotificationRecipient();
if (recipientType == ProgramNotificationRecipient.ORGANISATION_UNIT_CONTACT) {
recipients.setOrganisationUnit(organisationUnit);
} else if (recipientType == ProgramNotificationRecipient.TRACKED_ENTITY_INSTANCE) {
recipients.setTrackedEntityInstance(trackedEntityInstance);
} else if (recipientType == ProgramNotificationRecipient.PROGRAM_ATTRIBUTE && template.getRecipientProgramAttribute() != null) {
List<String> recipientList = programInstance.getEntityInstance().getTrackedEntityAttributeValues().stream().filter(av -> template.getRecipientProgramAttribute().getUid().equals(av.getAttribute().getUid())).map(av -> av.getPlainValue()).collect(Collectors.toList());
if (template.getDeliveryChannels().contains(DeliveryChannel.SMS)) {
recipients.getPhoneNumbers().addAll(recipientList);
} else if (template.getDeliveryChannels().contains(DeliveryChannel.EMAIL)) {
recipients.getEmailAddresses().addAll(recipientList);
}
}
return recipients;
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class DeliveryChannelStrategy method getTrackedEntityInstance.
// -------------------------------------------------------------------------
// Public methods
// -------------------------------------------------------------------------
protected TrackedEntityInstance getTrackedEntityInstance(ProgramMessage message) {
if (message.getRecipients().getTrackedEntityInstance() == null) {
return null;
}
String uid = message.getRecipients().getTrackedEntityInstance().getUid();
TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(uid);
message.getRecipients().setTrackedEntityInstance(tei);
return tei;
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class EmailDeliveryChannelStrategy method setAttributes.
@Override
public ProgramMessage setAttributes(ProgramMessage message) {
validate(message);
OrganisationUnit orgUnit = getOrganisationUnit(message);
TrackedEntityInstance tei = getTrackedEntityInstance(message);
if (orgUnit != null) {
message.getRecipients().getEmailAddresses().add(getOrganisationUnitRecipient(orgUnit));
}
if (tei != null) {
message.getRecipients().getEmailAddresses().add(getTrackedEntityInstanceRecipient(tei, ValueType.EMAIL));
}
return message;
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method getAllActivityPlan.
@Override
public ActivityPlan getAllActivityPlan(OrganisationUnit unit, String localeString) {
List<Activity> items = new ArrayList<>();
TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams();
param.addOrganisationUnit(unit);
Grid trackedEntityDrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
List<List<Object>> entityInstanceList = trackedEntityDrid.getRows();
for (List<Object> entityInstance : entityInstanceList) {
TrackedEntityInstance trackedEntityInstance = entityInstanceService.getTrackedEntityInstance(entityInstance.get(0).toString());
for (ProgramStageInstance programStageInstance : programStageInstanceService.getProgramStageInstances(trackedEntityInstance, EventStatus.ACTIVE)) {
items.add(getActivity(programStageInstance, false));
}
}
if (items.isEmpty()) {
return null;
}
Collections.sort(items, activityComparator);
return new ActivityPlan(items);
}
use of org.hisp.dhis.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method updatePatient.
@Override
public Patient updatePatient(org.hisp.dhis.api.mobile.model.LWUITmodel.Patient patient, int orgUnitId, String programIdText) throws NotAllowedException {
TrackedEntityInstance entityInstance = entityInstanceService.getTrackedEntityInstance(patient.getId());
TrackedEntityInstance tempTEI = entityInstance;
TrackedEntity trackedEntity = null;
Program program = programService.getProgram(Integer.parseInt(programIdText));
trackedEntity = program.getTrackedEntity();
entityInstance.setTrackedEntity(trackedEntity);
// get attributes to be saved/updated/deleted
Collection<TrackedEntityAttribute> attributes = attributeService.getAllTrackedEntityAttributes();
List<TrackedEntityAttributeValue> valuesForSave = new ArrayList<>();
List<TrackedEntityAttributeValue> valuesForUpdate = new ArrayList<>();
Collection<TrackedEntityAttributeValue> valuesForDelete = null;
TrackedEntityAttributeValue attributeValue = null;
Collection<org.hisp.dhis.api.mobile.model.PatientAttribute> attributesMobile = patient.getAttributes();
if (attributes != null && attributes.size() > 0) {
valuesForDelete = attValueService.getTrackedEntityAttributeValues(entityInstance);
tempTEI.getTrackedEntityAttributeValues().clear();
for (TrackedEntityAttribute attribute : attributes) {
String value = getAttributeValue(attributesMobile, attribute.getName());
if (value != null) {
attributeValue = attValueService.getTrackedEntityAttributeValue(entityInstance, attribute);
if (attributeValue == null) {
attributeValue = new TrackedEntityAttributeValue();
attributeValue.setEntityInstance(entityInstance);
attributeValue.setAttribute(attribute);
attributeValue.setValue(value.trim());
valuesForSave.add(attributeValue);
} else {
attributeValue.setValue(value.trim());
valuesForUpdate.add(attributeValue);
valuesForDelete.remove(attributeValue);
}
tempTEI.getTrackedEntityAttributeValues().add(attributeValue);
}
}
}
// validate
String[] errorCode = entityInstanceService.validateTrackedEntityInstance(tempTEI, program).split("_");
int code = Integer.parseInt(errorCode[0]);
if (code >= 1) {
if (code == TrackedEntityInstanceService.ERROR_DUPLICATE_IDENTIFIER) {
throw new NotAllowedException("Duplicate value of " + attributeService.getTrackedEntityAttribute(Integer.parseInt(errorCode[1])).getDisplayName());
} else {
throw new NotAllowedException("Validation error");
}
}
entityInstanceService.updateTrackedEntityInstance(entityInstance, null, null, valuesForSave, valuesForUpdate, valuesForDelete);
enrollProgram(patient.getId() + "-" + programIdText, null, new Date());
entityInstance = entityInstanceService.getTrackedEntityInstance(patient.getId());
entityInstance.setTrackedEntity(trackedEntity);
return getPatientModel(entityInstance);
}
Aggregations