FHIR R4 Extension Constraint Blocking Migration to HAPI JPA Server

37 views
Skip to first unread message

Andrea Caloni

unread,
Mar 30, 2026, 8:24:13 AMMar 30
to HAPI FHIR

Hi everyone,

I am working on migrating all content from a Microsoft FHIR server to a HAPI JPA Server.

During this process, I encountered a Questionnaire that includes an extension containing both a value[x] and nested extensions.

This is an example:
{
    "extension": [
        {
            "url": "http://some.company.com/questionnaire/exceptions",
            "valueString": "There is an inconsistency in the answers given to items 1.7.1 and 1.7.2. Verify that the answers are completed correctly."
        }
    ],
    "url": "http://hl7.org/fhir/StructureDefinition/variable",
    "valueExpression": {
        "name": "e171_172",
        "language": "text/fhirpath",
        "expression": "(%v171_2019 = 'A' and (%v172 = 'C' or %v172 = 'D'))"
    }
}

I am fully aware that this structure is not compliant with FHIR R4, where an Extension must not have both a value and child extensions at the same time.

However, this constraint is currently blocking the migration. 

I need to understand whether HAPI provides any mechanism (configuration, validation override, or custom interceptor) to relax or bypass this rule,  in order to ingest the existing data as-is.

Many thanks, Andrea

James Agnew

unread,
Mar 30, 2026, 9:50:13 AMMar 30
to Andrea Caloni, HAPI FHIR
HAPI's validator needs to be explicitly enabled in order to be detecting an issue like this, and there are a number of ways of doing this. How you disable it depends on how you enabled it in the first place.

If you provide more details about which component you are using to do the validation, it should be possible to suggest how to turn it off.

Cheers,
James

--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/hapi-fhir/b8bd9da9-a6ff-4501-b5a9-9d7d82fe207an%40googlegroups.com.

Andrea Caloni

unread,
Mar 31, 2026, 6:26:16 AMMar 31
to HAPI FHIR
Hi James,

The HAPI validator in my project is effectively disabled. Both flags, requests_enabled and responses_enabled, are set to false by default, and the corresponding YAML configuration section is commented out. 

Let me clarify the context: since there are ~50 million resources on the Microsoft server, I’m not retrieving them via HTTP GET and then persisting them to HAPI via HTTP POST, as that would be too time-consuming.
Instead, I implemented a custom operation provider. Within it, I execute SQL queries directly against the Microsoft DB, parse each resource, and persist it into HAPI using an instance of IFhirResourceDao<IBaseResource>.

IFhirResourceDao<IBaseResource> dao = (IFhirResourceDao<IBaseResource>) daoRegistry.getResourceDao("Questionnaire");
dao.update(myBadQuestionnaire, null, true, true, null, new TransactionDetails());

When I invoke the update method, I encounter a validation error related to the extension, as described in my previous message:
" HAPI-1811: Extension (URL='http://hl7.org/fhir/StructureDefinition/variable') must not have both a value and other contained extensions"

Could it be that, by bypassing the HTTP layer, I’m not getting the expected behavior ?

Cheers,
Andrea

James Agnew

unread,
Mar 31, 2026, 7:24:34 AMMar 31
to Andrea Caloni, HAPI FHIR
Ah oops - that's a parser error and not a validator error. Unfortunately there is no current way of disabling that error (as FHIR strictly doesn't allow extensions to have both a value and a child extension).

I could see us relaxing that rule in the parser - it should probably trigger a call to the IParserErrorHandler so that it can decide whether or not to reject, but currently it doesn't work that way.

Can you correct the extensions as a part of your migration process? You're definitely asking for interoperability troubles storing such an invalid bit of data. If not, certainly a feature request and/or pull request to optionally relax the parser would be accepted.

Cheers,
James

Andrea Caloni

unread,
Mar 31, 2026, 7:39:43 AMMar 31
to HAPI FHIR
I cannot correct these extensions during my migration process, because we have a frontend tool that rely on this incorrect structure, in order to render the Questionnaire (and related QuestionnaireResponse).
So, I am going to check how I could optionally  relax the parser...

Cheers, 
Andrea

Reply all
Reply to author
Forward
0 new messages