use of org.openmrs.module.appui.TestUiUtils 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.module.appui.TestUiUtils in project openmrs-module-coreapps by openmrs.
the class EncounterDispositionTagHandlerComponentTest method testShouldNotDisplayAdmissionLocationAfterEnteringDischargeDisposition.
@Test
public void testShouldNotDisplayAdmissionLocationAfterEnteringDischargeDisposition() throws Exception {
final Date date = new Date();
final DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
final Concept dischargeDisposition = HtmlFormEntryUtil.getConcept("org.openmrs.module.emrapi: Discharged");
new RegressionTestHelper() {
@Override
public String getXmlDatasetPath() {
return "";
}
@Override
public String getFormName() {
return "encounterDispositionSimpleForm";
}
@Override
public Map<String, Object> getFormEntrySessionAttributes() {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("uiUtils", new TestUiUtils());
return attributes;
}
@Override
public String[] widgetLabels() {
return new String[] { "Date:", "Location:", "Provider:", "Disposition:", "Encounter Type:" };
}
@Override
public void setupRequest(MockHttpServletRequest request, Map<String, String> widgets) {
request.setParameter(widgets.get("Date:"), dateAsString(date));
request.setParameter(widgets.get("Location:"), "2");
request.setParameter(widgets.get("Provider:"), "1");
request.setParameter(widgets.get("Encounter Type:"), "1");
request.setParameter(widgets.get("Disposition:"), dischargeDisposition.toString());
}
@Override
public boolean doViewEncounter() {
return true;
}
@Override
public void testViewingEncounter(Encounter encounter, String html) {
// make sure the admission location is not displayed (ie, has style="display:none;")
TestUtil.assertFuzzyContains("p id=\"[^\"]+\" style=\"display:none;\"><label><uimessage code=\"Admission Location\">", html);
}
}.run();
}
use of org.openmrs.module.appui.TestUiUtils in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesFragmentControllerTest method testController_createdProperPriorDiagnoses.
@Test
public void testController_createdProperPriorDiagnoses() throws Exception {
EncounterDiagnosesFragmentController controller = new EncounterDiagnosesFragmentController();
ConceptName specificName = new ConceptName("Specific Name", Context.getLocale());
specificName.setId(1);
specificName.setLocalePreferred(true);
Concept conceptForSpecificName = new Concept();
conceptForSpecificName.setId(2);
conceptForSpecificName.addName(specificName);
Concept nonSpecificConcept = new Concept();
nonSpecificConcept.setId(3);
ConceptName nonSpecificConceptName = new ConceptName("Non-specific concept", Context.getLocale());
nonSpecificConceptName.setId(4);
nonSpecificConceptName.setLocalePreferred(true);
nonSpecificConcept.addName(nonSpecificConceptName);
List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(specificName), Diagnosis.Order.PRIMARY));
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(nonSpecificConcept), Diagnosis.Order.SECONDARY));
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer("Unknown Disease"), Diagnosis.Order.SECONDARY));
for (Diagnosis d : diagnoses) {
d.setExistingObs(new Obs());
}
FragmentModel model = new FragmentModel();
controller.controller(new TestUiUtils(), null, diagnoses, model);
assertThat(((List<String>) model.getAttribute("jsForExisting")).size(), is(0));
List<String> jsForPrior = (List<String>) model.getAttribute("jsForPrior");
assertThat(jsForPrior.get(0), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":{\"id\":1,\"uuid\":\"" + specificName.getUuid() + "\",\"conceptNameType\":\"FULLY_SPECIFIED\",\"name\":\"Specific Name\"},\"concept\":{\"id\":2,\"uuid\":\"" + conceptForSpecificName.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Specific Name\"}}), confirmed: false, primary: true, existingObs: null }"));
assertThat(jsForPrior.get(1), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":null,\"concept\":{\"id\":3,\"uuid\":\"" + nonSpecificConcept.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Non-specific concept\"}}), confirmed: false, primary: false, existingObs: null }"));
assertThat(jsForPrior.get(2), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer('Unknown Disease'), confirmed: false, primary: false, existingObs: null }"));
}
use of org.openmrs.module.appui.TestUiUtils in project openmrs-module-coreapps by openmrs.
the class ParserEncounterIntoSimpleObjectsTest method setUp.
@Before
public void setUp() throws Exception {
emrApiProperties = mock(EmrApiProperties.class);
conceptService = mock(ConceptService.class);
locationService = mock(LocationService.class);
dispositionService = mock(DispositionService.class);
MockMetadataTestUtil.setupMockConceptService(conceptService, emrApiProperties);
emrConceptService = mock(EmrConceptService.class);
diagnosisMetadata = MockMetadataTestUtil.setupDiagnosisMetadata(emrApiProperties, conceptService);
dispositionDescriptor = MockMetadataTestUtil.setupDispositionDescriptor(conceptService);
when(dispositionService.getDispositionDescriptor()).thenReturn(dispositionDescriptor);
TestUiUtils testUiUtils = new TestUiUtils();
testUiUtils.setMockFormattingConcepts(true);
uiUtils = testUiUtils;
encounter = new Encounter();
parser = new ParserEncounterIntoSimpleObjects(encounter, uiUtils, emrApiProperties, locationService, dispositionService);
}
use of org.openmrs.module.appui.TestUiUtils in project openmrs-module-coreapps by openmrs.
the class EncounterDiagnosesFragmentControllerTest method testController_createdProperExistingDiagnoses.
@Test
public void testController_createdProperExistingDiagnoses() throws Exception {
EncounterDiagnosesFragmentController controller = new EncounterDiagnosesFragmentController();
ConceptName specificName = new ConceptName("Specific Name", Context.getLocale());
specificName.setId(1);
specificName.setLocalePreferred(true);
Concept conceptForSpecificName = new Concept();
conceptForSpecificName.setId(2);
conceptForSpecificName.addName(specificName);
Concept nonSpecificConcept = new Concept();
nonSpecificConcept.setId(3);
ConceptName nonSpecificConceptName = new ConceptName("Non-specific concept", Context.getLocale());
nonSpecificConceptName.setId(4);
nonSpecificConceptName.setLocalePreferred(true);
nonSpecificConcept.addName(nonSpecificConceptName);
List<Diagnosis> diagnoses = new ArrayList<Diagnosis>();
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(specificName), Diagnosis.Order.PRIMARY));
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer(nonSpecificConcept), Diagnosis.Order.SECONDARY));
diagnoses.add(new Diagnosis(new CodedOrFreeTextAnswer("Unknown Disease"), Diagnosis.Order.SECONDARY));
for (Diagnosis d : diagnoses) {
d.setExistingObs(new Obs());
}
FragmentModel model = new FragmentModel();
controller.controller(new TestUiUtils(), diagnoses, null, model);
assertThat(((List<String>) model.getAttribute("jsForPrior")).size(), is(0));
List<String> jsForExisting = (List<String>) model.getAttribute("jsForExisting");
assertThat(jsForExisting.get(0), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":{\"id\":1,\"uuid\":\"" + specificName.getUuid() + "\",\"conceptNameType\":\"FULLY_SPECIFIED\",\"name\":\"Specific Name\"},\"concept\":{\"id\":2,\"uuid\":\"" + conceptForSpecificName.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Specific Name\"}}), confirmed: false, primary: true, existingObs: null }"));
assertThat(jsForExisting.get(1), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer({\"word\":null,\"conceptName\":null,\"concept\":{\"id\":3,\"uuid\":\"" + nonSpecificConcept.getUuid() + "\",\"conceptMappings\":[],\"preferredName\":\"Non-specific concept\"}}), confirmed: false, primary: false, existingObs: null }"));
assertThat(jsForExisting.get(2), is("{ diagnosis: diagnoses.CodedOrFreeTextConceptAnswer('Unknown Disease'), confirmed: false, primary: false, existingObs: null }"));
}
Aggregations