@mindbill/react 0.52.1 → 0.53.1

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/dist/index.js CHANGED
@@ -348,7 +348,7 @@ function organizationProfileOptions(profile) {
348
348
 
349
349
  // src/index.tsx
350
350
  import "@mindbill/embed";
351
- import { createElement, useEffect as useEffect16, useRef as useRef11 } from "react";
351
+ import { createElement, useEffect as useEffect16, useRef as useRef12 } from "react";
352
352
 
353
353
  // src/native-bill-review.tsx
354
354
  import { sanitizeBillReviewSaveInput } from "@mindbill/browser";
@@ -6980,6 +6980,15 @@ function billTeamNotes(data) {
6980
6980
  const legacy = (data.history ?? []).filter((entry) => entry.kind === "note" && !canonicalIds.has(entry.id) && !notes.some((note) => entry.id.endsWith(`:ev-${note.id}`)));
6981
6981
  return [...legacy, ...notes.map((note) => ({ id: note.id, summary: note.body, actor: note.author, date: note.createdAt }))].sort((left, right) => right.date.localeCompare(left.date));
6982
6982
  }
6983
+ function billLifecycleSubmissionSelection(data, selectedSubmissionId) {
6984
+ const mappedRibbonItems = billSubmissionsRibbonFromHistory(data.history ?? [], data.attempts);
6985
+ const activeSubmissionId = (mappedRibbonItems.some((item) => item.id === selectedSubmissionId) ? selectedSubmissionId : null) ?? mappedRibbonItems.find((item) => item.active)?.id ?? mappedRibbonItems[mappedRibbonItems.length - 1]?.id;
6986
+ const ribbonItems = mappedRibbonItems.map((item) => ({ ...item, active: item.id === activeSubmissionId }));
6987
+ const selectedAttempt = data.attempts?.find((attempt) => attempt.id === activeSubmissionId);
6988
+ const historical = selectedAttempt ? !selectedAttempt.isCurrent : !!activeSubmissionId && activeSubmissionId !== mappedRibbonItems.at(-1)?.id;
6989
+ const selectedDetail = selectedAttempt ? data.submissionDetails?.find((item) => item.attemptId === activeSubmissionId && item.billId === selectedAttempt.billId) : null;
6990
+ return { activeSubmissionId, ribbonItems, selectedAttempt, historical, selectedDetail };
6991
+ }
6983
6992
  function reservePreviewWindow() {
6984
6993
  const preview = window.open("about:blank", "_blank");
6985
6994
  if (preview) {
@@ -7560,12 +7569,7 @@ function ConnectedBillLifecycle({ appearance, actorName, claimsAdministratorHint
7560
7569
  const viewEor = data.lifecycle.actions.find((action) => action.id === "view_eor" && action.enabled);
7561
7570
  const supportedActions = /* @__PURE__ */ new Set(["resubmit", "submit_new_bill", "second_review", "independent_bill_review", "post_payment", "close", "reopen", "send_duplicate", "report_bill_status"]);
7562
7571
  const actions = data.lifecycle.actions.filter((action) => action.enabled && supportedActions.has(action.id));
7563
- const mappedRibbonItems = data.history ? billSubmissionsRibbonFromHistory(data.history, data.attempts) : [];
7564
- const activeSubmissionId = (mappedRibbonItems.some((item) => item.id === selectedSubmissionId) ? selectedSubmissionId : null) ?? mappedRibbonItems.find((item) => item.active)?.id ?? mappedRibbonItems[mappedRibbonItems.length - 1]?.id;
7565
- const ribbonItems = mappedRibbonItems.map((item) => ({ ...item, active: item.id === activeSubmissionId }));
7566
- const selectedAttempt = data.attempts?.find((attempt) => attempt.id === activeSubmissionId);
7567
- const historical = selectedAttempt ? !selectedAttempt.isCurrent : !!activeSubmissionId && activeSubmissionId !== mappedRibbonItems.at(-1)?.id;
7568
- const selectedDetail = historical && selectedAttempt ? data.submissionDetails?.find((item) => item.attemptId === activeSubmissionId && item.billId === selectedAttempt.billId) : null;
7572
+ const { activeSubmissionId, ribbonItems, selectedAttempt, historical, selectedDetail } = billLifecycleSubmissionSelection(data, selectedSubmissionId);
7569
7573
  const activePanel = historical ? "" : panel;
7570
7574
  const showSandboxControls = shouldShowSandboxControls(data.environment, sandboxControls) && !historical;
7571
7575
  const simulations = showSandboxControls ? sandboxScenarios(data.lifecycle.state) : [];
@@ -7648,7 +7652,7 @@ function ConnectedBillLifecycle({ appearance, actorName, claimsAdministratorHint
7648
7652
  ] }) : null,
7649
7653
  historical ? /* @__PURE__ */ jsx21("p", { className: "mb-lifecycle-card", children: selectedDetail?.source === "submission_snapshot" ? "Saved as submitted. This previous submission is read-only; payment balances and current actions are shown on the current bill." : displayedData ? "Historical bill record. An exact as-submitted snapshot was not recorded for this older attempt; these are the stored bill values, not a guaranteed copy of the original packet." : "Detailed values were not saved for this historical submission. Select the current submission to see the current bill. We will not substitute current data for this older attempt." }) : null,
7650
7654
  displayedData ? /* @__PURE__ */ jsx21(BillReadOnlyForm, { data: displayedData, ...!historical ? { onOpenAttachment: lifecycle.openAttachment } : {}, ...appearance ? { appearance } : {} }, activeSubmissionId) : null,
7651
- historical && selectedAttempt ? /* @__PURE__ */ jsxs21("section", { className: "mb-lifecycle-card", "aria-label": "Retained submission files", children: [
7655
+ selectedAttempt ? /* @__PURE__ */ jsxs21("section", { className: "mb-lifecycle-card", "aria-label": "Retained submission files", children: [
7652
7656
  /* @__PURE__ */ jsx21("h3", { children: "Retained submission files" }),
7653
7657
  /* @__PURE__ */ jsx21("p", { children: "Exact files saved for this submission. These downloads do not include a regenerated current bill or a later EOR." }),
7654
7658
  selectedDetail?.artifacts?.length ? selectedDetail.artifacts.map((artifact) => /* @__PURE__ */ jsxs21("button", { type: "button", className: "mb-lifecycle-button secondary", onClick: () => void lifecycle.downloadSubmissionArtifact(selectedAttempt.id, artifact.id, artifact.label).catch(() => void 0), children: [
@@ -8401,9 +8405,408 @@ function ConnectedBillingWorkspace({ appearance, className, style, initialView =
8401
8405
  ] });
8402
8406
  }
8403
8407
 
8408
+ // src/dental-draft-editor.tsx
8409
+ import { useState as useState20 } from "react";
8410
+
8411
+ // src/treatment-draft-shared.tsx
8412
+ import { useRef as useRef11, useState as useState19 } from "react";
8413
+ import { jsx as jsx23, jsxs as jsxs23 } from "react/jsx-runtime";
8414
+ function useDraftSave(onSave) {
8415
+ const pending = useRef11(false);
8416
+ const [busy, setBusy] = useState19(false);
8417
+ const [message, setMessage] = useState19("");
8418
+ const [error, setError] = useState19(null);
8419
+ const clear = () => {
8420
+ setMessage("");
8421
+ setError(null);
8422
+ };
8423
+ const save = async (value, failure) => {
8424
+ if (pending.current) return;
8425
+ clear();
8426
+ if (failure) {
8427
+ setError(failure);
8428
+ return;
8429
+ }
8430
+ pending.current = true;
8431
+ setBusy(true);
8432
+ try {
8433
+ await onSave(value);
8434
+ setMessage("Draft saved.");
8435
+ } catch {
8436
+ setError("The draft could not be saved. Review its status before retrying.");
8437
+ } finally {
8438
+ pending.current = false;
8439
+ setBusy(false);
8440
+ }
8441
+ };
8442
+ return { busy, message, error, clear, save };
8443
+ }
8444
+ function TreatmentDraftShell({ title, description, children, appearance, className = "", style }) {
8445
+ return /* @__PURE__ */ jsxs23("section", { className: `mbtd ${className}`.trim(), "aria-label": title, style: { ...mindBillAppearanceStyle(appearance), ...style }, children: [
8446
+ /* @__PURE__ */ jsx23("style", { children: `.mbtd{font:14px/1.5 ui-sans-serif,system-ui,sans-serif;color:var(--mb-text);min-width:0}.mbtd *{box-sizing:border-box}.mbtd h2{font-size:22px;margin:0 0 6px}.mbtd p{margin:6px 0 16px;color:var(--mb-muted)}.mbtd form{display:grid;gap:16px}.mbtd fieldset{margin:0;padding:16px;border:1px solid var(--mb-border);border-radius:var(--mb-radius);background:var(--mb-surface);min-width:0}.mbtd legend{font-weight:600;padding:0 6px}.mbtd .mbtd-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.mbtd label{display:grid;gap:5px;font-size:13px;min-width:0}.mbtd input,.mbtd select,.mbtd textarea,.mbtd button{font:inherit;max-width:100%;min-width:0;border:1px solid var(--mb-border);border-radius:var(--mb-control-radius);padding:9px 11px;color:var(--mb-text);background:var(--mb-input);min-height:40px}.mbtd textarea{resize:vertical;min-height:76px}.mbtd button{cursor:pointer;background:var(--mb-surface)}.mbtd button:disabled{opacity:.55;cursor:default}.mbtd .mbtd-primary{background:var(--mb-accent);color:var(--mb-accent-contrast);border-color:var(--mb-accent)}.mbtd .mbtd-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:12px}.mbtd .mbtd-wide{grid-column:1/-1}.mbtd [role=alert]{color:var(--mb-danger)}.mbtd [role=status]{margin:0}.mbtd :is(input,select,textarea,button):focus-visible{outline:2px solid var(--mb-accent);outline-offset:2px}.mbtd .mbtd-note{padding:12px;background:var(--mb-soft);border-radius:var(--mb-control-radius)}.mbtd .mbtd-attribution{font-size:12px;text-align:right}.mbtd a{color:var(--mb-accent)}@media(max-width:520px){.mbtd .mbtd-grid{grid-template-columns:minmax(0,1fr)}.mbtd fieldset{padding:12px}}` }),
8447
+ /* @__PURE__ */ jsx23("h2", { children: title }),
8448
+ /* @__PURE__ */ jsx23("p", { children: description }),
8449
+ children,
8450
+ /* @__PURE__ */ jsx23("p", { className: "mbtd-attribution", children: /* @__PURE__ */ jsx23("a", { href: "https://mindbill.org", target: "_blank", rel: "noopener noreferrer", children: "Powered by MindBill" }) })
8451
+ ] });
8452
+ }
8453
+ function isDraftDate(value) {
8454
+ return /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
8455
+ }
8456
+
8457
+ // src/dental-draft-editor.tsx
8458
+ import { jsx as jsx24, jsxs as jsxs24 } from "react/jsx-runtime";
8459
+ function dentalDraftChargeSummary(lines) {
8460
+ const knownChargeCents = lines.reduce((sum, line) => sum + (line.chargeCents ?? 0), 0);
8461
+ return { knownChargeCents, totalChargeCents: lines.some((line) => line.chargeCents === null) ? null : knownChargeCents };
8462
+ }
8463
+ function parseDentalCharge(value) {
8464
+ if (!value.trim()) return null;
8465
+ if (!/^\d+(?:\.\d{1,2})?$/.test(value)) throw new Error("Enter a positive charge with at most two decimal places, or leave it blank.");
8466
+ const [whole = "0", fraction = ""] = value.split(".");
8467
+ const cents = Number(whole) * 100 + Number(fraction.padEnd(2, "0"));
8468
+ if (!Number.isSafeInteger(cents) || cents < 1 || cents > 1e9) throw new Error("Enter a charge between $0.01 and $10,000,000, or leave it blank.");
8469
+ return cents;
8470
+ }
8471
+ function validateDentalDraftContent(content) {
8472
+ if (!content.renderingProviderId.trim() || content.renderingProviderId.length > 255) return "Choose a rendering provider in the host application.";
8473
+ if (content.billingProviderId != null && (!content.billingProviderId.trim() || content.billingProviderId.length > 255)) return "Choose a valid billing provider in the host application.";
8474
+ if (content.lines.length > 100) return "A draft can contain up to 100 service lines.";
8475
+ if (content.diagnosisCodes.length > 12 || content.diagnosisCodes.some((code) => !code.trim() || code.length > 20)) return "Enter up to 12 diagnosis codes of at most 20 characters each.";
8476
+ if (content.notes !== null && (!content.notes.trim() || content.notes.length > 5e3)) return "Notes must contain between 1 and 5,000 characters.";
8477
+ for (const [index, line] of content.lines.entries()) {
8478
+ const prefix = `Line ${index + 1}: `;
8479
+ if (line.code !== null && !/^D[0-9]{4}$/.test(line.code)) return prefix + "enter D followed by four digits, or leave the code blank.";
8480
+ if (!Number.isInteger(line.quantity) || line.quantity < 1 || line.quantity > 1e5) return prefix + "enter a whole quantity between 1 and 100,000.";
8481
+ if (line.chargeCents !== null && (!Number.isSafeInteger(line.chargeCents) || line.chargeCents < 1 || line.chargeCents > 1e9)) return prefix + "enter a positive extended charge, or leave it unknown.";
8482
+ if (line.serviceDate !== null && !isDraftDate(line.serviceDate)) return prefix + "enter a valid service date.";
8483
+ if (line.editionYear !== null && (!Number.isInteger(line.editionYear) || line.editionYear < 1900 || line.editionYear > 2200)) return prefix + "enter an edition year between 1900 and 2200.";
8484
+ for (const [value, limit] of [[line.description, 1e3], [line.chargeReference, 1e3], [line.oralCavity, 100], [line.prosthesisNotes, 2e3]]) {
8485
+ if (value !== null && (!value.trim() || value.length > limit)) return prefix + `text must contain between 1 and ${limit} characters.`;
8486
+ }
8487
+ if (line.teeth.length > 32 || line.surfaces.length > 10 || [...line.teeth, ...line.surfaces].some((value) => !value.trim() || value.length > 20)) return prefix + "check tooth and surface entries (up to 32 teeth and 10 surfaces, 20 characters each).";
8488
+ }
8489
+ return null;
8490
+ }
8491
+ var blankLine2 = () => ({ code: null, description: null, editionYear: null, serviceDate: null, quantity: 1, chargeCents: null, chargeReference: null, teeth: [], surfaces: [], oralCavity: null, prosthesisNotes: null });
8492
+ var nullable = (value) => value === "" ? null : value;
8493
+ var split = (value) => value.split(",").map((part) => part.trim()).filter(Boolean);
8494
+ var currency2 = (cents) => new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(cents / 100);
8495
+ function DentalDraftEditor({ initialContent, onSave, disabled = false, ...appearance }) {
8496
+ const [content, setContent] = useState20(() => structuredClone(initialContent));
8497
+ const [charges, setCharges] = useState20(() => initialContent.lines.map((line) => line.chargeCents === null ? "" : (line.chargeCents / 100).toFixed(2)));
8498
+ const [diagnoses, setDiagnoses] = useState20(() => initialContent.diagnosisCodes.join(", "));
8499
+ const [teeth, setTeeth] = useState20(() => initialContent.lines.map((line) => line.teeth.join(", ")));
8500
+ const [surfaces, setSurfaces] = useState20(() => initialContent.lines.map((line) => line.surfaces.join(", ")));
8501
+ const action = useDraftSave(onSave);
8502
+ const locked = disabled || action.busy;
8503
+ const updateLine = (index, patch) => {
8504
+ action.clear();
8505
+ setContent((current) => ({ ...current, lines: current.lines.map((line, position) => position === index ? { ...line, ...patch } : line) }));
8506
+ };
8507
+ const parsed = () => ({ ...content, diagnosisCodes: split(diagnoses), lines: content.lines.map((line, index) => ({ ...line, teeth: split(teeth[index] ?? ""), surfaces: split(surfaces[index] ?? ""), chargeCents: parseDentalCharge(charges[index] ?? "") })) });
8508
+ let summary = null;
8509
+ try {
8510
+ summary = dentalDraftChargeSummary(parsed().lines);
8511
+ } catch {
8512
+ }
8513
+ return /* @__PURE__ */ jsxs24(TreatmentDraftShell, { ...appearance, title: "Dental draft", description: "Record dental services, tooth details, and practice charges for review.", children: [
8514
+ /* @__PURE__ */ jsx24("p", { className: "mbtd-note", children: "Codes and prices need review. Saving does not send a dental claim. A blank charge remains unknown." }),
8515
+ /* @__PURE__ */ jsxs24("form", { onSubmit: (event) => {
8516
+ event.preventDefault();
8517
+ if (locked) return;
8518
+ let next;
8519
+ try {
8520
+ next = parsed();
8521
+ } catch {
8522
+ void action.save(content, "Enter positive charges with at most two decimal places, or leave them blank.");
8523
+ return;
8524
+ }
8525
+ void action.save(next, validateDentalDraftContent(next));
8526
+ }, children: [
8527
+ /* @__PURE__ */ jsxs24("fieldset", { disabled: locked, children: [
8528
+ /* @__PURE__ */ jsx24("legend", { children: "Claim details" }),
8529
+ /* @__PURE__ */ jsxs24("div", { className: "mbtd-grid", children: [
8530
+ /* @__PURE__ */ jsxs24("label", { children: [
8531
+ "Diagnosis codes, comma separated",
8532
+ /* @__PURE__ */ jsx24("input", { value: diagnoses, onChange: (event) => {
8533
+ action.clear();
8534
+ setDiagnoses(event.target.value);
8535
+ } })
8536
+ ] }),
8537
+ /* @__PURE__ */ jsxs24("label", { children: [
8538
+ "Notes",
8539
+ /* @__PURE__ */ jsx24("textarea", { maxLength: 5e3, value: content.notes ?? "", onChange: (event) => {
8540
+ action.clear();
8541
+ setContent({ ...content, notes: nullable(event.target.value) });
8542
+ } })
8543
+ ] })
8544
+ ] })
8545
+ ] }),
8546
+ content.lines.map((line, index) => /* @__PURE__ */ jsxs24("fieldset", { disabled: locked, children: [
8547
+ /* @__PURE__ */ jsxs24("legend", { children: [
8548
+ "Service ",
8549
+ index + 1
8550
+ ] }),
8551
+ /* @__PURE__ */ jsxs24("div", { className: "mbtd-grid", children: [
8552
+ /* @__PURE__ */ jsxs24("label", { children: [
8553
+ "Dental code",
8554
+ /* @__PURE__ */ jsx24("input", { placeholder: "D0120", maxLength: 5, value: line.code ?? "", onChange: (event) => updateLine(index, { code: nullable(event.target.value.toUpperCase()) }) })
8555
+ ] }),
8556
+ /* @__PURE__ */ jsxs24("label", { children: [
8557
+ "Code edition year",
8558
+ /* @__PURE__ */ jsx24("input", { type: "number", min: 1900, max: 2200, value: line.editionYear ?? "", onChange: (event) => updateLine(index, { editionYear: event.target.value === "" ? null : Number(event.target.value) }) })
8559
+ ] }),
8560
+ /* @__PURE__ */ jsxs24("label", { children: [
8561
+ "Date of service",
8562
+ /* @__PURE__ */ jsx24("input", { type: "date", value: line.serviceDate ?? "", onChange: (event) => updateLine(index, { serviceDate: nullable(event.target.value) }) })
8563
+ ] }),
8564
+ /* @__PURE__ */ jsxs24("label", { children: [
8565
+ "Quantity",
8566
+ /* @__PURE__ */ jsx24("input", { type: "number", min: 1, max: 1e5, step: 1, value: line.quantity, onChange: (event) => updateLine(index, { quantity: Number(event.target.value) }) })
8567
+ ] }),
8568
+ /* @__PURE__ */ jsxs24("label", { children: [
8569
+ "Extended line charge ($)",
8570
+ /* @__PURE__ */ jsx24("input", { inputMode: "decimal", placeholder: "Unknown", value: charges[index] ?? "", onChange: (event) => {
8571
+ action.clear();
8572
+ setCharges(charges.map((value, position) => position === index ? event.target.value : value));
8573
+ } }),
8574
+ /* @__PURE__ */ jsx24("small", { children: "Includes all units. This is the practice charge, not a fee allowance." })
8575
+ ] }),
8576
+ /* @__PURE__ */ jsxs24("label", { children: [
8577
+ "Charge source / reference",
8578
+ /* @__PURE__ */ jsx24("input", { maxLength: 1e3, value: line.chargeReference ?? "", onChange: (event) => updateLine(index, { chargeReference: nullable(event.target.value) }) })
8579
+ ] }),
8580
+ /* @__PURE__ */ jsxs24("label", { children: [
8581
+ "Teeth, comma separated",
8582
+ /* @__PURE__ */ jsx24("input", { value: teeth[index] ?? "", onChange: (event) => {
8583
+ action.clear();
8584
+ setTeeth(teeth.map((value, position) => position === index ? event.target.value : value));
8585
+ } })
8586
+ ] }),
8587
+ /* @__PURE__ */ jsxs24("label", { children: [
8588
+ "Surfaces, comma separated",
8589
+ /* @__PURE__ */ jsx24("input", { value: surfaces[index] ?? "", onChange: (event) => {
8590
+ action.clear();
8591
+ setSurfaces(surfaces.map((value, position) => position === index ? event.target.value.toUpperCase() : value));
8592
+ } })
8593
+ ] }),
8594
+ /* @__PURE__ */ jsxs24("label", { children: [
8595
+ "Oral cavity",
8596
+ /* @__PURE__ */ jsx24("input", { maxLength: 100, value: line.oralCavity ?? "", onChange: (event) => updateLine(index, { oralCavity: nullable(event.target.value) }) })
8597
+ ] }),
8598
+ /* @__PURE__ */ jsxs24("label", { children: [
8599
+ "Service description",
8600
+ /* @__PURE__ */ jsx24("input", { maxLength: 1e3, value: line.description ?? "", onChange: (event) => updateLine(index, { description: nullable(event.target.value) }) })
8601
+ ] }),
8602
+ /* @__PURE__ */ jsxs24("label", { className: "mbtd-wide", children: [
8603
+ "Prosthesis notes",
8604
+ /* @__PURE__ */ jsx24("textarea", { maxLength: 2e3, value: line.prosthesisNotes ?? "", onChange: (event) => updateLine(index, { prosthesisNotes: nullable(event.target.value) }) })
8605
+ ] })
8606
+ ] }),
8607
+ /* @__PURE__ */ jsx24("div", { className: "mbtd-actions", children: /* @__PURE__ */ jsxs24("button", { type: "button", onClick: () => {
8608
+ action.clear();
8609
+ setContent({ ...content, lines: content.lines.filter((_, position) => position !== index) });
8610
+ setCharges(charges.filter((_, position) => position !== index));
8611
+ setTeeth(teeth.filter((_, position) => position !== index));
8612
+ setSurfaces(surfaces.filter((_, position) => position !== index));
8613
+ }, children: [
8614
+ "Remove service ",
8615
+ index + 1
8616
+ ] }) })
8617
+ ] }, index)),
8618
+ /* @__PURE__ */ jsx24("div", { children: /* @__PURE__ */ jsx24("button", { type: "button", disabled: locked || content.lines.length >= 100, onClick: () => {
8619
+ action.clear();
8620
+ setContent({ ...content, lines: [...content.lines, blankLine2()] });
8621
+ setCharges([...charges, ""]);
8622
+ setTeeth([...teeth, ""]);
8623
+ setSurfaces([...surfaces, ""]);
8624
+ }, children: "Add dental service" }) }),
8625
+ /* @__PURE__ */ jsx24("p", { role: "status", children: summary ? summary.totalChargeCents === null ? `Known charges: ${currency2(summary.knownChargeCents)} \xB7 Total incomplete` : `Total practice charge: ${currency2(summary.totalChargeCents)}` : "Review charge amounts before saving." }),
8626
+ action.error ? /* @__PURE__ */ jsx24("p", { role: "alert", children: action.error }) : null,
8627
+ /* @__PURE__ */ jsxs24("div", { className: "mbtd-actions", children: [
8628
+ /* @__PURE__ */ jsx24("button", { type: "submit", className: "mbtd-primary", disabled: locked, children: action.busy ? "Saving\u2026" : "Save dental draft" }),
8629
+ /* @__PURE__ */ jsx24("p", { role: "status", children: action.message })
8630
+ ] })
8631
+ ] })
8632
+ ] });
8633
+ }
8634
+
8635
+ // src/rfa-draft-form.tsx
8636
+ import { useState as useState21 } from "react";
8637
+ import { jsx as jsx25, jsxs as jsxs25 } from "react/jsx-runtime";
8638
+ function normalizeRfaDraft(draft) {
8639
+ const copy = structuredClone(draft);
8640
+ for (const item of copy.items) {
8641
+ for (const key of ["externalId", "procedureCode", "frequency", "duration", "requestedFrom", "requestedTo"]) {
8642
+ if (item[key] !== void 0 && !item[key]?.trim()) delete item[key];
8643
+ }
8644
+ }
8645
+ delete copy.signedAt;
8646
+ return copy;
8647
+ }
8648
+ function validateRfaDraft(draft) {
8649
+ for (const value of [draft.claimId, draft.patientId, draft.renderingProviderId]) if (!value.trim() || value.length > 255) return "Select a claim, patient, and rendering provider in the host application.";
8650
+ for (const value of [draft.externalId, draft.claimsAdminId]) if (value !== void 0 && (!value.trim() || value.length > 255)) return "Check the request and claims administrator identifiers.";
8651
+ for (const value of [draft.employeeName, draft.providerName]) if (!value.trim() || value.length > 200) return "Employee and provider names are required (up to 200 characters).";
8652
+ if (draft.requestType !== void 0 && !["new", "resubmission_material_change", "oral_authorization_confirmation"].includes(draft.requestType)) return "Choose a valid request type.";
8653
+ if (draft.reviewType !== void 0 && !["prospective", "concurrent", "retrospective"].includes(draft.reviewType)) return "Choose a valid review type.";
8654
+ if (draft.requestType === "resubmission_material_change" && !draft.materialChange?.trim()) return "Describe the material change for this resubmission.";
8655
+ if ((draft.rationale?.length ?? 0) > 2e4 || (draft.materialChange?.length ?? 0) > 2e4) return "Rationale and material change must each be at most 20,000 characters.";
8656
+ if (draft.placeOfServiceCode !== void 0 && !/^\d{2}$/.test(draft.placeOfServiceCode)) return "Place of service must contain two digits.";
8657
+ if ((draft.providerNpi?.length ?? 0) > 20 || (draft.providerPhone?.length ?? 0) > 30 || (draft.claimNumber?.length ?? 0) > 100) return "Check provider contact and claim number lengths.";
8658
+ if (draft.providerFax && (draft.providerFax.length > 30 || !/^[+\d().\s-]+$/.test(draft.providerFax) || !/^\d{10,15}$/.test(draft.providerFax.replace(/\D/g, "")))) return "Enter a return fax with 10 to 15 digits, or leave it blank.";
8659
+ if (draft.dateOfInjury !== void 0 && !isDraftDate(draft.dateOfInjury)) return "Check the injury date in the host application.";
8660
+ if (draft.items.length < 1 || draft.items.length > 100) return "Include between 1 and 100 requested services.";
8661
+ for (const [index, item] of draft.items.entries()) {
8662
+ const prefix = `Service ${index + 1}: `;
8663
+ if (!item.diagnosisCode.trim() || item.diagnosisCode.length > 16 || !item.serviceDescription.trim() || item.serviceDescription.length > 1e3) return prefix + "a diagnosis code and service description are required.";
8664
+ for (const [value, max] of [[item.externalId, 255], [item.procedureCode, 16], [item.frequency, 200], [item.duration, 200]]) if (value !== void 0 && (!value.trim() || value.length > max)) return prefix + `optional text must contain 1 to ${max} characters.`;
8665
+ if (item.units !== void 0 && (!Number.isInteger(item.units) || item.units < 1 || item.units > 1e5)) return prefix + "units must be a whole number between 1 and 100,000.";
8666
+ if (item.quantity !== void 0 && (!Number.isFinite(item.quantity) || item.quantity <= 0 || item.quantity > 1e5)) return prefix + "quantity must be positive and at most 100,000.";
8667
+ if (item.requestedFrom !== void 0 && !isDraftDate(item.requestedFrom) || item.requestedTo !== void 0 && (!isDraftDate(item.requestedTo) || !item.requestedFrom || item.requestedTo < item.requestedFrom)) return prefix + "enter valid dates with the end on or after the start.";
8668
+ }
8669
+ return null;
8670
+ }
8671
+ function RfaDraftForm({ initialDraft, onSave, disabled = false, ...appearance }) {
8672
+ const [draft, setDraft] = useState21(() => normalizeRfaDraft(initialDraft));
8673
+ const action = useDraftSave(onSave), locked = disabled || action.busy;
8674
+ const update = (patch) => {
8675
+ action.clear();
8676
+ setDraft((current) => ({ ...current, ...patch }));
8677
+ };
8678
+ const updateItem = (index, patch) => {
8679
+ action.clear();
8680
+ setDraft((current) => ({ ...current, items: current.items.map((item, position) => position === index ? { ...item, ...patch } : item) }));
8681
+ };
8682
+ const updateNumber = (index, key, value) => {
8683
+ action.clear();
8684
+ setDraft((current) => ({ ...current, items: current.items.map((item, position) => {
8685
+ if (position !== index) return item;
8686
+ const next = { ...item };
8687
+ if (value === "") delete next[key];
8688
+ else next[key] = Number(value);
8689
+ return next;
8690
+ }) }));
8691
+ };
8692
+ return /* @__PURE__ */ jsxs25(TreatmentDraftShell, { ...appearance, title: "Request for authorization", description: "Prepare services and supporting rationale for utilization review.", children: [
8693
+ /* @__PURE__ */ jsx25("p", { className: "mbtd-note", children: "Saving creates an unsigned draft. It does not send the request or authorize treatment." }),
8694
+ /* @__PURE__ */ jsxs25("form", { onSubmit: (event) => {
8695
+ event.preventDefault();
8696
+ if (locked) return;
8697
+ const next = normalizeRfaDraft(draft);
8698
+ void action.save(next, validateRfaDraft(next));
8699
+ }, children: [
8700
+ /* @__PURE__ */ jsxs25("fieldset", { disabled: locked, children: [
8701
+ /* @__PURE__ */ jsx25("legend", { children: "Request details" }),
8702
+ /* @__PURE__ */ jsxs25("div", { className: "mbtd-grid", children: [
8703
+ /* @__PURE__ */ jsxs25("label", { children: [
8704
+ "Employee",
8705
+ /* @__PURE__ */ jsx25("input", { readOnly: true, value: draft.employeeName })
8706
+ ] }),
8707
+ /* @__PURE__ */ jsxs25("label", { children: [
8708
+ "Requesting provider",
8709
+ /* @__PURE__ */ jsx25("input", { readOnly: true, value: draft.providerName })
8710
+ ] }),
8711
+ /* @__PURE__ */ jsxs25("label", { children: [
8712
+ "Request type",
8713
+ /* @__PURE__ */ jsxs25("select", { value: draft.requestType ?? "new", onChange: (event) => update({ requestType: event.target.value }), children: [
8714
+ /* @__PURE__ */ jsx25("option", { value: "new", children: "New request" }),
8715
+ /* @__PURE__ */ jsx25("option", { value: "resubmission_material_change", children: "Resubmission with material change" }),
8716
+ /* @__PURE__ */ jsx25("option", { value: "oral_authorization_confirmation", children: "Confirm oral authorization" })
8717
+ ] })
8718
+ ] }),
8719
+ /* @__PURE__ */ jsxs25("label", { children: [
8720
+ "Review type",
8721
+ /* @__PURE__ */ jsxs25("select", { value: draft.reviewType ?? "prospective", onChange: (event) => update({ reviewType: event.target.value }), children: [
8722
+ /* @__PURE__ */ jsx25("option", { value: "prospective", children: "Prospective \u2014 before treatment" }),
8723
+ /* @__PURE__ */ jsx25("option", { value: "concurrent", children: "Concurrent \u2014 during treatment" }),
8724
+ /* @__PURE__ */ jsx25("option", { value: "retrospective", children: "Retrospective \u2014 after treatment" })
8725
+ ] })
8726
+ ] }),
8727
+ /* @__PURE__ */ jsxs25("label", { children: [
8728
+ "Review priority",
8729
+ /* @__PURE__ */ jsxs25("select", { value: draft.expedited ? "expedited" : "standard", onChange: (event) => update({ expedited: event.target.value === "expedited" }), children: [
8730
+ /* @__PURE__ */ jsx25("option", { value: "standard", children: "Standard" }),
8731
+ /* @__PURE__ */ jsx25("option", { value: "expedited", children: "Expedited review requested" })
8732
+ ] })
8733
+ ] }),
8734
+ /* @__PURE__ */ jsxs25("label", { children: [
8735
+ "Return fax",
8736
+ /* @__PURE__ */ jsx25("input", { maxLength: 30, value: draft.providerFax ?? "", onChange: (event) => update({ providerFax: event.target.value }) }),
8737
+ /* @__PURE__ */ jsx25("small", { children: "Review the return contact. Organization defaults are not applied automatically." })
8738
+ ] }),
8739
+ /* @__PURE__ */ jsxs25("label", { className: "mbtd-wide", children: [
8740
+ "Clinical rationale",
8741
+ /* @__PURE__ */ jsx25("textarea", { maxLength: 2e4, value: draft.rationale ?? "", onChange: (event) => update({ rationale: event.target.value }) })
8742
+ ] }),
8743
+ draft.requestType === "resubmission_material_change" ? /* @__PURE__ */ jsxs25("label", { className: "mbtd-wide", children: [
8744
+ "Material change (required)",
8745
+ /* @__PURE__ */ jsx25("textarea", { required: true, maxLength: 2e4, value: draft.materialChange ?? "", onChange: (event) => update({ materialChange: event.target.value }) })
8746
+ ] }) : null
8747
+ ] })
8748
+ ] }),
8749
+ draft.items.map((item, index) => /* @__PURE__ */ jsxs25("fieldset", { disabled: locked, children: [
8750
+ /* @__PURE__ */ jsxs25("legend", { children: [
8751
+ "Requested service ",
8752
+ index + 1
8753
+ ] }),
8754
+ /* @__PURE__ */ jsxs25("div", { className: "mbtd-grid", children: [
8755
+ /* @__PURE__ */ jsxs25("label", { children: [
8756
+ "Diagnosis code",
8757
+ /* @__PURE__ */ jsx25("input", { required: true, maxLength: 16, value: item.diagnosisCode, onChange: (event) => updateItem(index, { diagnosisCode: event.target.value }) })
8758
+ ] }),
8759
+ /* @__PURE__ */ jsxs25("label", { children: [
8760
+ "Procedure code",
8761
+ /* @__PURE__ */ jsx25("input", { maxLength: 16, value: item.procedureCode ?? "", onChange: (event) => updateItem(index, { procedureCode: event.target.value }) })
8762
+ ] }),
8763
+ /* @__PURE__ */ jsxs25("label", { className: "mbtd-wide", children: [
8764
+ "Service description",
8765
+ /* @__PURE__ */ jsx25("textarea", { required: true, maxLength: 1e3, value: item.serviceDescription, onChange: (event) => updateItem(index, { serviceDescription: event.target.value }) })
8766
+ ] }),
8767
+ /* @__PURE__ */ jsxs25("label", { children: [
8768
+ "Quantity",
8769
+ /* @__PURE__ */ jsx25("input", { type: "number", min: 1e-3, max: 1e5, step: "any", value: item.quantity ?? "", onChange: (event) => updateNumber(index, "quantity", event.target.value) })
8770
+ ] }),
8771
+ /* @__PURE__ */ jsxs25("label", { children: [
8772
+ "Units",
8773
+ /* @__PURE__ */ jsx25("input", { type: "number", min: 1, max: 1e5, step: 1, value: item.units ?? "", onChange: (event) => updateNumber(index, "units", event.target.value) })
8774
+ ] }),
8775
+ /* @__PURE__ */ jsxs25("label", { children: [
8776
+ "Frequency",
8777
+ /* @__PURE__ */ jsx25("input", { maxLength: 200, value: item.frequency ?? "", onChange: (event) => updateItem(index, { frequency: event.target.value }) })
8778
+ ] }),
8779
+ /* @__PURE__ */ jsxs25("label", { children: [
8780
+ "Duration",
8781
+ /* @__PURE__ */ jsx25("input", { maxLength: 200, value: item.duration ?? "", onChange: (event) => updateItem(index, { duration: event.target.value }) })
8782
+ ] }),
8783
+ /* @__PURE__ */ jsxs25("label", { children: [
8784
+ "Requested from",
8785
+ /* @__PURE__ */ jsx25("input", { type: "date", value: item.requestedFrom ?? "", onChange: (event) => updateItem(index, { requestedFrom: event.target.value }) })
8786
+ ] }),
8787
+ /* @__PURE__ */ jsxs25("label", { children: [
8788
+ "Requested through",
8789
+ /* @__PURE__ */ jsx25("input", { type: "date", value: item.requestedTo ?? "", onChange: (event) => updateItem(index, { requestedTo: event.target.value }) })
8790
+ ] })
8791
+ ] }),
8792
+ /* @__PURE__ */ jsxs25("button", { type: "button", disabled: draft.items.length === 1, onClick: () => update({ items: draft.items.filter((_, position) => position !== index) }), children: [
8793
+ "Remove requested service ",
8794
+ index + 1
8795
+ ] })
8796
+ ] }, index)),
8797
+ /* @__PURE__ */ jsx25("div", { children: /* @__PURE__ */ jsx25("button", { type: "button", disabled: locked || draft.items.length >= 100, onClick: () => update({ items: [...draft.items, { diagnosisCode: "", serviceDescription: "" }] }), children: "Add requested service" }) }),
8798
+ action.error ? /* @__PURE__ */ jsx25("p", { role: "alert", children: action.error }) : null,
8799
+ /* @__PURE__ */ jsxs25("div", { className: "mbtd-actions", children: [
8800
+ /* @__PURE__ */ jsx25("button", { type: "submit", className: "mbtd-primary", disabled: locked, children: action.busy ? "Saving\u2026" : "Save RFA draft" }),
8801
+ /* @__PURE__ */ jsx25("p", { role: "status", children: action.message })
8802
+ ] })
8803
+ ] })
8804
+ ] });
8805
+ }
8806
+
8404
8807
  // src/index.tsx
8405
8808
  function widget(tagName, props) {
8406
- const ref = useRef11(null);
8809
+ const ref = useRef12(null);
8407
8810
  const { onMindBill, onMindBillError } = props;
8408
8811
  useEffect16(() => {
8409
8812
  const element = ref.current;
@@ -8492,6 +8895,7 @@ export {
8492
8895
  DEFAULT_BILL_SUBMISSION_MODIFIERS,
8493
8896
  DEFAULT_BILL_SUBMISSION_PROCEDURES,
8494
8897
  DEFAULT_BILL_SUBMISSION_TAXONOMIES,
8898
+ DentalDraftEditor,
8495
8899
  MED_LEGAL_REPORT_TYPE_CODE,
8496
8900
  MindBillBillReview,
8497
8901
  MindBillBillTimeline,
@@ -8501,6 +8905,7 @@ export {
8501
8905
  PSYCH_QME_DEFAULT_DIAGNOSIS,
8502
8906
  REPORT_BILL_STATUS_OPTIONS2 as REPORT_BILL_STATUS_OPTIONS,
8503
8907
  ReportBillStatusDialog,
8908
+ RfaDraftForm,
8504
8909
  SECOND_REVIEW_REASON_TEMPLATE,
8505
8910
  SECOND_REVIEW_REASON_TEMPLATES,
8506
8911
  SECOND_REVIEW_WINDOW_DAYS,
@@ -8529,6 +8934,7 @@ export {
8529
8934
  createBillLifecycleClient2 as createBillLifecycleClient,
8530
8935
  createBillStatusClient,
8531
8936
  createBillingOperationsClient,
8937
+ dentalDraftChargeSummary,
8532
8938
  ensureTrailingBillSubmissionLine,
8533
8939
  ensureTrailingProcedureLine,
8534
8940
  exactClaimsAdministratorMatch,
@@ -8539,8 +8945,10 @@ export {
8539
8945
  mindBillAppearanceStyle,
8540
8946
  mindBillThemePresets,
8541
8947
  normalizeClaimsAdministratorName,
8948
+ normalizeRfaDraft,
8542
8949
  organizationProfileOptions,
8543
8950
  parseBillSubmissionDate,
8951
+ parseDentalCharge,
8544
8952
  prepareBillSubmissionDocuments,
8545
8953
  reportBillStatusContacts2 as reportBillStatusContacts,
8546
8954
  resolveMindBillAppearance,
@@ -8550,6 +8958,8 @@ export {
8550
8958
  useBillLifecycle,
8551
8959
  useBillStatus,
8552
8960
  validateBillSubmission,
8961
+ validateDentalDraftContent,
8962
+ validateRfaDraft,
8553
8963
  visibleBillLifecycleActions
8554
8964
  };
8555
8965
  //# sourceMappingURL=index.js.map