@Test(expected = DS4PException.class) public void testSegmentDocument_Given_Real_Marshaller_Throws_DS4PException() throws IOException, InvalidOriginalClinicalDocumentException, InvalidSegmentedClinicalDocumentException, AuditException { final boolean xdm = true; final boolean ecrypt = true; final XmlValidationResult xmlValidationResultMock = mock(XmlValidationResult.class); when(xmlValidationResultMock.isValid()).thenReturn(true); when(xmlValidatorMock.validateWithAllErrors("")).thenReturn( xmlValidationResultMock); final DocumentSegmentationImpl documentSegmentationWithRealMarshaller = new DocumentSegmentationImpl( ruleExecutionServiceClientMock, auditServiceMock, documentEditorMock, new SimpleMarshallerImpl(), documentRedactorMock, documentTaggerMock, documentFactModelExtractorMock, embeddedClinicalDocumentExtractorMock, new ValueSetServiceImplMock(fileReader), additionalMetadataGeneratorForSegmentedClinicalDocumentImplMock); ReflectionTestUtils.setField(documentSegmentationWithRealMarshaller, "xmlValidator", xmlValidatorMock); @SuppressWarnings("unused") final SegmentDocumentResponse resp = documentSegmentationWithRealMarshaller .segmentDocument("", "", false, true, true); }
@SuppressWarnings("unchecked") @Override public SegmentDocumentResponse segmentDocument(String document, String enforcementPolicies, boolean isAudited, boolean isAuditFailureByPass, boolean enableTryPolicyResponse) throws XmlDocumentReadFailureException, InvalidSegmentedClinicalDocumentException, AuditException { Assert.notNull(document); final String originalDocument = document; XmlValidationResult originalClinicalDocumentValidationResult = null; try { originalClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(originalClinicalDocumentValidationResult); } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!originalClinicalDocumentValidationResult.isValid()) { logger.error("Schema validation is failed for original clinical document."); final String err = "InvalidOriginalClinicalDocumentException: "; for (final SAXParseException e : originalClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } } Assert.notNull(enforcementPolicies); RuleExecutionContainer ruleExecutionContainer = null; RedactedDocument redactedDocument = null; String rulesFired = null; final SegmentDocumentResponse segmentDocumentResponse = new SegmentDocumentResponse(); FactModel factModel = null; try { document = documentEditor.setDocumentCreationDate(document); String factModelXml = documentFactModelExtractor.extractFactModel( document, enforcementPolicies); document = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = documentRedactor .cleanUpEmbeddedClinicalDocumentFromFactModel(factModelXml); factModel = marshaller.unmarshalFromXml(FactModel.class, factModelXml); final List<CodeAndCodeSystemSetDto> codeAndCodeSystemSetDtoList = new ArrayList<CodeAndCodeSystemSetDto>(); for (final ClinicalFact fact : factModel.getClinicalFactList()) { final CodeAndCodeSystemSetDto codeAndCodeSystemSetDto = new CodeAndCodeSystemSetDto(); codeAndCodeSystemSetDto.setConceptCode(fact.getCode()); codeAndCodeSystemSetDto.setCodeSystemOid(fact.getCodeSystem()); codeAndCodeSystemSetDtoList.add(codeAndCodeSystemSetDto); } final List<Map<String, Object>> valueSetCategories = valueSetService .lookupValuesetCategoriesOfMultipleCodeAndCodeSystemSet(codeAndCodeSystemSetDtoList); for (int i = 0; i < factModel.getClinicalFactList().size(); i++) { final Map<String, Object> valueSetMap = valueSetCategories .get(i); final ClinicalFact fact = factModel.getClinicalFactList() .get(i); Assert.isTrue(fact.getCode().equals( valueSetMap.get("conceptCode"))); Assert.isTrue(fact.getCodeSystem().equals( valueSetMap.get("codeSystemOid"))); if (valueSetMap.get("vsCategoryCodes") != null) { fact.setValueSetCategories(new HashSet<String>( (ArrayList<String>) valueSetMap .get("vsCategoryCodes"))); } } final AssertAndExecuteClinicalFactsResponse brmsResponse = ruleExecutionService .assertAndExecuteClinicalFacts(factModel); String executionResponseContainer = brmsResponse .getRuleExecutionResponseContainer(); rulesFired = brmsResponse.getRulesFired(); ruleExecutionContainer = marshaller.unmarshalFromXml( RuleExecutionContainer.class, executionResponseContainer); logger.info("Fact model: " + factModelXml); logger.info("Rule Execution Container size: " + ruleExecutionContainer.getExecutionResponseList().size()); redactedDocument = documentRedactor.redactDocument(document, ruleExecutionContainer, factModel); document = redactedDocument.getRedactedDocument(); if (enableTryPolicyResponse) { segmentDocumentResponse .setTryPolicyDocumentXml(redactedDocument .getTryPolicyDocument()); } executionResponseContainer = marshaller .marshal(ruleExecutionContainer); document = documentTagger.tagDocument(document, executionResponseContainer); document = documentRedactor.cleanUpGeneratedEntryIds(document); document = documentRedactor .cleanUpGeneratedServiceEventIds(document); segmentDocumentResponse.setSegmentedDocumentXml(document); segmentDocumentResponse .setExecutionResponseContainerXml(executionResponseContainer); } catch (final JAXBException e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } catch (final Throwable e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } XmlValidationResult segmentedClinicalDocumentValidationResult = null; try { segmentedClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(segmentedClinicalDocumentValidationResult); if (isAudited) { auditSegmentation(originalDocument, document, factModel.getXacmlResult(), redactedDocument, rulesFired, originalClinicalDocumentValidationResult, segmentedClinicalDocumentValidationResult, isAuditFailureByPass); } } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!segmentedClinicalDocumentValidationResult.isValid()) { final String segmentationErr = "Schema validation is failed for segmented clinical document."; logger.error(segmentationErr); final String err = "InvalidSegmentedClinicalDocumentException: "; for (final SAXParseException e : segmentedClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } throw new InvalidSegmentedClinicalDocumentException(segmentationErr); } return segmentDocumentResponse; }
DocumentSegmentationImpl implements DocumentSegmentation { @SuppressWarnings("unchecked") @Override public SegmentDocumentResponse segmentDocument(String document, String enforcementPolicies, boolean isAudited, boolean isAuditFailureByPass, boolean enableTryPolicyResponse) throws XmlDocumentReadFailureException, InvalidSegmentedClinicalDocumentException, AuditException { Assert.notNull(document); final String originalDocument = document; XmlValidationResult originalClinicalDocumentValidationResult = null; try { originalClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(originalClinicalDocumentValidationResult); } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!originalClinicalDocumentValidationResult.isValid()) { logger.error("Schema validation is failed for original clinical document."); final String err = "InvalidOriginalClinicalDocumentException: "; for (final SAXParseException e : originalClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } } Assert.notNull(enforcementPolicies); RuleExecutionContainer ruleExecutionContainer = null; RedactedDocument redactedDocument = null; String rulesFired = null; final SegmentDocumentResponse segmentDocumentResponse = new SegmentDocumentResponse(); FactModel factModel = null; try { document = documentEditor.setDocumentCreationDate(document); String factModelXml = documentFactModelExtractor.extractFactModel( document, enforcementPolicies); document = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = documentRedactor .cleanUpEmbeddedClinicalDocumentFromFactModel(factModelXml); factModel = marshaller.unmarshalFromXml(FactModel.class, factModelXml); final List<CodeAndCodeSystemSetDto> codeAndCodeSystemSetDtoList = new ArrayList<CodeAndCodeSystemSetDto>(); for (final ClinicalFact fact : factModel.getClinicalFactList()) { final CodeAndCodeSystemSetDto codeAndCodeSystemSetDto = new CodeAndCodeSystemSetDto(); codeAndCodeSystemSetDto.setConceptCode(fact.getCode()); codeAndCodeSystemSetDto.setCodeSystemOid(fact.getCodeSystem()); codeAndCodeSystemSetDtoList.add(codeAndCodeSystemSetDto); } final List<Map<String, Object>> valueSetCategories = valueSetService .lookupValuesetCategoriesOfMultipleCodeAndCodeSystemSet(codeAndCodeSystemSetDtoList); for (int i = 0; i < factModel.getClinicalFactList().size(); i++) { final Map<String, Object> valueSetMap = valueSetCategories .get(i); final ClinicalFact fact = factModel.getClinicalFactList() .get(i); Assert.isTrue(fact.getCode().equals( valueSetMap.get("conceptCode"))); Assert.isTrue(fact.getCodeSystem().equals( valueSetMap.get("codeSystemOid"))); if (valueSetMap.get("vsCategoryCodes") != null) { fact.setValueSetCategories(new HashSet<String>( (ArrayList<String>) valueSetMap .get("vsCategoryCodes"))); } } final AssertAndExecuteClinicalFactsResponse brmsResponse = ruleExecutionService .assertAndExecuteClinicalFacts(factModel); String executionResponseContainer = brmsResponse .getRuleExecutionResponseContainer(); rulesFired = brmsResponse.getRulesFired(); ruleExecutionContainer = marshaller.unmarshalFromXml( RuleExecutionContainer.class, executionResponseContainer); logger.info("Fact model: " + factModelXml); logger.info("Rule Execution Container size: " + ruleExecutionContainer.getExecutionResponseList().size()); redactedDocument = documentRedactor.redactDocument(document, ruleExecutionContainer, factModel); document = redactedDocument.getRedactedDocument(); if (enableTryPolicyResponse) { segmentDocumentResponse .setTryPolicyDocumentXml(redactedDocument .getTryPolicyDocument()); } executionResponseContainer = marshaller .marshal(ruleExecutionContainer); document = documentTagger.tagDocument(document, executionResponseContainer); document = documentRedactor.cleanUpGeneratedEntryIds(document); document = documentRedactor .cleanUpGeneratedServiceEventIds(document); segmentDocumentResponse.setSegmentedDocumentXml(document); segmentDocumentResponse .setExecutionResponseContainerXml(executionResponseContainer); } catch (final JAXBException e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } catch (final Throwable e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } XmlValidationResult segmentedClinicalDocumentValidationResult = null; try { segmentedClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(segmentedClinicalDocumentValidationResult); if (isAudited) { auditSegmentation(originalDocument, document, factModel.getXacmlResult(), redactedDocument, rulesFired, originalClinicalDocumentValidationResult, segmentedClinicalDocumentValidationResult, isAuditFailureByPass); } } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!segmentedClinicalDocumentValidationResult.isValid()) { final String segmentationErr = "Schema validation is failed for segmented clinical document."; logger.error(segmentationErr); final String err = "InvalidSegmentedClinicalDocumentException: "; for (final SAXParseException e : segmentedClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } throw new InvalidSegmentedClinicalDocumentException(segmentationErr); } return segmentDocumentResponse; } }
DocumentSegmentationImpl implements DocumentSegmentation { @SuppressWarnings("unchecked") @Override public SegmentDocumentResponse segmentDocument(String document, String enforcementPolicies, boolean isAudited, boolean isAuditFailureByPass, boolean enableTryPolicyResponse) throws XmlDocumentReadFailureException, InvalidSegmentedClinicalDocumentException, AuditException { Assert.notNull(document); final String originalDocument = document; XmlValidationResult originalClinicalDocumentValidationResult = null; try { originalClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(originalClinicalDocumentValidationResult); } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!originalClinicalDocumentValidationResult.isValid()) { logger.error("Schema validation is failed for original clinical document."); final String err = "InvalidOriginalClinicalDocumentException: "; for (final SAXParseException e : originalClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } } Assert.notNull(enforcementPolicies); RuleExecutionContainer ruleExecutionContainer = null; RedactedDocument redactedDocument = null; String rulesFired = null; final SegmentDocumentResponse segmentDocumentResponse = new SegmentDocumentResponse(); FactModel factModel = null; try { document = documentEditor.setDocumentCreationDate(document); String factModelXml = documentFactModelExtractor.extractFactModel( document, enforcementPolicies); document = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = documentRedactor .cleanUpEmbeddedClinicalDocumentFromFactModel(factModelXml); factModel = marshaller.unmarshalFromXml(FactModel.class, factModelXml); final List<CodeAndCodeSystemSetDto> codeAndCodeSystemSetDtoList = new ArrayList<CodeAndCodeSystemSetDto>(); for (final ClinicalFact fact : factModel.getClinicalFactList()) { final CodeAndCodeSystemSetDto codeAndCodeSystemSetDto = new CodeAndCodeSystemSetDto(); codeAndCodeSystemSetDto.setConceptCode(fact.getCode()); codeAndCodeSystemSetDto.setCodeSystemOid(fact.getCodeSystem()); codeAndCodeSystemSetDtoList.add(codeAndCodeSystemSetDto); } final List<Map<String, Object>> valueSetCategories = valueSetService .lookupValuesetCategoriesOfMultipleCodeAndCodeSystemSet(codeAndCodeSystemSetDtoList); for (int i = 0; i < factModel.getClinicalFactList().size(); i++) { final Map<String, Object> valueSetMap = valueSetCategories .get(i); final ClinicalFact fact = factModel.getClinicalFactList() .get(i); Assert.isTrue(fact.getCode().equals( valueSetMap.get("conceptCode"))); Assert.isTrue(fact.getCodeSystem().equals( valueSetMap.get("codeSystemOid"))); if (valueSetMap.get("vsCategoryCodes") != null) { fact.setValueSetCategories(new HashSet<String>( (ArrayList<String>) valueSetMap .get("vsCategoryCodes"))); } } final AssertAndExecuteClinicalFactsResponse brmsResponse = ruleExecutionService .assertAndExecuteClinicalFacts(factModel); String executionResponseContainer = brmsResponse .getRuleExecutionResponseContainer(); rulesFired = brmsResponse.getRulesFired(); ruleExecutionContainer = marshaller.unmarshalFromXml( RuleExecutionContainer.class, executionResponseContainer); logger.info("Fact model: " + factModelXml); logger.info("Rule Execution Container size: " + ruleExecutionContainer.getExecutionResponseList().size()); redactedDocument = documentRedactor.redactDocument(document, ruleExecutionContainer, factModel); document = redactedDocument.getRedactedDocument(); if (enableTryPolicyResponse) { segmentDocumentResponse .setTryPolicyDocumentXml(redactedDocument .getTryPolicyDocument()); } executionResponseContainer = marshaller .marshal(ruleExecutionContainer); document = documentTagger.tagDocument(document, executionResponseContainer); document = documentRedactor.cleanUpGeneratedEntryIds(document); document = documentRedactor .cleanUpGeneratedServiceEventIds(document); segmentDocumentResponse.setSegmentedDocumentXml(document); segmentDocumentResponse .setExecutionResponseContainerXml(executionResponseContainer); } catch (final JAXBException e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } catch (final Throwable e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } XmlValidationResult segmentedClinicalDocumentValidationResult = null; try { segmentedClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(segmentedClinicalDocumentValidationResult); if (isAudited) { auditSegmentation(originalDocument, document, factModel.getXacmlResult(), redactedDocument, rulesFired, originalClinicalDocumentValidationResult, segmentedClinicalDocumentValidationResult, isAuditFailureByPass); } } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!segmentedClinicalDocumentValidationResult.isValid()) { final String segmentationErr = "Schema validation is failed for segmented clinical document."; logger.error(segmentationErr); final String err = "InvalidSegmentedClinicalDocumentException: "; for (final SAXParseException e : segmentedClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } throw new InvalidSegmentedClinicalDocumentException(segmentationErr); } return segmentDocumentResponse; } DocumentSegmentationImpl(
			RuleExecutionService ruleExecutionService,
			AuditService auditService,
			DocumentEditor documentEditor,
			SimpleMarshaller marshaller,
			DocumentRedactor documentRedactor,
			DocumentTagger documentTagger,
			DocumentFactModelExtractor documentFactModelExtractor,
			EmbeddedClinicalDocumentExtractor embeddedClinicalDocumentExtractor,
			ValueSetService valueSetService,
			AdditionalMetadataGeneratorForSegmentedClinicalDocument additionalMetadataGeneratorForSegmentedClinicalDocument);  DocumentSegmentationImpl(
			RuleExecutionService ruleExecutionService,
			DocumentEditor documentEditor,
			SimpleMarshaller marshaller,
			DocumentRedactor documentRedactor,
			DocumentTagger documentTagger,
			DocumentFactModelExtractor documentFactModelExtractor,
			EmbeddedClinicalDocumentExtractor embeddedClinicalDocumentExtractor,
			ValueSetService valueSetService,
			AdditionalMetadataGeneratorForSegmentedClinicalDocument additionalMetadataGeneratorForSegmentedClinicalDocument); }
DocumentSegmentationImpl implements DocumentSegmentation { @SuppressWarnings("unchecked") @Override public SegmentDocumentResponse segmentDocument(String document, String enforcementPolicies, boolean isAudited, boolean isAuditFailureByPass, boolean enableTryPolicyResponse) throws XmlDocumentReadFailureException, InvalidSegmentedClinicalDocumentException, AuditException { Assert.notNull(document); final String originalDocument = document; XmlValidationResult originalClinicalDocumentValidationResult = null; try { originalClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(originalClinicalDocumentValidationResult); } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!originalClinicalDocumentValidationResult.isValid()) { logger.error("Schema validation is failed for original clinical document."); final String err = "InvalidOriginalClinicalDocumentException: "; for (final SAXParseException e : originalClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } } Assert.notNull(enforcementPolicies); RuleExecutionContainer ruleExecutionContainer = null; RedactedDocument redactedDocument = null; String rulesFired = null; final SegmentDocumentResponse segmentDocumentResponse = new SegmentDocumentResponse(); FactModel factModel = null; try { document = documentEditor.setDocumentCreationDate(document); String factModelXml = documentFactModelExtractor.extractFactModel( document, enforcementPolicies); document = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = documentRedactor .cleanUpEmbeddedClinicalDocumentFromFactModel(factModelXml); factModel = marshaller.unmarshalFromXml(FactModel.class, factModelXml); final List<CodeAndCodeSystemSetDto> codeAndCodeSystemSetDtoList = new ArrayList<CodeAndCodeSystemSetDto>(); for (final ClinicalFact fact : factModel.getClinicalFactList()) { final CodeAndCodeSystemSetDto codeAndCodeSystemSetDto = new CodeAndCodeSystemSetDto(); codeAndCodeSystemSetDto.setConceptCode(fact.getCode()); codeAndCodeSystemSetDto.setCodeSystemOid(fact.getCodeSystem()); codeAndCodeSystemSetDtoList.add(codeAndCodeSystemSetDto); } final List<Map<String, Object>> valueSetCategories = valueSetService .lookupValuesetCategoriesOfMultipleCodeAndCodeSystemSet(codeAndCodeSystemSetDtoList); for (int i = 0; i < factModel.getClinicalFactList().size(); i++) { final Map<String, Object> valueSetMap = valueSetCategories .get(i); final ClinicalFact fact = factModel.getClinicalFactList() .get(i); Assert.isTrue(fact.getCode().equals( valueSetMap.get("conceptCode"))); Assert.isTrue(fact.getCodeSystem().equals( valueSetMap.get("codeSystemOid"))); if (valueSetMap.get("vsCategoryCodes") != null) { fact.setValueSetCategories(new HashSet<String>( (ArrayList<String>) valueSetMap .get("vsCategoryCodes"))); } } final AssertAndExecuteClinicalFactsResponse brmsResponse = ruleExecutionService .assertAndExecuteClinicalFacts(factModel); String executionResponseContainer = brmsResponse .getRuleExecutionResponseContainer(); rulesFired = brmsResponse.getRulesFired(); ruleExecutionContainer = marshaller.unmarshalFromXml( RuleExecutionContainer.class, executionResponseContainer); logger.info("Fact model: " + factModelXml); logger.info("Rule Execution Container size: " + ruleExecutionContainer.getExecutionResponseList().size()); redactedDocument = documentRedactor.redactDocument(document, ruleExecutionContainer, factModel); document = redactedDocument.getRedactedDocument(); if (enableTryPolicyResponse) { segmentDocumentResponse .setTryPolicyDocumentXml(redactedDocument .getTryPolicyDocument()); } executionResponseContainer = marshaller .marshal(ruleExecutionContainer); document = documentTagger.tagDocument(document, executionResponseContainer); document = documentRedactor.cleanUpGeneratedEntryIds(document); document = documentRedactor .cleanUpGeneratedServiceEventIds(document); segmentDocumentResponse.setSegmentedDocumentXml(document); segmentDocumentResponse .setExecutionResponseContainerXml(executionResponseContainer); } catch (final JAXBException e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } catch (final Throwable e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } XmlValidationResult segmentedClinicalDocumentValidationResult = null; try { segmentedClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(segmentedClinicalDocumentValidationResult); if (isAudited) { auditSegmentation(originalDocument, document, factModel.getXacmlResult(), redactedDocument, rulesFired, originalClinicalDocumentValidationResult, segmentedClinicalDocumentValidationResult, isAuditFailureByPass); } } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!segmentedClinicalDocumentValidationResult.isValid()) { final String segmentationErr = "Schema validation is failed for segmented clinical document."; logger.error(segmentationErr); final String err = "InvalidSegmentedClinicalDocumentException: "; for (final SAXParseException e : segmentedClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } throw new InvalidSegmentedClinicalDocumentException(segmentationErr); } return segmentDocumentResponse; } DocumentSegmentationImpl(
			RuleExecutionService ruleExecutionService,
			AuditService auditService,
			DocumentEditor documentEditor,
			SimpleMarshaller marshaller,
			DocumentRedactor documentRedactor,
			DocumentTagger documentTagger,
			DocumentFactModelExtractor documentFactModelExtractor,
			EmbeddedClinicalDocumentExtractor embeddedClinicalDocumentExtractor,
			ValueSetService valueSetService,
			AdditionalMetadataGeneratorForSegmentedClinicalDocument additionalMetadataGeneratorForSegmentedClinicalDocument);  DocumentSegmentationImpl(
			RuleExecutionService ruleExecutionService,
			DocumentEditor documentEditor,
			SimpleMarshaller marshaller,
			DocumentRedactor documentRedactor,
			DocumentTagger documentTagger,
			DocumentFactModelExtractor documentFactModelExtractor,
			EmbeddedClinicalDocumentExtractor embeddedClinicalDocumentExtractor,
			ValueSetService valueSetService,
			AdditionalMetadataGeneratorForSegmentedClinicalDocument additionalMetadataGeneratorForSegmentedClinicalDocument); @SuppressWarnings("unchecked") @Override SegmentDocumentResponse segmentDocument(String document,
			String enforcementPolicies, boolean isAudited,
			boolean isAuditFailureByPass, boolean enableTryPolicyResponse); @Override void setAdditionalMetadataForSegmentedClinicalDocument(
			SegmentDocumentResponse segmentDocumentResponse,
			String senderEmailAddress, String recipientEmailAddress,
			String xdsDocumentEntryUniqueId, XacmlResult xacmlResult); @Override void setDocumentPayloadRawData(
			SegmentDocumentResponse segmentDocumentResponse,
			boolean packageAsXdm, String senderEmailAddress,
			String recipientEmailAddress, XacmlResult xacmlResult); }
DocumentSegmentationImpl implements DocumentSegmentation { @SuppressWarnings("unchecked") @Override public SegmentDocumentResponse segmentDocument(String document, String enforcementPolicies, boolean isAudited, boolean isAuditFailureByPass, boolean enableTryPolicyResponse) throws XmlDocumentReadFailureException, InvalidSegmentedClinicalDocumentException, AuditException { Assert.notNull(document); final String originalDocument = document; XmlValidationResult originalClinicalDocumentValidationResult = null; try { originalClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(originalClinicalDocumentValidationResult); } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!originalClinicalDocumentValidationResult.isValid()) { logger.error("Schema validation is failed for original clinical document."); final String err = "InvalidOriginalClinicalDocumentException: "; for (final SAXParseException e : originalClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } } Assert.notNull(enforcementPolicies); RuleExecutionContainer ruleExecutionContainer = null; RedactedDocument redactedDocument = null; String rulesFired = null; final SegmentDocumentResponse segmentDocumentResponse = new SegmentDocumentResponse(); FactModel factModel = null; try { document = documentEditor.setDocumentCreationDate(document); String factModelXml = documentFactModelExtractor.extractFactModel( document, enforcementPolicies); document = embeddedClinicalDocumentExtractor .extractClinicalDocumentFromFactModel(factModelXml); factModelXml = documentRedactor .cleanUpEmbeddedClinicalDocumentFromFactModel(factModelXml); factModel = marshaller.unmarshalFromXml(FactModel.class, factModelXml); final List<CodeAndCodeSystemSetDto> codeAndCodeSystemSetDtoList = new ArrayList<CodeAndCodeSystemSetDto>(); for (final ClinicalFact fact : factModel.getClinicalFactList()) { final CodeAndCodeSystemSetDto codeAndCodeSystemSetDto = new CodeAndCodeSystemSetDto(); codeAndCodeSystemSetDto.setConceptCode(fact.getCode()); codeAndCodeSystemSetDto.setCodeSystemOid(fact.getCodeSystem()); codeAndCodeSystemSetDtoList.add(codeAndCodeSystemSetDto); } final List<Map<String, Object>> valueSetCategories = valueSetService .lookupValuesetCategoriesOfMultipleCodeAndCodeSystemSet(codeAndCodeSystemSetDtoList); for (int i = 0; i < factModel.getClinicalFactList().size(); i++) { final Map<String, Object> valueSetMap = valueSetCategories .get(i); final ClinicalFact fact = factModel.getClinicalFactList() .get(i); Assert.isTrue(fact.getCode().equals( valueSetMap.get("conceptCode"))); Assert.isTrue(fact.getCodeSystem().equals( valueSetMap.get("codeSystemOid"))); if (valueSetMap.get("vsCategoryCodes") != null) { fact.setValueSetCategories(new HashSet<String>( (ArrayList<String>) valueSetMap .get("vsCategoryCodes"))); } } final AssertAndExecuteClinicalFactsResponse brmsResponse = ruleExecutionService .assertAndExecuteClinicalFacts(factModel); String executionResponseContainer = brmsResponse .getRuleExecutionResponseContainer(); rulesFired = brmsResponse.getRulesFired(); ruleExecutionContainer = marshaller.unmarshalFromXml( RuleExecutionContainer.class, executionResponseContainer); logger.info("Fact model: " + factModelXml); logger.info("Rule Execution Container size: " + ruleExecutionContainer.getExecutionResponseList().size()); redactedDocument = documentRedactor.redactDocument(document, ruleExecutionContainer, factModel); document = redactedDocument.getRedactedDocument(); if (enableTryPolicyResponse) { segmentDocumentResponse .setTryPolicyDocumentXml(redactedDocument .getTryPolicyDocument()); } executionResponseContainer = marshaller .marshal(ruleExecutionContainer); document = documentTagger.tagDocument(document, executionResponseContainer); document = documentRedactor.cleanUpGeneratedEntryIds(document); document = documentRedactor .cleanUpGeneratedServiceEventIds(document); segmentDocumentResponse.setSegmentedDocumentXml(document); segmentDocumentResponse .setExecutionResponseContainerXml(executionResponseContainer); } catch (final JAXBException e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } catch (final Throwable e) { logger.error(e.getMessage(), e); throw new DS4PException(e.toString(), e); } XmlValidationResult segmentedClinicalDocumentValidationResult = null; try { segmentedClinicalDocumentValidationResult = xmlValidator .validateWithAllErrors(document); Assert.notNull(segmentedClinicalDocumentValidationResult); if (isAudited) { auditSegmentation(originalDocument, document, factModel.getXacmlResult(), redactedDocument, rulesFired, originalClinicalDocumentValidationResult, segmentedClinicalDocumentValidationResult, isAuditFailureByPass); } } catch (final XmlDocumentReadFailureException e) { logger.error(e.getMessage(), e); throw e; } if (!segmentedClinicalDocumentValidationResult.isValid()) { final String segmentationErr = "Schema validation is failed for segmented clinical document."; logger.error(segmentationErr); final String err = "InvalidSegmentedClinicalDocumentException: "; for (final SAXParseException e : segmentedClinicalDocumentValidationResult .getExceptions()) { logger.error(err + e.getMessage()); } throw new InvalidSegmentedClinicalDocumentException(segmentationErr); } return segmentDocumentResponse; } DocumentSegmentationImpl(
			RuleExecutionService ruleExecutionService,
			AuditService auditService,
			DocumentEditor documentEditor,
			SimpleMarshaller marshaller,
			DocumentRedactor documentRedactor,
			DocumentTagger documentTagger,
			DocumentFactModelExtractor documentFactModelExtractor,
			EmbeddedClinicalDocumentExtractor embeddedClinicalDocumentExtractor,
			ValueSetService valueSetService,
			AdditionalMetadataGeneratorForSegmentedClinicalDocument additionalMetadataGeneratorForSegmentedClinicalDocument);  DocumentSegmentationImpl(
			RuleExecutionService ruleExecutionService,
			DocumentEditor documentEditor,
			SimpleMarshaller marshaller,
			DocumentRedactor documentRedactor,
			DocumentTagger documentTagger,
			DocumentFactModelExtractor documentFactModelExtractor,
			EmbeddedClinicalDocumentExtractor embeddedClinicalDocumentExtractor,
			ValueSetService valueSetService,
			AdditionalMetadataGeneratorForSegmentedClinicalDocument additionalMetadataGeneratorForSegmentedClinicalDocument); @SuppressWarnings("unchecked") @Override SegmentDocumentResponse segmentDocument(String document,
			String enforcementPolicies, boolean isAudited,
			boolean isAuditFailureByPass, boolean enableTryPolicyResponse); @Override void setAdditionalMetadataForSegmentedClinicalDocument(
			SegmentDocumentResponse segmentDocumentResponse,
			String senderEmailAddress, String recipientEmailAddress,
			String xdsDocumentEntryUniqueId, XacmlResult xacmlResult); @Override void setDocumentPayloadRawData(
			SegmentDocumentResponse segmentDocumentResponse,
			boolean packageAsXdm, String senderEmailAddress,
			String recipientEmailAddress, XacmlResult xacmlResult); static final String C32_CDA_XSD_PATH; static final String C32_CDA_XSD_NAME; }