Ні! I am trying to retrieving patient data from test server (https://api.logicahealth.org/DVJan21CnthnPDex/open) If i log response like that
log.info("Returning: {}", client.getFhirContext().newJsonParser().setPrettyPrint(true).encodeToString(patient));
i get json what i need,
{"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"}]}
but if i try to return patient object in mvc controller
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;
i receive in browser 404 entity-not-found. I also create message converters like this
@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());
}`
How to convert fhir resources to json via converter bean? Who can tell what i do wrong? Thenks for any reply!
Your search is looking at Patients with Patient.identifier matching your value. This looks at the list of business identifiers that are part of the Patient data, instead of looking at the Patient.id field which contains the technical identity. You will probably get better results when you change your
where
clause to:Or you could do a
read
instead of asearch
, if you're using only the technical identity anyway. Then, instead of the Bundle you'll get your Patient object right away.