Search in sources :

Example 46 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class DiagnosesFragmentController method simplify.

/**
 * This is public so that it can be used by a fragment that needs to prepopulate a diagnoses widget that is normally
 * populated with AJAX results from the #search method.
 * @param result
 * @param ui
 * @param locale
 * @return
 * @throws Exception
 */
public SimpleObject simplify(ConceptSearchResult result, UiUtils ui, Locale locale) throws Exception {
    SimpleObject simple = SimpleObject.fromObject(result, ui, "word", "conceptName.id", "conceptName.uuid", "conceptName.conceptNameType", "conceptName.name", "concept.id", "concept.uuid", "concept.conceptMappings.conceptMapType", "concept.conceptMappings.conceptReferenceTerm.code", "concept.conceptMappings.conceptReferenceTerm.name", "concept.conceptMappings.conceptReferenceTerm.conceptSource.name");
    Concept concept = result.getConcept();
    ConceptName conceptName = result.getConceptName();
    ConceptName preferredName = getPreferredName(locale, concept);
    PropertyUtils.setProperty(simple, "concept.preferredName", preferredName.getName());
    return simple;
}
Also used : Concept(org.openmrs.Concept) SimpleObject(org.openmrs.ui.framework.SimpleObject) ConceptName(org.openmrs.ConceptName)

Example 47 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class DiagnosesFragmentController method search.

public List<SimpleObject> search(UiSessionContext context, UiUtils ui, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("emrConceptService") EmrConceptService emrConceptService, @RequestParam("term") String query, @RequestParam(value = "start", defaultValue = "0") Integer start, @RequestParam(value = "size", defaultValue = "50") Integer size) throws Exception {
    Collection<Concept> diagnosisSets = emrApiProperties.getDiagnosisSets();
    Locale locale = context.getLocale();
    List<ConceptSource> sources = emrApiProperties.getConceptSourcesForDiagnosisSearch();
    List<ConceptSearchResult> hits = emrConceptService.conceptSearch(query, locale, null, diagnosisSets, sources, null);
    List<SimpleObject> ret = new ArrayList<SimpleObject>();
    for (ConceptSearchResult hit : hits) {
        ret.add(simplify(hit, ui, locale));
    }
    return ret;
}
Also used : Concept(org.openmrs.Concept) Locale(java.util.Locale) SimpleObject(org.openmrs.ui.framework.SimpleObject) ArrayList(java.util.ArrayList) ConceptSource(org.openmrs.ConceptSource) ConceptSearchResult(org.openmrs.ConceptSearchResult)

Example 48 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class PatientPageController method controller.

public void controller(@RequestParam("patientId") Patient patient, UiUtils ui, UiSessionContext emrContext, PageModel model, @SpringBean("formService") FormService formService, @SpringBean("patientService") PatientService patientService, @SpringBean("adtService") AdtService adtService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
    patientDomainWrapper.setPatient(patient);
    SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.message("referenceapplication.app.capturevitals.title"), "link", ui.pageLink("coreapps", "findpatient/findPatient?app=referenceapplication.vitals"));
    SimpleObject patientPageBreadcrumb = SimpleObject.create("label", patient.getFamilyName() + ", " + patient.getGivenName(), "link", ui.thisUrlWithContextPath());
    Form vitalsForm = formService.getFormByUuid("a000cb34-9ec1-4344-a1c8-f692232f6edd");
    Location visitLocation = adtService.getLocationThatSupportsVisits(emrContext.getSessionLocation());
    VisitDomainWrapper activeVisit = adtService.getActiveVisit(patient, visitLocation);
    List<Encounter> existingEncounters = new ArrayList<Encounter>();
    if (activeVisit != null) {
        for (Encounter encounter : activeVisit.getVisit().getEncounters()) {
            if (!encounter.isVoided() && vitalsForm.equals(encounter.getForm())) {
                existingEncounters.add(encounter);
            }
        }
    }
    model.addAttribute("visit", activeVisit != null ? activeVisit.getVisit() : null);
    model.addAttribute("existingEncounters", existingEncounters);
    model.addAttribute("patient", patientDomainWrapper);
    model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Form(org.openmrs.Form) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Location(org.openmrs.Location)

Example 49 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class ParserEncounterIntoSimpleObjectsTest method testParsingDispositionWithTransferLocation.

@Test
public void testParsingDispositionWithTransferLocation() throws Exception {
    Concept admit = new ConceptBuilder(null, conceptService.getConceptDatatypeByName("N/A"), conceptService.getConceptClassByName("Misc")).addName("Transfer").get();
    when(emrConceptService.getConcept("test:transfer")).thenReturn(admit);
    Obs dispositionObs = dispositionDescriptor.buildObsGroup(new Disposition("emrapi.transfer", "Transfer", "test:transfer", Collections.<String>emptyList(), Collections.<DispositionObs>emptyList()), emrConceptService);
    Obs transferLocationObs = new Obs();
    transferLocationObs.setObsId(100);
    transferLocationObs.setConcept(dispositionDescriptor.getInternalTransferLocationConcept());
    transferLocationObs.setValueText("3");
    dispositionObs.addGroupMember(transferLocationObs);
    Location transferLocation = new Location();
    transferLocation.setName("Outpatient clinic");
    when(locationService.getLocation(3)).thenReturn(transferLocation);
    encounter.addObs(doNotGoToServiceToFormatMembers(dispositionObs));
    ParsedObs parsed = parser.parseObservations(Locale.ENGLISH);
    SimpleObject expectedTransferLocationObject = SimpleObject.create("obsId", transferLocationObs.getObsId());
    expectedTransferLocationObject.put("question", "Transfer location");
    expectedTransferLocationObject.put("answer", "Outpatient clinic");
    List<SimpleObject> expectedAdditionalObsList = new ArrayList<SimpleObject>();
    expectedAdditionalObsList.add(expectedTransferLocationObject);
    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) "Transfer"));
    assertThat(path(parsed.getDispositions(), 0, "additionalObs"), is((Object) expectedAdditionalObsList));
}
Also used : Concept(org.openmrs.Concept) DispositionObs(org.openmrs.module.emrapi.disposition.DispositionObs) Obs(org.openmrs.Obs) ConceptBuilder(org.openmrs.module.emrapi.test.builder.ConceptBuilder) SimpleObject(org.openmrs.ui.framework.SimpleObject) Disposition(org.openmrs.module.emrapi.disposition.Disposition) ArrayList(java.util.ArrayList) DispositionObs(org.openmrs.module.emrapi.disposition.DispositionObs) SimpleObject(org.openmrs.ui.framework.SimpleObject) Location(org.openmrs.Location) Test(org.junit.Test)

Example 50 with SimpleObject

use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-coreapps by openmrs.

the class RetrospectiveVisitFragmentControllerTest method test_shouldReturnConflictingVisits.

@Test
public void test_shouldReturnConflictingVisits() throws Exception {
    Patient patient = new Patient();
    Location location = new Location();
    Date startDate = new DateTime(2012, 1, 1, 12, 12, 12).toDate();
    // should round to the time components to the start and end of the days, respectively
    Date expectedStartDate = new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate();
    Date expectedStopDate = new DateTime(2012, 1, 1, 23, 59, 59, 999).toDate();
    Visit conflictingVisit = new Visit();
    conflictingVisit.setStartDatetime(new DateTime(2012, 1, 1, 0, 0, 0, 0).toDate());
    conflictingVisit.setStopDatetime(new DateTime(2012, 1, 3, 0, 0, 0, 999).toDate());
    when(adtService.createRetrospectiveVisit(patient, location, expectedStartDate, expectedStopDate)).thenThrow(ExistingVisitDuringTimePeriodException.class);
    when(adtService.getVisits(patient, location, expectedStartDate, expectedStopDate)).thenReturn(Collections.singletonList(new VisitDomainWrapper(conflictingVisit)));
    when(ui.format(any())).thenReturn("someDate");
    List<SimpleObject> result = (List<SimpleObject>) controller.create(adtService, patient, location, startDate, null, request, ui);
    assertThat(result.size(), is(1));
    assertThat(result.get(0).toJson(), is("{\"startDate\":\"someDate\",\"stopDate\":\"someDate\",\"id\":null,\"uuid\":\"" + conflictingVisit.getUuid() + "\"}"));
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) Visit(org.openmrs.Visit) Patient(org.openmrs.Patient) List(java.util.List) VisitDomainWrapper(org.openmrs.module.emrapi.visit.VisitDomainWrapper) Date(java.util.Date) DateTime(org.joda.time.DateTime) Location(org.openmrs.Location) Test(org.junit.Test)

Aggregations

SimpleObject (org.openmrs.ui.framework.SimpleObject)67 Test (org.junit.Test)37 Location (org.openmrs.Location)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)29 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)26 ArrayList (java.util.ArrayList)18 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)17 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)13 Config (org.openmrs.module.pihcore.config.Config)12 DateTime (org.joda.time.DateTime)11 Date (java.util.Date)9 Encounter (org.openmrs.Encounter)9 Concept (org.openmrs.Concept)6 Patient (org.openmrs.Patient)6 Obs (org.openmrs.Obs)5 Visit (org.openmrs.Visit)5 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)3 ConceptSearchResult (org.openmrs.ConceptSearchResult)3 Form (org.openmrs.Form)3