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;
}
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"));
}
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));
}
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());
}
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
}
Aggregations