Skip to main content

laterality

Eye-side vocabulary, shared across EHR backends.

Two readers share these patterns. bitfount.steps.filters._code_laterality reads a side from a code display or a body site. NextGenPatientQuerier reads one from a medication's dosage text and writes it into BodySite.text, which the first then reads back. A wording one recognises and the other does not is a side lost between them, so they must read the same words. The FHIR readers read a body site's side with the same words and site codes (eye_from_site) when merging several sites into one, for the same reason.

Every caller upper-cases the text first, so the patterns are upper case.

Eye and EyeOrBoth are the types an eye is stated in once read. Source wording (OD, OS, OU, "right", "left") is matched by the patterns here and never carried further.

Module​

Functions​

eye_from_body_structure_reference​

def eye_from_body_structure_reference(reference: str) ‑> Literal['L', 'R', 'B'] | None:

Read the eye a BodyStructure reference names in its own ID.

For a server that references a BodyStructure it does not serve, the ID is all there is to go on. ModMed's are the HL7 Eye Care IG's own example IDs, BodyStructure/bodystructure-left-eye and BodyStructure/bodystructure-right-eye. FHIR treats an ID as opaque, so this is a reading of one convention rather than of the resource: an ID must name an eye (eye, eyes, OD, OS or OU) and a side before it counts. An ID naming both left and right reads as both eyes, as the IG's "Right and left" qualifier (SNOMED 51440002) does.

Arguments

  • reference: A literal reference, relative (BodyStructure/<id>) or absolute (https://host/fhir/BodyStructure/<id>).

Returns "L", "R" or "B"; None when the reference is not to a BodyStructure, or its ID names no eye or no side.

eye_from_site​

def eye_from_site(words: str | None, code: str | None) ‑> Literal['L', 'R', 'B'] | None:

Read the eye a body site names, in words or as a code.

Reads the words first and the code only when the words name no side, the order bitfount.steps.filters._code_laterality reads a site's side in, so the two agree on every site.

Arguments

  • words: The site's words (its text and its coding's display), in any case.
  • code: The site's code.

Returns "L", "R" or "B"; None when the site names no eye.

merge_eyes​

def merge_eyes(eyes: Iterable[EyeOrBoth]) ‑> Literal['L', 'R', 'B'] | None:

Merge several statements of an eye into the eye they name together.

Arguments

  • eyes: The eyes stated.

Returns "B" when the statements name both eyes, between them or in one; the one eye when they all name the same; None when there are none.

Global variables​

  • BOTH_EYES_RE : Final[re.Pattern[str]] - Bilateral wording, abbreviations and plain English alike.

    "both eyes"/"each eye" sit alongside OU because ordinary clinical English states a bilateral finding or order that way far more often than it writes the abbreviation, and NextGen's own sig builder writes "into both eyes" and never OU.

    Deliberately absent: "affected eye(s)", NextGen's default ophthalmic wording. It states that a side exists without saying which, so it stays indeterminate rather than resolving to one — where an indication, if the medication has one, may still supply the side.

  • EYES : Final[tuple[Literal['L', 'R'], Literal['L', 'R']]] - Both eyes, left first.
  • Eye - One eye: "L" for the left, "R" for the right.
  • EyeOrBoth - One eye, or "B" for both together, as a binocular reading is taken.