@Test
@Verifies(value = "should return encounter with all child objects voided according to schema", method = "voidEncounterByHtmlFormSchema")
public void testVoidEncounterByHtmlFormSchema_shouldReturnEncounterCorrectly() throws Exception {
executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REGRESSION_TEST_DATASET));
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));
//add a bunch of obs...
TestUtil.addObs(e, 2474, Context.getConceptService().getConcept(656), date); //matches
TestUtil.addObs(e, 3017, Context.getConceptService().getConcept(767), date); //matches
TestUtil.addObs(e, 3032, new Date(), date); //matches
TestUtil.addObs(e, 1, 5000, date); // matches
TestUtil.addObs(e, 2, 5000, date); //not in form schema
TestUtil.addObs(e, 3, 5000, date); //not in form schema
TestUtil.addObs(e, 6, "blah blah", date); // matches
//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()); //matches
//7 IS ALLERGY CONSTRUCT, 1000 IS ALLERGY CODED, 1003 IS OPENMRS
TestUtil.addObsGroup(e, 7, new Date(), 1000, Context.getConceptService().getConcept(1003), new Date()); //matches
TestUtil.addObsGroup(e, 1000, new Date(), 7, Context.getConceptService().getConcept(1003), new Date()); //does not match
Context.getEncounterService().saveEncounter(e);
Form form = new Form();
HtmlForm htmlform = new HtmlForm();
htmlform.setForm(form);
form.setEncounterType(new EncounterType());
htmlform.setDateChanged(new Date());
htmlform.setXmlData(new TestUtil().loadXmlFromFile(XML_DATASET_PATH
+ "returnSectionsAndConceptsInSectionsTestFormWithGroups.xml"));
HtmlFormEntryUtil.voidEncounterByHtmlFormSchema(e, htmlform, null);
//this is going to test out the voided state of the obs in the encounter after processing:
Assert.assertTrue(!e.isVoided());
for (Obs o : e.getAllObs(true)) {
if (o.getConcept().getConceptId().equals(2474))
Assert.assertTrue(o.isVoided());
if (o.getConcept().getConceptId().equals(3017))
Assert.assertTrue(o.isVoided());
if (o.getConcept().getConceptId().equals(3032))