接受FHIR资源'患者'作为春季启动中的请求机构
我想在春季靴子API中接受病人FHIR资源的JSON主体。我尝试这样做:
@RestController
@RequestMapping("/api")
public class DemoController {
@PostMapping("/Patient/save")
public String savePatientDetails(@RequestBody Patient p) {
IGenericClient client = fhirContext.newRestfulGenericClient("http://localhost:8080/fhir");
MethodOutcome s = client.create().resource(p).prettyPrint()
.encodedJson()
.execute();
return s.toString();
}
}
使用Hapi Fhir的患者模型( https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-sonstructures-r4/org/org/org/hl7/fhir/fhir/fhir/r4/r4/model/model/patient.html )
并使用以下请求主体使用Postman调用上述端点:
{
"resourceType":"Patient",
"name": [{
"use": "official",
"given": ["temp"],
"family": "temp"
}],
"birthDate": "1996-04-07"
}
但其在杰克逊估算错误下方的给出:
[nio-8081-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class org.hl7.fhir.r4.model.Patient]]: com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "referenceElement": org.hl7.fhir.r4.model.Reference#setReferenceElement(1 params) vs org.hl7.fhir.r4.model.Reference#setReferenceElement(1 params)
2022-02-25 09:32:43.332 WARN 71185 --- [nio-8081-exec-1] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class org.hl7.fhir.r4.model.Patient]]: com.fasterxml.jackson.databind.JsonMappingException: Conflicting setter definitions for property "referenceElement": org.hl7.fhir.r4.model.Reference#setReferenceElement(1 params) vs org.hl7.fhir.r4.model.Reference#setReferenceElement(1 params)
2022-02-25 09:32:43.356 WARN 71185 --- [nio-8081-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported]
预先感谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
第二种溶液的略有变化。您可以创建一个自定义的弹簧MessageConverter,以序列化/供应fhir。为此:
A slight variation on the second solution. You can create a custom Spring MessageConverter to serialize/deserialize FHIR. To do that:
Springboot并不本地理解FHIR对象。每当您尝试在请求Body Body中接受FHIR时,杰克逊都会尝试对fHir对象进行挑选并抛出给定的错误。
解决方案:
自定义Deserilizer
sstatic.net/tg7kb.png“ rel =“ nofollow noreferrer”>自定义serilizer
SpringBoot does not natively understand the FHIR objects. Any time you will try to accept FHIR in the RequestBody Jackson will try to deserialize the FHIR object and throws the given error.
Solutions:
Custom Deserilizer
Custom Serilizer
Registering custom Serializer and Deserializer
@Andrew Hall的解决方案为我工作。我不得不改变它,因为我使用RESTTEMPLATE将FHIR R4患者资源对象从我的专有APP代码发送到FHIR服务器的代替,而是使用RESTTEMPLATE将FHIR R4患者资源对象发送到FHIR APP代码。
我做了安德鲁·霍尔(Andrew Hall)的解决方案指出的事情,只是我不必将Hapimessageconverter注册到MVCCONFIGURER,而是必须将它们注册到REST模板中。在这里为其他遇到这种变化的其他人提供代码。
另外,只有在专有代码依赖项中具有FHIRCONTEXT和R4的情况下,注册转换器才能正常工作。
The solution of @Andrew Hall worked for me. I had to vary it because instead of a controller, I was using sending a FHIR R4 Patient resource object to from my proprietary app code to a FHIR server using RestTemplate.
I did what Andrew Hall's solution points to except that instead of registering the HapiMessageConverter to a MvcConfigurer, I had to register them to a Rest Template. Fleshing out the code here for others who come across this variation.
Also, registering the converter will only work if you have FhirContext and R4 in your proprietary code dependencies.