From 2ea81c868a31bdf8c41b4ecb255dd330e8c01a33 Mon Sep 17 00:00:00 2001 From: Chi Bong Ho Date: Tue, 15 Oct 2024 15:32:42 -0400 Subject: [PATCH] PoC add Fhir rep to PatientResource --- .../web/v1_0/resource/openmrs1_8/PatientResource1_8.java | 8 +++++++- .../web/v1_0/resource/openmrs1_9/PatientResource1_9.java | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java index 19178907f..bbdcc32f1 100644 --- a/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java +++ b/omod-1.8/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_8/PatientResource1_8.java @@ -41,6 +41,7 @@ import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.module.webservices.validation.ValidateUtil; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; @@ -137,6 +138,11 @@ public DelegatingResourceDescription getRepresentationDescription(Representation description.addProperty("person", Representation.FULL); description.addProperty("voided"); description.addProperty("auditInfo"); + try { + description.addProperty("fhir", this.getClass().getMethod("toFhirResource", Patient.class)); + } catch(ReflectiveOperationException e) { + log.warn(">>>> reflection failed", e); + } description.addSelfLink(); return description; } @@ -366,5 +372,5 @@ public Patient getPatientForUpdate(String uuid, Map propertiesTo personResource.getUpdatableProperties(), false); return patient; } - + } diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/PatientResource1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/PatientResource1_9.java index 50b548595..2a85dfddf 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/PatientResource1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_9/PatientResource1_9.java @@ -9,6 +9,7 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_9; +import java.lang.reflect.Method; import java.util.List; import org.openmrs.Patient; @@ -40,4 +41,11 @@ public void delete(Patient patient, String reason, RequestContext context) throw super.delete(patient, reason, context); } + public Object toFhirResource(Patient patient) throws ReflectiveOperationException { + Class translatorClass = Context.loadClass("org.openmrs.module.fhir2.api.translators.impl.PatientTranslatorImpl"); + Method m = translatorClass.getDeclaredMethod("toFhirResource", Patient.class); + Object translator = translatorClass.newInstance(); + m.setAccessible(true); + return m.invoke(translator, patient); + } }