Skip to main content
@photon-rx/core sits underneath Prescribe. It handles the prescriber’s sign-in and tokens, calls the API, and enforces the workflow rules: which drug was meant, when a draft is created, and when an order is ready to send. Use it when you’re building your own UI in another framework, or when your backend wants typed calls. It has no dependencies and runs in browsers and Node.
⚠️ Not published to npm yet.

Create a client

With clientId, ph.session handles sign-in: start() on load, signIn() from a click, and signOut(). Its status and user show who is signed in. Create one client per signed-in person. On a server, that means one per request, never one shared module-wide.

Get, sync, update

ph.patient, ph.prescription and ph.order each have the same three calls:
sync and update return the live object, any candidates when Photon isn’t sure which record you meant, and the changes it reported. The client never picks a candidate for you. Pick one with patient.pick(id).

Live objects

Each record is a live object. state is the record, and status is idle, loading, saving or error. subscribe calls you on every change, and every method waits for the call it makes. There’s one object per record per client, so a patient opened twice is the same object.
The rules live in the objects, so every UI built on them behaves the same:
  • A new prescription without a patient only looks the drug up and never creates anything.
  • The newest response always wins, so a slow early reply can’t overwrite a later one.
  • rx.sign() waits for saves in flight, then signs only what’s stored.
  • order.readyToSend is true once the patient is found, every prescription is signed, and nothing is still saving.
  • order.submit() refuses until it’s ready, and never sets a pharmacy.

Choices

When Photon offers options, such as which of several drugs a name meant, choicesIn(obj.changes) lists them. obj.choose(option) applies one.

Errors

Anything Photon answers about your data comes back as a result. Only failures that different data can’t fix throw a PhotonError, and its kind says which: ph.url(…) and ph.frame(…) build deep links and iframe URLs. linkPath(…) builds the same paths without a client.