LinuxForHealth / FHIR

The LinuxForHealth FHIR® Server and related projects
https://linuxforhealth.github.io/FHIR
Apache License 2.0
332 stars 157 forks source link

Implement conditional update feature (BUNDLE) #2754

Open evbaron opened 3 years ago

evbaron commented 3 years ago

Is your feature request related to a problem? Please describe. It seems like "POST" "IfNoneExist" is supported, but the conditional PUT is not working. We tried "ifNoneExist" and "ifNoneMatch" and it is being ignored.

Request to Implement conditional PUT.

Describe the solution you'd like Simple example:

    "resourceType": "Bundle",
    "id": "2b22d27e-a119-44d4-83b1-1d76cd1849c0",
    "type": "transaction",
    "entry": [
        {
            "fullUrl": "urn:uuid:a441",
            "request": {
                "method": "PUT",
                "url":"Patient/a441",
                "ifNoneMatch": "_id=a441"
            },
            "resource": {
                "resourceType": "Patient",
                "id": "a441",
                "meta": {
                    "extension": [
                        {
                            "url": "http://ibm.com/fhir/cdm/StructureDefinition/source-event-trigger",
                            "valueCodeableConcept": {
                                "coding": [
                                    {
                                        "system": "http://terminology.hl7.org/CodeSystem/v2-0003",
                                        "code": "PAT"
                                    }
                                ]
                            }
                        },
                        {
                            "url": "http://ibm.com/fhir/cdm/StructureDefinition/source-record-type",
                            "valueCodeableConcept": {
                                "coding": [
                                    {
                                        "system": "http://terminology.hl7.org/CodeSystem/v2-0076",
                                        "code": "HIST"
                                    }
                                ]
                            }
                        },
                        {
                            "url": "http://ibm.com/fhir/cdm/StructureDefinition/source-event-timestamp",
                            "valueString": "2021-07-26T10:45:00+08:00"
                        },
                        {
                            "url": "http://ibm.com/fhir/cdm/StructureDefinition/source-record-id",
                            "valueString": "20210726104500"
                        },
                        {
                            "url": "http://ibm.com/fhir/cdm/StructureDefinition/source-data-model-version",
                            "valueString": "2.6"
                        },
                        {
                            "url": "http://ibm.com/fhir/cdm/StructureDefinition/process-client-id",
                            "valueString": "WHI BULK"
                        }
                    ]
                },
                "identifier": [
                    {
                        "system": "urn:id:FAC",
                        "value": "100000"
                    }
                ],
                "name": [
                    {
                        "text": "Ahsoka Tano",
                        "family": "Tano",
                        "given": [
                            "Ahsoka"
                        ]
                    }
                ],
                "telecom": [
                    {
                        "system": "phone",
                        "value": "6155255754",
                        "use": "home"
                    }
                ],
                "gender": "female",
                "birthDate": "1999-10-28",
                "address": [
                    {
                        "line": [
                            "229 S Tyler St"
                        ],
                        "city": "BEVERLY HILLS",
                        "state": "FL",
                        "postalCode": "34465",
                        "country": " US"
                    }
                ],
                "maritalStatus": {
                    "coding": [
                        {
                            "system": "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus",
                            "code": "S",
                            "display": "Never Married"
                        }
                    ],
                    "text": "Never Married"
                }
            }
        }
    ]
}

Expected: result to be returned (similar to POST with IfNoneExist) 200- OK (where resource was not updated because it is already exist) 201 -resource created

Currently resource is always being updated and version incremented.

Describe alternatives you've considered We have considered POST with IfNoneExist (which would do the same thing) BUT it will overwrite resource.id and we need to preserve resource.id from the original.

Acceptance Criteria One of the acceptance criteria would be to make sure that even for conditional updates, the local url resolution is still working. It doesn't seem like it is working on the POST/IfNoneExist.

  1. GIVEN [a precondition] AND [another precondition] WHEN [test step] AND [test step] THEN [verification step] AND [verification step]

Additional context Add any other context or screenshots about the feature request here.

lmsurpre commented 3 years ago

I believe conditional update is implemented as according to https://www.hl7.org/fhir/http.html#cond-update (and I think it should work from a bundle).

In your sample request, you have:

            "request": {
                "method": "PUT",
                "url":"Patient/a441",
                "ifNoneMatch": "_id=a441"
            },

But ifNoneMatch is not defined for updates. If you intend to use the spec-defined conditional update support, try something like this instead:

            "request": {
                "method": "PUT",
                "url":"Patient?_id=a441"
            },

With that said, we do have a separate issue, #2050 which proposes to add special ifNoneMatch support for updates and I agree it would be good to extend that support to include PUTs within bundles. If the above suggestion works for you, then maybe just add a comment there and we can close this one?

lmsurpre commented 3 years ago

I wonder if we could/should add a warning to the output when a user sets one of these Bundle.entry.request fields (ifNoneMatch, ifModifiedSince, ifMatch, or ifNoneExist) on a request method that doesn't support that... Probably using the table from https://www.hl7.org/fhir/http.html#summary (except for the special case that we want to support in #2050).

lmsurpre commented 3 years ago

I wonder if we could/should add a warning to the output when a user sets one of these Bundle.entry.request fields (ifNoneMatch, ifModifiedSince, ifMatch, or ifNoneExist) on a request method that doesn't support that...

team decision: lets cover this scenario (setting these values for requests where they aren't supported) in the documentation (Conformance.md) and then close this one. we should point to https://www.hl7.org/fhir/http.html#summary

punktilious commented 3 years ago

Issue #2050 implements If-None-Match support for PUT within bundles. If the resource exists, the response will be 304 Not Modified.

punktilious commented 2 years ago

Although Conformance.md documents how we handle If-None-Match, it would be useful to add a summary table to provide a clear description of what is/isn't supported and the behavior of the various ifXX fields.

lmsurpre commented 2 years ago

https://linuxforhealth.github.io/FHIR/Conformance/#http-headers does link to https://hl7.org/fhir/R4B/http.html#summary which lists various headers. Its somewhat typical for us to document our deviations from the specification without repeating all of the information in the spec.

@punktilious In my opinion this is good enough for this one. Unless you're planning to add some additional documentation here I think we can close it out. Let me know.