fhirbase / fhirbase-plv8

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

Transactional integrity in transactions doesn't work #132

Closed draakhan closed 8 years ago

draakhan commented 8 years ago

Hi!

Tested on v1.3.0.22

SELECT fhir_truncate_storage('{"resourceType": "Patient"}');
SELECT fhir_create_resource('{"allowId": true, "resource": {"resourceType": "Patient","name": [{"given": ["Tim"]}], "id": "2345"}}');
-[ RECORD 1 ]--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fhir_create_resource | {"resourceType":"Patient","name":[{"given":["Tim"]}],"id":"2345","meta":{"versionId":"8ccf6b67-7206-45d2-8e91-f63ca1f80828","lastUpdated":"2016-06-13T16:23:20.232Z","extension":[{"url":"fhir-request-method","valueString":"POST"},{"url":"fhir-request-uri","valueUri":"Patient"}]}}

First update using versionId from create response as ifMatch value

SELECT fhir_transaction('{"resourceType":"Bundle","type":"transaction","entry":[{"resource":{"resourceType":"Patient","name":[{"given":["Jim"]}],"id":"2345","meta":{"versionId":"8ccf6b67-7206-45d2-8e91-f63ca1f80828","lastUpdated":"2016-06-13T16:23:20.232Z","extension":[{"url":"fhir-request-method","valueString":"POST"},{"url":"fhir-request-uri","valueUri":"Patient"}]}},"request":{"method":"PUT","url":"Patient/2345","ifMatch":"8ccf6b67-7206-45d2-8e91-f63ca1f80828"}}]}');
-[ RECORD 1 ]----+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fhir_transaction | {"resourceType":"Bundle","type":"transaction-response","entry":[{"resource":{"resourceType":"Patient","name":[{"given":["Jim"]}],"id":"2345","meta":{"versionId":"70b62a2b-4bce-4e9c-b098-55de6257a7ae","lastUpdated":"2016-06-13T16:26:07.844Z","extension":[{"url":"fhir-request-method","valueString":"PUT"},{"url":"fhir-request-uri","valueUri":"Patient"}]}}}]}

passed and it's correct, but the second update using the same value of ifMatch as the first request should have failed:

SELECT fhir_transaction('{"resourceType":"Bundle","type":"transaction","entry":[{"resource":{"resourceType":"Patient","name":[{"given":["John"]}],"id":"2345","meta":{"versionId":"8ccf6b67-7206-45d2-8e91-f63ca1f80828","lastUpdated":"2016-06-13T16:23:20.232Z","extension":[{"url":"fhir-request-method","valueString":"POST"},{"url":"fhir-request-uri","valueUri":"Patient"}]}},"request":{"method":"PUT","url":"Patient/2345","ifMatch":"8ccf6b67-7206-45d2-8e91-f63ca1f80828"}}]}');
-[ RECORD 1 ]----+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fhir_transaction | {"resourceType":"Bundle","type":"transaction-response","entry":[{"resource":{"resourceType":"Patient","name":[{"given":["John"]}],"id":"2345","meta":{"versionId":"0a40b1ab-4c34-48e0-a28b-139ccb8fe763","lastUpdated":"2016-06-13T16:27:45.225Z","extension":[{"url":"fhir-request-method","valueString":"PUT"},{"url":"fhir-request-uri","valueUri":"Patient"}]}}}]}

fhirbase=# SELECT fhir_resource_history('{"resourceType": "Patient", "id": "2345"}');
-[ RECORD 1 ]---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fhir_resource_history | {"resourceType":"Bundle","total":3,"meta":{"lastUpdated":"2016-06-13T16:27:57.125Z"},"type":"history","entry":[{"request":{"method":"PUT","url":"Patient"},"resource":{"id":"2345","meta":{"extension":[{"url":"fhir-request-method","valueString":"PUT"},{"url":"fhir-request-uri","valueUri":"Patient"}],"versionId":"0a40b1ab-4c34-48e0-a28b-139ccb8fe763","lastUpdated":"2016-06-13T16:27:45.225Z"},"name":[{"given":["John"]}],"resourceType":"Patient"}},{"request":{"method":"PUT","url":"Patient"},"resource":{"id":"2345","meta":{"extension":[{"url":"fhir-request-method","valueString":"PUT"},{"url":"fhir-request-uri","valueUri":"Patient"}],"versionId":"70b62a2b-4bce-4e9c-b098-55de6257a7ae","lastUpdated":"2016-06-13T16:26:07.844Z"},"name":[{"given":["Jim"]}],"resourceType":"Patient"}},{"request":{"method":"POST","url":"Patient"},"resource":{"id":"2345","meta":{"extension":[{"url":"fhir-request-method","valueString":"POST"},{"url":"fhir-request-uri","valueUri":"Patient"}],"versionId":"8ccf6b67-7206-45d2-8e91-f63ca1f80828","lastUpdated":"2016-06-13T16:23:20.232Z"},"name":[{"given":["Tim"]}],"resourceType":"Patient"}}]}

Besides, I have problem with interpreting two parts of a documentation related to a transactional integrity. On the one hand according to a pattern mentioned in the transactional integrity documentation it should be enough to read the latest version, update what is needed on the read resource (preserving versionId of reseources) and make an update, to be sure that the second update from two simultaneous updates won't be performed by a server. On the other hand we have the ifMatch field which looks like something additional to the above-mentioned pattern. Is ifMatch required to perform a version-aware update?

danil commented 8 years ago

@draakhan

Is ifMatch required to perform a version-aware update?

in my opinion, yes

danil commented 8 years ago

@draakhan transaction update with "ifMatch" supported in v1.3.0.25 https://github.com/fhirbase/fhirbase-plv8/blob/v1.3.0.25/test/fhir/transaction_spec.coffee#L55