Skip to content

Commit

Permalink
PoC add Fhir rep to PatientResource
Browse files Browse the repository at this point in the history
  • Loading branch information
chibongho committed Oct 15, 2024
1 parent 5568278 commit 2ea81c8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -366,5 +372,5 @@ public Patient getPatientForUpdate(String uuid, Map<String, Object> propertiesTo
personResource.getUpdatableProperties(), false);
return patient;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2ea81c8

Please sign in to comment.