use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.
the class CheckinPageController method controller.
public Object controller(@RequestParam("patientId") Patient patient, @RequestParam(value = "closeVisit", required = false) Boolean closeVisit, UiUtils ui, UiSessionContext uiSessionContext, PageModel model, EmrApiProperties emrApiProperties, @SpringBean AdtService adtService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
patientDomainWrapper.setPatient(patient);
VisitDomainWrapper activeVisit = patientDomainWrapper.getActiveVisit(uiSessionContext.getSessionLocation());
if (closeVisit != null && closeVisit && activeVisit != null) {
adtService.closeAndSaveVisit(activeVisit.getVisit());
activeVisit = null;
}
// if there is no active visit, redirect directly to the form
if (activeVisit == null) {
return new Redirect("/registrationapp/registrationSummary.page?patientId=" + patient.getId() + "&appId=registrationapp.registerPatient" + "&breadcrumbOverrideProvider=coreapps&breadcrumbOverridePage=findpatient%2FfindPatient&breadcrumbOverrideApp=mirebalais.liveCheckin&breadcrumbOverrideLabel=mirebalais.app.patientRegistration.checkin.label");
} else // prompt the user to see if they want close the existing visit
{
List<Encounter> existingEncounters = new ArrayList<Encounter>();
if (activeVisit != null) {
for (Encounter encounter : activeVisit.getVisit().getEncounters()) {
if (!encounter.isVoided() && emrApiProperties.getCheckInEncounterType().equals(encounter.getEncounterType())) {
existingEncounters.add(encounter);
}
}
}
SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.escapeJs(ui.message("mirebalais.checkin.title")));
SimpleObject patientPageBreadcrumb = SimpleObject.create("label", ui.escapeJs(patient.getFamilyName()) + ", " + ui.escapeJs(patient.getGivenName()), "link", ui.thisUrlWithContextPath());
model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
model.addAttribute("activeVisit", activeVisit);
model.addAttribute("existingEncounters", existingEncounters);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("appName", "mirebalais.liveCheckin");
return null;
}
}
use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.
the class EncounterListPageController method get.
public void get(PageModel model, UiUtils ui, @InjectBeans PatientDomainWrapper patientDomainWrapper, @RequestParam(value = "patient") Patient patient, @SpringBean("encounterService") EncounterService encounterService) throws IOException {
// Get all of the encounters for the patient
EncounterSearchCriteriaBuilder b = new EncounterSearchCriteriaBuilder();
b.setPatient(patient).setIncludeVoided(false);
List<Encounter> encounters = encounterService.getEncounters(b.createEncounterSearchCriteria());
encounters.sort(Comparator.comparing(Encounter::getEncounterDatetime).reversed());
patientDomainWrapper.setPatient(patient);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("encounters", encounters);
}
use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.
the class PatientPageController method controller.
public void controller(@RequestParam("patientId") Patient patient, UiUtils ui, EmrContext emrContext, PageModel model, @SpringBean("formService") FormService formService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
patientDomainWrapper.setPatient(patient);
SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.message("mirebalais.outpatientVitals.title"), "link", ui.pageLink("coreapps", "findpatient/findPatient", Collections.singletonMap("app", (Object) "mirebalais.outpatientVitals")));
SimpleObject patientPageBreadcrumb = SimpleObject.create("label", patient.getFamilyName() + ", " + patient.getGivenName(), "link", ui.thisUrlWithContextPath());
Form outpatientVitalsForm = formService.getFormByUuid("68728aa6-4985-11e2-8815-657001b58a90");
List<Encounter> existingEncounters = new ArrayList<Encounter>();
if (emrContext.getActiveVisit() != null) {
for (Encounter encounter : emrContext.getActiveVisit().getVisit().getEncounters()) {
if (!encounter.isVoided() && outpatientVitalsForm.equals(encounter.getForm())) {
existingEncounters.add(encounter);
}
}
}
model.addAttribute("visit", emrContext.getActiveVisit() != null ? emrContext.getActiveVisit().getVisit() : null);
model.addAttribute("existingEncounters", existingEncounters);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
model.addAttribute("appName", CustomAppLoaderConstants.Apps.UHM_VITALS);
}
use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.
the class VitalsListPageController method get.
public String get(PageModel model, UiUtils ui, @SpringBean("encounterService") EncounterService encounterService, @SpringBean("patientService") PatientService patientService, @SpringBean Config config) throws IOException {
// TODO restrict by location at some point if necessary
ResourceFactory resourceFactory = ResourceFactory.getInstance();
Map<Patient, Encounter> patientsWithCheckInEncounter = new LinkedHashMap<Patient, Encounter>();
// all patients that have a check-in encounter today, but no vitals encounter
List<Encounter> checkInEncounters = encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, Collections.singletonList(Metadata.lookupEncounterType(PihEmrConfigConstants.ENCOUNTERTYPE_CHECK_IN_UUID)), null, null, null, false);
List<Encounter> vitalsEncounters = encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, Collections.singletonList(Metadata.lookupEncounterType(PihEmrConfigConstants.ENCOUNTERTYPE_VITALS_UUID)), null, null, null, false);
for (Encounter encounter : checkInEncounters) {
// sanity check on visit
if (encounter.getVisit() != null) {
// we check that the patient isn't already in the list instead of just inserting again because we want to keep the earliest date
if (!patientsWithCheckInEncounter.containsKey(encounter.getPatient())) {
patientsWithCheckInEncounter.put(encounter.getPatient(), encounter);
}
}
}
for (Encounter encounter : vitalsEncounters) {
if (patientsWithCheckInEncounter.containsKey(encounter.getPatient())) {
patientsWithCheckInEncounter.remove(encounter.getPatient());
}
}
String formPath = PihCoreUtil.getFormResource("vitals.xml");
SimpleObject vitalsListBreadcrumb = SimpleObject.create("label", ui.message("pihcore.vitalsList.title"), "link", ui.pageLink("pihcore", "vitals/vitalsList"));
PatientIdentifierType dossierNumberType = patientService.getPatientIdentifierTypeByUuid(ZlConfigConstants.PATIENTIDENTIFIERTYPE_DOSSIERNUMBER_UUID);
// used to determine whether or not we display a link to the patient in the results list
model.addAttribute("patientWithCheckInEncounter", patientsWithCheckInEncounter);
model.addAttribute("mothersFirstName", Metadata.getMothersFirstNameAttributeType());
model.addAttribute("dossierIdentifierName", dossierNumberType == null ? null : dossierNumberType.getName());
model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(vitalsListBreadcrumb)));
model.addAttribute("formPath", formPath);
return null;
}
use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.
the class PihEncounterValidatorTest method testShouldNotRemoveVisitIfSuitable.
@Test
public void testShouldNotRemoveVisitIfSuitable() throws Exception {
Patient patient = new Patient();
Location location = new Location();
Visit suitable = new Visit();
suitable.setPatient(patient);
suitable.setStartDatetime(DateUtils.addDays(new Date(), -1));
suitable.setLocation(location);
Encounter encounter = new Encounter();
encounter.setId(1);
encounter.setPatient(patient);
encounter.setLocation(location);
encounter.setEncounterDatetime(new Date());
suitable.addEncounter(encounter);
validator.validate(encounter, null);
Assert.assertThat(encounter.getVisit(), is(suitable));
Assert.assertThat(suitable.getEncounters(), contains(encounter));
}
Aggregations