use of org.hisp.dhis.api.mobile.NotAllowedException 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);
}
use of org.hisp.dhis.api.mobile.NotAllowedException 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);
}
use of org.hisp.dhis.api.mobile.NotAllowedException in project dhis2-core by dhis2.
the class ActivityReportingServiceImpl method findLostToFollowUp.
@Override
public String findLostToFollowUp(int orgUnitId, String searchEventInfos) throws NotAllowedException {
String[] searchEventInfosArray = searchEventInfos.split("-");
EventStatus eventStatus = EventStatus.ACTIVE;
if (searchEventInfosArray[1].equalsIgnoreCase("Scheduled in future")) {
eventStatus = EventStatus.SCHEDULE;
} else if (searchEventInfosArray[1].equalsIgnoreCase("Overdue")) {
eventStatus = EventStatus.OVERDUE;
}
String eventsInfo = "";
Calendar toCalendar = new GregorianCalendar();
toCalendar.add(Calendar.DATE, -1);
toCalendar.add(Calendar.YEAR, 100);
Date toDate = toCalendar.getTime();
Calendar fromCalendar = new GregorianCalendar();
fromCalendar.add(Calendar.DATE, -1);
fromCalendar.add(Calendar.YEAR, -100);
Date fromDate = fromCalendar.getTime();
TrackedEntityInstanceQueryParams param = new TrackedEntityInstanceQueryParams();
List<TrackedEntityAttribute> trackedEntityAttributeList = new ArrayList<>(attributeService.getTrackedEntityAttributesByDisplayOnVisitSchedule(true));
for (TrackedEntityAttribute trackedEntityAttribute : trackedEntityAttributeList) {
QueryItem queryItem = new QueryItem(trackedEntityAttribute);
param.addAttribute(queryItem);
}
param.addOrganisationUnit(organisationUnitService.getOrganisationUnit(orgUnitId));
param.setEventStatus(eventStatus);
param.setEventStartDate(fromDate);
param.setEventEndDate(toDate);
Grid programStageInstanceGrid = entityInstanceService.getTrackedEntityInstancesGrid(param);
List<List<Object>> rows = programStageInstanceGrid.getRows();
if (rows.size() == 0) {
throw NotAllowedException.NO_EVENT_FOUND;
} else if (rows.size() > 0) {
for (List<Object> row : rows) {
for (int i = 5; i < row.size(); i++) {
eventsInfo += row.get(i) + "/";
if (i == row.size() - 1) {
eventsInfo += "$";
}
}
}
throw new NotAllowedException(eventsInfo);
} else {
return "";
}
}
Aggregations