hl7-fhir

How to add multiple patients to a FHIR AdverseEvent


I'm using Hl7.Fhir.STU3 v4.3.0 and I'm trying to create a FHIR AdverseEvent with multiple Patients.

I can create a single patient by using the subject with a reference to a contained resource

adverseEvent.Contained.Add(myFhirDomainResource); adverseEvent.Subject = new ResourceReference($"#{myFhirDomainResource.Id}");

This is creating a single patient as follows:

    {
        "resourceType": "AdverseEvent",
        "meta": {
            "profile": [
                "https://psims-uat.azure-api.net/taxonomy/fhir/StructureDefinition/patient-safety-adverse-event-5"
            ]
        },
        "contained": [
            {
                "resourceType": "Patient",
                "id": "6f084956-eab3-4fda-b12d-6dbd74f2beb5",
                "extension": [
                    {
                        "url": "https://psims-uat.azure-api.net/taxonomy/fhir/StructureDefinition/patient-information-5",
                        "extension": [
                            // ...
                        ]
                    }
                ]
            }
            // ...
        "subject": {
            "reference": "#fb3f330b-6cb7-4e27-ab99-df7fe1b06693"
        }
        //...
    }

I can create multiple items within the contained collection, but can't work out how to generate multiple subjects.

How do I add multiple subjects using Fhirly C# ?
Or
What is the correct formatted JSON for a record with multiple subjects?


Solution

  • The correct JSON format for STU3 is as follows:

    {
        "resourceType": "AdverseEvent",   
        "meta": {
            "profile": [
                "https://psims-uat.azure-api.net/taxonomy/fhir/StructureDefinition/patient-safety-adverse-event-5"
            ]
        },
        "contained": [
            {
                "resourceType": "Patient",
                "id": "subject1",
                "extension": [
                    {
                        "extension": [
                            //... extension values for patient 1
                        ],
                        "url": "https://...."
                    },
                    {
                        "extension": [
                            //... extension values for patient 2
                        ],
                        "url": "https://...."
                    }
                ]
            },
            //... other extensions and values
        ],
        "subject": {
            "reference": "#subject1"
        },
        //... other references
    }
    

    This then provide the clues on how to structure the code to generate by adding multiple patients to the contained.extension collection and then still only referencing this once from the subject