Search in sources :

Example 21 with Encounter

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;
    }
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Redirect(org.openmrs.ui.framework.page.Redirect)

Example 22 with Encounter

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);
}
Also used : EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter)

Example 23 with Encounter

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);
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Form(org.openmrs.Form) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter)

Example 24 with Encounter

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;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) DateMidnight(org.joda.time.DateMidnight) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) ResourceFactory(org.openmrs.ui.framework.resource.ResourceFactory) PatientIdentifierType(org.openmrs.PatientIdentifierType) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with Encounter

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));
}
Also used : Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) Date(java.util.Date) Location(org.openmrs.Location) Test(org.junit.Test)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19