Я столкнулся со следующей проблемой. Я пытаюсь создать функцию (макрос) поверх API hapi-fhir.
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)
)))
Этот макрос работает, когда вы делаете что-то вроде
(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]"]
но не когда я делаю
(let [id 10465 res "Observation"]
(search-patient-resource "Observation" id true))
=> CompilerException java.lang.NullPointerException, compiling:(apycare_emrspp/hapi_fhir_helper.clj:122:1)
Конечно, я не могу написать (символ ~res), потому что тогда читатель оценивает (символ «Наблюдение») во время компиляции, и я получаю
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)
Также ни
(resolve (symbol ~res)
ни
(resolve ~(symbol re)
работай.
Исходный код Java выглядит так
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();
Что я делаю, так это пытаюсь позвонить с помощью
client
.search()
.forResource(another-resource.class)
.where(another-resource.PATIENT.hasId(another-id))
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class)
.execute();
edit
, чтобы изменить исходный вопрос, добавив код туда, а не в разделComments
. Затем вы можете удалить комментарии (слишком тяжело читать здесь) - person Alan Thompson   schedule 29.03.2017