use of org.openmrs.module.reporting.dataset.definition.PatientDataSetDefinition in project openmrs-module-pihcore by PIH.
the class ActiveVisitsAjaxController method getActiveVisits.
@RequestMapping(value = "/module/pihcore/reports/ajax/activeVisitsList.form", method = RequestMethod.GET, headers = "Accept=application/json")
public void getActiveVisits(@RequestParam(value = "patientIds", required = false) Integer[] patientIds, HttpServletResponse response) throws EvaluationException, IOException {
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
AllDefinitionLibraries definitionLibraries = Context.getRegisteredComponents(AllDefinitionLibraries.class).get(0);
EvaluationContext context = new EvaluationContext();
Cohort c = null;
if (patientIds != null && patientIds.length > 0) {
if (patientIds[0] == null) {
// there are no patients with last encounter at this specific location
return;
}
c = new Cohort("active", "Patients with active visits", patientIds);
}
DataSet result = null;
PatientDataSetDefinition dsd = new PatientDataSetDefinition();
VisitCohortDefinition visitCohortDefinition = new VisitCohortDefinition();
visitCohortDefinition.setActive(true);
if (c != null) {
context.setBaseCohort(c);
}
dsd.addRowFilter(visitCohortDefinition, null);
dsd.addColumn("patientId", definitionLibraries.getDefinition(PatientDataDefinition.class, "reporting.library.patientDataDefinition.builtIn.patientId"), "");
dsd.addColumn("familyName", definitionLibraries.getDefinition(PatientDataDefinition.class, "reporting.library.patientDataDefinition.builtIn.preferredName.familyName"), "");
dsd.addColumn("givenName", definitionLibraries.getDefinition(PatientDataDefinition.class, "reporting.library.patientDataDefinition.builtIn.preferredName.givenName"), "");
dsd.addColumn("zlEmrId", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.preferredZlEmrId.identifier"), "");
dsd.addColumn("firstCheckinLocation", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.checkin.location"), "");
dsd.addColumn("checkinDateTime", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.checkin.encounterDatetime"), "");
dsd.addColumn("lastEncounterType", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.lastEncounter.type"), "");
dsd.addColumn("lastEncounterLocation", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.lastEncounter.location"), "");
dsd.addColumn("lastEncounterDateTime", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.lastEncounter.encounterDatetime"), "");
dsd.addColumn("visitUuid", definitionLibraries.getDefinition(PatientDataDefinition.class, "mirebalais.patientDataCalculation.lastEncounter.visit.uuid"), "");
result = dsdService.evaluate(dsd, context);
String json = toJson(DataSetUtil.simplify(result));
PrintWriter out = response.getWriter();
out.print(json);
}
Aggregations