The sandbox's tests
The newest run on main of the tests of cascade-sandbox, read as a
tree of package, capability and situation, each with what it is for and each case linked to its source.
Failures come first within a capability, and the levels that hold one are open.
npm test, node:test over the sandbox. For an agent: cascade-sandbox.ctrf.json.
@the-cascade-protocol/sandbox 0.0.0 · commit f1a59b8 · unreleased: what main does today, not a compatibility promise
Pretend hospitals with made-up patients, which an app or a test signs in to and pulls records from with no account and no network.
Glossary
- aud
- the parameter of an authorize request in which the app names the FHIR base it means to read from; a hospital refuses one that is not its own.
- the one-time code that arrives at the redirect URI from a sign-in, which the app trades for the token.
- brands bundle (brands bundles)
- the list of the hospitals that use a vendor's system, as the vendor publishes it in SMART's User-access Brands format: a FHIR Bundle of Organizations, each pointing to the endpoint its records are served from.
https://hl7.org/fhir/smart-app-launch/brands.html - Bundle (Bundles)
- FHIR's resource that holds a list of other resources, each in an `entry`; its `type` says what the list is, such as `collection`, `history` or `searchset`.
- C-CDA
- Consolidated Clinical Document Architecture: HL7's standard for the XML summary documents patient portals hand out.
- client id (client ids)
- the name an app gives for itself when it asks to sign a patient in; a demo hospital accepts any.
- clinical date (clinical dates)
- the date a record gives for the thing it records, such as a result's `effectiveDateTime` or a condition's `onsetDateTime`.
- code system (code systems)
- a published list of codes for one kind of thing, such as RxNorm for medicines, LOINC for lab tests and SNOMED CT for clinical findings.
- deletion (deletions, deleted)
- an entry of a record's history that says the hospital removed the record at that time; it carries no resource.
- demo hospital (demo hospitals)
- a pretend hospital with made-up patients, which an app or a test signs in to and pulls from with no account and no network; Cascade North and Cascade South are the two this package carries.
- difference (differences, declared difference)
- a place where one hospital's record of a person disagrees with who the person is, such as a misspelt name, which the person's `person.json` declares so that the load accepts it.
- discovery
- the request for a hospital's SMART configuration, with which every sign-in begins.
- Endpoint (Endpoints)
- FHIR's resource for an address a system is reached at; in a brands bundle, a hospital's FHIR base.
- etag (etags)
- the version stamp of a history entry, written `W/"<version id>"`.
- FHIR
- Fast Healthcare Interoperability Resources: HL7's standard for health records as JSON.
https://hl7.org/fhir/R4/ - FHIR base (FHIR bases)
- the URL of a hospital's FHIR server; each record there is at `<FHIR base>/<type>/<id>`.
cascade:serverBaseUrl - Forwarded
- the HTTP header in which a go-between says which host and protocol the client asked for; `demoRemapFetch()` sends it to the listener.
- generated people (generated person, generated patient)
- the people this package made with Synthea: ten years of visits, conditions, medications and results each.
- hand-written people
- the people written by hand for tests, which this package copies from cascade-vocabulary and does not edit.
- history (histories)
- every version of one record, newest first, as a hospital answers `<type>/<id>/_history`; also the type of a patient file that holds one entry for each version.
- Host
- the HTTP header in which a client says which server name it asked for.
- instant (instants)
- a date and time to the second with its time zone, such as `2024-02-01T00:00:00Z`.
- kit (kits)
- a story and the exports it uses, which the vocabulary carries for testing, such as `alex-rivera`.
- launcher
- the SMART Health IT launcher, `launch.smarthealthit.org`: a public test hospital on the internet, kept by the SMART project, which this project did not write. Its code is smart-launcher-v2.
- listener (listeners)
- the demo hospitals served on a port of this machine by `serveDemo()` or `npm run serve`, each at `<origin>/<id>/fhir`.
- metadata
- `<FHIR base>/metadata`, where a FHIR server says what it supports: the types it serves, how each is searched, and where its sign-in is.
- official name
- the name of a Patient marked `use: "official"`, or its only name.
- OperationOutcome
- FHIR's resource for a server's warning or error message; it is no record of the patient.
- Organization (Organizations)
- FHIR's resource for a hospital, a clinic, a laboratory or another body that gives care.
cascade:Organization - origin (origins)
- the scheme, server name and port of a URL, such as `https://hospital.example`: what a browser treats as one site.
- patient (patients)
- a person as one hospital knows them, under that hospital's own patient id.
- patient file (patient files)
- the file of what one hospital holds of one person, `people/<person>/sources/<hospital>/fhir.json`: a FHIR Bundle of type `collection` or `history`.
- person (people)
- a made-up human being, with a name, a birth date and a gender in `person.json`, who is a patient at one hospital or more.
- PKCE
- Proof Key for Code Exchange, RFC 7636: the part of a sign-in by which an app shows, at the token exchange, that it is the app that began the sign-in. A demo hospital takes only its S256 method.
- plain record (plain records, plain collection)
- a record written once in a `collection` file, with no version: it is there at every date and is served as written.
- preflight
- the OPTIONS request a browser sends before a page on one origin calls a server on another, to ask whether it may.
- pull (pulls, pulled)
- the records one patient has at one hospital, fetched in one go: a search of each type, page by page, and a read of the Patient.
- record (records)
- one thing said about a person's health, such as an allergy, a medication or a lab result.
cascade:Record - record time (record times)
- when a hospital recorded a version, the entry's `response.lastModified`.
- redirect URI (redirect URIs)
- the app's own URL to which a hospital sends the person's browser when the sign-in is over.
- reference tables (reference table)
- public code lists, such as RxNorm for medicines, that tell an app when two codes mean one thing; the hand-written people carry codes chosen to reach them.
- resource (resources)
- one record in FHIR, named by its type and its id, such as `Observation/ldl-1`.
- root (roots)
- a folder of hospital folders or of person folders that a load reads; a load takes a list of them.
- scope (scopes)
- what an app asks to be let read, in SMART's notation: `patient/Observation.rs` is to read and search the patient's Observations.
- searchset
- the type of Bundle a hospital answers a search with: one page of matches and, where there are more, a link to the next.
- shorthand
- a way to write a record's change in a patient file as two dates, `active` and `stopped`, in place of two versions.
- sign-in page (sign-in pages)
- the page a hospital shows at its authorize address, where the patient is picked and allows or cancels what the app asks.
- SMART configuration
- what a hospital's server publishes at `<FHIR base>/.well-known/smart-configuration`: where its sign-in page and its token exchange are, and what they support.
- SMART on FHIR
- the standard by which an app signs a person in to a hospital and is then let read that person's records: OAuth 2.0 as HL7's SMART App Launch profiles it for FHIR servers.
https://hl7.org/fhir/smart-app-launch/ - source (sources)
- what one hospital holds of one person: the folder `sources/<hospital>/` of the person, with a patient file, C-CDA documents, or both.
- state
- a value the app sends with the authorize request and the hospital sends back unchanged, so the app can tell its own sign-in's answer.
- story (stories)
- a made-up patient at a demo hospital whose records were written to show one outcome, such as a lab result that falls after a medication starts, with that outcome written down beside them.
- Synthea
- an open-source program that makes up whole patient histories; the generated people came from it.
- token (tokens, access token)
- the access token a hospital issues when a person signs in: the credential an app sends with each request for that person's records.
- key
- the secret a hospital signs its tokens with (`hospital.json`'s `key`).
- invalid_client
- OAuth's error for a client the server does not accept; the token exchange answers 401 with it. The launcher's switch for it is named `token_invalid_token`, which differs from the error it gives.
- token exchange
- the request in which an app trades the authorization code for the token.
- version (versions)
- what a record says at one time; when a hospital changes a record, its history keeps the old version and adds a new one.
- world's date (world date)
- the date a hospital answers for, an instant given as `asOf`: it serves each record as it stood then. With none, it serves each record's latest version.
No entry matches.
Signing a patient in to a demo hospital demoHospital() 37 passed
`demoHospital()` makes a demo hospital: one function from a `Request` to a `Response` that answers as a hospital's SMART on FHIR server does. An app signs a patient in to it as it would to a real one: discovery, the sign-in page, then the token exchange.
Source hospital.test.ts
demoHospital(options) 2 passed
when a client reads discovery 3 passed
- passed names the hospital's FHIR base as the issuer0 ms
- passed offers S256 as the only PKCE method1 ms
- passed places the sign-in page at `<FHIR base>/authorize`0 ms
with `autoApprove` 3 passed
when the sign-in page is shown 10 passed
- passed lists every patient of the hospital, family name first, in order of family name1 ms
- passed names the app by its client id0 ms
- passed says each scope the app asks for in words0 ms
- passed lists a scope it has no words for once, as written0 ms
- passed omits the list of scopes when the app asks for none0 ms
- passed marks each patient choice `required`0 ms
- passed marks Cancel `formnovalidate`0 ms
- passed preselects the patient whose person id is the `login_hint`1 ms
- passed preselects the patient whose name is the `login_hint`, in either order of words0 ms
- passed preselects no one for any other `login_hint`1 ms
when the patient answers the page 2 passed
when the authorize request is wrong 7 passed
- passed redirects with `invalid_request` for no `code_challenge`7 ms
- passed redirects with `invalid_request` for the `plain` challenge method6 ms
- passed redirects with `invalid_request` for a challenge method it does not know9 ms
- passed redirects with `invalid_request` for an `aud` that is another hospital's FHIR base10 ms
- passed answers 400 with no redirect for no `redirect_uri`6 ms
- passed answers 400 with no redirect for no `client_id`6 ms
- passed redirects with `access_denied` for a patient the hospital does not hold6 ms
when the token request is wrong 8 passed
- passed answers 400 `invalid_grant` for a `code_verifier` that is not the challenge's8 ms
- passed answers 400 `invalid_grant` for a code it did not issue8 ms
- passed answers 400 `invalid_grant` for a code older than five minutes7 ms
- passed answers 400 `invalid_grant` for another `redirect_uri` than the code's7 ms
- passed answers 400 `invalid_grant` for another `client_id` than the code's9 ms
- passed answers 400 `invalid_request` for no `code_verifier`9 ms
- passed answers 400 `invalid_request` for no `grant_type`9 ms
- passed answers 400 `unsupported_grant_type` for a grant that is not `authorization_code`9 ms
when a request uses the wrong method 2 passed
Reading a patient's records from a demo hospital demoHospital() 30 passed
With a token, a client searches a patient's records one type at a time, a page at a time, or reads one by its id. The hospital serves only the token's patient, and only what the token's scopes cover.
Source hospital.test.ts
when a client searches a patient's records 9 passed
- passed returns every record of the patient across its searches and the read of the Patient0 ms
- passed returns no record of another patient or of another hospital1 ms
- passed answers each page as a `searchset` Bundle whose every `fullUrl` is at the FHIR base0 ms
- passed pages a search by the hospital's `pageSize`, each page linking the next0 ms
- passed omits a record the hospital lists in `hiddenFromSearch`0 ms
- passed serves a record hidden from search when it is read by its id0 ms
- passed takes `category` as a code, as `system|code`, or as a list joined by commas3 ms
- passed takes `patient` as an id or as `Patient/<id>`9 ms
- passed names `patient` as a search parameter of every type it searches, in `metadata`1 ms
with two hospitals 2 passed
- passed serves a person at each hospital as that hospital's own patient20 ms
- passed answers 401 for a token another hospital issued21 ms
given a token's scopes 6 passed
- passed serves a search and a read under `patient/Observation.read`11 ms
- passed serves a record's history under `patient/*.*`7 ms
- passed serves a search under `patient/Observation.s`8 ms
- passed answers 403 for a search of a type the scopes do not cover6 ms
- passed answers 403 for a read under no scope7 ms
- passed answers 403 for a read under a scope that grants no read25 ms
when a request is refused 13 passed
- passed answers 401 `login` with a `Bearer` challenge for no token12 ms
- passed answers 401 `login` with a `Bearer` challenge for a token it cannot read6 ms
- passed answers 401 `login` with a `Bearer` challenge for a code sent as a token7 ms
- passed answers 401 `login` with a `Bearer` challenge for a token older than an hour8 ms
- passed answers 403 `forbidden` for a search of another patient4 ms
- passed answers 400 `required` for a search with no `patient`5 ms
- passed answers 400 `invalid` for a `_page` it cannot read5 ms
- passed answers 404 `not-found` for another patient's record4 ms
- passed answers 404 `not-found` for an id it does not hold4 ms
- passed answers 404 `not-found` for a version of another patient's record5 ms
- passed answers 404 `not-found` for the history of another patient's record6 ms
- passed answers 404 `not-found` for a type the hospital does not serve5 ms
- passed answers 404 `not-found` for a search of Patient6 ms
People to sign in as loadHospitals(), loadPeople(), loadStories() 14 passed
The package carries two demo hospitals, Cascade North and Cascade South, and the made-up people who are patients there: hand-written ones, five stories, and three generated by Synthea. A test signs in as one of them by the patient id listed here.
Source data.test.ts
loadHospitals() 2 passed
- passed returns Cascade North with its nine patients1 ms
- passed returns Cascade South with its three patients0 ms
given Rowan Ellery Marsh 3 passed
- passed holds a source at each hospital0 ms
- passed serves the person under each hospital's own patient id0 ms
- passed serves at a hospital the file that is the person's source there0 ms
loadStories() 2 passed
given the codes the reference tables join 7 passed
- passed holds a retired ICD-10-CM code and its replacement, the retired one recorded first1 ms
- passed holds an immunization under CVX 1540 ms
- passed holds two HDL results under two LOINC codes, 2086-7 before 2085-90 ms
- passed holds a brand at North and its generic at South0 ms
- passed holds an allergy at each hospital, under RxNorm 723 and 3081910 ms
- passed holds one medicine at two strengths, the 10 mg order before the 20 mg0 ms
- passed holds the brand, the generic and the 20 mg order as active0 ms
Reading records as they stood on a date asOf, recordsAt(), versionsOf() 43 passed
Given `asOf`, the world's date, a hospital answers with its records as they stood then: each record's latest version recorded at or before it. A test pulls one patient at two dates and sees what changed between them.
Source history.test.ts
when a record is read 6 passed
- passed answers 404 before the record's first version6 ms
- passed serves the version current on the date1 ms
- passed serves a version from the instant it was recorded1 ms
- passed serves the latest version after the record's last change2 ms
- passed serves the latest version when no date is given1 ms
- passed answers 410 for a record deleted by the date2 ms
when a patient's records are searched 6 passed
- passed returns each record's version current on the date3 ms
- passed omits a record deleted by the date1 ms
- passed omits a record made after the date2 ms
- passed counts the records there on the date in `total`2 ms
- passed keeps the date out of the link to the next page2 ms
- passed serves the next page as of the same date2 ms
when one version is read 4 passed
- passed serves a version recorded by the date2 ms
- passed answers 404 for a version recorded after the date2 ms
- passed answers 404 for a version the record never had1 ms
- passed answers 410 for the version that is a deletion1 ms
when a record's history is read 7 passed
- passed lists the record's versions newest first2 ms
- passed lists only the versions recorded by the date2 ms
- passed lists a deletion as an entry with no resource1 ms
- passed lists a record made again after its deletion as made, not updated5 ms
- passed answers 404 for a record that is not there on the date1 ms
- passed answers 404 `not-supported` for a type's history, saying how a history is read1 ms
- passed answers 404 `not-supported` for the whole hospital's history1 ms
with `_since` 2 passed
with `_at` 7 passed
- passed returns every version current at some time in a year2 ms
- passed returns the one version current through a year before the change1 ms
- passed returns the new version at the instant of the change1 ms
- passed returns the old version one second before the change1 ms
- passed returns the version current on a day3 ms
- passed narrows the versions by `_since` too when both are given1 ms
- passed answers 400 for a date that does not exist2 ms
when the sign-in page is shown 3 passed
given a patient who is not at the hospital on the date 4 passed
when `asOf` is not an instant 2 passed
- passed throws `HospitalDataError` from `demoHospital()`0 ms
- passed throws `HospitalDataError` from `recordsAt()`0 ms
recordsAt(bundle, asOf) 1 passed
- passed returns each record of a patient file as it stood at `asOf`1 ms
versionsOf(bundle, where) 1 passed
Making a sign-in or a request fail on purpose simulate_error 12 passed
An app tests its error handling by adding `simulate_error=<name>` to the authorize request, or by picking a failure on the sign-in page. Each name fails one later step the way the launcher fails it.
Source hospital.test.ts
given `token_invalid_token` 1 passed
- passed answers the token exchange 401 `invalid_client`0 ms
given `token_invalid_scope` 1 passed
- passed answers the token exchange 401 `invalid_scope`0 ms
given `request_invalid_token` 3 passed
given `request_expired_token` 1 passed
given a name it does not know 1 passed
- passed redirects with `invalid_request` and the client's `state`0 ms
with `simulate_error` on a later request 2 passed
- passed ignores a `simulate_error` posted to the token exchange8 ms
- passed ignores a `simulate_error` in a record request's query10 ms
when the sign-in page is shown 2 passed
Signing in from a test signInAs(), signInThrough(), answerSignIn(), pkcePair() 6 passed
What a test calls to get past the sign-in without writing the protocol out: `answerSignIn()` answers the sign-in page as a patient, and `signInAs()` does the whole sign-in and returns the token.
Source hospital.test.ts
answerSignIn(fetch, authorizeUrl, patient, decision) 3 passed
signInAs(hospital, patient, options) 1 passed
signInThrough(fetch, base, patient) 1 passed
`signInAs()` builds the hospital for you; `signInThrough()` signs in to one you reach by `fetch` and `base` (its FHIR base).
pkcePair() 1 passed
Sending an app's requests to the demo hospitals demoFetch(), isDemoRequest() 11 passed
`demoFetch()` is a `fetch` that answers a request for a demo hospital's address in the same process and passes every other request on. An app's test swaps it in for `fetch` and connects with no network.
Source route.test.ts
isDemoRequest(url, options) 3 passed
- passed returns true for a URL on a `.demo.invalid` host1 ms
- passed returns true for a URL under `authorizeBase`0 ms
- passed returns false for any other URL0 ms
demoFetch(hospitals, options) 5 passed
- passed answers a hospital's discovery with that hospital as the issuer21 ms
- passed reaches a hospital's sign-in page at `<FHIR base>/authorize`8 ms
- passed answers 404 for a demo address no hospital is at0 ms
- passed passes every other request to `fallback`1 ms
- passed exposes `Retry-After` to a page on another origin8 ms
with `authorizeBase` 3 passed
Serving the demo hospitals at a real address serveDemo(), demoRemapFetch() 45 passed
`serveDemo()` starts the demo hospitals on a port of this machine, the listener, for a caller that needs a real address: a browser, a tool in another language, an app in a container. `demoRemapFetch()` is a `fetch` that sends a request for a hospital's own address to the listener.
Source serve.test.ts
serveDemo(hospitals, options) 2 passed
- passed passes the caller's `Content-Type` and `Accept` on to the hospital33 ms
- passed answers as of `options.asOf` from its first request29 ms
demoRemapFetch(origin) 8 passed
- passed returns the records the in-process `demoFetch()` returns393 ms
- passed names the hospital's own address in every link and `fullUrl`0 ms
- passed follows a redirect to a demo address through the listener0 ms
- passed returns a redirect unfollowed under `redirect: "manual"`0 ms
- passed rejects a redirect that never ends with "too many redirects"1 ms
- passed keeps `Authorization` on a redirect within the origin0 ms
- passed drops `Authorization` on a redirect to another host0 ms
- passed drops `Authorization` on a redirect to another port of the host0 ms
when a caller has only the listener's address 6 passed
- passed names `<origin>/<id>/fhir` as the issuer in discovery189 ms
- passed names the sign-in and token addresses of discovery in `metadata` too0 ms
- passed returns the records a remapped pull returns0 ms
- passed names the listener's address in every link and `fullUrl`1 ms
- passed shows the sign-in page for an `aud` that is the base the caller came to7 ms
- passed redirects with `invalid_request` for an `aud` that is the hospital's own base1 ms
when the listener is asked by another name 6 passed
- passed answers at `localhost`, naming it as the issuer5 ms
- passed answers at `host.docker.internal`1 ms
- passed answers at a name given in `hosts`1 ms
- passed answers at an IPv6 address1 ms
- passed answers 403 for any other name1 ms
- passed answers 400 for a `Host` that is no host name1 ms
when a request cannot be placed 9 passed
- passed answers 400 for a `Forwarded` host that is another hospital's than the path's1 ms
- passed answers 400 for a `Forwarded` host that is no demo hospital's1 ms
- passed answers 400 for a `Forwarded` request with no hospital id in its path1 ms
- passed answers 400 for a `Forwarded` protocol that is not https1 ms
- passed answers 400 for a target that is a whole URL1 ms
- passed answers 400 for a target that begins with two slashes1 ms
- passed answers 404 for a hospital it does not serve1 ms
- passed answers 404 for a path with no hospital id1 ms
- passed serves a `Forwarded` host that names the https port as the same host1 ms
when a page on another origin asks 6 passed
- passed allows any origin to read discovery, `metadata` and the records2 ms
- passed allows any origin to post to the token endpoint, marking the answer `no-store`1 ms
- passed answers a preflight of those with the methods and headers a client sends2 ms
- passed allows no other origin to read the sign-in page1 ms
- passed allows no other origin to move the world's date2 ms
- passed sends no `Access-Control-Allow-Credentials` on any answer13 ms
when the world's date is moved 8 passed
- passed shows no date on the sign-in page until one is set8 ms
- passed answers the next request as of the date posted to `/world-date`8 ms
- passed answers a token issued before the move as of the new date26 ms
- passed answers 400 for an `asOf` that is not an instant, leaving the date14 ms
- passed answers 403 for a post from a page on another site, leaving the date9 ms
- passed returns to every version when `asOf` is posted empty14 ms
- passed returns to every version on `setWorldDate(undefined)`27 ms
- passed throws `HospitalDataError` from `setWorldDate()` for a value that is not an instant8 ms
Starting the demo hospitals from a terminal npm run serve 5 passed
`npm run serve` starts the same listener in a process of its own and prints where each hospital is, for a tool outside Node such as curl or Inferno.
Source serve.test.ts
when it starts 3 passed
- passed prints `Listening at <origin>`0 ms
- passed prints each hospital's base at the listener and at `host.docker.internal`0 ms
- passed serves a hospital at the base it printed13 ms
when an argument is wrong 2 passed
Listing the demo hospitals as a brands bundle brandsBundle() 8 passed
`brandsBundle()` gives the hospitals as a brands bundle, the standard document an app's list of hospitals to connect to is read from. An app tests its hospital search against it with no vendor's list.
Source brands.test.ts
brandsBundle(hospitals, timestamp) 8 passed
- passed returns a `collection` Bundle stamped with the timestamp and the brands-bundle profile2 ms
- passed lists an Organization and then its Endpoint for each hospital, in the order given0 ms
- passed gives each entry a `fullUrl` its Organization's reference resolves against0 ms
- passed names each Organization for its hospital, with the hospital's site as identifier and telecom0 ms
- passed points each Organization to its Endpoint, by `endpoint` and by its portal extension1 ms
- passed gives each Endpoint the hospital's FHIR base as its address, active, as FHIR 4.0.1 over REST2 ms
- passed splits each place at its last comma into a city and a state0 ms
- passed omits `address` for a hospital with no places0 ms
Loading hospitals and people from an app's own folders loadHospitals(), loadHospital(), loadStories() 53 passed
An app keeps hospitals and people of its own in folders laid out as this package's are, the roots, and loads them beside the package's or in place of them. Every load checks each person's sources against who the person is, and refuses what disagrees with a `HospitalDataError`.
Source roots.test.ts
loadHospitals(roots) 5 passed
- passed returns the hospitals root by root, each root's in order of folder name5 ms
- passed skips a root that is not a folder1 ms
- passed skips a file and a dot-folder beside the hospital folders2 ms
- passed ignores what a hospital folder holds beside its `hospital.json`2 ms
- passed returns the package's two hospitals when no roots are given129 ms
loadHospital(id, roots) 2 passed
- passed returns the hospital of that id2 ms
- passed throws `HospitalDataError` for an id no root holds2 ms
when a hospital folder is refused 15 passed
- passed refuses one id held by two roots3 ms
- passed refuses a FHIR base that is on no demo host1 ms
- passed refuses a folder with no `hospital.json`1 ms
- passed refuses a `hospital.json` that is not JSON1 ms
- passed refuses a `hospital.json` that is not an object1 ms
- passed refuses a `hospital.json` with no `name`1 ms
- passed refuses a `hospital.json` with no `fhirBase`1 ms
- passed refuses a `hospital.json` with no `types`1 ms
- passed refuses a `pageSize` that is not a whole number of 1 or more2 ms
- passed refuses an empty `key`1 ms
- passed refuses a `hospital.json` with no `hiddenFromSearch`1 ms
- passed refuses a `colour` that is not a string1 ms
- passed refuses `places` that are not a list of strings1 ms
- passed refuses a folder named for another id than its FHIR base's1 ms
- passed refuses a hospital folder that holds `patients/`2 ms
given a person's sources 6 passed
- passed compares the Patient's official name, whatever other names it carries3 ms
- passed compares every version of the Patient2 ms
- passed skips a field the Patient leaves out2 ms
- passed accepts a difference the person declares, where a version of the Patient shows it2 ms
- passed accepts a difference declared at a source that also holds a C-CDA document3 ms
- passed accepts a difference declared for a kit person at a source they have no folder for2 ms
when a person is refused 22 passed
- passed refuses a Patient whose name differs from the person's4 ms
- passed refuses given names in another order2 ms
- passed refuses a birth date that differs2 ms
- passed refuses a gender that differs in a later version3 ms
- passed refuses a declared difference the Patient does not show2 ms
- passed refuses a difference declared at a source the person does not have6 ms
- passed refuses a `fhir.json` named in another case12 ms
- passed refuses a stray file beside a source's `fhir.json`8 ms
- passed refuses an empty source folder8 ms
- passed refuses a person folder with no `person.json`2 ms
- passed refuses a `person.json` that is not JSON4 ms
- passed refuses a `person.json` with no `id`3 ms
- passed refuses a `name` without family and given names2 ms
- passed refuses a `birthDate` that is not `YYYY-MM-DD`2 ms
- passed refuses a `gender` that is not one of FHIR's four1 ms
- passed refuses an `id` that is not the folder's name3 ms
- passed refuses a source with no Patient7 ms
- passed refuses a source with two Patients2 ms
- passed refuses a source at a hospital that is not loaded3 ms
- passed refuses one person held by two roots2 ms
- passed refuses one Patient id held by two people at a hospital7 ms
- passed refuses a `fullUrl` at another base than the hospital's12 ms
loadStories(roots) 3 passed
Adding a patient to an app's hospital addPatient() 23 passed
`addPatient()` checks a patient's file as the app would load it at one of its hospitals, then writes it into the app's `people/` folder. A developer brings a patient of their own without learning the folder layout.
Source roots.test.ts
addPatient(app, hospital, file) 7 passed
- passed returns the path it wrote, `people/<Patient id>/sources/<hospital>/fhir.json`0 ms
- passed writes a file the hospital then loads the patient from0 ms
- passed compiles a file with `shorthand` to a history before writing it0 ms
- passed writes a plain collection as it is0 ms
- passed writes `person.json` from the Patient's official name, birth date and gender0 ms
- passed leaves the `person.json` of a person already there as it is0 ms
- passed accepts a second source of a person who declares a difference at their first0 ms
when the file is refused 16 passed
- passed refuses a patient who is already at the hospital64 ms
- passed refuses a patient who disagrees with the person already there55 ms
- passed refuses a hospital the app does not have3 ms
- passed refuses a file that cannot be read0 ms
- passed refuses a file that is not JSON1 ms
- passed refuses a file that is not an object1 ms
- passed refuses a file that is not a Bundle3 ms
- passed refuses an entry that is not an object1 ms
- passed refuses a `shorthand` that is not an object1 ms
- passed refuses a file with no Patient1 ms
- passed refuses a Patient id that is no folder name1 ms
- passed refuses a Patient id that is a person of the package already55 ms
- passed refuses a Patient with no birth date48 ms
- passed refuses a record of a type the hospital does not serve77 ms
- passed refuses a record another patient's file holds75 ms
- passed writes nothing for a file it refuses155 ms
Writing a patient's changes in shorthand addPatient(), shorthand 16 passed
A patient file's history can be written short: a plain collection in which an entry says when its record began and when it stopped, as `shorthand: { active, stopped }`. `addPatient()` compiles it to the versions a hospital serves, so a developer writes two dates and not two copies of a record.
Source shorthand.test.ts
given a collection whose entries carry `shorthand` 4 passed
- passed compiles to a `history` Bundle1 ms
- passed gives a record with `active` and `stopped` two versions, recorded on those days1 ms
- passed places a record with no `shorthand` at its own clinical date0 ms
- passed places the Patient at the file's earliest record time0 ms
when a hospital serves the compiled file as of a date 3 passed
when the file cannot be compiled 9 passed
- passed refuses `stopped` on a MedicationRequest1 ms
- passed refuses `stopped` on a type with no field that dates a stop0 ms
- passed refuses a record with no date to place it at0 ms
- passed refuses a Patient with no record to place it by0 ms
- passed refuses a stop that is not after the start0 ms
- passed refuses a day that does not exist0 ms
- passed refuses a `shorthand` key that is neither `active` nor `stopped`0 ms
- passed refuses a record written twice0 ms
- passed refuses a file that is not a collection0 ms
Checking a patient file demoHospital(), loadHospital(), HospitalDataError 17 passed
A patient file is a FHIR Bundle of type `collection`, plain records, or `history`, one entry for each version. A hospital and the loader refuse a file that breaks a rule with a `HospitalDataError` whose `reason` says which, so a developer's own patient fails when it is loaded and not in the middle of a pull.
Source patient-file.test.ts
when a patient file breaks a rule 17 passed
- passed refuses a Bundle that is neither a collection nor a history7 ms
- passed refuses a collection that holds a record twice3 ms
- passed refuses a history entry whose method is not POST, PUT or DELETE3 ms
- passed refuses an entry whose `request.url` names another record3 ms
- passed refuses a record time that is a date3 ms
- passed refuses a record time on a day that does not exist3 ms
- passed refuses a version with no `meta.versionId`3 ms
- passed refuses a `meta.lastUpdated` that is not the entry's record time3 ms
- passed refuses an etag of another version3 ms
- passed refuses a version id used twice3 ms
- passed refuses two versions of a record at one time3 ms
- passed refuses a deletion with no etag3 ms
- passed refuses a deletion that carries a resource3 ms
- passed refuses a deletion of a record that does not exist2 ms
- passed refuses a `fullUrl` at another base than the hospital's6 ms
- passed refuses a record held in two patients' files5 ms
- passed refuses a file whose Patient is not the id it is held under0 ms
Exporting a patient's records as a file exportCollection() 7 passed
`exportCollection()` gives a patient's records as they stood on a date as one `collection` Bundle, each `fullUrl` the hospital's own. The file reads as what a pull of that hospital on that date would have brought.
Source export.test.ts
exportCollection(hospital, patient, asOf) 7 passed
- passed returns each record's version current at `asOf`, a deleted record left out5 ms
- passed returns each record's latest version when no `asOf` is given0 ms
- passed addresses each record at the hospital's FHIR base0 ms
- passed throws `HospitalDataError` for a patient the hospital does not hold0 ms
- passed throws `HospitalDataError` for a patient made after `asOf`0 ms
- passed throws `HospitalDataError` for a patient who is deleted0 ms
- passed throws `HospitalDataError` for an `asOf` that is not an instant0 ms
Build and packaging 53 passed
Making the generated people from Synthea's output fromSynthea(), medicationRows(), payerNames(), providerDetails() 34 passed
`npm run synthea` turns one Synthea person into a patient file for each hospital that holds them: real providers' names removed, ids made the hospital's own, and each record cut into versions by the dates Synthea gave.
Source synthea.test.ts
fromSynthea() 15 passed
- passed returns a `history` file for each hospital2 ms
- passed drops a record of a type the hospital does not serve0 ms
- passed sends the provider with the most visits to the first hospital0 ms
- passed drops an Observation that is neither a lab result nor a vital sign0 ms
- passed drops a DiagnosticReport with no text whose results are not served there0 ms
- passed keeps a report's text, cleaned of the digits in names and of the payer's name0 ms
- passed keeps a note at the hospital of its visit, as current, with the hospital as custodian0 ms
- passed rewrites each reference to the hospital's own id for the record0 ms
- passed removes a reference to a record the other hospital holds0 ms
- passed resolves every reference inside the file1 ms
- passed leaves no `urn:uuid:`, real provider's name or Synthea URL in a file0 ms
- passed names the hospital as each visit's provider, with none of Synthea's identifiers0 ms
- passed strips the digits from the Patient's names, and removes Synthea's own extensions0 ms
- passed gives the Patient the hospital's own id and medical record number0 ms
- passed gives the Patient one version, at the earliest record time of its file0 ms
when a record changes after it is first held 9 passed
- passed gives a stopped order two versions: active when written, completed at its stop in `medications.csv`0 ms
- passed ends an order at its renewal when that comes before the stop0 ms
- passed gives an order stopped at its start one version0 ms
- passed gives a condition that abates later two versions0 ms
- passed gives a condition abated when it was recorded one version0 ms
- passed gives a record that never changes one version0 ms
- passed starts the second hospital's copy at its first visit that finds the record active0 ms
- passed places an allergy with no visit on its own date at the first hospital0 ms
- passed leaves out of the second hospital a record no visit there finds active1 ms
medicationRows() 2 passed
payerNames() 1 passed
- passed returns each insurer but a public programme0 ms
providerDetails() 2 passed
when a person cannot be held faithfully 5 passed
- passed throws for three hospitals0 ms
- passed throws for a Medication the bundle does not hold1 ms
- passed throws for a completed order with no stop in `medications.csv`0 ms
- passed throws for a resolved condition with no abatement date0 ms
- passed throws for a record with no date to be first held at0 ms
The package's people, held to the hospitals' data rules 15 passed
Source data-rules.test.ts
given every patient file 9 passed
- passed keeps each file under 2 MiB1 ms
- passed holds each record in one patient's file of its hospital1 ms
- passed holds no record id at both hospitals1 ms
- passed holds only the types its hospital serves1 ms
- passed gives each Observation exactly one of the categories the hospitals search by6 ms
- passed keeps addresses and telecoms off every record but the Patient1 ms
- passed resolves every reference inside the patient's own file28 ms
- passed names only the hospital as provider, location, performer or custodian, practitioners apart2 ms
- passed holds at least two people at both hospitals11 ms
given a generated patient's file 6 passed
- passed names no provider, payer or address that `synthea/removed.json` lists62 ms
- passed carries no `urn:uuid:` reference and no Synthea URL38 ms
- passed is a `history` file, one of four0 ms
- passed gives a record at most two versions, none recorded before the Patient's4 ms
- passed gives a second version only to a MedicationRequest or a Condition1 ms
- passed holds a DiagnosticReport and a DocumentReference with their text0 ms
Tripwire: the generated people as npm run synthea writes them 3 passed
Source data-rules.test.ts
given `synthea/people.json` 3 passed
- passed matches `generatedPerson()` for each person it chooses21 ms
- passed lists the hospitals it gives each person, in its order0 ms
- passed holds no generated person it does not choose0 ms
Writing a hospital's answer to a Node response send() 1 passed
The listener writes each answer of a hospital to a Node response with `send()`; nothing else of the package calls it.
Source serve.test.ts
send(outgoing, response) 1 passed