Skip to content

feat: improve support for fhirpy client#80

Open
ruscoder wants to merge 4 commits intoatomic-ehr:mainfrom
beda-software:fhirpy-extended-support
Open

feat: improve support for fhirpy client#80
ruscoder wants to merge 4 commits intoatomic-ehr:mainfrom
beda-software:fhirpy-extended-support

Conversation

@ruscoder
Copy link

@ruscoder ruscoder commented Feb 24, 2026

  • cleanup readme for fhirpy
  • improve example of usage fhirpy with client.resources(r4b.Patient)
  • adjust python type generator to add specific type for leaf models (Patient and etc, excluding DomainResource/Resource) to be Literal['Patient']. It should not break anything, just specifies the proper type and makes it 100% compatible with fhirpy
  • adjust python type generator resourceType to be not frozen for fhirpy client
  • adjust python type generator for camelCase fhirpy client compatibility by excluding resourceType from base model, since resourceType is already defined in specific models
  • adjust python type generator for non camelCase fhirpy client compatibility by adding resourceType as class var that helps fhirpy client to guess the resource type

fhirpy tries to guess the resource type from class using two approaches:

  1. by resourceType on class
  2. by type specified by Literal['ResourceType']
def get_resource_type_from_class(cls: type[TResource]):
    try:
        return cls.resourceType
    except AttributeError:
        pass

    try:
        return get_args(get_type_hints(cls)["resourceType"])[0]
    except KeyError:  # pragma: no cover
        pass

    raise NotImplementedError(  # pragma: no cover
        f"Unsupported model {cls}. It should provide `resourceType` as class variable or as type annotation"
    )

For camelCase Literal is used, because there's no way to define class var descriptor, pydantic won't allow to override it
For non camelCase, class var descriptor is used to infer the resourceType from model.resource_type.default

Copy link
Collaborator

@ryukzak ryukzak left a comment

Choose a reason for hiding this comment

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

LGTM

@ryukzak
Copy link
Collaborator

ryukzak commented Feb 25, 2026

@ruscoder Please commit the updated version of the SDK into the examples path. It is required to have up-to-date examples in the repository.

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