From 9906b619879fcab06e5ac06dc4a8baf88be390ad Mon Sep 17 00:00:00 2001 From: lmds1 Date: Wed, 17 Sep 2014 11:35:15 -0400 Subject: [PATCH] added UserInfoInterceptor to pass user context for auditing, added narratives for Medication Prescription, moved URL into RequestDetails so it's available to interceptors --- .../interceptor/UserInfoInterceptor.java | 64 +++++++++++++++++++ .../java/ca/uhn/fhir/rest/method/Request.java | 9 --- .../uhn/fhir/rest/method/RequestDetails.java | 9 +++ .../ca/uhn/fhir/narrative/Medication.html | 20 ++++++ .../narrative/MedicationPrescription.html | 36 +++++++++++ .../uhn/fhir/narrative/narratives.properties | 8 +++ .../title/MedicationPrescription.html | 3 + ...efaultThymeleafNarrativeGeneratorTest.java | 24 +++++++ 8 files changed, 164 insertions(+), 9 deletions(-) create mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/UserInfoInterceptor.java create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/Medication.html create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/MedicationPrescription.html create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/MedicationPrescription.html diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/UserInfoInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/UserInfoInterceptor.java new file mode 100644 index 00000000000..12f75c0e512 --- /dev/null +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/interceptor/UserInfoInterceptor.java @@ -0,0 +1,64 @@ +package ca.uhn.fhir.rest.client.interceptor; + +/* + * #%L + * HAPI FHIR - Core Library + * %% + * Copyright (C) 2014 University Health Network + * %% + * 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 java.io.IOException; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpRequestBase; + +import ca.uhn.fhir.rest.client.IClientInterceptor; + +/** + * HTTP interceptor to be used for adding HTTP headers containing user identifying info for auditing purposes to the request + *

+ * See the HAPI Documentation + * for information on how to use this class. + *

+ */ +public class UserInfoInterceptor implements IClientInterceptor { + + public static final String HEADER_USER_ID = "fhir-user-id"; + public static final String HEADER_USER_NAME = "fhir-user-name"; + + private String myUserId; + private String myUserName; + + public UserInfoInterceptor(String theUserId, String theUserName) { + super(); + myUserId = theUserId; + myUserName = theUserName; + } + + @Override + public void interceptRequest(HttpRequestBase theRequest) { + if(myUserId != null) theRequest.addHeader(HEADER_USER_ID, myUserId); + if(myUserName != null) theRequest.addHeader(HEADER_USER_NAME, myUserName); + } + + @Override + public void interceptResponse(HttpResponse theResponse) throws IOException { + // nothing + } + + + +} diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/Request.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/Request.java index 328905129fb..4cfc9517212 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/Request.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/Request.java @@ -37,7 +37,6 @@ import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType; */ public class Request extends RequestDetails { - private String myCompleteUrl; private String myFhirServerBase; private String myOperation; private RequestType myRequestType; @@ -47,10 +46,6 @@ public class Request extends RequestDetails { private HttpServletResponse myServletResponse; private Map> myUnqualifiedToQualifiedNames; - public String getCompleteUrl() { - return myCompleteUrl; - } - public String getFhirServerBase() { return myFhirServerBase; } @@ -84,10 +79,6 @@ public class Request extends RequestDetails { return myRespondGzip; } - public void setCompleteUrl(String theCompleteUrl) { - myCompleteUrl = theCompleteUrl; - } - public void setFhirServerBase(String theFhirServerBase) { myFhirServerBase = theFhirServerBase; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java index 5a6e829dc63..63ec484d6cb 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/RequestDetails.java @@ -35,6 +35,7 @@ public class RequestDetails { private String myResourceName; private RestfulOperationTypeEnum myResourceOperationType; private RestfulOperationSystemEnum mySystemOperationType; + private String myCompleteUrl; public String getCompartmentName() { return myCompartmentName; @@ -92,4 +93,12 @@ public class RequestDetails { mySystemOperationType = theSystemOperationType; } + public String getCompleteUrl() { + return myCompleteUrl; + } + + public void setCompleteUrl(String theCompleteUrl) { + myCompleteUrl = theCompleteUrl; + } + } diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/Medication.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/Medication.html new file mode 100644 index 00000000000..0d0dc8fdca6 --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/Medication.html @@ -0,0 +1,20 @@ + + + + + + + + +
+
+
+ + + + + diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/MedicationPrescription.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/MedicationPrescription.html new file mode 100644 index 00000000000..64b6c582e73 --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/MedicationPrescription.html @@ -0,0 +1,36 @@ + + + + + + + + +
+
+ + + + + + + + + + + + + + + +
Id
Date
Status
+
+ + + + + diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties index ca7b7dacb44..878df864b99 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties @@ -60,3 +60,11 @@ patient.class=ca.uhn.fhir.model.dstu.resource.Patient patient.narrative=classpath:ca/uhn/fhir/narrative/Patient.html patient.title=classpath:ca/uhn/fhir/narrative/title/Patient.html +medicationprescription.class=ca.uhn.fhir.model.dstu.resource.MedicationPrescription +medicationprescription.narrative=classpath:ca/uhn/fhir/narrative/MedicationPrescription.html +medicationprescription.title=classpath:ca/uhn/fhir/narrative/title/MedicationPrescription.html + +medication.class=ca.uhn.fhir.model.dstu.resource.Medication +medication.narrative=classpath:ca/uhn/fhir/narrative/Medication.html +medication.title=classpath:ca/uhn/fhir/narrative/Medication.html + diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/MedicationPrescription.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/MedicationPrescription.html new file mode 100644 index 00000000000..eff0b4ddd83 --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/MedicationPrescription.html @@ -0,0 +1,3 @@ +
+
+
\ No newline at end of file diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java index 05b4131a903..cbac4dee179 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java @@ -10,6 +10,7 @@ import org.junit.Before; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu.composite.NarrativeDt; @@ -19,6 +20,8 @@ import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu.resource.Conformance; import ca.uhn.fhir.model.dstu.resource.DiagnosticReport; import ca.uhn.fhir.model.dstu.resource.Encounter; +import ca.uhn.fhir.model.dstu.resource.Medication; +import ca.uhn.fhir.model.dstu.resource.MedicationPrescription; import ca.uhn.fhir.model.dstu.resource.Observation; import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.dstu.resource.Organization; @@ -26,6 +29,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.dstu.valueset.DiagnosticReportStatusEnum; import ca.uhn.fhir.model.dstu.valueset.EncounterClassEnum; import ca.uhn.fhir.model.dstu.valueset.EncounterTypeEnum; +import ca.uhn.fhir.model.dstu.valueset.MedicationPrescriptionStatusEnum; import ca.uhn.fhir.model.dstu.valueset.ObservationStatusEnum; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.StringDt; @@ -203,5 +207,25 @@ public class DefaultThymeleafNarrativeGeneratorTest { assertThat(output, StringContains.containsString("
Some & Diagnostic Report
")); } + + @Test + public void testGenerateMedicationPrescription(){ + MedicationPrescription mp = new MedicationPrescription(); + mp.setId("12345"); + Medication med = new Medication(); + med.setName("ciprofloaxin"); + ResourceReferenceDt medRef = new ResourceReferenceDt(med); + mp.setMedication(medRef ); + mp.setStatus(MedicationPrescriptionStatusEnum.ACTIVE); + mp.setDateWritten(new DateTimeDt("2014-09-01")); + + NarrativeDt narrative = gen.generateNarrative(mp); + assertTrue("Expected medication name of ciprofloaxin within narrative: " + narrative.getDiv().toString(), narrative.getDiv().toString().indexOf("ciprofloaxin")>-1); + assertTrue("Expected string status of ACTIVE within narrative: " + narrative.getDiv().toString(), narrative.getDiv().toString().indexOf("ACTIVE")>-1); + + String title = gen.generateTitle(mp); + assertEquals("ciprofloaxin", title); + + } }