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

2ic8powd  于 12个月前  发布在  Spring
关注(0)|答案(1)|浏览(175)

抱歉!如果我记录了这样的响应,我将尝试从测试服务器(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 entity-not-found.我还创建了这样消息转换器

@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?谁能告诉我做错了什么?谢谢回复!

eivgtgni

eivgtgni1#

您的搜索将查看具有与您的值匹配的Patient.id标识符的Patients。这将查看属于Patient数据一部分的业务标识符列表,而不是查看包含技术标识的Patient.id字段。如果将where子句更改为:

.where(Patient.RES_ID.matches().value("smart-1032702"))

字符串
或者,如果你只使用技术标识,你可以使用read来代替search,然后,你将立即得到你的Patient对象,而不是Bundle。

相关问题