use of org.openmrs.ui.framework.SimpleObject 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.ui.framework.SimpleObject 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.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentControllerTest method shouldReturnEncountersForVisit.
@Test
public void shouldReturnEncountersForVisit() throws ParseException {
CoreAppsProperties coreAppsProperties = mock(CoreAppsProperties.class);
when(coreAppsProperties.getPatientDashboardEncounterCount()).thenReturn(100);
UiSessionContext sessionContext = mock(UiSessionContext.class);
User authenticatedUser = new User();
when(sessionContext.getCurrentUser()).thenReturn(authenticatedUser);
AppContextModel appContextModel = new AppContextModel();
when(sessionContext.generateAppContextModel()).thenReturn(appContextModel);
authenticatedUser.addRole(createRoleForUser());
AdministrationService administrationService = mock(AdministrationService.class);
when(administrationService.getGlobalProperty(UiFrameworkConstants.GP_FORMATTER_DATETIME_FORMAT)).thenReturn("dd.MMM.yyyy, HH:mm:ss");
AppFrameworkService appFrameworkService = mock(AppFrameworkService.class);
when(appFrameworkService.getExtensionsForCurrentUser(CoreAppsConstants.ENCOUNTER_TEMPLATE_EXTENSION)).thenReturn(generateMockEncounterTemplateExtensions());
EncounterService encounterService = mock(EncounterService.class);
Patient patient = mock(Patient.class);
when(patient.getPatientId()).thenReturn(1);
when(patient.isDead()).thenReturn(false);
Visit visit = new Visit();
Location visitLocation = new Location();
visitLocation.setName("Visit Location");
visit.setVisitId(1);
visit.setLocation(visitLocation);
visit.setStartDatetime(new Date());
visit.setStopDatetime(new Date());
visit.setCreator(authenticatedUser);
visit.setPatient(patient);
Location encounterLocation = new Location();
encounterLocation.setName("Location");
EncounterType encounterType = new EncounterType();
encounterType.setName("Encounter Type");
encounterType.setUuid(encounterTypeUuid);
Provider primaryProvider = new Provider();
primaryProvider.setName("Primary Provider");
EncounterProvider primaryEncounterProvider = new EncounterProvider();
primaryEncounterProvider.setProvider(primaryProvider);
EncounterRole primaryEncounterRole = new EncounterRole();
primaryEncounterRole.setUuid(primaryEncounterRoleUuid);
primaryEncounterProvider.setEncounterRole(primaryEncounterRole);
when(encounterService.getEncounterRoleByUuid(primaryEncounterRoleUuid)).thenReturn(primaryEncounterRole);
Provider secondaryProvider = new Provider();
secondaryProvider.setName("Secondary Provider");
EncounterProvider secondaryEncounterProvider = new EncounterProvider();
secondaryEncounterProvider.setProvider(secondaryProvider);
secondaryEncounterProvider.setEncounterRole(new EncounterRole());
Encounter encounter = new Encounter();
encounter.setEncounterId(7);
encounter.setEncounterDatetime(new Date());
encounter.setLocation(encounterLocation);
encounter.setEncounterType(encounterType);
encounter.setEncounterProviders(new LinkedHashSet<EncounterProvider>());
// add secondary provider so that it is the one that is "arbitrarily" returned first
encounter.getEncounterProviders().add(secondaryEncounterProvider);
encounter.getEncounterProviders().add(primaryEncounterProvider);
encounter.setCreator(authenticatedUser);
encounter.setDateCreated(new Date());
visit.addEncounter(encounter);
UiUtils uiUtils = new TestUiUtils(administrationService);
VisitDetailsFragmentController controller = new VisitDetailsFragmentController();
SimpleObject response = controller.getVisitDetails(mock(EmrApiProperties.class), coreAppsProperties, appFrameworkService, encounterService, visit, null, null, uiUtils, sessionContext);
List<SimpleObject> actualEncounters = (List<SimpleObject>) response.get("encounters");
SimpleObject actualEncounter = actualEncounters.get(0);
assertThat(response.get("startDatetime"), notNullValue());
assertThat(response.get("stopDatetime"), notNullValue());
assertThat((String) response.get("location"), is("Visit Location"));
assertThat(actualEncounters.size(), is(1));
assertThat((Integer) actualEncounter.get("encounterId"), is(7));
assertThat((String) actualEncounter.get("location"), is("Location"));
assertThat((SimpleObject) actualEncounter.get("encounterType"), isSimpleObjectWith("uuid", encounterType.getUuid(), "name", encounterType.getName()));
assertThat(actualEncounter.get("encounterDatetime"), notNullValue());
assertThat(actualEncounter.get("encounterDate"), notNullValue());
assertThat(actualEncounter.get("encounterTime"), notNullValue());
assertTrue((Boolean) actualEncounter.get("canEdit"));
assertThat((String) actualEncounter.get("primaryProvider"), is("Primary Provider"));
List<SimpleObject> actualProviders = (List<SimpleObject>) actualEncounter.get("encounterProviders");
assertThat(actualProviders.size(), is(2));
}
use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.
the class ParserEncounterIntoSimpleObjectsTest method testParsingDispositionWithAdmissionLocation.
@Test
public void testParsingDispositionWithAdmissionLocation() throws Exception {
Concept admit = new ConceptBuilder(null, conceptService.getConceptDatatypeByName("N/A"), conceptService.getConceptClassByName("Misc")).addName("Admit").get();
when(emrConceptService.getConcept("test:admit")).thenReturn(admit);
Obs dispositionObs = dispositionDescriptor.buildObsGroup(new Disposition("emrapi.admit", "Admit", "test:admit", Collections.<String>emptyList(), Collections.<DispositionObs>emptyList()), emrConceptService);
Obs admissionLocationObs = new Obs();
admissionLocationObs.setObsId(100);
admissionLocationObs.setConcept(dispositionDescriptor.getAdmissionLocationConcept());
admissionLocationObs.setValueText("3");
dispositionObs.addGroupMember(admissionLocationObs);
Location admissionLocation = new Location();
admissionLocation.setName("Outpatient clinic");
when(locationService.getLocation(3)).thenReturn(admissionLocation);
encounter.addObs(doNotGoToServiceToFormatMembers(dispositionObs));
ParsedObs parsed = parser.parseObservations(Locale.ENGLISH);
SimpleObject expectedAdmissionLocationObject = SimpleObject.create("obsId", admissionLocationObs.getObsId());
expectedAdmissionLocationObject.put("question", "Admission location");
expectedAdmissionLocationObject.put("answer", "Outpatient clinic");
List<SimpleObject> expectedAdditionalObsList = new ArrayList<SimpleObject>();
expectedAdditionalObsList.add(expectedAdmissionLocationObject);
assertThat(parsed.getDiagnoses().size(), is(0));
assertThat(parsed.getDispositions().size(), is(1));
assertThat(parsed.getObs().size(), is(0));
assertThat(path(parsed.getDispositions(), 0, "disposition"), is((Object) "Admit"));
assertThat(path(parsed.getDispositions(), 0, "additionalObs"), is((Object) expectedAdditionalObsList));
}
use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.
the class ParserEncounterIntoSimpleObjectsTest method testParsingDispositionWithDateOfDeath.
@Test
public void testParsingDispositionWithDateOfDeath() throws Exception {
Concept admit = new ConceptBuilder(null, conceptService.getConceptDatatypeByName("N/A"), conceptService.getConceptClassByName("Misc")).addName("Death").get();
when(emrConceptService.getConcept("test:death")).thenReturn(admit);
Obs dispositionObs = dispositionDescriptor.buildObsGroup(new Disposition("emrapi.death", "Death", "test:death", Collections.<String>emptyList(), Collections.<DispositionObs>emptyList()), emrConceptService);
Date dateOfDeath = new DateTime(2012, 2, 20, 10, 10, 10).toDate();
Obs dateOfDeathObs = new Obs();
dateOfDeathObs.setObsId(100);
dateOfDeathObs.setConcept(dispositionDescriptor.getDateOfDeathConcept());
dateOfDeathObs.setValueDate(dateOfDeath);
dispositionObs.addGroupMember(dateOfDeathObs);
encounter.addObs(doNotGoToServiceToFormatMembers(dispositionObs));
ParsedObs parsed = parser.parseObservations(Locale.ENGLISH);
SimpleObject expectedAdmissionLocationObject = SimpleObject.create("obsId", dateOfDeathObs.getObsId());
expectedAdmissionLocationObject.put("question", "Date of death");
expectedAdmissionLocationObject.put("answer", "20 Feb 2012 10:10 AM");
List<SimpleObject> expectedAdditionalObsList = new ArrayList<SimpleObject>();
expectedAdditionalObsList.add(expectedAdmissionLocationObject);
assertThat(parsed.getDiagnoses().size(), is(0));
assertThat(parsed.getDispositions().size(), is(1));
assertThat(parsed.getObs().size(), is(0));
assertThat(path(parsed.getDispositions(), 0, "disposition"), is((Object) "Death"));
assertThat(path(parsed.getDispositions(), 0, "additionalObs"), is((Object) expectedAdditionalObsList));
}
Aggregations