Python Modules

Schema

class audit_builder.lfpse.schema.LFPSEFieldBuilder(form_link: LFPSEFormLink, parent_type: LFPSEFieldType | None = None)

Given a url to a profile of an LFPSE resource, creates custom fields which can be used to collect data relevant to the resource.

Creates builder instance

Parameters:
  • form_link – audit form link to LFPSE backend

  • parent_type – field parent’s type to override profile url being used

snapshot_map: dict[str, audit_builder.lfpse.types.SnapshotElement]

Snapshot elements from the API mapped by their id

differential_map: dict[str, audit_builder.lfpse.types.DifferentialElement]

Differential elements from the API mapped by their id

cleaned_property_ids: dict[str, str]

caches output from audit_builder.lfpse.utils.clean_property_id()

profile_fields: list[audit_builder.lfpse.types.DifferentialElement | audit_builder.lfpse.types.SnapshotElement]

Merged list of all fields from differential and snapshot list

Gets or creates field links for this form based on the profile fields .

Yield:

LFPSE field links

Warning

this generator does not delete outdated links, this needs to be done independently. For example:

>>> new_field_pks: list[int] = []
>>> form_link: LFPSEFormLink
>>> for field in LFPSEFieldBuilder(form_link).generate_field_links():
>>>     new_field_pks.append(field.pk)
>>> form_link.lfpsefieldlink_set.exclude(pk__in=new_field_pks).delete()
get_element_type_resource_type(element_type: ElementType | ExtensionElementType) str | None

Gets the resource type from the first profile URL.

For union types (fields with multiple profile URLs), all profiles should reference the same FHIR resource type. For example, suspectEntity.instance can be either adverse-event-medication-6 or adverse-event-device-6, but both are ‘Medication’ or ‘Device’ resource types respectively. We only need the first to determine the type.

Parameters:

element_type – The element type definition

Returns:

Resource type string, or None if no profiles found

get_extension_url(element: DifferentialElement, snapshot_lookup_key: str) str | None

Extracts the extension URL for a field element.

For value fields, the extension url is stored in the snapshot. For reference fields, the extension url is in the element’s type.

Parameters:
  • element – The differential element

  • snapshot_lookup_key – Key to lookup in snapshot map

Returns:

Extension URL string, or None

class audit_builder.lfpse.schema.LFPSERequestBuilder(form_link: LFPSEFormLink, observation: CustomObservation)

Builds and sends request representing observation to LFPSE. Usage:

>>> form_link: LFPSEFormLink
>>> observation: CustomObservation
>>> observation_link: LFPSEObservationLink = LFPSERequestBuilder(form_link=form_link, observation=observation).submit_request()
get_request_content() dict[str, Any]

Builds body of the request. If body is already built in this class, uses the cached version.

Returns:

request body dictionary

parse_reference_number(content: dict) str | None

Parses the LFPSE reference number from the response content.

Parameters:

content – The response content.

Returns:

Reference number as a string if it exists.

Client

class audit_builder.lfpse.client.LFPSEBackendClient(backend: LFPSEBackend)

Http client for interacting with LFPSE backends. Uses requests library under the hood and adds authentication layer

Create client instance

Parameters:

backend – the LFPSE backend to interact with

request(endpoint: str, method='GET', **kwargs) Response

Make a generic request

Parameters:
  • endpoint – url to send the request to

  • method – HTTP method

  • kwargs – any additional keyword-args for Session.request()

Returns:

The Response object

Raises:

HTTPError – if one occurred.

post(endpoint: str, data: dict, **kwargs) Response

Make POST a request using request()

get(endpoint: str, **kwargs) Response

Make GET a request using request()

put(endpoint: str, data: dict, **kwargs) Response

Make PUT a request using request()