@photonhealth/client 0.0.0-stage → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +234 -2
- package/dist/analytics/lifecycleEvents.d.ts +29 -0
- package/dist/analytics/lifecycleEvents.d.ts.map +1 -0
- package/dist/analytics/lifecycleEvents.js +72 -0
- package/dist/analytics/lifecycleEvents.js.map +1 -0
- package/dist/api/changes/applyOption.d.ts +41 -0
- package/dist/api/changes/applyOption.d.ts.map +1 -0
- package/dist/api/changes/applyOption.js +76 -0
- package/dist/api/changes/applyOption.js.map +1 -0
- package/dist/api/changes/classifyChanges.d.ts +9 -0
- package/dist/api/changes/classifyChanges.d.ts.map +1 -0
- package/dist/api/changes/classifyChanges.js +2 -0
- package/dist/api/changes/classifyChanges.js.map +1 -0
- package/dist/api/changes/index.d.ts +3 -0
- package/dist/api/changes/index.d.ts.map +1 -0
- package/dist/api/changes/index.js +3 -0
- package/dist/api/changes/index.js.map +1 -0
- package/dist/api/client.d.ts +48 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +91 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/health.d.ts +4 -0
- package/dist/api/health.d.ts.map +1 -0
- package/dist/api/health.js +6 -0
- package/dist/api/health.js.map +1 -0
- package/dist/api/index.d.ts +24 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +23 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/me.d.ts +37 -0
- package/dist/api/me.d.ts.map +1 -0
- package/dist/api/me.js +6 -0
- package/dist/api/me.js.map +1 -0
- package/dist/api/order.d.ts +33 -0
- package/dist/api/order.d.ts.map +1 -0
- package/dist/api/order.js +33 -0
- package/dist/api/order.js.map +1 -0
- package/dist/api/orders.d.ts +1047 -0
- package/dist/api/orders.d.ts.map +1 -0
- package/dist/api/orders.js +7 -0
- package/dist/api/orders.js.map +1 -0
- package/dist/api/patient.d.ts +36 -0
- package/dist/api/patient.d.ts.map +1 -0
- package/dist/api/patient.js +33 -0
- package/dist/api/patient.js.map +1 -0
- package/dist/api/prescription.d.ts +37 -0
- package/dist/api/prescription.d.ts.map +1 -0
- package/dist/api/prescription.js +39 -0
- package/dist/api/prescription.js.map +1 -0
- package/dist/api/results.d.ts +30 -0
- package/dist/api/results.d.ts.map +1 -0
- package/dist/api/results.js +26 -0
- package/dist/api/results.js.map +1 -0
- package/dist/gql/gql.d.ts +29 -0
- package/dist/gql/gql.d.ts.map +1 -0
- package/dist/gql/gql.js +15 -0
- package/dist/gql/gql.js.map +1 -0
- package/dist/gql/graphql.d.ts +18618 -0
- package/dist/gql/graphql.d.ts.map +1 -0
- package/dist/gql/graphql.js +6579 -0
- package/dist/gql/graphql.js.map +1 -0
- package/dist/gql/index.d.ts +2 -0
- package/dist/gql/index.d.ts.map +1 -0
- package/dist/gql/index.js +3 -0
- package/dist/gql/index.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/meta/version.d.ts +2 -0
- package/dist/meta/version.d.ts.map +1 -0
- package/dist/meta/version.js +2 -0
- package/dist/meta/version.js.map +1 -0
- package/dist/photon/analytics.d.ts +39 -0
- package/dist/photon/analytics.d.ts.map +1 -0
- package/dist/photon/analytics.js +91 -0
- package/dist/photon/analytics.js.map +1 -0
- package/dist/photon/auth.d.ts +52 -0
- package/dist/photon/auth.d.ts.map +1 -0
- package/dist/photon/auth.js +30 -0
- package/dist/photon/auth.js.map +1 -0
- package/dist/photon/choices.d.ts +44 -0
- package/dist/photon/choices.d.ts.map +1 -0
- package/dist/photon/choices.js +58 -0
- package/dist/photon/choices.js.map +1 -0
- package/dist/photon/context.d.ts +29 -0
- package/dist/photon/context.d.ts.map +1 -0
- package/dist/photon/context.js +2 -0
- package/dist/photon/context.js.map +1 -0
- package/dist/photon/environments.d.ts +27 -0
- package/dist/photon/environments.d.ts.map +1 -0
- package/dist/photon/environments.js +27 -0
- package/dist/photon/environments.js.map +1 -0
- package/dist/photon/errors.d.ts +26 -0
- package/dist/photon/errors.d.ts.map +1 -0
- package/dist/photon/errors.js +42 -0
- package/dist/photon/errors.js.map +1 -0
- package/dist/photon/index.d.ts +26 -0
- package/dist/photon/index.d.ts.map +1 -0
- package/dist/photon/index.js +12 -0
- package/dist/photon/index.js.map +1 -0
- package/dist/photon/inputs.d.ts +7 -0
- package/dist/photon/inputs.d.ts.map +1 -0
- package/dist/photon/inputs.js +25 -0
- package/dist/photon/inputs.js.map +1 -0
- package/dist/photon/links.d.ts +68 -0
- package/dist/photon/links.d.ts.map +1 -0
- package/dist/photon/links.js +187 -0
- package/dist/photon/links.js.map +1 -0
- package/dist/photon/live.d.ts +62 -0
- package/dist/photon/live.d.ts.map +1 -0
- package/dist/photon/live.js +107 -0
- package/dist/photon/live.js.map +1 -0
- package/dist/photon/machine.d.ts +28 -0
- package/dist/photon/machine.d.ts.map +1 -0
- package/dist/photon/machine.js +53 -0
- package/dist/photon/machine.js.map +1 -0
- package/dist/photon/map.d.ts +14 -0
- package/dist/photon/map.d.ts.map +1 -0
- package/dist/photon/map.js +311 -0
- package/dist/photon/map.js.map +1 -0
- package/dist/photon/order.d.ts +168 -0
- package/dist/photon/order.d.ts.map +1 -0
- package/dist/photon/order.js +558 -0
- package/dist/photon/order.js.map +1 -0
- package/dist/photon/orders.d.ts +5 -0
- package/dist/photon/orders.d.ts.map +1 -0
- package/dist/photon/orders.js +39 -0
- package/dist/photon/orders.js.map +1 -0
- package/dist/photon/patient.d.ts +80 -0
- package/dist/photon/patient.d.ts.map +1 -0
- package/dist/photon/patient.js +347 -0
- package/dist/photon/patient.js.map +1 -0
- package/dist/photon/photon.d.ts +188 -0
- package/dist/photon/photon.d.ts.map +1 -0
- package/dist/photon/photon.js +395 -0
- package/dist/photon/photon.js.map +1 -0
- package/dist/photon/prescription.d.ts +145 -0
- package/dist/photon/prescription.d.ts.map +1 -0
- package/dist/photon/prescription.js +418 -0
- package/dist/photon/prescription.js.map +1 -0
- package/dist/photon/session.d.ts +89 -0
- package/dist/photon/session.d.ts.map +1 -0
- package/dist/photon/session.js +352 -0
- package/dist/photon/session.js.map +1 -0
- package/dist/photon/types.d.ts +643 -0
- package/dist/photon/types.d.ts.map +1 -0
- package/dist/photon/types.js +7 -0
- package/dist/photon/types.js.map +1 -0
- package/dist/test-utils/msw.d.ts +23 -0
- package/dist/test-utils/msw.d.ts.map +1 -0
- package/dist/test-utils/msw.js +51 -0
- package/dist/test-utils/msw.js.map +1 -0
- package/dist/testing/fakeNetworkApiClient.d.ts +39 -0
- package/dist/testing/fakeNetworkApiClient.d.ts.map +1 -0
- package/dist/testing/fakeNetworkApiClient.js +56 -0
- package/dist/testing/fakeNetworkApiClient.js.map +1 -0
- package/dist/testing/fixtures.d.ts +1098 -0
- package/dist/testing/fixtures.d.ts.map +1 -0
- package/dist/testing/fixtures.js +200 -0
- package/dist/testing/fixtures.js.map +1 -0
- package/dist/testing.d.ts +11 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +10 -0
- package/dist/testing.js.map +1 -0
- package/package.json +67 -4
- package/src/analytics/lifecycleEvents.test.ts +417 -0
- package/src/analytics/lifecycleEvents.ts +155 -0
- package/src/api/changes/applyOption.ts +103 -0
- package/src/api/changes/classifyChanges.ts +10 -0
- package/src/api/changes/index.ts +2 -0
- package/src/api/client.ts +149 -0
- package/src/api/health.ts +7 -0
- package/src/api/index.ts +24 -0
- package/src/api/me.ts +7 -0
- package/src/api/order.ts +64 -0
- package/src/api/orders.ts +8 -0
- package/src/api/patient.ts +67 -0
- package/src/api/prescription.ts +86 -0
- package/src/api/results.ts +45 -0
- package/src/gql/gql.ts +68 -0
- package/src/gql/graphql.ts +9027 -0
- package/src/gql/index.ts +2 -0
- package/src/index.ts +14 -0
- package/src/meta/version.test.ts +10 -0
- package/src/meta/version.ts +1 -0
- package/src/operations/fragments.graphql +497 -0
- package/src/operations/health.graphql +4 -0
- package/src/operations/me.graphql +38 -0
- package/src/operations/order.graphql +42 -0
- package/src/operations/orders.graphql +35 -0
- package/src/operations/patient.graphql +62 -0
- package/src/operations/prescription.graphql +90 -0
- package/src/photon/analytics.ts +129 -0
- package/src/photon/auth.ts +69 -0
- package/src/photon/choices.ts +79 -0
- package/src/photon/context.ts +30 -0
- package/src/photon/environments.ts +49 -0
- package/src/photon/errors.ts +56 -0
- package/src/photon/index.ts +49 -0
- package/src/photon/inputs.ts +24 -0
- package/src/photon/links.ts +197 -0
- package/src/photon/live.ts +135 -0
- package/src/photon/machine.ts +90 -0
- package/src/photon/map.ts +371 -0
- package/src/photon/order.test.ts +142 -0
- package/src/photon/order.ts +661 -0
- package/src/photon/orders.ts +42 -0
- package/src/photon/patient.ts +386 -0
- package/src/photon/photon.ts +646 -0
- package/src/photon/prescription.ts +506 -0
- package/src/photon/session.ts +454 -0
- package/src/photon/types.ts +583 -0
- package/src/test-utils/msw.ts +72 -0
- package/src/testing/fakeNetworkApiClient.ts +56 -0
- package/src/testing/fixtures.ts +233 -0
- package/src/testing.ts +25 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orders.js","sourceRoot":"","sources":["../../src/photon/orders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAG7C,wGAAwG;AACxG,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAqB,EAAE,QAAqB,EAAE;IAC7E,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,CAChC,MAAM,CAAC,MAAM,EAAE;QACb,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,QAAQ,EAAE,KAAK,CAAC,kBAAkB,EAAE,QAAQ;QAC5C,IAAI,EAAE,KAAK,CAAC,kBAAkB,EAAE,IAAI;QACpC,iBAAiB,EAAE,KAAK,CAAC,kBAAkB,KAAK,SAAS;KAC1D,CAAC,CACH,CAAC;IACF,IAAI,MAAM,CAAC,UAAU,KAAK,uBAAuB;QAC/C,OAAO;YACL,MAAM,EAAE,EAAE;YACV,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACxC,EAAE,EAAE,CAAC,CAAC,EAAE;gBACR,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,WAAW,EAAE,CAAC,CAAC,WAAW;aAC3B,CAAC,CAAC;YACH,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;IACJ,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAChC,GAAG,OAAO,CAAC,CAAC,CAAC;YACb,kBAAkB,EAAE,CAAC,CAAC,kBAAkB;gBACtC,CAAC,CAAC;oBACE,OAAO,EAAE,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;oBACnD,UAAU,EAAE,CAAC,CAAC,kBAAkB,CAAC,UAAU;oBAC3C,UAAU,EAAE,CAAC,CAAC,kBAAkB,CAAC,UAAU;iBAC5C;gBACH,CAAC,CAAC,IAAI;SACT,CAAC,CAAC;QACH,UAAU,EAAE,EAAE;QACd,MAAM,EAAE,IAAI;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Context } from "./context.ts";
|
|
2
|
+
import { LiveRecord } from "./live.ts";
|
|
3
|
+
import type { ChangeOption, Changes, PatientCandidate, PatientInput, PatientRecord } from "./types.ts";
|
|
4
|
+
/** sent before the record */
|
|
5
|
+
type Known = Pick<PatientInput, "demographic" | "contact" | "preferredPharmacy">;
|
|
6
|
+
export interface PatientExtra {
|
|
7
|
+
/** The server wasn't certain who this is: who it might be (even one). Pick with `pick(id)`. */
|
|
8
|
+
candidates: PatientCandidate[];
|
|
9
|
+
/**
|
|
10
|
+
* Names for clinical entries the server returns with name = id (allergies, diagnoses on boson): what the
|
|
11
|
+
* prescriber typed or picked, by entry id.
|
|
12
|
+
*/
|
|
13
|
+
pickedNames: Readonly<Record<string, string>>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A patient — from an id, from a record the host has, or not yet known. `sync({ demographic, contact })` sends what
|
|
17
|
+
* you know, and the server decides — the patient (found, or created when nothing matches and it has enough),
|
|
18
|
+
* candidates (pick one), or nothing yet (`changes` says what's missing). Keep adding what you know until it
|
|
19
|
+
* has an id; then `update(fields)` changes that patient. The client never decides "now create".
|
|
20
|
+
*
|
|
21
|
+
* Sync what's been committed (a field the prescriber left), not every keystroke: a sync with enough to
|
|
22
|
+
* create can create. While they type, `search` — it only lists who it might be.
|
|
23
|
+
*/
|
|
24
|
+
export declare class Patient extends LiveRecord<PatientRecord, PatientExtra> {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(ctx: Context, record: PatientRecord | null, changes?: Changes);
|
|
27
|
+
protected onRecord(): void;
|
|
28
|
+
protected settle(state: PatientRecord | null, changes: Changes): void;
|
|
29
|
+
adopt(state: PatientRecord, changes?: Changes): void;
|
|
30
|
+
/**
|
|
31
|
+
* What's been sent to find or add the patient, before the record — e.g. a host's details the server hasn't
|
|
32
|
+
* matched yet (not enough to add them). A form starts from it.
|
|
33
|
+
*/
|
|
34
|
+
get known(): Readonly<Known>;
|
|
35
|
+
/**
|
|
36
|
+
* SyncPatient: send what's known. Before a record it's added to what was sent before, and the server finds,
|
|
37
|
+
* lists candidates, says what's missing, or creates. With a record, the server syncs these fields to it.
|
|
38
|
+
*/
|
|
39
|
+
sync(input: Omit<PatientInput, "id">): Promise<{
|
|
40
|
+
changes: Changes;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* UpdatePatient: change this patient — only what's given: demographics, contact, benefits, preferred pharmacy
|
|
44
|
+
* and/or clinical lists (`{ allergies: { add: [{ name }] } }`, `{ allergies: { none: true } }` for no known
|
|
45
|
+
* allergies). Needs its id.
|
|
46
|
+
*/
|
|
47
|
+
update(input: Omit<PatientInput, "id">): Promise<{
|
|
48
|
+
changes: Changes;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Type-ahead, before the record: who it might be, from what's known plus what's being typed (not kept —
|
|
52
|
+
* `sync` commits). Sent without sex, so it can never add anyone (network-api adds a patient only with first,
|
|
53
|
+
* last, date of birth and sex), and what it finds is only listed in `candidates` — even a sure match is the
|
|
54
|
+
* prescriber's pick mid-typing. A newer search or sync aborts one in flight; the same query isn't sent twice.
|
|
55
|
+
*/
|
|
56
|
+
search(input: Omit<PatientInput, "id">): Promise<{
|
|
57
|
+
changes: Changes;
|
|
58
|
+
}>;
|
|
59
|
+
/** One of `candidates`: read it, and this becomes that patient. Phone / email sent to find them fill gaps on it. */
|
|
60
|
+
pick(candidateId: string): Promise<{
|
|
61
|
+
changes: Changes;
|
|
62
|
+
}>;
|
|
63
|
+
/** A choice the server asked for (e.g. which penicillin): sent again with the pick applied to the last patch. */
|
|
64
|
+
choose(option: ChangeOption): Promise<{
|
|
65
|
+
changes: Changes;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* The Photon Rx app's link to this patient (`/patient/<id>`); `ph.url(this)`. Refused before the record: there's
|
|
69
|
+
* no id to link to, and a link never carries their details.
|
|
70
|
+
*/
|
|
71
|
+
url(): string;
|
|
72
|
+
/** The same, embeddable in an iframe; `ph.frame(this)`. */
|
|
73
|
+
frame(): string;
|
|
74
|
+
/** Read it again. */
|
|
75
|
+
reload(): Promise<{
|
|
76
|
+
changes: Changes;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
80
|
+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Y,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAMtE;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAmCtE,oHAAoH;IACpH,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAQxD,iHAAiH;IACjH,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAY3D;;;OAGG;IACH,GAAG,IAAI,MAAM;IAIb,2DAA2D;IAC3D,KAAK,IAAI,MAAM;IAIf,qBAAqB;IACrB,MAAM,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAwIxC"}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { getPatient, syncPatient, updatePatient } from "../api/index.js";
|
|
2
|
+
import { choicesIn, declaredChoice, optionKey, withChoice } from "./choices.js";
|
|
3
|
+
import { PhotonError } from "./errors.js";
|
|
4
|
+
import { LiveRecord } from "./live.js";
|
|
5
|
+
import { noChanges, toChanges, toPatient } from "./map.js";
|
|
6
|
+
const candidateOf = (p) => ({
|
|
7
|
+
id: p.id,
|
|
8
|
+
firstName: p.demographic?.name.first ?? "",
|
|
9
|
+
lastName: p.demographic?.name.last ?? null,
|
|
10
|
+
dateOfBirth: p.demographic?.dateOfBirth ?? null,
|
|
11
|
+
});
|
|
12
|
+
const validDob = (dob) => Boolean(dob && /^\d{4}-\d{2}-\d{2}$/.test(dob));
|
|
13
|
+
const trimmed = (v) => v?.trim() || undefined;
|
|
14
|
+
/** What's synced before the record: trimmed, empty fields dropped, a date of birth only when it's a whole date. */
|
|
15
|
+
function cleanDemographic(d = {}) {
|
|
16
|
+
const first = trimmed(d.name?.first);
|
|
17
|
+
const last = trimmed(d.name?.last);
|
|
18
|
+
return {
|
|
19
|
+
...(first || last ? { name: { first, last } } : {}),
|
|
20
|
+
...(validDob(d.dateOfBirth) ? { dateOfBirth: d.dateOfBirth } : {}),
|
|
21
|
+
...(d.sex ? { sex: d.sex } : {}),
|
|
22
|
+
...(trimmed(d.gender) ? { gender: trimmed(d.gender) } : {}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function cleanContact(c = {}) {
|
|
26
|
+
return {
|
|
27
|
+
...(trimmed(c.phone) ? { phone: trimmed(c.phone) } : {}),
|
|
28
|
+
...(trimmed(c.email) ? { email: trimmed(c.email) } : {}),
|
|
29
|
+
...(c.address ? { address: c.address } : {}),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const nonEmpty = (v) => (Object.keys(v).length ? v : undefined);
|
|
33
|
+
/** drops empty groups */
|
|
34
|
+
function cleanKnown(k) {
|
|
35
|
+
const demographic = nonEmpty(cleanDemographic(k.demographic));
|
|
36
|
+
const contact = nonEmpty(cleanContact(k.contact));
|
|
37
|
+
return {
|
|
38
|
+
...(demographic ? { demographic } : {}),
|
|
39
|
+
...(contact ? { contact } : {}),
|
|
40
|
+
...(k.preferredPharmacy ? { preferredPharmacy: k.preferredPharmacy } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const mergeKnown = (a, b) => ({
|
|
44
|
+
preferredPharmacy: b.preferredPharmacy ?? a.preferredPharmacy,
|
|
45
|
+
demographic: {
|
|
46
|
+
...a.demographic,
|
|
47
|
+
...b.demographic,
|
|
48
|
+
...(a.demographic?.name || b.demographic?.name ? { name: { ...a.demographic?.name, ...b.demographic?.name } } : {}),
|
|
49
|
+
},
|
|
50
|
+
contact: {
|
|
51
|
+
...a.contact,
|
|
52
|
+
...b.contact,
|
|
53
|
+
...(a.contact?.address || b.contact?.address ? { address: { ...a.contact?.address, ...b.contact?.address } } : {}),
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const knownOf = ({ demographic, contact, preferredPharmacy }) => ({
|
|
57
|
+
demographic,
|
|
58
|
+
contact,
|
|
59
|
+
preferredPharmacy,
|
|
60
|
+
});
|
|
61
|
+
const clinicalIds = (p) => new Set([...(p?.clinical?.allergies ?? []), ...(p?.clinical?.medications ?? []), ...(p?.clinical?.diagnoses ?? [])].map((e) => e.id));
|
|
62
|
+
/**
|
|
63
|
+
* A patient — from an id, from a record the host has, or not yet known. `sync({ demographic, contact })` sends what
|
|
64
|
+
* you know, and the server decides — the patient (found, or created when nothing matches and it has enough),
|
|
65
|
+
* candidates (pick one), or nothing yet (`changes` says what's missing). Keep adding what you know until it
|
|
66
|
+
* has an id; then `update(fields)` changes that patient. The client never decides "now create".
|
|
67
|
+
*
|
|
68
|
+
* Sync what's been committed (a field the prescriber left), not every keystroke: a sync with enough to
|
|
69
|
+
* create can create. While they type, `search` — it only lists who it might be.
|
|
70
|
+
*/
|
|
71
|
+
export class Patient extends LiveRecord {
|
|
72
|
+
#ctx;
|
|
73
|
+
/** Everything synced so far, before the record — each sync adds to it. */
|
|
74
|
+
#known = {};
|
|
75
|
+
#lastQuery = null;
|
|
76
|
+
/** The search in flight: any newer query aborts it. */
|
|
77
|
+
#searching = null;
|
|
78
|
+
/** The last clinical patch — what a choice's path applies to. */
|
|
79
|
+
#lastClinical = {};
|
|
80
|
+
#declared = new Set();
|
|
81
|
+
/**
|
|
82
|
+
* Lists recorded as "none" here: their record says `[]`, not null (not recorded). network-api can't read a
|
|
83
|
+
* "none" back for these yet — so only this object knows, until an entry is added to the list.
|
|
84
|
+
*/
|
|
85
|
+
#none = new Set();
|
|
86
|
+
constructor(ctx, record, changes) {
|
|
87
|
+
super(record, { candidates: [], pickedNames: {} }, changes);
|
|
88
|
+
this.#ctx = ctx;
|
|
89
|
+
}
|
|
90
|
+
onRecord() {
|
|
91
|
+
this.#ctx.register(this);
|
|
92
|
+
}
|
|
93
|
+
settle(state, changes) {
|
|
94
|
+
super.settle(state && this.#withNone(state), changes);
|
|
95
|
+
}
|
|
96
|
+
adopt(state, changes) {
|
|
97
|
+
super.adopt(this.#withNone(state), changes);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What's been sent to find or add the patient, before the record — e.g. a host's details the server hasn't
|
|
101
|
+
* matched yet (not enough to add them). A form starts from it.
|
|
102
|
+
*/
|
|
103
|
+
get known() {
|
|
104
|
+
return this.#known;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* SyncPatient: send what's known. Before a record it's added to what was sent before, and the server finds,
|
|
108
|
+
* lists candidates, says what's missing, or creates. With a record, the server syncs these fields to it.
|
|
109
|
+
*/
|
|
110
|
+
sync(input) {
|
|
111
|
+
if (this.id)
|
|
112
|
+
return Object.values(input).some(Boolean)
|
|
113
|
+
? this.#write("sync", input)
|
|
114
|
+
: Promise.resolve({ changes: this.changes });
|
|
115
|
+
if (input.clinical)
|
|
116
|
+
return Promise.reject(new PhotonError("invalid", "Clinical changes need the patient's id: sync them first."));
|
|
117
|
+
return this.#match(knownOf(input));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* UpdatePatient: change this patient — only what's given: demographics, contact, benefits, preferred pharmacy
|
|
121
|
+
* and/or clinical lists (`{ allergies: { add: [{ name }] } }`, `{ allergies: { none: true } }` for no known
|
|
122
|
+
* allergies). Needs its id.
|
|
123
|
+
*/
|
|
124
|
+
update(input) {
|
|
125
|
+
if (!this.id)
|
|
126
|
+
return Promise.reject(new PhotonError("invalid", "update() needs the patient's id; until it has one, sync()."));
|
|
127
|
+
return this.#write("update", input);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Type-ahead, before the record: who it might be, from what's known plus what's being typed (not kept —
|
|
131
|
+
* `sync` commits). Sent without sex, so it can never add anyone (network-api adds a patient only with first,
|
|
132
|
+
* last, date of birth and sex), and what it finds is only listed in `candidates` — even a sure match is the
|
|
133
|
+
* prescriber's pick mid-typing. A newer search or sync aborts one in flight; the same query isn't sent twice.
|
|
134
|
+
*/
|
|
135
|
+
search(input) {
|
|
136
|
+
if (this.id)
|
|
137
|
+
return Promise.resolve({ changes: this.changes });
|
|
138
|
+
const { demographic: { sex: _, ...demographic } = {}, contact } = cleanKnown(mergeKnown(this.#known, knownOf(input)));
|
|
139
|
+
const query = { ...(nonEmpty(demographic) ? { demographic } : {}), ...(contact ? { contact } : {}) };
|
|
140
|
+
const key = JSON.stringify(query);
|
|
141
|
+
if (!Object.keys(query).length || key === this.#lastQuery)
|
|
142
|
+
return Promise.resolve({ changes: this.changes });
|
|
143
|
+
this.#lastQuery = key;
|
|
144
|
+
this.#searching?.abort();
|
|
145
|
+
const search = new AbortController();
|
|
146
|
+
this.#searching = search;
|
|
147
|
+
return this.run("loading", async () => {
|
|
148
|
+
if (key !== this.#lastQuery || this.id)
|
|
149
|
+
return { changes: this.changes };
|
|
150
|
+
let outcome;
|
|
151
|
+
try {
|
|
152
|
+
outcome = await syncPatient(this.#ctx.client, query, search.signal);
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
if (search.signal.aborted)
|
|
156
|
+
return { changes: this.changes }; // a newer query answers instead
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
if (key !== this.#lastQuery || this.id)
|
|
160
|
+
return { changes: this.changes };
|
|
161
|
+
const found = outcome.kind === "ambiguous"
|
|
162
|
+
? outcome.candidates.map((c) => ({ ...c }))
|
|
163
|
+
: outcome.patient
|
|
164
|
+
? [candidateOf(toPatient(outcome.patient))]
|
|
165
|
+
: [];
|
|
166
|
+
this.patch({ candidates: found });
|
|
167
|
+
return { changes: this.changes };
|
|
168
|
+
}).finally(() => {
|
|
169
|
+
if (this.#searching === search)
|
|
170
|
+
this.#searching = null;
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
/** One of `candidates`: read it, and this becomes that patient. Phone / email sent to find them fill gaps on it. */
|
|
174
|
+
pick(candidateId) {
|
|
175
|
+
return this.run("loading", async () => {
|
|
176
|
+
const result = this.#settle(await getPatient(this.#ctx.client, candidateId));
|
|
177
|
+
this.patch({ candidates: [] });
|
|
178
|
+
return result;
|
|
179
|
+
}).then((result) => this.#fillMissingContact(result));
|
|
180
|
+
}
|
|
181
|
+
/** A choice the server asked for (e.g. which penicillin): sent again with the pick applied to the last patch. */
|
|
182
|
+
choose(option) {
|
|
183
|
+
if (option.operation === "patient" && /^(demographic|contact|benefits|preferredPharmacy)\./.test(option.path ?? ""))
|
|
184
|
+
return this.update(withChoice({}, option));
|
|
185
|
+
if (option.id && option.displayName)
|
|
186
|
+
this.patch({ pickedNames: { ...this.snapshot.pickedNames, [option.id]: option.displayName } });
|
|
187
|
+
const rooted = option.path?.startsWith("clinical.");
|
|
188
|
+
const clinical = rooted
|
|
189
|
+
? (withChoice({ clinical: this.#lastClinical }, option).clinical ?? {})
|
|
190
|
+
: withChoice(this.#lastClinical, option);
|
|
191
|
+
return this.update({ clinical });
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The Photon Rx app's link to this patient (`/patient/<id>`); `ph.url(this)`. Refused before the record: there's
|
|
195
|
+
* no id to link to, and a link never carries their details.
|
|
196
|
+
*/
|
|
197
|
+
url() {
|
|
198
|
+
return this.#ctx.url(this);
|
|
199
|
+
}
|
|
200
|
+
/** The same, embeddable in an iframe; `ph.frame(this)`. */
|
|
201
|
+
frame() {
|
|
202
|
+
return this.#ctx.frame(this);
|
|
203
|
+
}
|
|
204
|
+
/** Read it again. */
|
|
205
|
+
reload() {
|
|
206
|
+
if (!this.id)
|
|
207
|
+
return Promise.resolve({ changes: this.changes });
|
|
208
|
+
return this.run("loading", async () => this.#settle(await getPatient(this.#ctx.client, this.id)));
|
|
209
|
+
}
|
|
210
|
+
#write(kind, input) {
|
|
211
|
+
return this.run("saving", async () => {
|
|
212
|
+
const id = this.id;
|
|
213
|
+
const before = clinicalIds(this.state);
|
|
214
|
+
if (input.clinical)
|
|
215
|
+
this.#lastClinical = input.clinical;
|
|
216
|
+
const outcome = kind === "sync"
|
|
217
|
+
? await syncPatient(this.#ctx.client, { id, ...input })
|
|
218
|
+
: await updatePatient(this.#ctx.client, id, input);
|
|
219
|
+
this.#noteNone(input);
|
|
220
|
+
const result = this.#settle(outcome);
|
|
221
|
+
if (input.clinical)
|
|
222
|
+
this.#nameNewEntries(input.clinical, before);
|
|
223
|
+
return result;
|
|
224
|
+
}).then((result) => this.#takeDeclared(result));
|
|
225
|
+
}
|
|
226
|
+
#match(known) {
|
|
227
|
+
this.#known = mergeKnown(this.#known, known);
|
|
228
|
+
const query = cleanKnown(this.#known);
|
|
229
|
+
if (!Object.keys(query).length)
|
|
230
|
+
return Promise.resolve({ changes: this.changes });
|
|
231
|
+
const key = JSON.stringify(query);
|
|
232
|
+
// The same query gets the same answer: keep it (blur and a debounce often ask twice).
|
|
233
|
+
if (key === this.#lastQuery)
|
|
234
|
+
return Promise.resolve({ changes: this.changes });
|
|
235
|
+
this.#lastQuery = key;
|
|
236
|
+
this.#searching?.abort();
|
|
237
|
+
return this.run("loading", async () => {
|
|
238
|
+
// A newer query was made while this one waited: it answers instead.
|
|
239
|
+
if (key !== this.#lastQuery || this.id)
|
|
240
|
+
return { changes: this.changes };
|
|
241
|
+
const outcome = await syncPatient(this.#ctx.client, query);
|
|
242
|
+
// Answered after a newer query was made: only a patient found (or added) still counts.
|
|
243
|
+
if (key !== this.#lastQuery && !(outcome.kind === "ok" && outcome.patient))
|
|
244
|
+
return { changes: this.changes };
|
|
245
|
+
if (outcome.kind === "ambiguous") {
|
|
246
|
+
this.patch({ candidates: outcome.candidates.map((c) => ({ ...c })), changes: noChanges });
|
|
247
|
+
return { changes: noChanges };
|
|
248
|
+
}
|
|
249
|
+
this.patch({ candidates: [] });
|
|
250
|
+
return this.#settle(outcome);
|
|
251
|
+
}).then((result) => this.#fillMissingContact(result));
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Phone / email sent to help find the patient: once a sync or a pick gives the record, save the ones it
|
|
255
|
+
* doesn't have — fill in, never overwrite.
|
|
256
|
+
*/
|
|
257
|
+
async #fillMissingContact(result) {
|
|
258
|
+
if (!this.id || !this.state)
|
|
259
|
+
return result;
|
|
260
|
+
const had = this.state.contact;
|
|
261
|
+
const sent = this.#known.contact;
|
|
262
|
+
const missing = {
|
|
263
|
+
...(sent?.phone && !had?.phone ? { phone: trimmed(sent.phone) } : {}),
|
|
264
|
+
...(sent?.email && !had?.email ? { email: trimmed(sent.email) } : {}),
|
|
265
|
+
};
|
|
266
|
+
this.#known = {};
|
|
267
|
+
return Object.keys(missing).length ? this.update({ contact: missing }) : result;
|
|
268
|
+
}
|
|
269
|
+
/** A choice the server declared (one option, an exact match) or a clinical match it is sure of is taken without asking — once each. */
|
|
270
|
+
#takeDeclared(result) {
|
|
271
|
+
const option = declaredChoice(this.changes) ?? this.#clinicalMatch();
|
|
272
|
+
const key = option && optionKey(option);
|
|
273
|
+
if (!option || !key || this.#declared.has(key))
|
|
274
|
+
return result;
|
|
275
|
+
this.#declared.add(key);
|
|
276
|
+
return this.choose(option);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* An allergy, medication or diagnosis the server is sure of: its only option (a single row), or its one
|
|
280
|
+
* HIGH-confidence option ("callers may auto-resolve when HIGH"). Taken like a declared match.
|
|
281
|
+
*/
|
|
282
|
+
#clinicalMatch() {
|
|
283
|
+
for (const change of choicesIn(this.changes)) {
|
|
284
|
+
if (!/allergies|medications|diagnoses/.test(change.key))
|
|
285
|
+
continue;
|
|
286
|
+
const options = change.options.filter((o) => o.path);
|
|
287
|
+
const high = options.filter((o) => o.matchReasons.some((r) => r.confidence === "HIGH"));
|
|
288
|
+
if (options.length === 1)
|
|
289
|
+
return options[0];
|
|
290
|
+
if (high.length === 1)
|
|
291
|
+
return high[0];
|
|
292
|
+
}
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
/** What a write recorded: "none" for a list, or an entry on it (it isn't "none" any more). */
|
|
296
|
+
#noteNone(input) {
|
|
297
|
+
const patches = {
|
|
298
|
+
medications: input.clinical?.medications,
|
|
299
|
+
diagnoses: input.clinical?.diagnoses,
|
|
300
|
+
benefits: input.benefits,
|
|
301
|
+
};
|
|
302
|
+
for (const [list, patch] of Object.entries(patches)) {
|
|
303
|
+
if (patch?.none)
|
|
304
|
+
this.#none.add(list);
|
|
305
|
+
if (patch?.add?.length)
|
|
306
|
+
this.#none.delete(list);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/** The record with each list recorded as "none" here as `[]` (network-api answers those as nothing on file). */
|
|
310
|
+
#withNone(p) {
|
|
311
|
+
if (!this.#none.size)
|
|
312
|
+
return p;
|
|
313
|
+
const none = (list, name) => list ?? (this.#none.has(name) ? [] : null);
|
|
314
|
+
return {
|
|
315
|
+
...p,
|
|
316
|
+
benefits: none(p.benefits, "benefits"),
|
|
317
|
+
clinical: p.clinical && {
|
|
318
|
+
...p.clinical,
|
|
319
|
+
medications: none(p.clinical.medications, "medications"),
|
|
320
|
+
diagnoses: none(p.clinical.diagnoses, "diagnoses"),
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/** An entry added from typed text can come back with name = id: label the one new entry per list with what was typed. */
|
|
325
|
+
#nameNewEntries(clinical, before) {
|
|
326
|
+
const typed = {
|
|
327
|
+
allergies: clinical.allergies?.add?.[0]?.name,
|
|
328
|
+
medications: clinical.medications?.add?.[0]?.name,
|
|
329
|
+
diagnoses: clinical.diagnoses?.add?.[0]?.name ?? clinical.diagnoses?.add?.[0]?.icd10Code,
|
|
330
|
+
};
|
|
331
|
+
const named = {};
|
|
332
|
+
for (const list of ["allergies", "medications", "diagnoses"]) {
|
|
333
|
+
const text = typed[list];
|
|
334
|
+
const added = (this.state?.clinical?.[list] ?? []).filter((e) => !before.has(e.id) && (!e.name || e.name === e.id));
|
|
335
|
+
if (text && added.length === 1)
|
|
336
|
+
named[added[0].id] = text;
|
|
337
|
+
}
|
|
338
|
+
if (Object.keys(named).length)
|
|
339
|
+
this.patch({ pickedNames: { ...named, ...this.snapshot.pickedNames } });
|
|
340
|
+
}
|
|
341
|
+
#settle(outcome) {
|
|
342
|
+
const changes = outcome.kind === "ok" ? toChanges(outcome.changes) : noChanges;
|
|
343
|
+
this.settle(outcome.kind === "ok" && outcome.patient ? toPatient(outcome.patient) : null, changes);
|
|
344
|
+
return { changes };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
//# sourceMappingURL=patient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patient.js","sourceRoot":"","sources":["../../src/photon/patient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAuB,MAAM,iBAAiB,CAAC;AAE9F,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAsB3D,MAAM,WAAW,GAAG,CAAC,CAAgB,EAAoB,EAAE,CAAC,CAAC;IAC3D,EAAE,EAAE,CAAC,CAAC,EAAE;IACR,SAAS,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,IAAI,EAAE;IAC1C,QAAQ,EAAE,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,IAAI,IAAI;IAC1C,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,WAAW,IAAI,IAAI;CAChD,CAAC,CAAC;AAEH,MAAM,QAAQ,GAAG,CAAC,GAAY,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACnF,MAAM,OAAO,GA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AAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CACvD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CACzD,CAAC;YACF,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;QAC7D,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM;YAAE,IAAI,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACzG,CAAC;IAED,OAAO,CAAC,OAAuB;QAC7B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/E,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACnG,OAAO,EAAE,OAAO,EAAE,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { type NetworkClient } from "../api/index.ts";
|
|
2
|
+
import { type LinkAuth, type PhotonAuth } from "./auth.ts";
|
|
3
|
+
import { type Session } from "./session.ts";
|
|
4
|
+
import { type Analytics, type AnalyticsTarget } from "./analytics.ts";
|
|
5
|
+
import { type EnvironmentUrls, type PhotonEnvironment } from "./environments.ts";
|
|
6
|
+
import { type FlowLink } from "./links.ts";
|
|
7
|
+
import { Order } from "./order.ts";
|
|
8
|
+
import { Patient } from "./patient.ts";
|
|
9
|
+
import { Prescription } from "./prescription.ts";
|
|
10
|
+
import type { Changes, OrderCandidate, OrderInput, OrdersInput, OrdersResult, PatientCandidate, PatientInput, PrescriptionCandidate, PrescriptionEdits, PrescriptionInput } from "./types.ts";
|
|
11
|
+
export { Order, Patient, Prescription };
|
|
12
|
+
/**
|
|
13
|
+
* Each call returns the live object. Without an id it always does — with its record when the server settled
|
|
14
|
+
* on one (found, created or updated), or still without one (`id: null`): then `candidates` says who it might
|
|
15
|
+
* be, or `changes` what's missing, and the object carries the same. `null` only for an id with no record.
|
|
16
|
+
*/
|
|
17
|
+
export interface PatientResult {
|
|
18
|
+
patient: Patient | null;
|
|
19
|
+
/** When the server isn't certain: who it might be (even one). Pick with `patient.pick(id)`. */
|
|
20
|
+
candidates: PatientCandidate[];
|
|
21
|
+
changes: Changes;
|
|
22
|
+
}
|
|
23
|
+
export interface PrescriptionResult {
|
|
24
|
+
prescription: Prescription | null;
|
|
25
|
+
/** The patient's in-progress prescriptions of this drug it could continue (`prescription.continueDraft(id)`). */
|
|
26
|
+
candidates: PrescriptionCandidate[];
|
|
27
|
+
changes: Changes;
|
|
28
|
+
}
|
|
29
|
+
export interface OrderResult {
|
|
30
|
+
order: Order | null;
|
|
31
|
+
/** The patient's draft orders it could be: open one with `ph.order({ id })`. */
|
|
32
|
+
candidates: OrderCandidate[];
|
|
33
|
+
changes: Changes;
|
|
34
|
+
}
|
|
35
|
+
/** Any live object, and its snapshot — for code that handles all three (an inspector, a logger). */
|
|
36
|
+
export type LiveObject = Patient | Prescription | Order;
|
|
37
|
+
export type PatientSnapshot = Patient["snapshot"];
|
|
38
|
+
export type PrescriptionSnapshot = Prescription["snapshot"];
|
|
39
|
+
export type OrderSnapshot = Order["snapshot"];
|
|
40
|
+
export type AnySnapshot = PatientSnapshot | PrescriptionSnapshot | OrderSnapshot;
|
|
41
|
+
export interface PhotonOptions {
|
|
42
|
+
/** Which Photon environment: every URL is inferred from it. Or pass `url`. */
|
|
43
|
+
environment?: PhotonEnvironment;
|
|
44
|
+
/** network-api's GraphQL endpoint, when not inferred from `environment`. */
|
|
45
|
+
url?: string;
|
|
46
|
+
auth: PhotonAuth;
|
|
47
|
+
/** How this caller is surfaced to network-api. Embeds: EMBEDDABLE_COMPONENT. */
|
|
48
|
+
source?: "WEB_APP" | "EMBEDDABLE_COMPONENT" | "DIRECT_API" | "LLM_AGENT" | "MCP_CONNECTOR";
|
|
49
|
+
/** Prefix for each request's client name ("photon-rx/SyncPatient"). */
|
|
50
|
+
clientName?: string;
|
|
51
|
+
sourceVersion?: string;
|
|
52
|
+
fetch?: typeof fetch;
|
|
53
|
+
/**
|
|
54
|
+
* Where the Photon Rx app is: `url()` and `frame()` links start with it. Unless said, the environment's
|
|
55
|
+
* (`rx.new` in production, `rx.<env>.health` otherwise); the app itself passes its own origin, so its links follow
|
|
56
|
+
* the domain it's served from. Without either (no `environment`), they're paths (`/order/…`).
|
|
57
|
+
*/
|
|
58
|
+
appUrl?: string;
|
|
59
|
+
/**
|
|
60
|
+
* The Photon organization (`org_…`) this instance is for, when the host knows it: `url()` and `frame()` links
|
|
61
|
+
* carry it, so the page they open signs straight in to it (no organization picker). An M2M client's is its
|
|
62
|
+
* `organizationId`.
|
|
63
|
+
*/
|
|
64
|
+
organization?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Turns analytics off: `ph.analytics` is null and nothing is sent. Analytics is on by default — prescribing events
|
|
67
|
+
* go to Photon's analytics-api with the prescriber's token (never for M2M, never PHI).
|
|
68
|
+
*/
|
|
69
|
+
disableAnalytics?: boolean;
|
|
70
|
+
}
|
|
71
|
+
/** Link to a flow: a live object (its record), or what a flow is given. `.parse(href)` reads a link back. */
|
|
72
|
+
export interface LinkTo {
|
|
73
|
+
(target: LiveObject | FlowLink): string;
|
|
74
|
+
/** What an app link holds — the flow and what it's given — or null if it isn't one. */
|
|
75
|
+
parse(href: string): FlowLink | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* One mutation's calls — the same three for each. `get` reads by id and changes nothing; `sync` sends whatever's
|
|
79
|
+
* known, an id or not, and the server finds, matches, creates or updates; `update` changes that one record.
|
|
80
|
+
* Calling it with an input is `sync`; with nothing, it's a new object before its record.
|
|
81
|
+
*/
|
|
82
|
+
export interface Calls<T, Input, Fields, Result> {
|
|
83
|
+
(): T;
|
|
84
|
+
(input: Input): Promise<Result>;
|
|
85
|
+
/** Id only: the object for that record, or null when there's none. Changes nothing. */
|
|
86
|
+
get(id: string): Promise<T | null>;
|
|
87
|
+
/** What's known — with an id or without: the server decides what it means. */
|
|
88
|
+
sync(input: Input): Promise<Result>;
|
|
89
|
+
/** That one record, by id: only the fields given change. */
|
|
90
|
+
update(id: string, fields: Fields): Promise<Result>;
|
|
91
|
+
/**
|
|
92
|
+
* The app's link to this flow, given Photon ids only: a record's (`"pat_…"` or `{ id }` → `/<flow>/<id>`), or a
|
|
93
|
+
* new one's (`{ templateId, patient: { id } }` → `/<flow>?patient=…&template=…`). Anything else — a patient's
|
|
94
|
+
* details, a drug's name, a sig — is refused: sync first, then link by id. Nothing is read or written.
|
|
95
|
+
*/
|
|
96
|
+
url(given?: Input | string): string;
|
|
97
|
+
/**
|
|
98
|
+
* The same, embeddable (`/<flow>/embed/…`): an iframe's `src`, signing the prescriber in with this instance's
|
|
99
|
+
* client id (`auth: { clientId }`). Throws without one, and for an M2M client.
|
|
100
|
+
*/
|
|
101
|
+
frame(given?: Input | string): string;
|
|
102
|
+
}
|
|
103
|
+
export interface Photon {
|
|
104
|
+
/** The environment's URLs, when created from one. */
|
|
105
|
+
readonly environment: EnvironmentUrls | null;
|
|
106
|
+
/**
|
|
107
|
+
* Photon's analytics, as the signed-in prescriber: `ph.analytics.track(event, properties)`. Null for M2M, without
|
|
108
|
+
* an `environment`, or with `disableAnalytics`.
|
|
109
|
+
*/
|
|
110
|
+
readonly analytics: Analytics | null;
|
|
111
|
+
/**
|
|
112
|
+
* Patients. `sync({ demographic })` finds the patient, lists candidates, says what's missing, or creates one
|
|
113
|
+
* when nothing matches and it has enough. `ph.patient()`: a new patient to `sync` as the prescriber types.
|
|
114
|
+
*/
|
|
115
|
+
readonly patient: Calls<Patient, PatientInput, Omit<PatientInput, "id">, PatientResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Prescriptions. `sync` without a patient is a drug lookup — the choices come back in `changes`; nothing is
|
|
118
|
+
* created. With a patient: created (or their in-progress one continued) once the drug is resolved. A signed
|
|
119
|
+
* prescription is final. `ph.prescription()`: a new line.
|
|
120
|
+
*/
|
|
121
|
+
readonly prescription: Calls<Prescription, PrescriptionInput, PrescriptionEdits, PrescriptionResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Orders. `sync({ patient, prescriptions })` saves the patient's draft order (or a new one) once the patient
|
|
124
|
+
* and a prescription have records. `ph.order()`: a new order to fill with `sync` (live objects, ids, or
|
|
125
|
+
* `{ templateId }` for a new line); its draft saves as it goes.
|
|
126
|
+
*/
|
|
127
|
+
readonly order: Calls<Order, OrderInput, Omit<OrderInput, "id" | "patient">, OrderResult>;
|
|
128
|
+
/** Read-only order snapshots and optional pharmacy choices. No live objects are opened or updated. */
|
|
129
|
+
orders(input?: OrdersInput): Promise<OrdersResult>;
|
|
130
|
+
/**
|
|
131
|
+
* network-api's health check: resolves once it's reachable and accepts this instance's token. Throws
|
|
132
|
+
* `PhotonError` — `unauthorized` (a token it won't take), `network` (unreachable, or `getToken` threw),
|
|
133
|
+
* `upstream`. Changes nothing.
|
|
134
|
+
*/
|
|
135
|
+
ping(): Promise<void>;
|
|
136
|
+
me(): Promise<Caller>;
|
|
137
|
+
/**
|
|
138
|
+
* The prescriber's sign-in, when core runs it (`auth: { clientId }`): a live object — `status`, `user`,
|
|
139
|
+
* `start()`, `signIn()`. Null when the host signs in (`auth: { getToken }`).
|
|
140
|
+
*/
|
|
141
|
+
readonly session: Session | null;
|
|
142
|
+
/**
|
|
143
|
+
* The Photon Rx app's link to a flow, to share — Photon ids only, in the clear: `/<flow>/<id>`, or
|
|
144
|
+
* `/<flow>?patient=…&template=…` (see links.ts) — on the app (`appUrl`, or the environment's). No client id: the
|
|
145
|
+
* app signs in with its own. A live object's: its record's id; before one, the ids it hangs off (a patient
|
|
146
|
+
* without a record is refused).
|
|
147
|
+
*/
|
|
148
|
+
readonly url: LinkTo;
|
|
149
|
+
/**
|
|
150
|
+
* The same, embeddable — `/<flow>/embed/…`, always zero chrome — for an iframe's `src`. The embed signs the
|
|
151
|
+
* prescriber in with the host's client id — the link's `auth.clientId`, or this instance's `{ clientId }` — and
|
|
152
|
+
* works only with one. Throws without one, and for an M2M client. Links carry no secret, ever.
|
|
153
|
+
*/
|
|
154
|
+
readonly frame: LinkTo;
|
|
155
|
+
}
|
|
156
|
+
export interface CallerName {
|
|
157
|
+
first: string | null;
|
|
158
|
+
last: string | null;
|
|
159
|
+
}
|
|
160
|
+
export interface CallerOrganization {
|
|
161
|
+
id: string;
|
|
162
|
+
name: string;
|
|
163
|
+
}
|
|
164
|
+
export type Caller = {
|
|
165
|
+
type: "user";
|
|
166
|
+
id: string;
|
|
167
|
+
name: CallerName;
|
|
168
|
+
organization: CallerOrganization | null;
|
|
169
|
+
permissions: string[];
|
|
170
|
+
} | {
|
|
171
|
+
type: "patient";
|
|
172
|
+
id: string;
|
|
173
|
+
name: CallerName;
|
|
174
|
+
} | {
|
|
175
|
+
type: "machine";
|
|
176
|
+
organization: CallerOrganization | null;
|
|
177
|
+
permissions: string[];
|
|
178
|
+
};
|
|
179
|
+
export declare const clientOf: (ph: Photon) => NetworkClient;
|
|
180
|
+
export declare function photon(options: PhotonOptions): Photon;
|
|
181
|
+
/** A photon instance over an existing client (tests, and internal use). */
|
|
182
|
+
export declare function photonOver(client: NetworkClient, environment?: EnvironmentUrls | null, options?: {
|
|
183
|
+
appUrl?: string;
|
|
184
|
+
session?: Session | null;
|
|
185
|
+
linkAuth?: LinkAuth;
|
|
186
|
+
analytics?: AnalyticsTarget | null;
|
|
187
|
+
}): Photon;
|
|
188
|
+
//# sourceMappingURL=photon.d.ts.map
|