API referenceresources

ovok_sdk.resources.fhir

Generic FHIR R4 reads, searches, writes and batches.

  • Stable unknown
  • Release candidate since 0.1.0-rc.4
  • Development since 0.1.0-dev.25+2ba84b0

Generic FHIR R4 reads, searches, writes and batches.

FhirResource

FhirResource(http: HttpClient)

Generic FHIR R4 on {base_url}/{fhir_path}.

Created by Ovok; access it as ovok.fhir. Resources are plain dicts in FHIR JSON shape.

Examples

patient = ovok.fhir.read("Patient", "patient-id")
page = ovok.fhir.search("Observation", {"patient": "Patient/patient-id"})

read()

read(resource_type: str, resource_id: str) -> Resource

Read one resource by type and ID.

Parameters

NameTypeDefaultDescription
resource_typestrFHIR resource type, such as "Patient".
resource_idstrThe resource's logical ID.

Returns

  • Resource: The resource.

Raises

  • OvokNotFoundError: The resource does not exist.
search(resource_type: str, params: QueryParams | None = None) -> Page[Resource]

Search one resource type and return the first page of matches.

A list value repeats its parameter, which FHIR reads as AND.

Parameters

NameTypeDefaultDescription
resource_typestrFHIR resource type to search.
paramsQueryParams | NoneNoneFHIR search parameters.

Returns

  • Page[Resource]: The first page; call next_page() or auto_paging_iter() for the rest.

search_one()

search_one(resource_type: str, params: QueryParams | None = None) -> Resource | None

Return the first resource matching a search, or None.

Parameters

NameTypeDefaultDescription
resource_typestrFHIR resource type to search.
paramsQueryParams | NoneNoneFHIR search parameters; _count is set to 1.

Returns

  • Resource | None: The first match, or None when nothing matches.

create()

create(resource: Resource, *, if_none_exist: str | None = None) -> Resource

Create a resource of its resourceType.

With if_none_exist, a retry cannot create a duplicate, so the request is safe to repeat.

Parameters

NameTypeDefaultDescription
resourceResourceThe resource to create; it needs resourceType.
if_none_existstr | NoneNoneFHIR search query for a conditional create, such as "identifier=x|1".

Returns

  • Resource: The created (or matched) resource.

Raises

  • OvokValidationError: The resource has no resourceType.

update()

update(resource: Resource) -> Resource

Replace a resource with a PUT to its type and ID.

Parameters

NameTypeDefaultDescription
resourceResourceThe full resource; it needs resourceType and id.

Returns

  • Resource: The updated resource.

Raises

  • OvokValidationError: The resource has no resourceType or id.

patch()

patch(
    resource_type: str,
    resource_id: str,
    operations: Sequence[PatchOperation],
) -> Resource

Apply JSON Patch operations to a resource.

Parameters

NameTypeDefaultDescription
resource_typestrFHIR resource type.
resource_idstrThe resource's logical ID.
operationsSequence[PatchOperation]JSON Patch operations, such as {"op": "replace", "path": "/active", "value": False}.

Returns

  • Resource: The patched resource.

delete()

delete(resource_type: str, resource_id: str) -> None

Delete a resource.

Parameters

NameTypeDefaultDescription
resource_typestrFHIR resource type.
resource_idstrThe resource's logical ID.

batch()

batch(bundle: Resource) -> Resource

Post a batch or transaction Bundle to the FHIR base.

Parameters

NameTypeDefaultDescription
bundleResourceThe Bundle resource.

Returns

  • Resource: The response Bundle.

Last updated on

On this page