htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH + "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));
String newXml = HtmlFormEntryExportUtil.getSectionAsFormXml(htmlform, 0);
htmlform.setXmlData(newXml);
Encounter e = new Encounter();
e.setPatient(Context.getPatientService().getPatient(2));
Date date = Context.getDateFormat().parse("01/02/2003");
e.setDateCreated(new Date());
e.setEncounterDatetime(date);
e.setLocation(Context.getLocationService().getLocation(2));
e.setProvider(Context.getPersonService().getPerson(502));
TestUtil.addObs(e, 2474, Context.getConceptService().getConcept(656), date);
TestUtil.addObs(e, 3017, Context.getConceptService().getConcept(767), date);
TestUtil.addObs(e, 3032, new Date(), date);
TestUtil.addObs(e, 1, 5000, date);
TestUtil.addObs(e, 2, 5000, date); //not in form schema, should not be included after trimEncounter
TestUtil.addObs(e, 3, 5000, date); //not in form schema, should not be included after trimEncounter
TestUtil.addObs(e, 6, "blah blah", date);
//1004 is ANOTHER ALLERGY CONSTRUCT, 1005 is HYPER-ALLERGY CODED, 1001 is PENICILLIN
TestUtil.addObsGroup(e, 1004, new Date(), 1005, Context.getConceptService().getConcept(1001), new Date());
//7 IS ALLERGY CONSTRUCT, 1000 IS ALLERGY CODED, 1003 IS OPENMRS
TestUtil.addObsGroup(e, 7, new Date(), 1000, Context.getConceptService().getConcept(1003), new Date());
Context.getEncounterService().saveEncounter(e);
e = HtmlFormEntryExportUtil.trimEncounterToMatchForm(e, htmlform);
if (log.isDebugEnabled()){
for (Obs otmp : e.getAllObs()){
log.debug("trimEncounterToMatchForm returned an obs with concept: " + otmp.getConcept());
}
}
//Note, this assertion corresponds to section index 0 in the form, so 5 obs should be returned
// the form has 6 obs under section 0, but we didn't create the obs for conceptId = 9
Assert.assertEquals(5, e.getAllObs().size());
}