C32DocumentLogic implements C32DocumentEntityFactory, Serializable { public C32DocumentEntity createDocument(String patientId, String doc) throws Exception { Document xmlDoc = null; if (doc!=null) { doc = doc.trim(); if (!"".equals(doc)) { Builder builder = new Builder(); xmlDoc = builder.build(new StringReader(doc)); } } return new C32DocumentEntity(patientId, getPatientId(xmlDoc), new java.sql.Timestamp(new java.util.Date().getTime()), getFilteredDocument(xmlDoc)); }  DateTimeFormatter getJodaDateFormat(); void setJodaDateFormat(DateTimeFormatter jodaDateFormat); C32DocumentEntity createDocument(String patientId, String doc);  }
@Test public void createDocument_happyPath() throws Exception { C32DocumentEntity doc = docLogic.createDocument("1012638924V546709", getFileAsString("/VA_C32_NWHINONE.xml")); Assert.assertEquals("1012638924V546709", doc.getDocumentPatientId()); }
@Test public void createDocument_emptyString() throws Exception { C32DocumentEntity doc = docLogic.createDocument("fred", ""); Assert.assertEquals("", doc.getDocumentPatientId()); }
@Test public void createDocument_nullString() throws Exception { C32DocumentEntity doc = docLogic.createDocument("jill", null); Assert.assertEquals("", doc.getDocumentPatientId()); }
@Test public void createDocument_noFiltering() throws Exception { String aDoc = getFileAsString("/VA_C32_NWHINONE.xml"); Builder builder = new Builder(); Document doc = builder.build(new StringReader(aDoc)); String expectedDoc = doc.toXML(); C32DocumentEntity c32 = docLogic.createDocument("1012638924V546709", aDoc); boolean matched = expectedDoc.equals(c32.getDocument()); if (!matched) { FileWriter fileWriter = new FileWriter("errorOutput.txt"); PrintWriter printWriter = new PrintWriter(fileWriter); printWriter.println("==============="); printWriter.println(expectedDoc); printWriter.println("==============="); printWriter.println(c32.getDocument()); printWriter.close(); } Assert.assertTrue(matched); }
@Test public void filterDocument_filterProblems() throws Exception{ DocElementTestParams youngParams = new DocElementTestParams(6, 20); DocElementTestParams olderParams = new DocElementTestParams(7, 21); String aDoc = getCompositeTestDoc(getProblemTextEntry(youngParams)+getProblemTextEntry(olderParams), getProblemEntry(youngParams)+getProblemEntry(olderParams), null, null); C32DocumentEntity filteredDoc = docLogic.createDocument("1012638924V546709",aDoc); Assert.assertTrue(filteredDoc.getDocument().indexOf("#pndProblem" + youngParams.getIndex())<0); Assert.assertTrue(filteredDoc.getDocument().indexOf("#pndProblem" + olderParams.getIndex())>=0); Assert.assertTrue(filteredDoc.getDocument().indexOf("pndDateOfOnset" + youngParams.getIndex())<0); }
@Test public void filterDocument_filterResults() throws Exception { DocElementTestParams youngParams = new DocElementTestParams(6, 50); DocElementTestParams olderParams = new DocElementTestParams(7, 51); String aDoc = getCompositeTestDoc(null, null, getLabTextEntry(youngParams)+getLabTextEntry(olderParams), getLabEntry(youngParams)+getLabEntry(olderParams)); C32DocumentEntity filteredDoc = docLogic.createDocument("1012638924V546709", aDoc); Assert.assertTrue(filteredDoc.getDocument().indexOf("#lndComment"+olderParams.getIndex())>=0); Assert.assertTrue(filteredDoc.getDocument().indexOf("#lndComment"+youngParams.getIndex())<0); Assert.assertTrue(filteredDoc.getDocument().indexOf("lndDateTime"+olderParams.getIndex())<0); Assert.assertTrue(filteredDoc.getDocument().indexOf("lndDateTime"+youngParams.getIndex())<0); }