Problems using the FHIR $import operation on resources with multiple versions

Peter Scott 0 Reputation points
2025-06-06T14:38:55.43+00:00

I am having problems with using the FHIR $import operation on resources with multiple versions of the same resource in the import file.

Background:

  1. I have the "initialImportMode" set to false on the FHIR Server in question.
  2. For the resource file I am trying to import (Patient.ndjson) to test the ability to have multiple versions of a resource be imported, I have 6 different versions of the same patient in the file - this is the only data in the file.
  3. In my Patient.ndjson file, if I provide the meta.versionId and meta.lastUpdated attributes ("meta":{"versionId":"1","lastUpdated":"1999-08-06T00:01:00.000-03:00"...), when I attempt to import the data, the import fails with the following message: "import operation failed for reason: Unable to generate internal IDs. If the lastUpdated meta element is provided as input, reduce the number of resources with the same up to millisecond lastUpdated below 10,000". This occurs even with only the versions for a single patient (6 rows in file) where the lastUpdated field is manually verified to be unique for each row.
  4. If the meta.lastUpdated attribute is omitted, I get different behavior: the import for version #1 works, but for version #2 thru #6, the error comes back as "Failed to import duplicate resource, resource id"
Azure Health Data Services
Azure Health Data Services
An Azure offering that provides a suite of purpose-built technologies for protected health information in the cloud.
190 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 34,661 Reputation points MVP Volunteer Moderator
    2025-06-08T05:47:54.4233333+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    This is a known limitation in Azure FHIR service related to the $import operation, particularly when importing multiple versions of the same resource ID.

    1. FHIR Versioning Support: The FHIR spec allows for multiple versions of a resource. However, many FHIR server implementations (including Azure's) do not fully support importing historical versions in one $import batch.
    2. Azure FHIR Service $import Behavior:
      • If initialImportMode = false, the server assumes data being imported may already exist and should respect existing IDs and versions.
      • When you include meta.versionId and meta.lastUpdated, the server tries to persist the exact version history.
      • Azure FHIR Server does not support creating multiple historical versions of the same resource via import. It only keeps the latest resource version when importing.
    3. Specific Errors:
      • Unable to generate internal IDs: This is a throttling or limitation issue triggered when too many resources have the same timestamp to the millisecond, even if resource IDs are the same.
      • Failed to import duplicate resource: When you omit meta.lastUpdated, the server assumes all resources are version #1. Any duplicate resource ID is rejected.

    Root Cause

    The $import operation on Azure FHIR Server is designed to:

    Load initial resource states into the system.

    Not support importing historical versions (multiple meta.versionIds of the same resource).

    Even if initialImportMode is set to false, the server:

    Cannot reconstruct version history from the import file.

    Always considers resource IDs to be current versions only.

    Workarounds

    1. Load only the latest version of the resource

    Simply include the latest resource version per ID.

    Do not try to simulate or import older versions.

    Let the FHIR server auto-manage meta.versionId.

    1. Manually replay changes via FHIR API (not via $import)

    For use cases where you must preserve version history, consider a script that:

    Sends each version sequentially via PUT to /Patient/{id}.

      Ensures correct order and timing to let the server assign `versionId` automatically.
      
    
    1. Avoid setting meta.versionId in the $import

    This will not give you version history but will import one version only.

    • All duplicates (same id) will be rejected after the first one.

    Please 'Upvote'(Thumbs-up) and 'Accept' as answer if the reply was helpful. This will be benefitting other community members who face the same issue.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.