HAPI FHIR 客户端 - 从公共测试服务器检索患者数据

问题描述 投票:0回答:1

Ні!我正在尝试从测试服务器检索患者数据(https://api.logicahealth.org/DVJan21CnthnPDex/open) 如果我像这样记录响应

log.info("Returning: {}", client.getFhirContext().newJsonParser().setPrettyPrint(true).encodeToString(patient));

我得到了我需要的json,

{"resourceType":"Patient","id":"smart-1032702","meta":{"versionId":"1","lastUpdated":"2020-07-15T02:51:25.000+00:00","source":"#KQSArAdbxORTtqVw"},"text":{"status":"generated","div":"<div xmlns=\"http://www.w3.org/1999/xhtml\">Amy Shaw</div>"},"identifier":[{"use":"official","type":{"coding":[{"system":"http://terminology.hl7.org/CodeSystem/v2-0203","code":"MR","display":"Medical Record Number"}],"text":"Medical Record Number"},"system":"http://hospital.smarthealthit.org","value":"smart-1032702"}],"active":true,"name":[{"use":"official","family":"Shaw","given":["Amy","V"]}],"telecom":[{"system":"phone","value":"800-782-6765","use":"mobile"},{"system":"email","value":"[email protected]"}],"gender":"female","birthDate":"2007-03-20","address":[{"use":"home","line":["49 Meadow St"],"city":"Mounds","state":"OK","postalCode":"74047","country":"USA"}],"generalPractitioner":[{"reference":"Practitioner/smart-Practitioner-72004454"}]}

但是如果我尝试在 mvc 控制器中返回病人对象

    Bundle bundle =
            client.search()
                    .forResource(Patient.class)
                    .where(Patient.IDENTIFIER.exactly().identifier("smart-1032702"))
                    .returnBundle(Bundle.class)
                    .execute();

    Patient patient = (Patient) bundle.getEntry().get(0).getResource();
    log.info("Returning: {}", client.getFhirContext().newJsonParser().setPrettyPrint(true).encodeToString(patient));
    return patient;

我在浏览器中收到 404 实体未找到。我也创建这样的消息转换器

@Bean
public IGenericClient fhirClient() {
    IGenericClient client = FhirContext.forR4().newRestfulGenericClient(base);
    client.getFhirContext().registerCustomType(Patient.class);
    return client;
}

@Bean
public RestTemplate restTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
    messageConverters.add(converter());
    messageConverters.add(hapiMessageConverter());
    return restTemplate;
}

@Bean
public MappingJackson2HttpMessageConverter converter() {
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    converter.setObjectMapper(objectMapper);

    MediaType fhir = new MediaType("application", "json+fhir");
    List<MediaType> jacksonTypes = new ArrayList<>(converter.getSupportedMediaTypes());
    jacksonTypes.add(fhir);
    converter.setSupportedMediaTypes(jacksonTypes);
    return converter;
}

@Bean
public HapiHttpMessageConverter hapiMessageConverter() {
    return new HapiHttpMessageConverter();
}

@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
    messageConverters.add(0, hapiMessageConverter());
}`  

如何通过转换器bean将fhir资源转换为json?谁能告诉我我做错了什么? 感谢您的回复!

java spring jackson hl7-fhir hapi-fhir
1个回答
0
投票

您的搜索正在寻找 Patient.identifier 与您的值匹配的患者。它查看属于患者数据一部分的业务标识符列表,而不是查看包含技术身份的 Patient.id 字段。当您将

where
子句更改为:

时,您可能会得到更好的结果
.where(Patient.RES_ID.matches().value("smart-1032702"))

或者,如果您只使用技术身份,则可以使用

read
而不是
search
。然后,您将立即获得 Patient 对象,而不是 Bundle。

© www.soinside.com 2019 - 2024. All rights reserved.