How to create (POST) multiple resources with one request?

1,407 views
Skip to first unread message

Gatoke

unread,
Sep 18, 2019, 4:21:55 AM9/18/19
to HAPI FHIR
Hello. Before I start I would like to admit I've checked that thread and the solution doesn't work to me: https://groups.google.com/forum/#!searchin/hapi-fhir/bundle%7Csort:date/hapi-fhir/7XLqp42yRfs/Tt6YAcFyBwAJ 

When I POST to the base URL of my jpa-server I receive an ERROR message:

10:10:20.043 [http-nio-8090-exec-6] WARN  c.u.f.r.s.i.ExceptionHandlingInterceptor - Failure during REST processing: ca.uhn.fhir.rest.server.exceptions.InvalidRequestException: This is the base URL of FHIR server. Unable to handle this request, as it does not contain a resource type or operation name.


When I use hapi-fhir-client the result is the same.

client.transaction()
.withResources(of(bloodPressureObservation, meanBloodPressureObservation, heartRateObservation))
.execute();

When I make a Bundle of my Observations and POST it - it is saved in jpa-server not as 3 Observations but as 1 Bundle. So when I GET /Observation I don't see them on the list.

My question is:
Is it possible to create multiple resources at once - instead of POSTing them one by one?

Message has been deleted

Gatoke

unread,
Sep 19, 2019, 8:10:44 AM9/19/19
to HAPI FHIR
> UPDATE
1. I have an example of a Bundle. I send it to http://hapi.fhir.org/baseDstu2/?_format=json&_pretty=true which responses with success and 3 created Observations with IDs.
{"resourceType":"Bundle","type":"transaction","entry":[{"resource":{"resourceType":"Observation","meta":{"profile":["http://fhir.org/guides/argonaut/StructureDefinition/argo-vitalsigns"]},"status":"final","category":{"coding":[{"system":"http://hl7.org/fhir/observation-category","code":"vital-signs"}]},"code":{"coding":[{"system":"http://loinc.org","code":"55284-4"}]},"effectiveDateTime":"2019-09-15T12:22:48+02:00","component":[{"code":{"coding":[{"system":"http://loinc.org","code":"8462-4"}]},"valueQuantity":{"value":77.0,"unit":"mmHg","system":"http://unitsofmeasure.org","code":"mm[Hg]"}},{"code":{"coding":[{"system":"http://loinc.org","code":"8480-6"}]},"valueQuantity":{"value":127.0,"unit":"mmHg","system":"http://unitsofmeasure.org","code":"mm[Hg]"}}]},"request":{"method":"POST","url":"Observation"}},{"resource":{"resourceType":"Observation","meta":{"profile":["http://fhir.org/guides/argonaut/StructureDefinition/argo-vitalsigns"]},"status":"final","category":{"coding":[{"system":"http://hl7.org/fhir/observation-category","code":"vital-signs"}]},"code":{"coding":[{"system":"http://loinc.org","code":"8478-0"}]},"effectiveDateTime":"2019-09-15T12:22:48+02:00","valueQuantity":{"value":0.0,"unit":"mmHg","system":"http://unitsofmeasure.org","code":"mm[Hg]"}},"request":{"method":"POST","url":"Observation"}},{"resource":{"resourceType":"Observation","meta":{"profile":["http://fhir.org/guides/argonaut/StructureDefinition/argo-vitalsigns"]},"status":"final","category":{"coding":[{"system":"http://hl7.org/fhir/observation-category","code":"vital-signs"}]},"code":{"coding":[{"system":"http://loinc.org","code":"8867-4"}]},"effectiveDateTime":"2019-09-15T12:22:48+02:00","valueQuantity":{"value":89,"unit":"{beats}/min","system":"http://unitsofmeasure.org","code":"{beats}/min"}},"request":{"method":"POST","url":"Observation"}}]}

2. I do the same request to my local jpa-server: http://localhost:8090/fhir/?_format=json&_pretty=true I use the same body and headers and my server responses with:
{
    "resourceType": "OperationOutcome",
    "issue": [
        {
            "severity": "error",
            "code": "processing",
            "diagnostics": "This is the base URL of FHIR server. Unable to handle this request, as it does not contain a resource type or operation name."
        }
    ]
}


Any suggestions? :-) 

James Agnew

unread,
Sep 19, 2019, 8:15:24 AM9/19/19
to Gatoke, HAPI FHIR
Is this JPA server built with the starter project at: https://github.com/hapifhir/hapi-fhir-jpaserver-starter ?

If not, that is the first thing to try.

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/175599ad-4fbc-4b13-afee-75e21ff23e72%40googlegroups.com.

Gatoke

unread,
Sep 19, 2019, 9:47:52 AM9/19/19
to HAPI FHIR
Thank you for your answer. I have a project based on https://github.com/jamesagnew/hapi-fhir/tree/master/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa
And I looked at what you posted: https://github.com/hapifhir/hapi-fhir-jpaserver-starter and I discovered what is wrong.

Solution: I had to add JpaSystemProviderDstu2 to my RestfulServer configuration.

@Configuration
@RequiredArgsConstructor
class RestfulServerConfig implements FhirRestfulServerCustomizer {

    private final JpaSystemProviderDstu2 mySystemProviderDstu2;

    @Override
    public void customize(final RestfulServer restfulServer) {
        restfulServer.registerProvider(mySystemProviderDstu2);
    }
}


The bean of JpaSystemProviderDstu2 is automatically created on startup but it is not registered. I am curious why isn't it registered by default when using hapi-fhir-spring-boot-starter
Anyway - problem solved. :-) Thank you!

James Agnew

unread,
Sep 19, 2019, 9:49:35 AM9/19/19
to Gatoke, HAPI FHIR
Glad to hear it!

If you're willing to submit a pull request to correct this, I'm sure others would appreciate it.

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.

Ivano Tomainu

unread,
Feb 10, 2020, 10:00:20 AM2/10/20
to HAPI FHIR
Same problem for me but I was not able to solve in this way, I've added the following lines (took from the jpaserver-starter) in the initialize() method of the class FhirAutoConfiguration:


     /*
      * Create a FhirContext object that uses the version of FHIR
      * specified in the properties file.
      */

     
ApplicationContext appCtx = (ApplicationContext) getServletContext()
         
.getAttribute("org.springframework.web.context.WebApplicationContext.ROOT");
     
/*
      * ResourceProviders are fetched from the Spring context
      */

     
FhirVersionEnum fhirVersion = properties.getVersion();
     
ResourceProviderFactory resourceProviders;
     
Object systemProvider;
     
if (fhirVersion == FhirVersionEnum.DSTU2) {
       resourceProviders
= appCtx.getBean("myResourceProvidersDstu2", ResourceProviderFactory.class);
       systemProvider
= appCtx.getBean("mySystemProviderDstu2", JpaSystemProviderDstu2.class);
     
} else if (fhirVersion == FhirVersionEnum.DSTU3) {
       resourceProviders
= appCtx.getBean("myResourceProvidersDstu3", ResourceProviderFactory.class);
       systemProvider
= appCtx.getBean("mySystemProviderDstu3", JpaSystemProviderDstu3.class);
     
} else if (fhirVersion == FhirVersionEnum.R4) {
       resourceProviders
= appCtx.getBean("myResourceProvidersR4", ResourceProviderFactory.class);
       systemProvider
= appCtx.getBean("mySystemProviderR4", JpaSystemProviderR4.class);
     
} else if (fhirVersion == FhirVersionEnum.R5) {
       resourceProviders
= appCtx.getBean("myResourceProvidersR5", ResourceProviderFactory.class);
       systemProvider
= appCtx.getBean("mySystemProviderR5", JpaSystemProviderR5.class);
     
} else {
       
throw new IllegalStateException();
     
}
     setFhirContext
(appCtx.getBean(FhirContext.class));
     registerProviders
(resourceProviders.createProviders());
     registerProvider
(systemProvider);


hope this helps.

Ciao
Ivano

Kishore Kumar Karanam

unread,
Oct 12, 2020, 9:02:21 AM10/12/20
to HAPI FHIR
Can you please give me full working example of above?
Reply all
Reply to author
Forward
0 new messages