Skip to content

Commit

Permalink
Merge pull request #17 from wellsync/refactor/patient-preference
Browse files Browse the repository at this point in the history
feat: select prescription based on preference
  • Loading branch information
jeroenrinzema authored Jan 16, 2025
2 parents 28ca112 + 65c33e2 commit 40496d1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ new PharmacyOrder("#order", "super-secret-key", {
clinician: "...",
privateKey: "...",
patient: "...",
drug: "...", // optional
drugs: {
message: "The medication was chosen based on the patient’s preference",
selected: ["..."],
}, // optional
});
```
19 changes: 17 additions & 2 deletions public/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
const widget = new URL("https://pharmacy.js.wellsync.io");

widget.searchParams.append("session", session);
widget.searchParams.append("case", options.case);
widget.searchParams.append("clinic", options.clinic);
widget.searchParams.append("clinician", options.clinician);
widget.searchParams.append("patient", options.patient);
Expand All @@ -39,8 +40,22 @@
widget.searchParams.append("environment", options.environment);
}

if (options.drug) {
widget.searchParams.append("drug", options.drug);
if (
options.drugs &&
typeof options.drugs === "object" &&
!Array.isArray(options.drugs)
) {
if (options.drugs.message) {
widget.searchParams.append("drugs.message", options.drugs.message);
}

if (Array.isArray(options.drugs)) {
if (options.drugs.length > 1) {
throw new Error("we only support one drug at the moment");
}

widget.searchParams.append("drugs.selected", options.drugs.join(","));
}
}

this._iframe = document.createElement("iframe");
Expand Down
12 changes: 10 additions & 2 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<script lang="ts">
const params = new URLSearchParams(window.location.search);
const caseId = params.get("case") || "";
const patient = params.get("patient") || "";
const clinician = params.get("clinician") || "";
const drug = params.get("drug") || "";
const drugs = {
message:
params.get("drugs.message") ||
"The medication was chosen based on the patient’s preference",
selected: (params.get("drugs.selected") || "").split(","),
};
import "@iframe-resizer/child";
Expand All @@ -23,9 +30,10 @@
</section>

<Prescription
{caseId}
patientId={patient}
clinicianId={clinician}
preferredDrugId={drug}
preferredDrugs={drugs}
/>
</form>
</main>
Expand Down
23 changes: 15 additions & 8 deletions src/components/Prescription.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@
import Empty from "./Empty.svelte";
import { signData } from "../lib/crypto";
export let caseId: string;
export let patientId: string;
export let clinicianId: string;
export let preferredDrugId: string = "";
type PreferredDrugs = {
message: string;
selected: string[];
};
// NOTE: we only support a single drug selection at the moment
export let preferredDrugs: PreferredDrugs;
let loading = false;
let submitted = false;
let drugs: Drug[] = [];
let dosages: Dosage[] = [];
let selectedDrugId: string = preferredDrugId ?? null;
console.log(preferredDrugs.message);
let selectedDrugId: string = preferredDrugs?.selected[0] ?? null;
let selectedDosageConcentration: string;
let prescriptionDirections: string;
let pharmacy: Pharmacy | null;
Expand All @@ -34,7 +44,7 @@
async function load() {
drugs = (await getDrugs(patientId)) || [];
if (!preferredDrugId) {
if (!preferredDrugs.selected) {
selectedDrugId = drugs[0].id!;
}
Expand Down Expand Up @@ -99,10 +109,8 @@
<section>
{#if !submitted}
<Header title="Prescription">
{#if preferredDrugId}
<Alert
message="The medication was chosen based on the patient’s preference and cannot be changed"
/>
{#if preferredDrugs}
<Alert message={preferredDrugs.message} />
{/if}
</Header>

Expand All @@ -113,7 +121,6 @@
</label>
<div class="mt-2 grid grid-cols-1">
<Select
disabled={preferredDrugId != ""}
options={drugOptions}
bind:value={selectedDrugId}
on:change={fetchPharmacy}
Expand Down

0 comments on commit 40496d1

Please sign in to comment.