use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.
the class FormFolder method getChildren.
public List<CatalogEntry> getChildren(ResourceId formId) {
Optional<FormStorage> storage = catalog.getForm(formId);
if (!storage.isPresent()) {
return Collections.emptyList();
}
List<CatalogEntry> entries = new ArrayList<>();
FormClass formClass = storage.get().getFormClass();
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
ResourceId subFormId = subFormType.getClassId();
CatalogEntry catalogEntry = new CatalogEntry(subFormId.asString(), formField.getLabel(), CatalogEntryType.FORM);
catalogEntry.setLeaf(true);
entries.add(catalogEntry);
}
}
return entries;
}
use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.
the class BatchingFormTreeBuilder method queryTrees.
public Map<ResourceId, FormTree> queryTrees(Collection<ResourceId> rootFormIds) {
// Fetch Required FormClasses in batches
Set<ResourceId> toFetch = Sets.newHashSet();
toFetch.addAll(rootFormIds);
while (!toFetch.isEmpty()) {
// First round: fetch root form classes
List<FormClass> fetched = fetchFormClasses(toFetch);
toFetch.clear();
// Find newly referenced forms
for (FormClass formClass : fetched) {
if (formClass.isSubForm()) {
if (!formCache.containsKey(formClass.getParentFormId().get())) {
toFetch.add(formClass.getParentFormId().get());
}
}
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof ReferenceType) {
ReferenceType refType = (ReferenceType) formField.getType();
for (ResourceId refFormId : refType.getRange()) {
if (!formCache.containsKey(refFormId)) {
toFetch.add(refFormId);
}
}
} else if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
if (!formCache.containsKey(subFormType.getClassId())) {
toFetch.add(subFormType.getClassId());
}
}
}
}
}
// Now assemble trees
Map<ResourceId, FormTree> treeMap = new HashMap<>();
FormTreeBuilder builder = new FormTreeBuilder(new FormClassProvider() {
@Override
public FormClass getFormClass(ResourceId formId) {
return formCache.get(formId);
}
});
for (ResourceId rootFormId : rootFormIds) {
treeMap.put(rootFormId, builder.queryTree(rootFormId));
}
return treeMap;
}
use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.
the class SchemaCsvWriterV3Test method setupSurveyForm.
private void setupSurveyForm() {
surveyForm = new FormClass(ResourceId.valueOf("FORM1"));
surveyForm.setLabel("Household Survey");
surveyForm.addElement(new FormField(ResourceId.valueOf("F1")).setCode("NAME").setLabel("What is your name?").setDescription("The head of household's name").setRequired(true).setType(TextType.SIMPLE));
surveyForm.addElement(new FormField(ResourceId.valueOf("F2")).setCode("AGE").setLabel("What is your age?").setType(new QuantityType("years")).setRequired(true));
surveyForm.addElement(new FormField(ResourceId.valueOf("F3")).setCode("GENDER").setLabel("Gender of head of household").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("GF"), "Female"), new EnumItem(ResourceId.valueOf("GM"), "Male"))).setRequired(true));
surveyForm.addElement(new FormField(ResourceId.valueOf("F4")).setLabel("Are you currently pregnant?").setRelevanceConditionExpression("AGE > 18 && GENDER == 'Female'").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("PY"), "Yes"), new EnumItem(ResourceId.valueOf("PN"), "No"))).setRequired(true));
surveyForm.addElement(new FormField(ResourceId.valueOf("F5")).setLabel("Remarks").setType(NarrativeType.INSTANCE).setRequired(false));
FormClass subFormClass = new FormClass(ResourceId.valueOf("FORM2"));
subFormClass.setSubFormKind(SubFormKind.REPEATING);
subFormClass.addElement(new FormField(ResourceId.valueOf("F21")).setLabel("Name").setType(TextType.SIMPLE).setRequired(true));
subFormClass.addElement(new FormField(ResourceId.valueOf("F22")).setLabel("Age").setType(new QuantityType("years")).setRequired(true));
subFormClass.addElement(new FormField(ResourceId.valueOf("F23")).setLabel("Gender").setType(new EnumType(Cardinality.SINGLE, new EnumItem(ResourceId.valueOf("GF"), "Female"), new EnumItem(ResourceId.valueOf("GM"), "Male"))).setRequired(true));
subFormClass.addElement(new FormField(ResourceId.valueOf("F24")).setLabel("Vaccinations").setType(new EnumType(Cardinality.MULTIPLE, new EnumItem(ResourceId.valueOf("V1"), "Measles"), new EnumItem(ResourceId.valueOf("V2"), "Mumps"), new EnumItem(ResourceId.valueOf("V3"), "Rubella"))));
surveyForm.addElement(new FormField(ResourceId.valueOf("SF")).setLabel("Household members").setType(new SubFormReferenceType(subFormClass.getId())));
formClassProvider.add(surveyForm);
formClassProvider.add(subFormClass);
}
use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.
the class SchemaCsvWriterV3Test method setupMonthly.
private void setupMonthly() {
washForm = new FormClass(ResourceId.valueOf("FORM3"));
washForm.setLabel("Emergency WASH");
washForm.addElement(new FormField(ResourceId.valueOf("WF1")).setLabel("Partner").setRequired(true).setType(new ReferenceType(Cardinality.SINGLE, ResourceId.valueOf("PARTNER_FORM"))));
washForm.addElement(new FormField(ResourceId.valueOf("Population")).setCode("POP").setLabel("Affected Population Size").setType(new QuantityType("households")).setRequired(true));
washForm.addElement(new FormField(ResourceId.valueOf("Population")).setCode("POP").setLabel("Affected Population Size").setType(new QuantityType("households")).setRequired(true));
FormClass subFormClass = new FormClass(ResourceId.valueOf("FORM4"));
subFormClass.setSubFormKind(SubFormKind.WEEKLY);
subFormClass.addElement(new FormField(ResourceId.valueOf("WSF1")).setLabel("Water Trucking").setType(new QuantityType("households")).setRequired(true));
subFormClass.addElement(new FormField(ResourceId.valueOf("WSF2")).setLabel("Cholorination").setType(new QuantityType("households")).setRequired(true));
washForm.addElement(new FormField(ResourceId.valueOf("SF")).setLabel("Monthly Output").setType(new SubFormReferenceType(subFormClass.getId())));
formClassProvider.add(washForm);
formClassProvider.add(subFormClass);
}
use of org.activityinfo.model.type.subform.SubFormReferenceType in project activityinfo by bedatadriven.
the class XlsFormBuilderTest method test.
@Test
public void test() throws IOException {
final FormClass formClass = new FormClass(ResourceId.valueOf("F1"));
formClass.addField(ResourceId.valueOf("X1")).setLabel("What is your name?").setRequired(true).setCode("RespName").setType(TextType.SIMPLE);
formClass.addField(ResourceId.valueOf("X2")).setLabel("How old are you?").setRequired(true).setCode("Age").setType(new QuantityType("years"));
formClass.addField(ResourceId.valueOf("X3")).setLabel("Age in dog years").setRequired(true).setCode("AgeDogYears").setType(new CalculatedFieldType("Age*7"));
formClass.addField(ResourceId.valueOf("X4")).setLabel("Date of birth").setRequired(false).setCode("DOB").setType(LocalDateType.INSTANCE);
formClass.addField(ResourceId.valueOf("X5")).setLabel("What is your favorite color?").setRequired(false).setCode("Color").setType(new EnumType(Cardinality.SINGLE, Lists.newArrayList(new EnumItem(ResourceId.valueOf("Z1"), "Blue"), new EnumItem(ResourceId.valueOf("Z2"), "Red"), new EnumItem(ResourceId.valueOf("Z3"), "Green"))));
formClass.addField(ResourceId.valueOf("X6")).setLabel("Who are your brothers?").setCode("Brothers").setType(new SubFormReferenceType(ResourceId.valueOf("F2")));
formClass.addField(ResourceId.valueOf("X7")).setLabel("Likes any color?").setCode("Colorful").setType(BooleanType.INSTANCE).setRelevanceConditionExpression("containsAny(X5,Z1,Z2,Z3)");
formClass.addField(ResourceId.valueOf("X8")).setLabel("Likes the color blue?").setCode("BlueLover").setType(BooleanType.INSTANCE).setRelevanceConditionExpression("X5==Z1");
formClass.addField(ResourceId.valueOf("X9")).setLabel("Likes the color red?").setCode("RedLover").setType(BooleanType.INSTANCE).setRelevanceConditionExpression("X5==\'Z2\'");
final FormClass subFormClass = new FormClass(ResourceId.valueOf("F2"));
subFormClass.setLabel("Sub Form");
subFormClass.addField(ResourceId.valueOf("Y1")).setLabel("What is his name?").setType(TextType.SIMPLE).setCode("Name");
FormClassProvider provider = new FormClassProvider() {
@Override
public FormClass getFormClass(ResourceId formId) {
if (formId.equals(formClass.getId())) {
return formClass;
} else if (formId.equals(subFormClass.getId())) {
return subFormClass;
} else {
throw new IllegalArgumentException();
}
}
};
XlsFormBuilder writer = new XlsFormBuilder(provider);
writer.build(formClass.getId());
try (FileOutputStream fos = new FileOutputStream("test.xls")) {
writer.write(fos);
}
}
Aggregations