Skip to content

Fix: Handle incorrectly labeled 'subtype' field in Contract resource#202

Open
pateldeep04 wants to merge 1 commit intosmart-on-fhir:mainfrom
pateldeep04:fix-subtype-field
Open

Fix: Handle incorrectly labeled 'subtype' field in Contract resource#202
pateldeep04 wants to merge 1 commit intosmart-on-fhir:mainfrom
pateldeep04:fix-subtype-field

Conversation

@pateldeep04
Copy link
Copy Markdown

@pateldeep04 pateldeep04 commented Mar 22, 2026

This PR fixes issue #202 by handling incorrectly labeled "subtype" field
returned by some DSTU2 APIs.

Changes:

  • Maps "subtype" → "subType" only for Contract resource
  • Normalizes string values into valid FHIR CodeableConcept structure
  • Ensures compatibility with non-compliant FHIR implementations
  • Does not affect other resources

All tests pass successfully.

Copy link
Copy Markdown
Contributor

@mikix mikix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the PR! But there are a few conceptual issues I have with this fix:

  • It shouldn't be done in this repo, actually - this file is a generated file, built by fhir-parser, it should be a PR over there, then once landed, we should generate these model files again in this repo.
  • This is an awfully specific fix for a very specific vendor quirk. Do we maybe instead want all field matching to be caseless? Why/why not? It feels odd for a schema compliance library to be so loose, but maybe this is something that could be controlled via the strict parameter to the FHIR classes.
  • The original issue is several years old now -- this vendor is still generating broken JSON?

Comment thread test_issue.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file presumably didn't mean to get checked in?

}

contract = Contract(data)
assert contract is not None No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a check that contract.subType == "example"

Comment on lines +168 to +169
if isinstance(value, str):
jsondict["subType"] = [{"text": value}]
Copy link
Copy Markdown
Contributor

@mikix mikix Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like more than just case fixing - why mutate the value here? Is this a DSTU2 vs v4 issue being papered over?

This whole block could maybe be simplified as much as:

if jsondict.get("resourceType") == "Contract" and "subtype" in jsondict:
  jsondict["subType"] = jsondict.pop("subtype")

.format(type(jsondict), type(self)))

# Fix incorrect field names and structure (ONLY for Contract)
if isinstance(jsondict, dict) and "subtype" in jsondict:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the dict check here, it's already done for you a few lines up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants