@Test public void encounterLocationTag_shouldNotSelectAnythingByDefaultIfNothingIsSpecified() throws Exception { String htmlform = "<htmlform><encounterLocation /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Matcher matcher = Pattern.compile("<option.+?value=\"(.+?)\".+?selected=\"true\".*?>").matcher(session.getHtmlToDisplay()); Assert.assertFalse(matcher.find()); }
@Test public void encounterLocationTag_shouldDisplaySelectInputByDefaultIfAnIvalidTypeValueIsEntered() throws Exception { String htmlform = "<htmlform><encounterLocation type=\"invalid\" /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Assert.assertTrue(session.getHtmlToDisplay().indexOf("<option value=\"\" selected=\"true\">htmlformentry.chooseALocation</option>") > -1); Assert.assertTrue(session.getHtmlToDisplay().indexOf("placeholder=\"htmlformentry.form.value.placeholder\"") == -1); }
@Test public void encounterTypeTag_shouldAutoSelectTheDefaultEncounterTypeIfAny() throws Exception { String htmlform = "<htmlform><encounterType default=\"07000be2-26b6-4cce-8b40-866d8435b613\" /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Assert.assertTrue(session.getHtmlToDisplay() .indexOf("<option value=\"\">htmlformentry.chooseEncounterType</option>") > -1); Assert.assertTrue(session.getHtmlToDisplay().indexOf("<option selected=\"true\" value=\"2\">Emergency</option>") > -1); } }
@Test public void encounterProviderTag_shouldDisplaySelectInputByDefaultIfAnIvalidTypeValueIsEntered() throws Exception { String htmlform = "<htmlform><encounterProvider type=\"invalid\" /></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Assert.assertTrue(session.getHtmlToDisplay().indexOf("<option value=\"\" selected=\"true\">htmlformentry.chooseAProvider</option>") > -1); Assert.assertTrue(session.getHtmlToDisplay().indexOf("placeholder=\"htmlformentry.form.value.placeholder\"") == -1); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfWorkflowIdMissing() throws Exception { String htmlform = "<htmlform><workflowState/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfNoStateIdAndCheckboxStyle() throws Exception { String htmlform = "<htmlform><workflowState workflowId=\"100\" type=\"checkbox\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfInvalidStyle() throws Exception { String htmlform = "<htmlform><workflowState workflowId=\"100\" type=\"invalid\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfSpecifiedStateAndDropdownStyle() throws Exception { String htmlform = "<htmlform><workflowState workflowId=\"100\" stateId=\"" + START_STATE + "\" type=\"dropdown\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfNoStatesAndStateLabel() throws Exception { String startState = "Transition to start state"; String htmlform = "<htmlform><workflowState workflowId=\"100\" stateLabel=\"" + startState + "\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
private HtmlFormSchema generateSchema(String xml, HttpSession httpSession, Encounter encounter) throws Exception { HtmlForm fakeForm = new HtmlForm(); fakeForm.setXmlData(xml); FormEntrySession fes = new FormEntrySession(encounter.getPatient(), encounter, FormEntryContext.Mode.VIEW, fakeForm, httpSession); fes.getHtmlToDisplay(); return fes.getContext().getSchema(); }
@Test public void editPatientProgram_shouldNotDisplayEnrollmentDateWidgetIfShowDateFalse() throws Exception { String htmlform = "<htmlform>Enroll In Program: <enrollInProgram programId=\"1\" showDate=\"false\" stateIds=\"2\" /><submit/></htmlform>"; FormEntrySession session = new FormEntrySession(Context.getPatientService().getPatient(2), htmlform, null); Assert.assertTrue(session.getHtmlToDisplay().indexOf("setupDatePicker") == -1); }
@Test public void encounterTypeTag_shouldIncludeAllEncounterTypesIfNoneAreSpecified() throws Exception { String htmlform = "<htmlform><encounterType/></htmlform>"; FormEntrySession session = new FormEntrySession(null, htmlform, null); Assert.assertTrue(session.getHtmlToDisplay() .indexOf("<option value=\"\">htmlformentry.chooseEncounterType</option>") > -1); Assert.assertEquals(1 + Context.getEncounterService().getAllEncounterTypes().size(), StringUtils.countMatches(session.getHtmlToDisplay(), "<option value=\"")); }
@Test public void shouldDisplayDropdownIfNoStyle() throws Exception { String htmlform = "<htmlform><workflowState workflowId=\"100\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); Assert.assertTrue("Result: " + session.getHtmlToDisplay(), session.getHtmlToDisplay().contains("option")); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfNotEnoughStateLabels() throws Exception { transitionToState(START_STATE); String startState = "Transition to start state"; String htmlform = "<htmlform><workflowState workflowId=\"100\" stateIds=\"" + START_STATE + "," + END_STATE + "\" stateLabels=\"" + startState + "\"/></htmlform>"; new FormEntrySession(patient, htmlform, null).getHtmlToDisplay(); }
@Test public void shouldSetDefaultDatetimeValue() throws Exception { String htmlform = "<htmlform><obs conceptId=\"1119\" defaultDatetime=\"2011-02-02-00-00\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); assertTrue("Result: " + session.getHtmlToDisplay(), session.getHtmlToDisplay().contains("2011-02-02")); }
@Test public void shouldSupportCheckboxForNumericObs() throws Exception { String htmlform = "<htmlform><obs conceptId=\"2\" answer=\"8\" answerLabel=\"Eight\" style=\"checkbox\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); assertTrue("Result: " + session.getHtmlToDisplay(), session.getHtmlToDisplay().contains("<input type=\"checkbox\" id=\"w2\" name=\"w2\" value=\"8.0\"/>")); }
@Test public void shouldSetDefaultBooleanValueToFalse() throws Exception { LogicUtil.registerDefaultRules(); String htmlform = "<htmlform><obs conceptId=\"4\" defaultValue=\"false\" style=\"no_yes_dropdown\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); assertTrue("Result: " + session.getHtmlToDisplay(), session.getHtmlToDisplay().contains("<option value=\"false\" selected=\"true\">")); }
@Test @Verifies(value = "should return correct xml after apply include tag", method = "applyIncludes(FormEntrySession,String)") public void applyIncludes_shouldReturnCorrectXmlAfterApplyIncludeTag() throws Exception { LogicUtil.registerDefaultRules(); String htmlform = "<htmlform><includeIf logicTest=\"GENDER = F\">This shows a logic test for a woman</includeIf><includeIf logicTest=\"GENDER = M\">This shows a logic test for a man</includeIf></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); Assert.assertEquals("<div class=\"htmlform\">This shows a logic test for a man</div>", session.getHtmlToDisplay()); }
@Test public void shouldDisplayEncounterTypeValuePropertyAccessorUsingCustomName() throws Exception { String htmlform = "<htmlform><encounterType id=\"myEncounter\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); session.getHtmlToDisplay(); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['myEncounter.value'\\]", session.getFieldAccessorJavascript()); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['myEncounter.error'\\]", session.getFieldAccessorJavascript()); }
@Test public void shouldDisplayLocationValuePropertyAccessor() throws Exception { String htmlform = "<htmlform><encounterLocation/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); session.getHtmlToDisplay(); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['encounterLocation.value'\\]", session.getFieldAccessorJavascript()); TestUtil.assertFuzzyContains("propertyAccessorInfo\\['encounterLocation.error'\\]", session.getFieldAccessorJavascript()); }