How to POST master/details FHIR objects using bundle?

Summary

I was helping a colleague to store the ReaserchStudy and ResearchSubject FHIR objects. The objects are in the master details format. Every ReaserchStudy has ResearchSubject and they are linked using the Reference objects. The ResearchSubject has the “study” property of the ResearchStudy object.

Solution

To create such objects in large numbers, it is better to use the Bundle FHIR object. The Bundle objects have many different types and one of them is “transaction”. Using the “transaction” type we can post both objects and let the FHIR server add the references with the ACID transaction.

You will need to make a POST query to the FHIR. Just specify the FHIR Url, now /Bundle is needed. Use the following in the body of the request.

{
    "resourceType": "Bundle",
    "id": "bundle-transaction",
    "type": "transaction",
    "entry": [
        {
            // Point # 1
            "fullUrl": "urn:uuid:61ebe359-bfdc-6754-8bf2-c6e300945f0a",
            // Point # 2 
            "request": {
                "method": "POST",
                "url": "ResearchStudy"
            },
            "resource": {
                "resourceType": "ResearchStudy",
                "identifier": [
                    {
                        "use": "official",
                        "system": "https://clinicaltrials.gov",
                        "value": "NCT04625647"
                    }
                ],
                "title": "NCT04625647",
                "status": "active",
                "primaryPurposeType": {
                    "coding": [
                        {
                            "system": "http://some-url",
                            "code": "diagnostic",
                            "display": "Diagnostic"
                        }
                    ]
                },
                "phase": {
                    "coding": [
                        {
                            "system": "http://some-url",
                            "code": "phase1",
                            "display": "phase1"
                        },
                        {
                            "system": "http://some-url",
                            "code": "phase2",
                            "display": "phase2"
                        }
                    ]
                },
                "condition": [
                    {
                        "text": "Small carcinoma of lung"
                    }
                ],
                "keyword": [
                    {
                        "text": "NCT04625647"
                    }
                ]
            }
        },
        {
            "fullUrl": "urn:uuid:61ebe359-bfdc-4613-8bf2-c5e300945f0a",
            "request": {
                "method": "POST",
                "url": "ResearchSubject"
            },
            "resource": {
                "resourceType": "ResearchSubject",
                "identifier": [
                    {
                        "value": "ResearchStudy-NCT04625647"
                    }
                ],
                "status": "candidate",
                "period": {
                    "start": "2022-06-10"
                },
                "study": {
                    // Point # 1 
                    "reference": "urn:uuid:61ebe359-bfdc-6754-8bf2-c6e300945f0a",
                    "type" : "ResearchStudy"
                },
                "individual": {
                    "reference": "Patient/b1e9b0b9-da6e-4f68-b603-bd896a50ca86"
                }
            }
        }
    ]
}

Point #1 from the above JSON code. The “fullURL” property of the master and the detail as the study is the reference you need to create dynamically by setting the “urn:uuid:guid”.

Point #2 from the above JSON code is the request must be specified as the “POST query for both objects.

Conclusion

There may be many blog posts or articles on the bundle object but this post is to simplify one specific case I worked on. I hope it may be useful to you.

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in FHIR. Bookmark the permalink.

Leave a comment