Search in sources :

Example 1 with Patient

use of org.openmrs.Patient 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 2 with Patient

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

the class AppEndRouterPageControllerTest method shouldRedirectToRegistrationSummaryfApp.

@Test
public void shouldRedirectToRegistrationSummaryfApp() {
    Patient patient = new Patient(1);
    when(session.getAttribute(PihCoreConstants.CURRENT_APP_SESSION_VARIABLE)).thenReturn("");
    Redirect redirect = new AppEndRouterPageController().controller(request, appFrameworkService, patient);
    assertThat(redirect.getUrl(), is("registrationapp/registrationSummary.page?patientId=1&appId=registrationapp.registerPatient"));
}
Also used : Patient(org.openmrs.Patient) Redirect(org.openmrs.ui.framework.page.Redirect) Test(org.junit.Test)

Example 3 with Patient

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

the class PihPatientMergeActionsTest method shouldRemoveNonPreferredPhoneNumberButNotMothersName.

@Test
public void shouldRemoveNonPreferredPhoneNumberButNotMothersName() {
    Patient preferred = new Patient();
    Patient nonPreferred = new Patient();
    PersonAttribute preferredPhoneNumber = new PersonAttribute(phoneNumber, "preferred");
    preferred.addAttribute(preferredPhoneNumber);
    PersonAttribute nonPreferredPhoneNumber = new PersonAttribute(phoneNumber, "non-preferred");
    PersonAttribute nonPreferredMothersName = new PersonAttribute(mothersName, "non-preferred");
    nonPreferred.addAttribute(nonPreferredPhoneNumber);
    nonPreferred.addAttribute(nonPreferredMothersName);
    // sanity check
    assertThat(preferred.getActiveAttributes().size(), is(1));
    assertThat(nonPreferred.getActiveAttributes().size(), is(2));
    pihPatientMergeActions.beforeMergingPatients(preferred, nonPreferred);
    assertThat(preferred.getActiveAttributes().size(), is(1));
    assertThat(nonPreferred.getActiveAttributes().size(), is(1));
    assertThat(nonPreferred.getActiveAttributes(), contains(nonPreferredMothersName));
}
Also used : Patient(org.openmrs.Patient) PersonAttribute(org.openmrs.PersonAttribute) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with Patient

use of org.openmrs.Patient 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)

Example 5 with Patient

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

the class PihPatientMergeActionsTest method shouldNotFailIfNoEncounters.

@Test
public void shouldNotFailIfNoEncounters() {
    Patient preferred = new Patient(1);
    Patient nonPreferred = new Patient(2);
    when(encounterService.getEncounters(preferred, null, null, null, null, Collections.singleton(registration), null, null, null, false)).thenReturn(null);
    when(encounterService.getEncounters(nonPreferred, null, null, null, null, Collections.singleton(registration), null, null, null, false)).thenReturn(Collections.singletonList(new Encounter()));
    pihPatientMergeActions.beforeMergingPatients(preferred, nonPreferred);
// just make sure no NPE
}
Also used : Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Patient (org.openmrs.Patient)389 Test (org.junit.Test)345 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)284 Date (java.util.Date)106 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)91 Encounter (org.openmrs.Encounter)76 PatientIdentifier (org.openmrs.PatientIdentifier)60 Location (org.openmrs.Location)57 OrderUtilTest (org.openmrs.order.OrderUtilTest)47 PersonName (org.openmrs.PersonName)43 DrugOrder (org.openmrs.DrugOrder)42 BindException (org.springframework.validation.BindException)38 Concept (org.openmrs.Concept)37 Order (org.openmrs.Order)36 PatientIdentifierType (org.openmrs.PatientIdentifierType)33 Errors (org.springframework.validation.Errors)33 Visit (org.openmrs.Visit)29 ArrayList (java.util.ArrayList)28 Obs (org.openmrs.Obs)28 TestOrder (org.openmrs.TestOrder)28