@WSDoc("Gets Full representation of Patient Lists for the uuid path")
@ResponseBody()
public String getAllPatientListByUuidFull(@PathVariable("uuid") String uuid, @RequestParam("v") String rep,
HttpServletRequest request) throws ResponseException {
initPatientListController();
PatientList patientList = service.getPatientListByUuid(uuid);
SimpleObject obj = new SimpleObject();
obj.add("uuid", patientList.getUuid());
obj.add("name", patientList.getName());
obj.add("description", patientList.getDescription());
obj.add("searchQuery", patientList.getSearchQuery());
ArrayList patients = new ArrayList();
List<Patient> patientsInPatientList = service.getPatientsInPatientList(patientList);
for (Patient p : patientsInPatientList) {
SimpleObject patient = new SimpleObject();
patient.add("uuid", p.getUuid());
patient.add("display", p.getPersonName().getFullName());
patient.add("gender", p.getGender());
patient.add("age", p.getAge());
ArrayList encounters = new ArrayList();
List<Encounter> encountersInPatientList = service.getEncountersInPatientList(patientList);
for (Encounter e : encountersInPatientList) {
if (e.getPatient().equals(p)) {
SimpleObject encounter = new SimpleObject();
encounter.add("uuid", e.getUuid());
encounter.add("display", e.getEncounterType().getName() + " - " + e.getEncounterDatetime());
encounter.add("encounterType", e.getEncounterType().getUuid());
encounter.add("encounterDatetime", df.format(e.getEncounterDatetime()));
if (e.getProvider() != null) {
encounter.add("provider", e.getProvider().getUuid());
} else {
encounter.add("provider", null);
}
ArrayList obsArray = new ArrayList();
Set<Obs> obsAll = e.getObs();
for (Obs o : obsAll) {
SimpleObject obs = new SimpleObject();
obs.add("uuid", o.getUuid());
obs.add("display", o.getConcept().getName().getName() + " = "
+ o.getValueAsString(request.getLocale()));
obs.add("obsDatetime", df.format(o.getObsDatetime()));
obs.add("value", o.getValueAsString(request.getLocale()));
obs.add("comment", o.getComment());
if (o.getOrder() != null) {
obs.add("order", o.getOrder().getUuid());
} else {
obs.add("order", null);
}
obsArray.add(obs);
}
encounter.add("obs", obsArray);
encounters.add(encounter);
}
}
patient.add("encounters", encounters);
patients.add(patient);
}
obj.add("patients", patients);
if (rep.equals("full")) {
obj.add("retired", patientList.getRetired());
if (patientList.getRetired()) {
obj.add("retiredBy", patientList.getRetiredBy().getUuid());
obj.add("retireReason", patientList.getRetireReason());
}
SimpleObject auditInfo = new SimpleObject();
auditInfo.add("creator", patientList.getCreator().getUuid());
auditInfo.add("dateCreated", df.format(patientList.getDateCreated()));
if (patientList.getChangedBy() != null) {
auditInfo.add("changedBy", patientList.getChangedBy().getUuid());
auditInfo.add("dateChanged", df.format(patientList.getDateChanged()));
}
obj.add("auditInfo", auditInfo);
}
obj.add("resourceVersion", getResourceVersion());
return gson.toJson(obj);