fhirbase / fhirbase-plv8

[DEPRECATED] Fhirbase 2.0 is an FHIR relational storage
https://health-samurai.io/fhirbase
Other
105 stars 39 forks source link

Conditional update requires id in resource body #81

Open Andrzej-Pietrzak opened 8 years ago

Andrzej-Pietrzak commented 8 years ago

This operation can be used in pretty much two, maybe three use-cases:

  1. The client knows the id, maybe even knows the last version but wants to be even more sure that the last value of a property is equal to something. And this use-case is really far fetched.
  2. The client wants to create a resource with a unique value of a particular field
  3. The client just doesn't store the id

What do you think about enforcing the id to be equal with the record being updated only when there's a single result from the query and the id was actually provided ?

Samples:

SELECT fhir_create_resource('{"allowId": true, "resource": {"resourceType": "Patient","name": [{"given": ["Tim"]}], "id": "2222"}}'); SELECT fhir_create_resource('{"allowId": true, "resource": {"resourceType": "Patient","name": [{"given": ["Tim"], "family": ["Second"]}], "id": "3333"}}'); SELECT fhir_create_resource('{"allowId": true, "resource": {"resourceType": "Patient","name": [{"given": ["Walter"], "family": ["White"]}], "id": "4444"}}'); SELECT fhir_create_resource('{"allowId": true, "resource": {"resourceType": "Patient","name": [{"given": ["Ala"], "family": ["Blue"]}], "id": "9999"}}'); SELECT fhir_create_resource('{"allowId": true, "resource": {"resourceType": "Patient","name": [{"given": ["Dana"], "family": ["Scully"]}], "id": "8888"}}');

SELECT fhir_update_resource('{"ifNoneExist": "given=nonexisting", "resource": {"resourceType": "Patient", "name": [{"given": ["Gary"], "family": ["Muvout"]}]}}'); --nok, not created SELECT fhir_update_resource('{"ifNoneExist": "given=nonexisting", "resource": {"resourceType": "Patient", "id": "RuthGlouc", "name": [{"given": ["Ruth"], "family": ["Gloucester"]}]}}'); --ok, created with given id

SELECT fhir_update_resource('{"ifNoneExist": "given=Ala", "resource": {"resourceType": "Patient", "name": [{"given": ["Ola"], "family": ["Gray"]}]}}'); --nok, got 400 SELECT fhir_update_resource('{"ifNoneExist": "given=Walter", "resource": {"resourceType": "Patient", "id": "4444","name": [{"given": ["Walter"], "family": ["Black"]}]}}'); --ok, updated SELECT fhir_update_resource('{"ifNoneExist": "given=Dana", "resource": {"resourceType": "Patient", "id": "8888changedTo7777WhichShouldNotHappen","name": [{"given": ["Dana"], "family": ["Shultz"]}]}}'); --ok, updated did not happen SELECT fhir_read_resource('{"resourceType": "Patient", "id": "8888"}'); --ok SELECT fhir_read_resource('{"resourceType": "Patient", "id": "8888changedTo7777WhichShouldNotHappen"}'); -- ok, no res SELECT fhir_resource_history('{"resourceType": "Patient", "id": "8888"}'); --ok SELECT fhir_resource_history('{"resourceType": "Patient", "id": "8888changedTo7777WhichShouldNotHappen"}'); --ok, no res

SELECT fhir_update_resource('{"ifNoneExist": "given=Tim", "resource": {"resourceType": "Patient","name": [{"given": ["Andy"], "family": ["Green"]}]}}'); --nok, 412 expected, got 400 SELECT fhir_update_resource('{"ifNoneExist": "given=Tim", "resource": {"resourceType": "Patient", "id":"TimORange" ,"name": [{"given": ["Timothy"], "family": ["Orange"]}]}}'); --ok

Andrzej-Pietrzak commented 8 years ago

Still present in 1.3.0.11

SELECT fhir_create_resource('{"allowId": true, "resource": {"resourceType": "Patient","name": [{"given": ["Ala"], "family": ["Blue"]}], "id": "9999"}}'); SELECT fhir_update_resource('{"ifNoneExist": "given=Ala", "resource": {"resourceType": "Patient", "name": [{"given": ["Ola"], "family": ["Blue"]}]}}'); --nok, got 400 SELECT fhir_update_resource('{"ifNoneExist": "given=Ala", "resource": {"resourceType": "Patient", "name": [{"given": ["Ola"], "family": ["Blue"]}], "id": "9999"}}'); -- passes SELECT fhir_update_resource('{"ifNoneExist": "given=Ola", "resource": {"resourceType": "Patient", "name": [{"given": ["Ula"], "family": ["Blue"]}], "id": "someOtherId9999"}}'); --passes, no update, ignores the id provided by the user anyway

szymonp-kainos commented 8 years ago

What's the status on this issue ?

danil commented 8 years ago

@szymonp-kainos

What's the status on this issue ?

open

szymonp-kainos commented 8 years ago

I meant: is it in progress or not started or left for later ?

vadi2 commented 7 years ago

Here's the relevant part of the FHIR spec: https://hl7-fhir.github.io/http.html#2.42.0.10.2. Basically, a client should be able to update a resource without knowing the server-assigned ID using this feature.