private Set<HtmlFormField> getAllFieldsRecursiveSectionHelper(Set<HtmlFormField> fields, HtmlFormSection section) { getAllFieldsRecursiveFieldHelper(fields, section == null ? this.getFields() : section.getFields()); for (HtmlFormSection s : section == null ? this.getSections() : section.getSections()) { getAllFieldsRecursiveSectionHelper(fields, s); } return fields; }
public Set<HtmlFormSection> getAllSectionsRecursiveHelper(Set<HtmlFormSection> sections, HtmlFormSection section) { if (sections != null) { for (HtmlFormSection s : section == null ? this.getSections() : section.getSections()) { sections.add(s); getAllSectionsRecursiveHelper(sections, s); } } return sections; }
@Test public void shouldBuildSchemaWithSections() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); HtmlFormSection section2 = new HtmlFormSection(); section2.setName("Section 2"); schema.getSections().add(section2); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("sections").get(1).get("name").getValueAsText(), is("Section 2")); }
Assert.assertThat(hfs.getFields().size(), is(1)); Assert.assertThat( ((ObsField) hfs.getFields().get(0)).getQuestion().getId(), is(6)); Assert.assertThat(hfs.getSections().size(), is(1)); Assert.assertThat(hfs.getSections().get(0).getName(), is("Section One")); Assert.assertThat(hfs.getSections().get(0).getFields().size(), is(1)); Assert.assertThat(((ObsField) hfs.getSections().get(0).getFields().get(0)).getQuestion().getId(), is(3032)); Assert.assertThat(hfs.getSections().get(0).getSections().size(), is(1)); Assert.assertThat(hfs.getSections().get(0).getSections().get(0).getName(), is("Section One Inner One")); List<HtmlFormField> fields = hfs.getSections().get(0).getSections().get(0).getFields(); Assert.assertThat(fields.size(), is(3)); Assert.assertTrue(fields.get(0) instanceof ObsGroup); Set<HtmlFormField> allFields = hfs.getAllFields(); Assert.assertThat(hfs.getAllFields().size(), is(8)); Assert.assertThat(hfs.getAllSections().size(), is(2));
@Test public void shouldBuildSchemaWithSectionAndSeparateField() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); ObsField field1 = new ObsField(); field1.setName("Field 1"); schema.getFields().add(field1); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("fields").get(0).get("name").getValueAsText(), is("Field 1")); }
public JsonNode buildSchemaAsJsonNode(HtmlFormSchema schema, ObjectMapper jackson) { ObjectNode schemaAsJson = jackson.createObjectNode(); schemaAsJson.put("sections", addSections(schema.getSections(), jackson)); schemaAsJson.put("fields", addFields(schema.getFields(), jackson)); return schemaAsJson; }
/** * Adds an HTML Form Field to the schema * * @param field the field to add */ public void addFieldToActiveSection(HtmlFormField field) { if (sectionsStack.size() > 0) { sectionsStack.peek().addField(field); } else { schema.getFields().add(field); } }
/** * Adds a new section */ public void beginSection(HtmlFormSection section) { // is this a top-level section or it is a child of the existing section if (sectionsStack.size() > 0) { sectionsStack.peek().addChildSection(section); } else { schema.getSections().add(section); } sectionsStack.push(section); }
Set<HtmlFormField> fields = hfs.getAllFields();
@Before public void setUp() throws Exception { HtmlFormSchema schema = new HtmlFormSchema(); Translator translator = new Translator() { @Override public String translate(String localeStr, String key) { return key; } }; params = new HashMap<String, String>(); context = mock(FormEntryContext.class); when(context.getSchema()).thenReturn(schema); when(context.getTranslator()).thenReturn(translator); }
/** * Returns the entire flattened set of fields */ public Set<HtmlFormField> getAllFields() { return getAllFieldsRecursiveSectionHelper(new HashSet<HtmlFormField>(), null); }
private Set<HtmlFormField> getAllFieldsRecursiveFieldHelper(Set<HtmlFormField> fields, List<HtmlFormField> fieldsToAdd) { if (fieldsToAdd != null) { for (HtmlFormField f : fieldsToAdd) { fields.add(f); if (f instanceof ObsGroup) { getAllFieldsRecursiveFieldHelper(fields, ((ObsGroup) f).getChildren()); } } } return fields; }
@Test public void shouldBuildSchemaWithSectionsNestedSections() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); HtmlFormSection section1a = new HtmlFormSection(); section1a.setName("Section 1a"); section1.addChildSection(section1a); HtmlFormSection section1b = new HtmlFormSection(); section1b.setName("Section 1b"); section1.addChildSection(section1b); schema.getSections().add(section1); HtmlFormSection section2 = new HtmlFormSection(); section2.setName("Section 2"); schema.getSections().add(section2); JsonNode schemaAsJson = new HtmlFormEncounterController().buildSchemaAsJsonNode(schema, new ObjectMapper()); assertThat(schemaAsJson.get("sections").get(0).get("name").getValueAsText(), is("Section 1")); assertThat(schemaAsJson.get("sections").get(0).get("sections").get(0).get("name").getValueAsText(), is("Section 1a")); assertThat(schemaAsJson.get("sections").get(0).get("sections").get(1).get("name").getValueAsText(), is("Section 1b")); assertThat(schemaAsJson.get("sections").get(1).get("name").getValueAsText(), is("Section 2")); }
@Test public void shouldAddConceptAnswersDefinedInConceptSet() throws Exception { String htmlform = "<htmlform><obs id=\"obs-id\" conceptId=\"1000\" answerConceptSetIds=\"1004\" labelText=\"Allergy\"/></htmlform>"; FormEntrySession session = new FormEntrySession(patient, htmlform, null); String htmlToDisplay = session.getHtmlToDisplay(); HtmlFormSchema schema = session.getContext().getSchema(); Assert.assertEquals(1, schema.getFields().size()); ObsField field = (ObsField) schema.getFields().get(0); // Expected Concept set = Context.getConceptService().getConcept(1004); List<Concept> setMembers = Context.getConceptService().getConceptsByConceptSet(set); Assert.assertEquals(setMembers.size(), field.getAnswers().size()); for (ObsFieldAnswer answer : field.getAnswers()) { Assert.assertTrue(setMembers.contains(answer.getConcept())); } }
@Test public void shouldBuildSchemaWithSectionsAndNestedObsGroup() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1);
@Test public void shouldBuildSchemaWithSectionsAndObsGroup() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1);
@Test public void shouldBuildSchemaWithSectionsAndObsFields() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); schema.getSections().add(section2);
@Test public void shouldBuildSchemaWithSectionsAndObsFieldsWithValues() { HtmlFormSchema schema = new HtmlFormSchema(); HtmlFormSection section1 = new HtmlFormSection(); section1.setName("Section 1"); schema.getSections().add(section1); HtmlFormSection section2 = new HtmlFormSection(); section2.setName("Section 2"); schema.getSections().add(section2);