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; }
/** * Closes the active {@see ObsGroup} and adds it to the Html Form Schema */ public void endObsGroup() { //remove itself if (!obsGroupStack.isEmpty()){ obsGroupStack.pop(); currentObsGroupConcepts.pop(); } //set the activeObsGroup back to parent, if there is one. if (!obsGroupStack.isEmpty()){ Map<ObsGroup, List<Obs>> map = obsGroupStack.peek(); for (Map.Entry<ObsGroup, List<Obs>> e : map.entrySet()){ e.getKey().addChild(activeObsGroup); currentObsGroupMembers = e.getValue(); activeObsGroup = e.getKey(); break; } } else { currentObsGroupMembers = null; addFieldToActiveSection(activeObsGroup); activeObsGroup = null; } }
private String getName(ObsGroup obsGroup) { String name = obsGroup.getLabel(); if (!StringUtils.hasText(name)) { if (obsGroup.getConcept() != null && obsGroup.getConcept().getName() != null) { name = obsGroup.getConcept().getName().getName(); } } return name; }
Concept groupConcept = mock(Concept.class); when(groupConcept.getName()).thenReturn(groupConceptName); ObsGroup obsGroup = new ObsGroup(groupConcept); section1.getFields().add(obsGroup); Concept nestedGroupConcept = mock(Concept.class); when(nestedGroupConcept.getName()).thenReturn(nestedGroupName); ObsGroup nestedGroup = new ObsGroup(nestedGroupConcept); obsGroup.addChild(nestedGroup); when(concept1.getDatatype()).thenReturn(datatype1); field1.setQuestion(concept1); nestedGroup.addChild(field1);
Assert.assertTrue(fields.get(0) instanceof ObsGroup); ObsGroup obsGroupField = (ObsGroup) fields.get(0); Assert.assertThat(obsGroupField.getLabel(), is("obsgroup1004")); Assert.assertTrue(fields.get(1) instanceof ObsField); Assert.assertThat(((ObsField) fields.get(1)).getQuestions().size(), is(3)); List<HtmlFormField> obsGroupFields = obsGroupField.getChildren(); Assert.assertThat(obsGroupFields.size(), is(2)); Assert.assertTrue(obsGroupFields.get(0) instanceof ObsGroup); ObsGroup nestedObsGroup = (ObsGroup) obsGroupFields.get(0); Assert.assertThat(nestedObsGroup.getLabel(), is("obsgroup7")); Assert.assertTrue(obsGroupFields.get(1) instanceof ObsField); Assert.assertThat(((ObsField) obsGroupFields.get(1)).getQuestion().getId(), is(1005)); Assert.assertThat(nestedObsGroup.getChildren().size(), is(1)); Assert.assertTrue(nestedObsGroup.getChildren().get(0) instanceof ObsField); Assert.assertThat(((ObsField) nestedObsGroup.getChildren().get(0)).getQuestion().getId(), is(1000));
ObsGroup ogSchemaObj = new ObsGroup(groupingConcept, name); session.getContext().beginObsGroup(groupingConcept, thisGroup, ogSchemaObj);
Concept groupConcept = mock(Concept.class); when(groupConcept.getName()).thenReturn(groupConceptName); ObsGroup obsGroup = new ObsGroup(groupConcept); section1.getFields().add(obsGroup); when(concept1.getDatatype()).thenReturn(datatype1); field1.setQuestion(concept1); obsGroup.addChild(field1); when(concept2.getDatatype()).thenReturn(datatype2); field2.setQuestion(concept2); obsGroup.addChild(field2);
public void addFieldToActiveObsGroup(HtmlFormField field) { getActiveObsGroup().getChildren().add(field); }
private JsonNode addFields(List<HtmlFormField> fields, ObjectMapper jackson) { ArrayNode node = jackson.createArrayNode(); for (HtmlFormField field : fields) { // only handling Obs and ObsGroup fields at this point if (field instanceof ObsField) { ObjectNode fieldNode = jackson.createObjectNode(); fieldNode.put("name", (getName((ObsField) field))); fieldNode.put("datatype", (getDatatype((ObsField) field))); fieldNode.put("value", (getValue((ObsField) field))); node.add(fieldNode); } else if (field instanceof ObsGroup) { ObjectNode fieldNode = jackson.createObjectNode(); fieldNode.put("name", (getName((ObsGroup) field))); if (((ObsGroup) field).getChildren() != null && ((ObsGroup) field).getChildren().size() > 0) { fieldNode.put("fields", addFields(((ObsGroup) field).getChildren(), jackson)); } node.add(fieldNode); } } return node; }