Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FHIR resource as pydantic request model in FastAPI #132

Open
ankushgovil opened this issue Jun 16, 2023 · 0 comments
Open

FHIR resource as pydantic request model in FastAPI #132

ankushgovil opened this issue Jun 16, 2023 · 0 comments

Comments

@ankushgovil
Copy link

ankushgovil commented Jun 16, 2023

FastAPI supports using pydantic models to define JSON request body for REST API endpoints;

I need the FHIR resources model to be used as a request in FastAPI
Going through the README; it doesn't seems to be compatible with pydantic model.

An example is shown of Patient resource from release 5.1.1, with python 3.10 FastAPI 0.85.0 and pydantic 1.10.2:

fastapi import APIRouter
from fhir.resources.patient import Patient

router = APIRouter()


@router.get(
    "/patient",
    response_model=Patient)
def get_patient(
        patient=Patient
):
    return patient

This gives a couple of type errors on endpoint setup:

File "/Users/ankush.govil/work/external-integration/venv/lib/python3.10/site-packages/fastapi/openapi/utils.py", line 103, in get_openapi_operation_parameters
"schema": field_schema(
File "pydantic/schema.py", line 247, in pydantic.schema.field_schema
File "pydantic/schema.py", line 215, in pydantic.schema.get_field_info_schema
File "pydantic/schema.py", line 985, in pydantic.schema.encode_default
File "pydantic/json.py", line 90, in pydantic.json.pydantic_encoder
TypeError: Object of type 'ModelMetaclass' is not JSON serializable

Also, If I able to comment this type issue the request model example in swagger is coming as

{
  "resource_type": "Patient",
  "fhir_comments": "string",
  "id": "7qIl65KS1dTPe6YnEzHGED",
  "_implicitRules": "Unknown Type: FHIRPrimitiveExtension",
  "meta": "Unknown Type: Meta",
  "contained": [
    "Unknown Type: Resource"
  ],
  "extension": [
    "Unknown Type: Extension"
  ],
  "modifierExtension": [
    "Unknown Type: Extension"
  ],
  "text": "Unknown Type: Narrative",
  "active": true,
  "address": [
    "Unknown Type: Address"
  ],
  "birthDate": "2023-06-16",
  "communication": [
    "Unknown Type: PatientCommunication"
  ],
  "contact": [
    "Unknown Type: PatientContact"
  ],
  "deceasedBoolean": true,
  "deceasedDateTime": "2023-06-16T07:50:51.114Z",
  "gender": "Unknown Type: FHIRPrimitiveExtension",
  "generalPractitioner": [
    "Unknown Type: Reference"
  ],
  "identifier": [
    "Unknown Type: Identifier"
  ],
  "link": [
    "Unknown Type: PatientLink"
  ],
  "managingOrganization": "Unknown Type: Reference",
  "maritalStatus": "Unknown Type: CodeableConcept",
  "multipleBirthBoolean": "Unknown Type: FHIRPrimitiveExtension",
  "multipleBirthInteger": "Unknown Type: FHIRPrimitiveExtension",
  "name": [
    "Unknown Type: HumanName"
  ],
  "photo": [
    "Unknown Type: Attachment"
  ],
  "telecom": [
    "Unknown Type: ContactPoint"
  ]
}

Does FastAPI support these FHIR resources as a request model in pydantic?

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

No branches or pull requests

1 participant