Skip to content

feat: pharmacy views, a HealthcareService search helper that sends both includes, and outcomes() - #99

Open
briankfung wants to merge 5 commits into
mainfrom
pharmacy-views
Open

briankfung wants to merge 5 commits into
mainfrom
pharmacy-views

Conversation

@briankfung

@briankfung briankfung commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Three additions for the pharmacy search, on the same footing as the slot and schedule views.

What it adds

  • pharmacy_views(page), a client method on both clients and a plain function. It reads one page of a HealthcareService search into one row per matched service, a frozen dataclass haau3.PharmacyView:
    • the values a list of pharmacies shows: npi, name, address (a FHIR Address), phone, active and specialties (NUCC codings), read from the service and the Organization and store Location the page holds for it;
    • what Medicare Part D says of it, from haau3's Part D Listing extension: part_d is a haau3.PartDListing (listed, as_of, contract_year), and None means not known, never not listed;
    • the networks NDH's Network Reference extension names, networks, each a haau3.PharmacyNetwork with a Part D network's plan and kind read from its documented id, and preferred (True, False, or None when no Part D network is named);
    • the three FHIR resources as the API served them: service, organization, locations.
  • search_healthcare_service_with_includes(), generated beside the Slot and Schedule helpers, on both clients and on with_response. It sends _include=HealthcareService:organization and _include=HealthcareService:location, and takes every keyword of search_healthcare_service() but include and summary, which Python refuses before anything is sent. The API does not combine _summary with an include, so a call with it could never succeed. The generator now writes a helper for a search that takes no _include:iterate, and leaves out the parameters a helper names in LEAVES_OUT.
  • outcomes(page), a client method on both clients and a plain function, reads a search page's own OperationOutcomes: the entries whose search mode is outcome, which matches() leaves out. A pharmacy search answers one when a Part D plan lists no pharmacy of the network's kind, and one when Part D's files could not be read.

pharmacy_views() raises a Haau3Error in three cases:

  • A pharmacy names an Organization or Location the page does not hold, on a pharmacy search that did not ask for that include. The error names the helper. The page's self link says what the search asked for, and a page without one is read as a search that asked for nothing.
  • The page holds the record, but not where FHIR's rules for a Bundle find it from the reference. The error says that.
  • Two entries could each be the one a reference names.

Anything else is left out:

  • a page from the directory's own search, which the API refuses includes on;
  • a service that is not a pharmacy;
  • a record the search asked for that the page still lacks;
  • a target of another type.

A value of another shape than FHIR gives it is read as absent.

The README gains a "Pharmacies" section with the field table, and "Paging" now points to outcomes().

Tests

  • tests/test_pharmacy_views.py, 68 tests:
    • the spec's own example answer read into rows, and served by a FastAPI route;
    • each field and its fallback;
    • the Part D listing as served, absent or malformed;
    • network ids, among them references on a server whose path has a capitalised segment before the type;
    • each of preferred's three answers;
    • the raise read from the self link, and where it does not apply;
    • contained, wrong-typed and ambiguous references;
    • values of another shape;
    • rows frozen and never hashed;
    • outcomes();
    • the helper on both clients and with_response.
  • Each test was proved by breaking the code it covers, 41 ways, each caught.
  • An adversarial review compared the rows with the TypeScript SDK's on 20,000 random pages. It found one difference: the two reference patterns were not anchored at the end of the address. They are now, and the review's other findings are fixed in "After review" and tested in the commit after it.
  • tests/typecheck/consumer.py covers the new names.

Checked

  • generate.py --check, ruff, ruff format, mypy and pyright (strict) over the sources, tests and README blocks, pyright --verifytypes (100%), uv build with check_package.py, and the customer type check on Python 3.10.
  • pytest: 1440 passed, on the spec at preview.45.

🤖 Generated with Claude Code

briankfung and others added 3 commits December 1, 2026 21:22
…ludes, and outcomes()

pharmacy_views() reads one page of a HealthcareService search into one row per matched service, a
frozen dataclass: the NPI, name, address, phone, whether it is active and its NUCC codes, read from
the service and the Organization and store the page holds for it; what Medicare Part D says of it,
from haau3's Part D Listing extension, as a PartDListing; the networks NDH's Network Reference
extension names, each a PharmacyNetwork with a Part D network's plan and kind read from its
documented id, and whether the plan prefers it; and the three FHIR resources as the API served them.

A pharmacy that names an Organization or Location the page does not hold raises, naming the helper,
when the page's self link shows a pharmacy search that did not ask for that include, or the page has
no self link. A page that holds the record where FHIR's rules for a Bundle do not find it from the
reference raises, saying so. Anything else is left out: a target of another type, a record a search
asked for and the page still lacks, and whatever a service that is not a pharmacy, or a page from the
directory's own search, names and the page does not hold. A value of another shape than FHIR gives
it is read as absent.

search_healthcare_service_with_includes() is generated beside the Slot and Schedule helpers, on both
clients and on with_response: it sends _include=HealthcareService:organization and
_include=HealthcareService:location, and takes every keyword of search_healthcare_service() but
include. The generator now writes a helper for a search that takes no _include:iterate. outcomes()
reads a search page's own OperationOutcomes, the entries whose search mode is outcome, for any
search.

The README gains a "Pharmacies" section, and "Paging" points to outcomes().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… outcomes()

The spec's own example answer read into rows, and served by a FastAPI route; each plain value and its
fallback, blank values among them; the Part D listing as served, absent, or with a part missing or of
another type; each network's plan and kind from a Part D id, another network with neither, a name
from a later reference, and a reference naming no Organization left out; preferred's three answers;
the raise read from the page's self link, a record held where FHIR's rules do not find it, a
reference to another type, and pages from the directory's own search; contained, wrong-typed and
ambiguous references, and values of another shape than FHIR gives them; rows frozen, compared by
value and never hashed; outcomes() reading only the entries whose search mode is outcome; and the
helper sending both includes and nothing else, on both clients and with_response, refusing include.
The customer's type check covers the new names.

Each test was proved by breaking the code it covers, 28 ways, each caught.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lper takes no summary

The patterns that read a reference's type and id, and a network's Organization id, are anchored at
the end of the reference, so an absolute reference on a server whose path has a capitalised segment
before the type (`/api/FHIR/R4/Organization/O1`) is read by its last type and id, as the TypeScript
SDK reads it. It was read as having no type, which raised where the record is left out, and missed
the error for a record held where FHIR's rules for a Bundle do not find it.

search_healthcare_service_with_includes() takes no summary: the API does not combine _summary with
an include, and the helper always sends one, so a call with summary could never succeed. The
generator leaves a helper's left-out parameters out of its keywords and its query, and stops when a
search no longer takes one.

A self link whose port is out of range is not read as a URL, as a URL parser does not read it. The
error for a record held where FHIR's rules do not find it names the version a reference names.
outcomes() is defined under the name the package exports. The clients' pharmacy_views() docstrings
name every error, and the README's Paging sentence is rewrapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An absolute reference on a server whose path has a capitalised segment, read for a held Organization
and for one of another type; a network on such a server; a version the page does not hold; a page
holding a resource of another type with the id a reference names; a blank reference; both includes
asked for in one comma-separated value of the self link, and a self link with a port out of range;
a network's first name kept when a later reference gives another, and an id with more after the
kind; summary refused, with nothing sent; the helper's keywords and query less include and summary,
and the generator stopping on a left-out parameter its search does not take; and outcomes() named
as the package exports it.

Each was proved by breaking the code it covers, 9 ways, each caught.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…isting, a part repeated, and a type name with something before it

Cases another SDK's review found the suites shared no test for, each proved to fail without the
code it covers: when the store and the Organization both have an address, the store's; of two whole
Part D listings, the first; a listing whose first listed part is not a boolean is unknown though a
later one is; and a reference whose type name has something before it is taken as having no type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@briankfung
briankfung marked this pull request as ready for review December 2, 2026 02:40

This branch has not been deployed

No deployments
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.

1 participant