Adding Bundles on FHIR Server and conditional (ifNoneExist) bundle post or put

976 views
Skip to first unread message

Artem Sopin

unread,
Feb 1, 2017, 9:22:31 PM2/1/17
to HAPI FHIR
Hello.

What is the proper syntax for IfNoneExist in bundle? I tried to ignore Patient resource creation if there is such with this id but it seems like this option is ignored. I tried:

1)            <ifNoneExist value="identifier=613876"/>
2)            <ifNoneExist value="Patient.identifier=613876"/>
3)            <ifNoneExist value="ID613876"/>  (referncing Patient.id)


I am on the latest FHIR Server ( https://www.hl7.org/FHIR/2017Jan/ )

Also, I am not sure if I follow the best approach trying to upload multiple linked resources. (I took the concept here: https://groups.google.com/forum/#!searchin/hapi-fhir/bundle%7Csort:relevance/hapi-fhir/UbcXLjKXzgk/DrU4EZF6W1cJ )  

I have a bundle with two resources: Patient and Encounter (see attached file). The Patient must be added to fhir Server if a patient with such id does not exist. The Encounter must be added as well and must reference newly added patient.

To solve this problem I create a bundle with type transaction. I specify id for every resource (do not want FHIR server to give out its ids), add "request" instruction where I set method=PUT, and add URL (see extract below). 


    <entry>
        <resource>
            <Patient>
                <id value="ID613876"/>
                <identifier>
                    <use value="usual"/>
                    <type>
                        <coding>
                            <system value="http://hl7.org/fhir/v2/0203"/>
                            <code value="MR"/>
                            <display value="Medical record number"/>
                        </coding>
                    </type>
                    <system value="http://hospital.smarthealthit.org"/>
                    <value value="613876"/>
                </identifier>
                <name>
                    <use value="official"/>
                    <family value="Hill"/>
                    <given value="Joshua"/>
                    <given value="H."/>
                </name>
                <gender value="male" />
                <birthDate value="1965-02-13" />
                <active value="true"/>
            </Patient>
        </resource>
   
         <request>
            <method value="PUT"/>
            <url value="Patient/ID613876"/>
            <ifNoneExist value="identifier=613876"/>
        </request>
    </entry>

However, when I resubmit my bundle it overrides existing Patient and Encounter (because I use  <request>/    <method value="PUT"/>). I also tried <method value="POST"/> but in this case Patient is created wtih FHIR provided id and following Encounter cannot be linked to this Patient (since I specify one id but FHIR server gives out another). 

Please help me understand how to ignore resource creation if there is a resource with such id. The key probably somewhere in IfNoneExist usage. 

Thank you,
Artem
BundleWithConditionalSample.xml

Artem Sopin

unread,
Feb 2, 2017, 9:46:54 PM2/2/17
to HAPI FHIR
Is that a bug in HAPI Server?

That seems like even if I use POST as the method and if there is a resource with such ID it will be overridden while should be skipped. 

POST bundle with this resource first

        <resource>
            <Patient>
                <id value="ID613876"/>
                 <identifier>
                   <value value="ID613876"/>
                </identifier>
               <name>
                  <given value="John"/> 
               </name>
            </Patient>
        </resource>      
<request>
            <method value="POST"/>
            <url value="Patient/ID613876"/>
    <ifNoneExist value="identifier=ID613876"/>
        </request>

POST bundle with the same but different name

        <resource>
            <Patient>
                <id value="ID613876"/>
                 <identifier>
                   <value value="ID613876"/>
                </identifier>
               <name>
                  <given value="Adam"/> 
               </name>
            </Patient>
        </resource>      
<request>
            <method value="POST"/>
            <url value="Patient/ID613876"/>
    <ifNoneExist value="identifier=ID613876"/>
        </request>

It will change the name to Adam but should ignore the update. 

James Agnew

unread,
Feb 5, 2017, 9:45:09 PM2/5/17
to Artem Sopin, HAPI FHIR
Hi Artem,

Are you testing this against our public server, or against a local one? If so, are you using the latest version of HAPI?

Would you be able to attach the two complete bundles you're using? (One containing the initial create, and the second containing the subsequent conditional create? If possible, please remove everything non-essential to the test)

That certainly sounds like incorrect behaviour, since a POST should not be able to update an existing resource. If this is happening against our public server, it sounds like a bug.

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+unsubscribe@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/47681d5a-f8c0-4458-8fc9-a949b2e098b2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Artem Sopin

unread,
Feb 6, 2017, 1:48:44 PM2/6/17
to HAPI FHIR, a.s...@gmail.com

Hi James,

I use my local installation of the DSTU3 FHIR Server. However, I have just checked it on public https://fhirtest.uhn.ca/baseDstu3/ and got the same behavior. 

Please take a look at two attached complete bundles. I simplified them till the minimum content and it seemed like one resource within bundle was enough to demonstrate my problem.

The contents of these bundle are the same except the name of the patient:

in the first one:
                <name>
                    <given value="Joshua"/>
                </name>

in the second one
                <name>
                    <given value="Adam"/>
                </name>

Thus after POSTing the first one, the resource is created. After posting the second one, it changes the patient name while the id and identifier remain the same. I get "200 OK" (i.e. not Create) response after submitting the second bundle. 

Not sure if it is important, I used Advanced REST client for Chrome, also tried to do this with curl tool. 

Thanks,
Artem

To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.
post1.xml
post2.xml

James Agnew

unread,
Feb 7, 2017, 9:53:41 AM2/7/17
to Artem Sopin, HAPI FHIR
Hi Artem,

Just to keep you in the loop, I tried your bundles out and I see the same thing. I'm investigating now.

Cheers,
James

To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.

James Agnew

unread,
Feb 7, 2017, 12:25:36 PM2/7/17
to Artem Sopin, HAPI FHIR
Alright, a fix has been pushed. Thanks for the testcase, that made this very easy to diagnose!

Cheers,
James

Artem Sopin

unread,
Feb 7, 2017, 7:36:43 PM2/7/17
to HAPI FHIR, a.s...@gmail.com
Thank you for the fix, James! I will check it out. 

Artem Sopin

unread,
Feb 7, 2017, 7:58:30 PM2/7/17
to HAPI FHIR, a.s...@gmail.com
I am still experiencing the same problem. I tried on https://fhirtest.uhn.ca/baseDstu3 and https://fhirtest.uhn.ca/baseDstu2

Do you need to restart servers to make changes take effect? 


On Tuesday, 7 February 2017 09:25:36 UTC-8, James Agnew wrote:

James Agnew

unread,
Feb 7, 2017, 9:16:14 PM2/7/17
to Artem Sopin, HAPI FHIR
Oh sorry, it's not redeployed on there yet. Will do that tomorrow at some point (the server is reindexing right now because I deleted the Lucene indexes and I don't want to interrupt).

Cheers,
James

To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.

To post to this group, send email to hapi...@googlegroups.com.

Artem Sopin

unread,
Feb 8, 2017, 5:37:48 PM2/8/17
to HAPI FHIR, a.s...@gmail.com
Ok, thanks. Just could you please let me know when ready? I will test this update. 
Reply all
Reply to author
Forward
0 new messages