How to clean up the FHIR objects in the Postman received as a bundle?

Summary

My need was to remove stale FHIR condition objects with the wrong concept codes in the Azure FHIR test server.

Here is the quick tip and Javascript code to remove such data for any FHIR resource.

Note: You should be aware of getting a bearer token for the FHIR in the Postman call. I will refer to that call at the end. You should know how to make the GET and POST calls in Postman.

### In Postman you can add the call with the query paramete CLEAN-UP

GET https://{your-instnace}.fhir.azurehealthcareapis.com/Condition?code=254637007,23986001,44054006&_count=1000&CLEAN-UP=yes
Authorization: Bearer {{bearerToken}}
Accept: application/json

Write the following code in the TEST tab of the Postman. The following code expects that you made the POST call to get the “bearerToken” and saved it in the environment variable.

var query = {};
pm.request.url.query.all().forEach((param) => { query[param.key] = param.value});
IsCleanUp = query['CLEAN-UP'];

if (( IsCleanUp !== undefined ) && ( IsCleanUp.toLowerCase() === 'yes' ) )
{
    console.log("CLEAN-UP is " + ' ' + IsCleanUp);
    var jsonData = JSON.parse(responseBody);
    if ( jsonData.entry !== undefined )
    {
        for (let i = 0; i < jsonData.entry.length; i++) {
            const resource = jsonData.entry[i];
            if ( undefined !== resource.fullUrl)
            {
                console.log("DELETE " + resource.fullUrl);  
                pm.sendRequest({
                    url:  resource.fullUrl, 
                    method: 'DELETE',
                    header: {
                        'Accept': 'application/json',
                        'Content-Type': 'application/x-www-form-urlencoded',
                        'Authorization': 'Bearer ' + pm.environment.get("bearerToken")
                    },
                    body: {
                    }
                }, function (err, res) {
                    console.log("DELETED " + resource.fullUrl);
                });
            }
        }
    }
}
else{
    console.log("CLEAN-UP is " + ' ' + IsCleanUp);
}

Summary

This is a quick tip to clean up the FHIR objects in the FHIR test server.

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s