LinuxForHealth / FHIR

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

Search response contains duplicate Element.id in certain cases #3058

Closed lmsurpre closed 2 years ago

lmsurpre commented 2 years ago

Describe the bug While validating a search response that uses _include / _revinclude to pull back different resource types with the same id, the searchset bundle fails base FHIR validation.

Example response:

{
    "resourceType": "Bundle",
    "id": "471b5222-55b5-4d30-b179-0e3c7021c5e4",
    "type": "searchset",
    "total": 1,
    "link": [
        {
            "relation": "self",
            "url": "https://cluster1-blue-250babbbe4c3000e15508cd07c1d282b-0000.us-east.containers.appdomain.cloud/fhir-server/api/v4/Procedure?_count=10&_id=zpxDuEwss146&_include=Procedure:performer:Practitioner&_include=Procedure:performer:Organization&_include=Procedure:performer:Device&_include=Procedure:performer:Patient&_include=Procedure:performer:PractitionerRole&_include=Procedure:performer:RelatedPerson&_include=Procedure:based-on:CarePlan&_include=Procedure:based-on:ServiceRequest&_include=Procedure:patient:Patient&_include=Procedure:subject:Group&_include=Procedure:subject:Patient&_include=Procedure:reason-reference:Condition&_include=Procedure:reason-reference:Observation&_include=Procedure:reason-reference:Procedure&_include=Procedure:reason-reference:DiagnosticReport&_include=Procedure:reason-reference:DocumentReference&_include=Procedure:instantiates-canonical:Questionnaire&_include=Procedure:instantiates-canonical:Measure&_include=Procedure:instantiates-canonical:PlanDefinition&_include=Procedure:instantiates-canonical:OperationDefinition&_include=Procedure:instantiates-canonical:ActivityDefinition&_include=Procedure:part-of:Observation&_include=Procedure:part-of:Procedure&_include=Procedure:part-of:MedicationAdministration&_include=Procedure:location:Location&_include=Procedure:encounter:Encounter&_include=Procedure:encounter:EpisodeOfCare&_revinclude=Provenance:target:Procedure&_page=1"
        }
    ],
    "entry": [
        {
            "id": "zpxDuEwss146",
            "fullUrl": "https://cluster1-blue-250babbbe4c3000e15508cd07c1d282b-0000.us-east.containers.appdomain.cloud/fhir-server/api/v4/Procedure/zpxDuEwss146",
            "resource": {
                "resourceType": "Procedure",
                "id": "zpxDuEwss146",
                "meta": {
                    "versionId": "1",
                    "lastUpdated": "2021-12-01T05:49:34.88328Z"
                },
                "text": {
                    "status": "generated",
                    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Sep 23, 2017: Biopsy of suspected melanoma L) arm</div>"
                },
                "identifier": [
                    {
                        "system": "http://happyvalley.com/procedure",
                        "value": "XoVVNp4NJsL"
                    }
                ],
                "status": "completed",
                "code": {
                    "coding": [
                        {
                            "system": "http://snomed.info/sct",
                            "code": "90105005",
                            "display": "Biopsy of soft tissue of forearm, superficial (procedure)"
                        }
                    ],
                    "text": "Biopsy of suspected melanoma L) arm"
                },
                "subject": {
                    "reference": "Patient/zpxDuEwss146"
                },
                "performedDateTime": "2017-09-23",
                "performer": [
                    {
                        "actor": {
                            "reference": "Practitioner/zpxDuEwss146"
                        }
                    }
                ],
                "reasonCode": [
                    {
                        "text": "Dark lesion l) forearm. getting darker last 3 months."
                    }
                ],
                "bodySite": [
                    {
                        "coding": [
                            {
                                "system": "http://snomed.info/sct",
                                "code": "368225008",
                                "display": "Entire Left Forearm"
                            }
                        ],
                        "text": "Left forearm"
                    }
                ],
                "followUp": [
                    {
                        "text": "Review in clinic"
                    }
                ],
                "note": [
                    {
                        "text": "Standard Biopsy"
                    }
                ]
            },
            "search": {
                "mode": "match",
                "score": 1
            }
        },
        {
            "id": "zpxDuEwss146",
            "fullUrl": "https://cluster1-blue-250babbbe4c3000e15508cd07c1d282b-0000.us-east.containers.appdomain.cloud/fhir-server/api/v4/Practitioner/zpxDuEwss146",
            "resource": {
                "resourceType": "Practitioner",
                "id": "zpxDuEwss146",
                "meta": {
                    "versionId": "1",
                    "lastUpdated": "2021-12-01T05:49:34.672169Z"
                },
                "identifier": [
                    {
                        "system": "http://happyvalley.com/practitioner",
                        "value": "zpxDuEwss146"
                    }
                ],
                "name": [
                    {
                        "family": "HeartbeatXoVVN",
                        "given": [
                            "TerranceXoVVN"
                        ],
                        "prefix": [
                            "Dr"
                        ]
                    }
                ],
                "telecom": [
                    {
                        "system": "phone",
                        "value": "(146) 146-2305",
                        "use": "work"
                    }
                ],
                "address": [
                    {
                        "use": "work",
                        "line": [
                            "2305 Wellness Way"
                        ],
                        "city": "Fairfax",
                        "state": "VA"
                    }
                ],
                "gender": "male",
                "birthDate": "1976-10-07"
            },
            "search": {
                "mode": "include",
                "score": 1
            }
        },
        {
            "id": "zpxDuEwss146",
            "fullUrl": "https://cluster1-blue-250babbbe4c3000e15508cd07c1d282b-0000.us-east.containers.appdomain.cloud/fhir-server/api/v4/Patient/zpxDuEwss146",
            "resource": {
                "resourceType": "Patient",
                "id": "zpxDuEwss146",
                "meta": {
                    "versionId": "1",
                    "lastUpdated": "2021-12-01T05:49:34.611097Z"
                },
                "identifier": [
                    {
                        "system": "http://happyvalley.com/patient",
                        "value": "XoVVNp4NJsL-2305"
                    }
                ],
                "active": true,
                "name": [
                    {
                        "use": "official",
                        "family": "TimminsXoVVN",
                        "given": [
                            "JessicaXoVVN"
                        ]
                    }
                ],
                "gender": "female",
                "birthDate": "1986-10-14"
            },
            "search": {
                "mode": "include",
                "score": 1
            }
        },
        {
            "id": "zpxDuEwss146",
            "fullUrl": "https://cluster1-blue-250babbbe4c3000e15508cd07c1d282b-0000.us-east.containers.appdomain.cloud/fhir-server/api/v4/Provenance/zpxDuEwss146",
            "resource": {
                "resourceType": "Provenance",
                "id": "zpxDuEwss146",
                "meta": {
                    "versionId": "2",
                    "lastUpdated": "2021-12-01T05:49:35.564133Z"
                },
                "text": {
                    "status": "generated",
                    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">procedure record authored on 27-June 2015 by Harold Hippocrates, MD.</div>"
                },
                "target": [
                    {
                        "reference": "Procedure/zpxDuEwss146"
                    }
                ],
                "occurredPeriod": {
                    "start": "2021-06-27",
                    "end": "2021-06-28"
                },
                "recorded": "2021-06-27T08:39:24+10:00",
                "policy": [
                    "http://acme.com/fhir/Consent/25"
                ],
                "reason": [
                    {
                        "coding": [
                            {
                                "system": "http://terminology.hl7.org/CodeSystem/v3-ActReason",
                                "code": "CAREMGT",
                                "display": "care management"
                            }
                        ]
                    }
                ],
                "activity": {
                    "coding": [
                        {
                            "system": "http://terminology.hl7.org/CodeSystem/v3-DocumentCompletion",
                            "code": "LA",
                            "display": "legally authenticated"
                        }
                    ]
                },
                "agent": [
                    {
                        "type": {
                            "coding": [
                                {
                                    "system": "http://terminology.hl7.org/CodeSystem/provenance-participant-type",
                                    "code": "performer"
                                }
                            ]
                        },
                        "who": {
                            "reference": "Practitioner/zpxDuEwss146"
                        },
                        "onBehalfOf": {
                            "reference": "Patient/zpxDuEwss146"
                        }
                    }
                ],
                "entity": [
                    {
                        "role": "source",
                        "what": {
                            "reference": "Consent/zpxDuEwss146",
                            "display": "Consent granted for procedure"
                        }
                    }
                ]
            },
            "search": {
                "mode": "include",
                "score": 1
            }
        }
    ]
}

Which leads to this validation error:

Validation of response body against profile 'http://hl7.org/fhir/StructureDefinition/Bundle' by FHIR specification's Validation Engine produced the following results:ERROR: Duplicate id value 'zpxDuEwss146'. Location: Bundle.entry[1] (line 68, col 28).ERROR: Duplicate id value 'zpxDuEwss146'. Location: Bundle.entry[2] (line 106, col 28).ERROR: Duplicate id value 'zpxDuEwss146'. Location: Bundle.entry[3] (line 134, col 28).

Environment main

To Reproduce Steps to reproduce the behavior:

  1. create two resources with the same id (PUT) and ensure one references the other
  2. perform a search for the one and _include the other
  3. run the response through fhir validation

Expected behavior a valid response bundle

Additional context The problem is that we're using the non-unique resource ids to set Element.id for each Entry element. This is not typical and I'm not sure why we're doing that. If we're doing that for a reason, we could make it unique by using resource-type/id instead of just id.

lmsurpre commented 2 years ago

the failed touchstone test is now passing (and all the others are as well)