接受FHIR资源'患者'作为春季启动中的请求机构

发布于 2025-01-28 04:31:12 字数 2214 浏览 4 评论 0 原文

我想在春季靴子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]

预先感谢。

I want to accept the JSON body of Patient FHIR resource as @RequestBody in Spring boot API. I tried to do this:

@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();
    }
}

Using the Patient model from HAPI FHIR(https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-structures-r4/org/hl7/fhir/r4/model/Patient.html)

And called the above endpoint using postman with below request body:

{
    "resourceType":"Patient",
    "name": [{
        "use": "official",
        "given": ["temp"],
        "family": "temp"
    }],
    "birthDate": "1996-04-07"
}

but its giving below Jackson deserialization error:

[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]

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无人问我粥可暖 2025-02-04 04:31:12

第二种溶液的略有变化。您可以创建一个自定义的弹簧MessageConverter,以序列化/供应fhir。为此:

  1. 创建一个hapihttpmessageconverter serialize/deserialize fhir Resources
  2. 创建一个hapimessageconverterconfigurer 注册转换器

A slight variation on the second solution. You can create a custom Spring MessageConverter to serialize/deserialize FHIR. To do that:

  1. Create a HapiHttpMessageConverter to serialize/deserialize FHIR Resources
  2. Create a HapiMessageConverterConfigurer to register the converter
  3. Register the HapiMessgeConverterConfigurer with the Application Context
一个人的旅程 2025-02-04 04:31:12

Springboot并不本地理解FHIR对象。每当您尝试在请求Body Body中接受FHIR时,杰克逊都会尝试对fHir对象进行挑选并抛出给定的错误。

解决方案:

  1. 将fhir对象作为原始对象(字符串)发送,并使用hapi fhir进行相同的序列化。应对字符串。
@RestController
@RequestMapping("/api")
public class DemoController {

    @PostMapping("/Patient/save")
    public String savePatientDetails(@RequestBody String p) {
        IGenericClient client = fhirContext.newRestfulGenericClient("http://localhost:8080/fhir");
        
        IParser parser = fhirContext.newJsonParser();
        
          Patient firObject=parser.parseResource(Patient.class,p);
    
        MethodOutcome s = client.create().resource(firObject).prettyPrint()
                .encodedJson()
                .execute();
                
        return s.toString();
    }
}

  1. 创建客户序列机&使用hapi 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:

  1. Send the FHIR object as a raw object(String) and deserialize the same using HAPI FHIR to deserialize the string.

@RestController
@RequestMapping("/api")
public class DemoController {

    @PostMapping("/Patient/save")
    public String savePatientDetails(@RequestBody String p) {
        IGenericClient client = fhirContext.newRestfulGenericClient("http://localhost:8080/fhir");
        
        IParser parser = fhirContext.newJsonParser();
        
          Patient firObject=parser.parseResource(Patient.class,p);
    
        MethodOutcome s = client.create().resource(firObject).prettyPrint()
                .encodedJson()
                .execute();
                
        return s.toString();
    }
}

  1. Creating the customer serializer & deserializer using HAPI FHIR overriding the Jackson

Custom Deserilizer

Custom Serilizer

Registering custom Serializer and Deserializer

猥琐帝 2025-02-04 04:31:12

@Andrew Hall的解决方案为我工作。我不得不改变它,因为我使用RESTTEMPLATE将FHIR R4患者资源对象从我的专有APP代码发送到FHIR服务器的代替,而是使用RESTTEMPLATE将FHIR R4患者资源对象发送到FHIR APP代码。

我做了安德鲁·霍尔(Andrew Hall)的解决方案指出的事情,只是我不必将Hapimessageconverter注册到MVCCONFIGURER,而是必须将它们注册到REST模板中。在这里为其他遇到这种变化的其他人提供代码。

 @Bean(name = "intAppFhirRestClient")
public RestTemplate fhirRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(0,new HapiHttpMessageConverter(FhirContext.forR4()));
    return restTemplate;
}

另外,只有在专有代码依赖项中具有FHIRCONTEXT和R4的情况下,注册转换器才能正常工作。

<dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-r4</artifactId>
            <version>5.5.7</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-base</artifactId>
            <version>5.5.7</version>
        </dependency>

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.

 @Bean(name = "intAppFhirRestClient")
public RestTemplate fhirRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(0,new HapiHttpMessageConverter(FhirContext.forR4()));
    return restTemplate;
}

Also, registering the converter will only work if you have FhirContext and R4 in your proprietary code dependencies.

<dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-structures-r4</artifactId>
            <version>5.5.7</version>
        </dependency>
        <dependency>
            <groupId>ca.uhn.hapi.fhir</groupId>
            <artifactId>hapi-fhir-base</artifactId>
            <version>5.5.7</version>
        </dependency>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文