I am facing the following problem. I am trying to construct a function (macro) on top of the hapi-fhir api
function (macro) on topo of hapi-fhir api
(defmacro search-patient-resource
"This macro searches for a specified resource based on the
Patient Id"
[res id json?]
(let [tmp (symbol res)]
(if json?
`(. (. (. (. (. (. @restful-client search) (forResource ~(symbol res))) encodedJson) (where (. (. ~(resolve tmp) PATIENT)
(hasId (str ~id))))) (returnBundle Bundle)) execute)
)))
This macros works when a do something like
(let [id 10465]
(search-patient-resource "Observation" id true))
=>#object[ca.uhn.fhir.model.dstu2.resource.Bundle 0x520a3cc9 "Bundle[id=Bundle/9ca62ae1-82af-488f-a166-5b014f45886e]"]
but not when I do
(let [id 10465 res "Observation"]
(search-patient-resource "Observation" id true))
=> CompilerException java.lang.NullPointerException, compiling:(apycare_emrspp/hapi_fhir_helper.clj:122:1)
Of course I cannot write (symbol ~res) because then the reader evaluates (symbol "Observation") at compile time and I get
CompilerException java.lang.IllegalArgumentException: No matching method found: forResource for class ca.uhn.fhir.rest.client.GenericCl
ient$SearchInternal, compiling:(apycare_emrspp/hapi_fhir_helper.clj:122:1)
Also neither
(resolve (symbol ~res)
nor
(resolve ~(symbol re)
work.
The original java code looks like this
FhirContext ctx = FhirContext.forDstu2();
String serverBase = "fhirtest.uhn.ca/baseDstu2";
IGenericClient client = ctx.newRestfulGenericClient(serverBase);
Bundle results = client .search() .forResource(Observation.class)
.where(Observation.PATIENT.hasId("1234"))
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
.execute();
What I do is attempt to Make the call with
client
.search()
.forResource(another-resource.class)
.where(another-resource.PATIENT.hasId(another-id))
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
.execute();