Search in sources :

Example 6 with RegressionTestHelper

use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-coreapps by openmrs.

the class EncounterDispositionTagHandlerComponentTest method testShouldDisplayAdmissionLocationAfterEnteringAdmissionDisposition.

@Test
public void testShouldDisplayAdmissionLocationAfterEnteringAdmissionDisposition() throws Exception {
    final Date date = new Date();
    final DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
    final Concept admissionDisposition = HtmlFormEntryUtil.getConcept("org.openmrs.module.emrapi: Admit to hospital");
    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:"), admissionDisposition.toString());
            // hack, manually reference the widget the location
            request.setParameter("w10", "1");
        }

        @Override
        public boolean doViewEncounter() {
            return true;
        }

        @Override
        public void testViewingEncounter(Encounter encounter, String html) {
            // make sure the admission location is displayed (ie, does not have style="display:none;")
            TestUtil.assertFuzzyContains("p id=\"[^\"]+\"><label><uimessage code=\"Admission Location\">", html);
        }
    }.run();
}
Also used : Concept(org.openmrs.Concept) TestUiUtils(org.openmrs.module.appui.TestUiUtils) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) Date(java.util.Date) Encounter(org.openmrs.Encounter) HashMap(java.util.HashMap) Map(java.util.Map) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) Test(org.junit.Test) BaseModuleWebContextSensitiveTest(org.openmrs.web.test.BaseModuleWebContextSensitiveTest)

Example 7 with RegressionTestHelper

use of org.openmrs.module.htmlformentry.RegressionTestHelper in project openmrs-module-coreapps by openmrs.

the class EncounterDispositionTagHandlerComponentTest method testFormOnlyShowsDispositionsInDescriptor.

@Test
public void testFormOnlyShowsDispositionsInDescriptor() throws Exception {
    ConceptClass misc = conceptService.getConceptClassByName("Misc");
    ConceptDatatype naDatatype = conceptService.getConceptDatatypeByName("N/A");
    Concept dispositionConcept = dispositionService.getDispositionDescriptor().getDispositionConcept();
    dispositionConcept.addAnswer(new ConceptAnswer(new ConceptBuilder(conceptService, naDatatype, misc).addName("Should not be in option list").saveAndGet()));
    new RegressionTestHelper() {

        @Override
        public void testBlankFormHtml(String html) {
            assertThat(html, containsString("disposition.admission"));
            assertThat(html, containsString("disposition.transfer"));
            assertThat(html, containsString("disposition.discharge"));
            assertThat(html, not(containsString("Should not be in option list")));
        }

        @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:" };
        }
    }.run();
}
Also used : Concept(org.openmrs.Concept) ConceptClass(org.openmrs.ConceptClass) ConceptBuilder(org.openmrs.module.emrapi.test.builder.ConceptBuilder) ConceptAnswer(org.openmrs.ConceptAnswer) TestUiUtils(org.openmrs.module.appui.TestUiUtils) Matchers.containsString(org.hamcrest.Matchers.containsString) ConceptDatatype(org.openmrs.ConceptDatatype) HashMap(java.util.HashMap) Map(java.util.Map) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) Test(org.junit.Test) BaseModuleWebContextSensitiveTest(org.openmrs.web.test.BaseModuleWebContextSensitiveTest)

Example 8 with RegressionTestHelper

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

the class CauseOfDeathListTagHandlerComponentTest method testCreateAndEdit.

@Test
public void testCreateAndEdit() throws Exception {
    final ConceptName causeOne = conceptService.getConceptNameByUuid("2f7263e4-2a57-49b5-aef0-af9a259aac65");
    final Concept causeTwo = conceptService.getConcept(13);
    final Concept editedCauseTwo = conceptService.getConcept(11);
    final String causeThree = "Cause Three";
    final String editedCauseThree = "Edited Cause Three";
    final Concept causeFour = conceptService.getConcept(16);
    ArrayNode submission = jackson.createArrayNode();
    ObjectNode one = submission.addObject();
    one.put("ConceptName", causeOne.getUuid());
    ObjectNode two = submission.addObject();
    two.put("Concept", causeTwo.getUuid());
    ObjectNode three = submission.addObject();
    three.put("NonCodedValue", causeThree);
    ObjectNode four = submission.addObject();
    four.put("Concept", causeFour.getUuid());
    final String createJson = jackson.writeValueAsString(submission);
    two.put("Concept", editedCauseTwo.getUuid());
    three.put("NonCodedValue", editedCauseThree);
    // this removes 'four'
    submission.remove(3);
    final String editJson = jackson.writeValueAsString(submission);
    final Date date = new Date();
    new RegressionTestHelper() {

        @Override
        public String getXmlDatasetPath() {
            return "";
        }

        @Override
        public String getFormName() {
            return "causesOfDeathForm";
        }

        @Override
        public String[] widgetLabels() {
            return new String[] { "Date:", "Location:", "Provider:", "Causes:" };
        }

        @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("Causes:"), createJson);
        }

        @Override
        public void testResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterCreated();
            results.assertProvider(1);
            results.assertLocation(2);
            results.assertObsGroupCreatedCount(4);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeOne, sequenceConcept.getId(), 1);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeTwo, sequenceConcept.getId(), 2);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), nonCodedCauseConcept.getId(), causeThree, sequenceConcept.getId(), 3);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeFour, sequenceConcept.getId(), 4);
            assertThat(results.getPatient().getCauseOfDeath(), is(causeFour));
        }

        @Override
        public boolean doEditEncounter() {
            return true;
        }

        @Override
        public String[] widgetLabelsForEdit() {
            return widgetLabels();
        }

        @Override
        public void setupEditRequest(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("Causes:"), editJson);
        }

        @Override
        public void testEditedResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterCreated();
            results.assertProvider(1);
            results.assertLocation(2);
            // there should be one voided member obs (causeTwo->causeTwoEdited), and one voided obs group (causeThree)
            // was causeThree
            results.assertObsVoided(groupingConcept.getConceptId(), null);
            assertVoidedObsInObsGroup(results.getEncounterCreated(), groupingConcept, codedCauseConcept, causeTwo);
            results.assertObsGroupCreatedCount(3);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), causeOne, sequenceConcept.getId(), 1);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), codedCauseConcept.getId(), editedCauseTwo, sequenceConcept.getId(), 2);
            results.assertObsGroupCreated(groupingConcept.getConceptId(), nonCodedCauseConcept.getId(), editedCauseThree, sequenceConcept.getId(), 3);
            assertThat(results.getPatient().getCauseOfDeath(), is(unknownConcept));
        }

        private void assertVoidedObsInObsGroup(Encounter encounter, Concept groupingConcept, Concept concept, Concept value) {
            for (Obs candidate : encounter.getObsAtTopLevel(true)) {
                if (groupingConcept.equals(candidate.getConcept())) {
                    for (Obs member : candidate.getGroupMembers(true)) {
                        if (member.getVoided() && member.getConcept().equals(concept) && member.getValueCoded().equals(value)) {
                            return;
                        }
                    }
                }
            }
            Assert.fail("Did not find a voided obs of " + concept + "=" + value + " inside a group of " + groupingConcept);
        }
    }.run();
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) ObjectNode(org.codehaus.jackson.node.ObjectNode) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Date(java.util.Date) ConceptName(org.openmrs.ConceptName) Encounter(org.openmrs.Encounter) ArrayNode(org.codehaus.jackson.node.ArrayNode) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 9 with RegressionTestHelper

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

the class FamilyHistoryRelativeCheckboxesTagHandlerTest method testCreateAndEdit.

@Test
public void testCreateAndEdit() throws Exception {
    final Date date = new Date();
    final Concept construct = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_CONSTRUCT);
    final Concept which = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_DIAGNOSIS);
    final Concept relative = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_RELATIONSHIP);
    final Concept presence = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_PRESENCE);
    final Concept comment = MetadataUtils.existing(Concept.class, ClinicalConsultationConcepts.Concepts.FAMILY_HISTORY_COMMENT);
    new RegressionTestHelper() {

        @Override
        public String getXmlDatasetPath() {
            return "";
        }

        @Override
        public String getFormName() {
            return "familyHistoryForm";
        }

        @Override
        public String[] widgetLabels() {
            // Cancer:!!1 is because we need to skip the text field that comes before the checkbox
            return new String[] { "Date:", "Location:", "Provider:", "Asthma:", "Cancer:!!1", "zl.familyHistoryRelativeCheckboxes.specifyLabel" };
        }

        @Override
        public void testBlankFormHtml(String html) {
            System.out.println(html);
        }

        @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("Asthma:"), father.getUuid());
            request.setParameter(widgets.get("Cancer:!!1"), father.getUuid());
            request.setParameter(widgets.get("zl.familyHistoryRelativeCheckboxes.specifyLabel"), "");
        }

        @Override
        public void testResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterCreated();
            results.assertObsGroupCreatedCount(2);
            results.assertObsGroupCreated(construct.getConceptId(), which.getId(), ashthma, relative.getId(), father, presence.getId(), yes);
            results.assertObsGroupCreated(construct.getConceptId(), which.getId(), cancer, relative.getId(), father, presence.getId(), yes);
        }

        @Override
        public boolean doEditEncounter() {
            return true;
        }

        @Override
        public String[] widgetLabelsForEdit() {
            return widgetLabels();
        }

        @Override
        public void setupEditRequest(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");
            // this is an unchecked checkbox (but HFE isn't smart enough to know this)
            request.removeParameter(widgets.get("Asthma:"));
            request.setParameter(widgets.get("Cancer:!!1"), father.getUuid());
            request.setParameter(widgets.get("zl.familyHistoryRelativeCheckboxes.specifyLabel"), "Melanoma");
        }

        @Override
        public void testEditedResults(SubmissionResults results) {
            results.assertNoErrors();
            results.assertEncounterCreated();
            // there should be one voided obs group (asthma)
            results.assertObsVoided(construct.getConceptId(), null);
            // there should be one obs group (Cancer), now also with a comment
            results.assertObsGroupCreatedCount(1);
            results.assertObsGroupCreated(construct.getConceptId(), which.getId(), cancer, relative.getId(), father, presence.getId(), yes, comment.getId(), "Melanoma");
        }
    }.run();
}
Also used : Concept(org.openmrs.Concept) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Date(java.util.Date) RegressionTestHelper(org.openmrs.module.htmlformentry.RegressionTestHelper) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 RegressionTestHelper (org.openmrs.module.htmlformentry.RegressionTestHelper)9 Date (java.util.Date)8 Concept (org.openmrs.Concept)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 TestUiUtils (org.openmrs.module.appui.TestUiUtils)6 BaseModuleWebContextSensitiveTest (org.openmrs.web.test.BaseModuleWebContextSensitiveTest)6 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Encounter (org.openmrs.Encounter)4 ArrayNode (org.codehaus.jackson.node.ArrayNode)3 ObjectNode (org.codehaus.jackson.node.ObjectNode)3 DispositionDescriptor (org.openmrs.module.emrapi.disposition.DispositionDescriptor)3 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 Obs (org.openmrs.Obs)2 DiagnosisMetadata (org.openmrs.module.emrapi.diagnosis.DiagnosisMetadata)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1