From d5a69d82b268c050bf137705c63e3030a7565170 Mon Sep 17 00:00:00 2001 From: Etienne Poirier <33007955+epeartree@users.noreply.github.com> Date: Thu, 28 Jul 2022 16:07:58 -0400 Subject: [PATCH] 3859 hapi fhir doc snippet link referring a file as opposed to classpath (#3860) * Using snippet type of classpath as opposed to file. * Modifying documentation. Co-authored-by: peartree --- ...meModifierMdmPreProcessingInterceptor.java | 55 +++++++++++++++++++ .../docs/server_jpa_mdm/mdm_customizations.md | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-docs/src/main/java/ca/uhn/hapi/fhir/docs/interceptor/PatientNameModifierMdmPreProcessingInterceptor.java diff --git a/hapi-fhir-docs/src/main/java/ca/uhn/hapi/fhir/docs/interceptor/PatientNameModifierMdmPreProcessingInterceptor.java b/hapi-fhir-docs/src/main/java/ca/uhn/hapi/fhir/docs/interceptor/PatientNameModifierMdmPreProcessingInterceptor.java new file mode 100644 index 00000000000..4cb1a11c891 --- /dev/null +++ b/hapi-fhir-docs/src/main/java/ca/uhn/hapi/fhir/docs/interceptor/PatientNameModifierMdmPreProcessingInterceptor.java @@ -0,0 +1,55 @@ +package ca.uhn.hapi.fhir.docs.interceptor; + +/*- + * #%L + * HAPI FHIR - Docs + * %% + * Copyright (C) 2014 - 2022 Smile CDR, Inc. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.interceptor.api.Hook; +import ca.uhn.fhir.interceptor.api.Pointcut; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.HumanName; +import org.hl7.fhir.r4.model.Patient; +import java.util.List; +import java.util.stream.Collectors; + +import static java.util.Arrays.asList; + +// START SNIPPET: patientInterceptor +/** + * This is a simple interceptor that will remove a humanName when it is found to be + * black listed. + */ +public class PatientNameModifierMdmPreProcessingInterceptor { + List myNamesToIgnore = asList("John Doe", "Jane Doe"); + + @Hook(Pointcut.MDM_BEFORE_PERSISTED_RESOURCE_CHECKED) + public void invoke(IBaseResource theResource) { + + Patient patient = (Patient) theResource; + List nameList = patient.getName(); + + List validHumanNameList = nameList.stream() + .filter(theHumanName -> !myNamesToIgnore.contains(theHumanName.getNameAsSingleString())) + .collect(Collectors.toList()); + + patient.setName(validHumanNameList); + } +} + +// END SNIPPET: patientInterceptor diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_customizations.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_customizations.md index 678ba4fa01a..cc193e23b40 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_customizations.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_mdm/mdm_customizations.md @@ -17,7 +17,7 @@ In a scenario where a patient was given a placeholder name(John Doe), it would b The following provides a full implementation of an interceptor that prevents matching on a patient name when it detects a placeholder value. ```java -{{snippet:file:hapi-fhir/hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/PatientNameModifierMdmPreProcessingInterceptor.java}} +{{snippet:classpath:/ca/uhn/hapi/fhir/docs/interceptor/PatientNameModifierMdmPreProcessingInterceptor.java|patientInterceptor}} ``` See the [Pointcut](/apidocs/hapi-fhir-base/ca/uhn/fhir/interceptor/api/Pointcut.html) JavaDoc for further details on the pointcut MDM_BEFORE_PERSISTED_RESOURCE_CHECKED.