@Test public void testRedactDocument_RemC32() throws Throwable { initDocumentRedactorWithActualServices(); String remC32 = fileReader.readFile("testRemC32.xml"); final String remRuleExecutionContainerActual = fileReader .readFile("testRemRuleExecutionContainerActual.xml"); final RuleExecutionContainer remRuleExecutionContainerActualObj = marshaller .unmarshalFromXml(RuleExecutionContainer.class, remRuleExecutionContainerActual); final String remXacmlResult = fileReader .readFile("testRemXacmlResult.xml"); final XacmlResult remXacmlResultObj = marshaller.unmarshalFromXml( XacmlResult.class, remXacmlResult); final String factModelXml = factModelExtractor.extractFactModel(remC32, marshaller.marshal(remXacmlResultObj)); final FactModel factModel = marshaller.unmarshalFromXml( FactModel.class, factModelXml); setValueSetCategories(factModel); remC32 = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); final String ethObservationId = "d17e379"; final String hivObservationId = "d17e356"; factModel.setXacmlResult(xacmlResultMock); final String redactedC32 = documentRedactor.redactDocument(remC32, remRuleExecutionContainerActualObj, factModel) .getRedactedDocument(); assertNotNull(getSectionElement(remC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(remC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(remC32, ALLERGIES_SECTION)); assertNull(getSectionElement(remC32, RESULTS_SECTION)); assertNotNull(getSectionElement(redactedC32, PROBLEMS_SECTION)); assertNotNull(getSectionElement(redactedC32, MEDICATIONS_SECTION)); assertNull(getSectionElement(redactedC32, ALLERGIES_SECTION)); assertNull(getSectionElement(redactedC32, RESULTS_SECTION)); assertNotNull(getEntryElement(remC32, ethObservationId)); assertNotNull(getEntryElement(remC32, hivObservationId)); assertNull(getEntryElement(redactedC32, ethObservationId)); assertNull(getEntryElement(redactedC32, hivObservationId)); assertTrue(getHumanReadableTextNodeList(remC32, "substance abuse") .getLength() > 0); assertTrue(getHumanReadableTextNodeList(remC32, "hiv").getLength() > 0); assertTrue(getHumanReadableTextNodeList(redactedC32, "substance abuse") .getLength() == 0); assertTrue(getHumanReadableTextNodeList(redactedC32, "hiv").getLength() == 0); }
@Override public RedactedDocument redactDocument(String document, RuleExecutionContainer ruleExecutionContainer, FactModel factModel) { Document xmlDocument = null; String tryPolicyDocument = null; final List<Node> redactNodeList = new LinkedList<Node>(); final Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); final Set<String> redactSectionSet = new HashSet<String>(); final Set<String> redactCategorySet = new HashSet<String>(); final XacmlResult xacmlResult = factModel.getXacmlResult(); try { xmlDocument = documentXmlConverter.loadDocument(document); final Document factModelDocument = documentXmlConverter .loadDocument(marshaller.marshal(factModel)); for (final AbstractDocumentLevelRedactionHandler documentLevelRedactionHandler : documentLevelRedactionHandlers) { documentLevelRedactionHandler.execute(xmlDocument, redactSectionCodesAndGeneratedEntryIds, redactNodeList); } for (final String obligation : xacmlResult.getPdpObligations()) { for (final AbstractObligationLevelRedactionHandler obligationLevelRedactionHandler : obligationLevelRedactionHandlers) { obligationLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactSectionSet, obligation); } } for (final ClinicalFact fact : factModel.getClinicalFactList()) { for (final AbstractClinicalFactLevelRedactionHandler clinicalFactLevelRedactionHandler : clinicalFactLevelRedactionHandlers) { clinicalFactLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, fact, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactCategorySet); } } tryPolicyDocument = documentXmlConverter .convertXmlDocToString(xmlDocument); for (final Node nodeToBeReadacted : redactNodeList) { redactNodeIfNotNull(nodeToBeReadacted); } for (final AbstractPostRedactionLevelRedactionHandler postRedactionRedactionHandler : postRedactionLevelRedactionHandlers) { postRedactionRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds); } document = documentXmlConverter.convertXmlDocToString(xmlDocument); } catch (final Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } return new RedactedDocument(document, tryPolicyDocument, redactSectionSet, redactCategorySet); }
DocumentRedactorImpl implements DocumentRedactor { @Override public RedactedDocument redactDocument(String document, RuleExecutionContainer ruleExecutionContainer, FactModel factModel) { Document xmlDocument = null; String tryPolicyDocument = null; final List<Node> redactNodeList = new LinkedList<Node>(); final Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); final Set<String> redactSectionSet = new HashSet<String>(); final Set<String> redactCategorySet = new HashSet<String>(); final XacmlResult xacmlResult = factModel.getXacmlResult(); try { xmlDocument = documentXmlConverter.loadDocument(document); final Document factModelDocument = documentXmlConverter .loadDocument(marshaller.marshal(factModel)); for (final AbstractDocumentLevelRedactionHandler documentLevelRedactionHandler : documentLevelRedactionHandlers) { documentLevelRedactionHandler.execute(xmlDocument, redactSectionCodesAndGeneratedEntryIds, redactNodeList); } for (final String obligation : xacmlResult.getPdpObligations()) { for (final AbstractObligationLevelRedactionHandler obligationLevelRedactionHandler : obligationLevelRedactionHandlers) { obligationLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactSectionSet, obligation); } } for (final ClinicalFact fact : factModel.getClinicalFactList()) { for (final AbstractClinicalFactLevelRedactionHandler clinicalFactLevelRedactionHandler : clinicalFactLevelRedactionHandlers) { clinicalFactLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, fact, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactCategorySet); } } tryPolicyDocument = documentXmlConverter .convertXmlDocToString(xmlDocument); for (final Node nodeToBeReadacted : redactNodeList) { redactNodeIfNotNull(nodeToBeReadacted); } for (final AbstractPostRedactionLevelRedactionHandler postRedactionRedactionHandler : postRedactionLevelRedactionHandlers) { postRedactionRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds); } document = documentXmlConverter.convertXmlDocToString(xmlDocument); } catch (final Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } return new RedactedDocument(document, tryPolicyDocument, redactSectionSet, redactCategorySet); } }
DocumentRedactorImpl implements DocumentRedactor { @Override public RedactedDocument redactDocument(String document, RuleExecutionContainer ruleExecutionContainer, FactModel factModel) { Document xmlDocument = null; String tryPolicyDocument = null; final List<Node> redactNodeList = new LinkedList<Node>(); final Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); final Set<String> redactSectionSet = new HashSet<String>(); final Set<String> redactCategorySet = new HashSet<String>(); final XacmlResult xacmlResult = factModel.getXacmlResult(); try { xmlDocument = documentXmlConverter.loadDocument(document); final Document factModelDocument = documentXmlConverter .loadDocument(marshaller.marshal(factModel)); for (final AbstractDocumentLevelRedactionHandler documentLevelRedactionHandler : documentLevelRedactionHandlers) { documentLevelRedactionHandler.execute(xmlDocument, redactSectionCodesAndGeneratedEntryIds, redactNodeList); } for (final String obligation : xacmlResult.getPdpObligations()) { for (final AbstractObligationLevelRedactionHandler obligationLevelRedactionHandler : obligationLevelRedactionHandlers) { obligationLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactSectionSet, obligation); } } for (final ClinicalFact fact : factModel.getClinicalFactList()) { for (final AbstractClinicalFactLevelRedactionHandler clinicalFactLevelRedactionHandler : clinicalFactLevelRedactionHandlers) { clinicalFactLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, fact, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactCategorySet); } } tryPolicyDocument = documentXmlConverter .convertXmlDocToString(xmlDocument); for (final Node nodeToBeReadacted : redactNodeList) { redactNodeIfNotNull(nodeToBeReadacted); } for (final AbstractPostRedactionLevelRedactionHandler postRedactionRedactionHandler : postRedactionLevelRedactionHandlers) { postRedactionRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds); } document = documentXmlConverter.convertXmlDocToString(xmlDocument); } catch (final Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } return new RedactedDocument(document, tryPolicyDocument, redactSectionSet, redactCategorySet); } DocumentRedactorImpl(
			SimpleMarshaller marshaller,
			DocumentXmlConverter documentXmlConverter,
			DocumentAccessor documentAccessor,
			Set<AbstractDocumentLevelRedactionHandler> documentLevelRedactionHandlers,
			Set<AbstractObligationLevelRedactionHandler> obligationLevelRedactionHandlers,
			Set<AbstractClinicalFactLevelRedactionHandler> clinicalFactLevelRedactionHandlers,
			Set<AbstractPostRedactionLevelRedactionHandler> postRedactionLevelRedactionHandlers); }
DocumentRedactorImpl implements DocumentRedactor { @Override public RedactedDocument redactDocument(String document, RuleExecutionContainer ruleExecutionContainer, FactModel factModel) { Document xmlDocument = null; String tryPolicyDocument = null; final List<Node> redactNodeList = new LinkedList<Node>(); final Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); final Set<String> redactSectionSet = new HashSet<String>(); final Set<String> redactCategorySet = new HashSet<String>(); final XacmlResult xacmlResult = factModel.getXacmlResult(); try { xmlDocument = documentXmlConverter.loadDocument(document); final Document factModelDocument = documentXmlConverter .loadDocument(marshaller.marshal(factModel)); for (final AbstractDocumentLevelRedactionHandler documentLevelRedactionHandler : documentLevelRedactionHandlers) { documentLevelRedactionHandler.execute(xmlDocument, redactSectionCodesAndGeneratedEntryIds, redactNodeList); } for (final String obligation : xacmlResult.getPdpObligations()) { for (final AbstractObligationLevelRedactionHandler obligationLevelRedactionHandler : obligationLevelRedactionHandlers) { obligationLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactSectionSet, obligation); } } for (final ClinicalFact fact : factModel.getClinicalFactList()) { for (final AbstractClinicalFactLevelRedactionHandler clinicalFactLevelRedactionHandler : clinicalFactLevelRedactionHandlers) { clinicalFactLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, fact, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactCategorySet); } } tryPolicyDocument = documentXmlConverter .convertXmlDocToString(xmlDocument); for (final Node nodeToBeReadacted : redactNodeList) { redactNodeIfNotNull(nodeToBeReadacted); } for (final AbstractPostRedactionLevelRedactionHandler postRedactionRedactionHandler : postRedactionLevelRedactionHandlers) { postRedactionRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds); } document = documentXmlConverter.convertXmlDocToString(xmlDocument); } catch (final Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } return new RedactedDocument(document, tryPolicyDocument, redactSectionSet, redactCategorySet); } DocumentRedactorImpl(
			SimpleMarshaller marshaller,
			DocumentXmlConverter documentXmlConverter,
			DocumentAccessor documentAccessor,
			Set<AbstractDocumentLevelRedactionHandler> documentLevelRedactionHandlers,
			Set<AbstractObligationLevelRedactionHandler> obligationLevelRedactionHandlers,
			Set<AbstractClinicalFactLevelRedactionHandler> clinicalFactLevelRedactionHandlers,
			Set<AbstractPostRedactionLevelRedactionHandler> postRedactionLevelRedactionHandlers); @Override String cleanUpEmbeddedClinicalDocumentFromFactModel(
			String factModelXml); @Override String cleanUpGeneratedEntryIds(String document); @Override String cleanUpGeneratedServiceEventIds(String document); @Override RedactedDocument redactDocument(String document,
			RuleExecutionContainer ruleExecutionContainer, FactModel factModel); }
DocumentRedactorImpl implements DocumentRedactor { @Override public RedactedDocument redactDocument(String document, RuleExecutionContainer ruleExecutionContainer, FactModel factModel) { Document xmlDocument = null; String tryPolicyDocument = null; final List<Node> redactNodeList = new LinkedList<Node>(); final Set<String> redactSectionCodesAndGeneratedEntryIds = new HashSet<String>(); final Set<String> redactSectionSet = new HashSet<String>(); final Set<String> redactCategorySet = new HashSet<String>(); final XacmlResult xacmlResult = factModel.getXacmlResult(); try { xmlDocument = documentXmlConverter.loadDocument(document); final Document factModelDocument = documentXmlConverter .loadDocument(marshaller.marshal(factModel)); for (final AbstractDocumentLevelRedactionHandler documentLevelRedactionHandler : documentLevelRedactionHandlers) { documentLevelRedactionHandler.execute(xmlDocument, redactSectionCodesAndGeneratedEntryIds, redactNodeList); } for (final String obligation : xacmlResult.getPdpObligations()) { for (final AbstractObligationLevelRedactionHandler obligationLevelRedactionHandler : obligationLevelRedactionHandlers) { obligationLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactSectionSet, obligation); } } for (final ClinicalFact fact : factModel.getClinicalFactList()) { for (final AbstractClinicalFactLevelRedactionHandler clinicalFactLevelRedactionHandler : clinicalFactLevelRedactionHandlers) { clinicalFactLevelRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, fact, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds, redactCategorySet); } } tryPolicyDocument = documentXmlConverter .convertXmlDocToString(xmlDocument); for (final Node nodeToBeReadacted : redactNodeList) { redactNodeIfNotNull(nodeToBeReadacted); } for (final AbstractPostRedactionLevelRedactionHandler postRedactionRedactionHandler : postRedactionLevelRedactionHandlers) { postRedactionRedactionHandler.execute(xmlDocument, xacmlResult, factModel, factModelDocument, ruleExecutionContainer, redactNodeList, redactSectionCodesAndGeneratedEntryIds); } document = documentXmlConverter.convertXmlDocToString(xmlDocument); } catch (final Exception e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } return new RedactedDocument(document, tryPolicyDocument, redactSectionSet, redactCategorySet); } DocumentRedactorImpl(
			SimpleMarshaller marshaller,
			DocumentXmlConverter documentXmlConverter,
			DocumentAccessor documentAccessor,
			Set<AbstractDocumentLevelRedactionHandler> documentLevelRedactionHandlers,
			Set<AbstractObligationLevelRedactionHandler> obligationLevelRedactionHandlers,
			Set<AbstractClinicalFactLevelRedactionHandler> clinicalFactLevelRedactionHandlers,
			Set<AbstractPostRedactionLevelRedactionHandler> postRedactionLevelRedactionHandlers); @Override String cleanUpEmbeddedClinicalDocumentFromFactModel(
			String factModelXml); @Override String cleanUpGeneratedEntryIds(String document); @Override String cleanUpGeneratedServiceEventIds(String document); @Override RedactedDocument redactDocument(String document,
			RuleExecutionContainer ruleExecutionContainer, FactModel factModel);  }