MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.12k stars 21.18k forks source link

How to fix Azure FHIR service import failure #123515

Open BGDSW opened 3 weeks ago

BGDSW commented 3 weeks ago

I am using $import operation to import data into Azure FHIR service. I am using ndjson format. Part of my code is below:

def import_data2FHIR(access_token, file_info):
    # Azure FHIR service URL
    fhir_service_url = "https://<my_fhir_service>.fhir.azurehealthcareapis.com"

    # Set up the headers with the token
    headers = {
        "Authorization": f"Bearer {access_token}",
        'Prefer': 'respond-async',
        'Content-Type': 'application/fhir+json'
    }

    # Example FHIR resource (Patient)
    fhir_resource = {
        "resourceType": "Parameters",
        "parameter": [
            {
                "name": "inputFormat",
                "valueString": "application/fhir+ndjson"
            },
            {
                "name": "mode",
                "valueString": "InitialLoad",
            },
            {
                "name": "input",
                "part": [
                    {
                        "name": "url",
                        "valueUri": file_info["url"]
                    },
                    {
                        "name": "etag",
                        "valueUri": file_info["etag"]
                    }
                ]
            }
        ]
    }

    # POST the FHIR resource to the FHIR server
    response = requests.post(f"{fhir_service_url}/$import", json=fhir_resource, headers=headers)

    # Check the response
    if response.status_code == 201:
        print("Resource created successfully")
        print("Response:", response.json())
    else:
        print("Failed to create resource")
        print("Status Code:", response.status_code)
        print("Response:", response.json())

if __name__ == "__main__":
    access_token = get_token() # I get my access token successfully
    file_info = {"url": "https://<my_storage_account>.blob.core.windows.net/tmp-file-system/my-directory/patient-fhir-data-2019Jul10-0903.ndjson",
                 "etag": "0x8DC9402319782B2"}
    import_data2FHIR(access_token, file_info8)
has been already assigned to Contributor and Storage Blob Data Contributor role to . But I got status code 202 with error: ```python Traceback (most recent call last): File "D:\code_for_python\FHIR_service_import.py", line 112, in import_data2FHIR(access_token, file_info8) File "D:\code_for_python\FHIR_service_import.py", line 85, in import_data2FHIR print("Response:", response.json()) File "D:\anaconda3\envs\Epic\lib\site-packages\requests\models.py", line 978, in json raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0) ``` Would you please help how to troubleshoot this issue? I really appreciate your help. --- #### Document Details ⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.* * ID: 0e00c9ee-5004-921a-fbb3-fe3e07c89be1 * Version Independent ID: 144ff1bd-c02a-fd61-15c5-8a7ee574ef8c * Content: [Import data into the FHIR service in Azure Health Data Services](https://learn.microsoft.com/en-us/azure/healthcare-apis/fhir/import-data) * Content Source: [articles/healthcare-apis/fhir/import-data.md](https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/healthcare-apis/fhir/import-data.md) * Service: **healthcare-apis** * Sub-service: **fhir** * GitHub Login: @EXPEkesheth * Microsoft Alias: **kesheth**
PesalaPavan commented 3 weeks ago

@BGDSW It would be great if you could add a link to the documentation you are following for these steps? This would help us redirect the issue to the appropriate team. Thanks!!

BGDSW commented 3 weeks ago

@PesalaPavan Thank you for your reply. I am following this document. https://learn.microsoft.com/en-us/azure/healthcare-apis/fhir/import-data

PesalaPavan commented 2 weeks ago

@BGDSW Thanks for your feedback! I've assigned this issue to the author who will investigate and update as appropriate.