DocumentTaggerImpl implements DocumentTagger { @Override public String tagDocument(String document, String executionResponseContainer) { executionResponseContainer = executionResponseContainer.replace( "<ruleExecutionContainer>", "<ruleExecutionContainer xmlns=\"urn:hl7-org:v3\">"); final String xslUrl = Thread.currentThread().getContextClassLoader() .getResource(TAG_XSL).toString(); final StringURIResolver stringURIResolver = new StringURIResolver(); stringURIResolver.put( URI_RESOLVER_HREF_RULE_EXECUTION_RESPONSE_CONTAINER, executionResponseContainer); stringURIResolver.put(URI_RESOLVER_HREF_DISCLAMER, disclaimerText); final Optional<URIResolver> uriResolver = Optional .of(stringURIResolver); final String taggedDocument = xmlTransformer.transform(document, xslUrl, Optional.empty(), uriResolver); logger.debug("Tagged Document:"); logger.debug(taggedDocument); return taggedDocument; } DocumentTaggerImpl(String disclaimerText,
			XmlTransformer xmlTransformer); @Override String tagDocument(String document, String executionResponseContainer);  }
@Test public void testTagDocument() throws Exception { logger.debug(c32); final String taggedDocument = documentTagger.tagDocument(c32, executionResponseContainer); logger.debug(taggedDocument); assertTrue(!taggedDocument.contains("<confidentialityCode/>")); assertTrue(taggedDocument .contains("<confidentialityCode xmlns:ds4p=\"http: assertTrue(taggedDocument.contains(DISCLAIMER_TEXT)); assertTrue(taggedDocument.contains("code=\"R\"")); assertTrue(taggedDocument .contains("codeSystem=\"2.16.840.1.113883.5.25\"")); assertTrue(c32.contains("<confidentialityCode/>")); assertTrue(!c32 .contains("<confidentialityCode xmlns:ds4p=\"http: assertTrue(!c32.contains("code=\"R\"")); assertTrue(!c32.contains("codeSystem=\"2.16.840.1.113883.5.25\"")); }
@Test public void testTagDocument_Confidentiality_R() throws Exception { final String responseContainer = remExecutionResponseContainer.replace( "@itemAction", REDACT); final String expectedDocumentLevelConfidentiality = R; final String expectedProblemsSectionLevelConfidentiality = R; final String taggedDocument = documentTagger.tagDocument(remC32, responseContainer); final Document doc = documentXmlConverter.loadDocument(taggedDocument); verifyDocumentLevelConfidentiality(doc, expectedDocumentLevelConfidentiality); verifySectionLevelConfidentiality(doc, PROBLEMS_SECTION, expectedProblemsSectionLevelConfidentiality); }
@Test public void testTagDocument_Confidentiality_V() throws Exception { final String responseContainer = remExecutionResponseContainer.replace( "@itemAction", NO_ACTION); final String expectedDocumentLevelConfidentiality = V; final String expectedProblemsSectionLevelConfidentiality = V; final String taggedDocument = documentTagger.tagDocument(remC32, responseContainer); final Document doc = documentXmlConverter.loadDocument(taggedDocument); verifyDocumentLevelConfidentiality(doc, expectedDocumentLevelConfidentiality); verifySectionLevelConfidentiality(doc, PROBLEMS_SECTION, expectedProblemsSectionLevelConfidentiality); }
@Test public void testTagDocument_Entry_Level_Tagging() throws Exception { logger.debug(c32); String factModelXml = documentFactModelExtractor.extractFactModel(c32, fileReader.readFile("testXacmlResultRedactHIV.xml")); c32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); final String executionResponseContainer = ruleExecutionService .assertAndExecuteClinicalFacts(factModel) .getRuleExecutionResponseContainer(); final String taggedDocument = documentTagger.tagDocument(c32, executionResponseContainer); logger.debug(taggedDocument); assertTrue(!taggedDocument.contains("<confidentialityCode/>")); assertTrue(taggedDocument .contains("<confidentialityCode xmlns:ds4p=\"http: assertTrue(taggedDocument.contains("code=\"R\"")); assertTrue(taggedDocument.contains(DISCLAIMER_TEXT)); assertTrue(taggedDocument .contains("codeSystem=\"2.16.840.1.113883.5.25\"")); assertTrue(c32.contains("<confidentialityCode/>")); assertTrue(!c32 .contains("<confidentialityCode xmlns:ds4p=\"http: assertTrue(!c32.contains("code=\"R\"")); assertTrue(!c32.contains("codeSystem=\"2.16.840.1.113883.5.25\"")); final Document taggedDoc = documentXmlConverter .loadDocument(taggedDocument); verifyEntryLevelTags(taggedDoc, "d1e259", Arrays.asList(new String[] { "R", "NODSCLCD", "ENCRYPT" })); verifyEntryLevelTags(taggedDoc, "d1e220", Arrays.asList(new String[] { "V", "ENCRYPT", "NODSCLCD" })); verifyEntryLevelTags(taggedDoc, "d1e1261", Arrays.asList(new String[] { "R", "ENCRYPT", "NORDSCLCD" })); }
@Test public void testTagDocument_Entry_Level_Tagging_Four_Sections() throws Exception { logger.debug(c32); String factModelXml = documentFactModelExtractor.extractFactModel(c32, fileReader.readFile("testXacmlResultRedactHIV.xml")); c32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = removeEmbeddedClinicalDocument(factModelXml); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); final String executionResponseContainer = ruleExecutionService .assertAndExecuteClinicalFacts(factModel) .getRuleExecutionResponseContainer(); final String taggedDocument = documentTagger.tagDocument(c32, executionResponseContainer); final Document taggedDoc = documentXmlConverter .loadDocument(taggedDocument); verifyEntryLevelTags(taggedDoc, "d1e1168", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "V" })); verifyEntryLevelTags(taggedDoc, "d1e503", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "R" })); verifyEntryLevelTags(taggedDoc, "d1e1168", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "V" })); verifyEntryLevelTags(taggedDoc, "d1e341", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "V" })); verifyEntryLevelTags(taggedDoc, "d1e849", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "V" })); verifyEntryLevelTags(taggedDoc, "d1e798", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "V" })); verifyEntryLevelTags(taggedDoc, "d1e220", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "V" })); verifyEntryLevelTags(taggedDoc, "d1e259", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "R" })); verifyEntryLevelTags(taggedDoc, "d1e564", Arrays.asList(new String[] { "ENCRYPT", "NODSCLCD", "V" })); verifyEntryLevelTags(taggedDoc, "d1e1261", Arrays.asList(new String[] { "ENCRYPT", "NORDSCLCD", "R" })); }
@Test(expected = DS4PException.class) public void testTagDocument_Throws_DS4PException() { @SuppressWarnings("unused") final String taggedDocument = documentTagger.tagDocument("", executionResponseContainer); }