Search in sources :

Example 1 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class RedirectToDeathNoteIfMissing method hasDeathCertificateEncounter.

private boolean hasDeathCertificateEncounter(Patient patient) {
    EncounterService encounterService = Context.getEncounterService();
    EncounterType deathCertificateEncounterType = Context.getEncounterService().getEncounterTypeByUuid(PihCoreConstants.DEATH_CERTIFICATE_ENCOUNTER_TYPE_UUID);
    List<Encounter> deathCertificateEncounters = encounterService.getEncounters(patient, null, null, null, null, Arrays.asList(deathCertificateEncounterType), null, null, null, false);
    return deathCertificateEncounters.size() > 0;
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) EncounterService(org.openmrs.api.EncounterService)

Example 2 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 3 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class VisitPageController method get.

public void get(@SpringBean("visitService") VisitService visitService, @InjectBeans PatientDomainWrapper patientDomainWrapper, @RequestParam(required = false, value = "patient") Patient patient, @RequestParam(required = false, value = "visit") Visit visit, @RequestParam(required = false, value = "encounter") Encounter enc, // passed by the htmformentryui module after form submission creates new encounter (really should be "encounter" for consistency)
@RequestParam(required = false, value = "encounterId") Encounter encounterById, @RequestParam(required = false, value = "goToNextSection") String goToNextSection, UiSessionContext uiSessionContext, PageModel model) {
    // there are two params that could pass in an encounter, test which one, if any, was used to pass in a value
    Encounter encounter = enc != null ? enc : (encounterById != null ? encounterById : null);
    // fwiw, you are allowed to have a patient without a visit, but only if viewing the "visitList" view
    if (patient == null) {
        if (visit != null) {
            patient = visit.getPatient();
        } else if (encounter != null) {
            patient = encounter.getPatient();
        } else {
            throw new MissingRequiredParameterException("patient or visit or encounter is required");
        }
    }
    // see if we can get a visit from the encounter
    if (visit == null && encounter != null) {
        visit = encounter.getVisit();
    }
    patientDomainWrapper.setPatient(patient);
    model.addAttribute("patient", patientDomainWrapper);
    model.addAttribute("visit", visit);
    model.addAttribute("encounter", encounter);
    model.addAttribute("locale", uiSessionContext.getLocale());
    model.addAttribute("goToNextSection", goToNextSection);
}
Also used : Encounter(org.openmrs.Encounter) MissingRequiredParameterException(org.openmrs.ui.framework.MissingRequiredParameterException)

Example 4 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("personService") PersonService personService) {
    // TODO restrict by location at some point if necessary
    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(encounterService.getEncounterTypeByUuid(EncounterTypes.CHECK_IN.uuid())), null, null, null, false);
    List<Encounter> vitalsEncounters = encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, Collections.singletonList(encounterService.getEncounterTypeByUuid(EncounterTypes.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());
        }
    }
    SimpleObject vitalsListBreadcrumb = SimpleObject.create("label", ui.message("pihcore.vitalsList.title"), "link", ui.pageLink("pihcore", "vitals/vitalsList"));
    // used to determine whether or not we display a link to the patient in the results list
    model.addAttribute("patientWithCheckInEncounter", patientsWithCheckInEncounter);
    model.addAttribute("mothersFirstName", personService.getPersonAttributeTypeByUuid(HaitiPersonAttributeTypes.MOTHERS_FIRST_NAME.uuid()));
    model.addAttribute("dossierIdentifierName", PihHaitiPatientIdentifierTypes.DOSSIER_NUMBER.name());
    model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(vitalsListBreadcrumb)));
    return null;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) DateMidnight(org.joda.time.DateMidnight) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with Encounter

use of org.openmrs.Encounter in project openmrs-module-pihcore by PIH.

the class PihPatientMergeActionsTest method shouldNotVoidMostRecentRegistrationEncounterOnNonPreferredPatientIfNotMoreRecentThanPreferred.

@Test
public void shouldNotVoidMostRecentRegistrationEncounterOnNonPreferredPatientIfNotMoreRecentThanPreferred() {
    Patient preferred = new Patient(1);
    Patient nonPreferred = new Patient(2);
    Encounter preferredEncounter1 = createEncounter(1, new DateTime(2012, 10, 10, 0, 0, 0).toDate());
    Encounter preferredEncounter2 = createEncounter(2, new DateTime(2012, 11, 10, 0, 0, 0).toDate());
    Encounter nonPreferredEncounter1 = createEncounter(3, new DateTime(2012, 1, 10, 0, 0, 0).toDate());
    Encounter nonPreferredEncounter2 = createEncounter(4, new DateTime(2012, 2, 10, 0, 0, 0).toDate());
    when(encounterService.getEncounters(preferred, null, null, null, null, Collections.singleton(registration), null, null, null, false)).thenReturn(Arrays.asList(preferredEncounter1, preferredEncounter2));
    when(encounterService.getEncounters(nonPreferred, null, null, null, null, Collections.singleton(registration), null, null, null, false)).thenReturn(Arrays.asList(nonPreferredEncounter1, nonPreferredEncounter2));
    pihPatientMergeActions.beforeMergingPatients(preferred, nonPreferred);
    verify(encounterService, never()).voidEncounter(eq(preferredEncounter1), anyString());
    verify(encounterService, never()).voidEncounter(eq(preferredEncounter2), anyString());
    verify(encounterService, never()).voidEncounter(eq(nonPreferredEncounter1), anyString());
    verify(encounterService, never()).voidEncounter(eq(nonPreferredEncounter2), anyString());
}
Also used : Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Encounter (org.openmrs.Encounter)229 Test (org.junit.Test)188 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Date (java.util.Date)79 Patient (org.openmrs.Patient)74 Order (org.openmrs.Order)40 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 Obs (org.openmrs.Obs)36 TestOrder (org.openmrs.TestOrder)34 Visit (org.openmrs.Visit)30 Location (org.openmrs.Location)29 BindException (org.springframework.validation.BindException)25 ArrayList (java.util.ArrayList)23 Errors (org.springframework.validation.Errors)21 Concept (org.openmrs.Concept)20 User (org.openmrs.User)20 Calendar (java.util.Calendar)19 EncounterType (org.openmrs.EncounterType)19 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)18