/** * 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); } }
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 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; }
@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")); }
@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())); } }