import { useState } from "react"; import { AlertCircle, Building2, FileInput, KeyRound, ListChecks, Loader2, Pencil, Plus, Power, PowerOff, SlidersHorizontal, } from "lucide-react"; import { Button } from "../../../../components/ui/button.tsx"; import { Badge } from "../../../../components/ui/badge.tsx"; import { Alert, AlertDescription } from "../../../../components/ui/alert.tsx"; import { EmptyState } from "../../../../components/ui/empty-state.tsx"; import { AKASHIC_LAB_CONNECTION, LAB_CONNECTION_TYPES, useLabConnections, type LabConnection, } from "../../../../hooks/useLabConnections.ts"; import LabConnectionEditor, { type ConnectionTarget } from "./LabConnectionEditor.tsx"; import LabProfileEditor, { type ProfileTarget } from "./LabProfileEditor.tsx"; import LabCredentialsDialog, { type CredentialsTarget } from "./LabCredentialsDialog.tsx"; import LabTestCodesDialog, { type TestCodesTarget } from "./LabTestCodesDialog.tsx"; import LabResultReturnDialog, { type ResultReturnTarget } from "./LabResultReturnDialog.tsx"; import { returnWords } from "./labResultReturnWords.ts"; import "./DiagnosticsPage.css"; // The laboratories this practice sends to. // // ITS OWN TAB BECAUSE IT IS ITS OWN QUESTION. The catalogue beside it answers "what can this practice // order"; this answers "where does an order go", and the two change for different reasons and are // edited by different people on different days. // // A LABORATORY IS SWITCHED OFF RATHER THAN DELETED, so there is no delete here and none on the // server. A practice that has stopped using one keeps its account number and the history of what was // sent through it -- and the account number is exactly what they need when that laboratory rings // about work sent last year. A switched-off one stays on the list, greyed and marked. // // Each laboratory says where its orders go, from the server's own answer: electronically, or on paper and why. const transportLabel = (connection: LabConnection) => LAB_CONNECTION_TYPES.find((each) => each.id === connection.connectionType)?.label; /** What the server does with this laboratory's orders. A laboratory on Akashic is reached in-network and needs no line. */ const sendWords = (connection: LabConnection): string | undefined => { const transport = LAB_CONNECTION_TYPES.find((each) => each.id === connection.connectionType); if (!transport || transport.id === AKASHIC_LAB_CONNECTION) return undefined; if (!transport.sends) return `Orders go on paper: Akashic does not send over ${transport.label} yet.`; if (connection.electronic) return "Orders for paired tests go to it electronically."; if (connection.active === false) return "Orders go on paper while it is switched off."; if (!connection.address?.trim()) return "Orders go on paper until it has an address."; // No decision in the answer is unknown, never paper. if (connection.electronic === undefined || connection.credentialsConfigured === undefined) { return "Whether its orders go electronically could not be read just now."; } if (!connection.credentialsConfigured) return "Orders go on paper until a sign-in is saved."; return "Orders go on paper."; }; const reviewedCount = (connection: LabConnection) => (connection.testMappings ?? []).filter((each) => each.reviewedAt).length; const LabConnections = () => { const { connections, loading, error, accountsUnreadable, reload, addConnection, saveConnection, saveProfile, saveTestMappings, setActive, saveCredentials, removeCredentials, saveAccountParameter, checkResultReturn, readResults, } = useLabConnections(); const [returning, setReturning] = useState(); const [target, setTarget] = useState(); const [describing, setDescribing] = useState(); const [signingIn, setSigningIn] = useState(); const [pairing, setPairing] = useState(); const [switching, setSwitching] = useState(); const [switchFailure, setSwitchFailure] = useState(); const toggle = async (connection: LabConnection) => { setSwitching(connection.id); setSwitchFailure(undefined); try { await setActive(connection.id as string, connection.active === false); } catch (failure) { console.error("Error switching a laboratory connection:", failure); setSwitchFailure("That laboratory could not be changed. Please try again."); } finally { setSwitching(undefined); } }; if (loading) { return (

Loading the laboratories…

); } return (
{error ? ( {error} ) : null} {switchFailure ? ( {switchFailure} ) : null}

External laboratories

Your practice keeps its own laboratory accounts. Connection settings do not prove delivery.

{accountsUnreadable ? (

Account numbers and sign-ins could not be read just now, so they are not shown.

) : null} {error && connections.length === 0 ? null : connections.length === 0 ? ( ) : (
    {connections.map((connection) => (
  • {connection.name ?? "Unnamed laboratory"} {transportLabel(connection) ? ( {transportLabel(connection)} ) : null} {connection.active === false ? Off : null}

    {[ // An Akashic link's address is the practice's record id, not somewhere a person sends to. connection.connectionType === AKASHIC_LAB_CONNECTION ? undefined : connection.address, connection.npi ? `NPI ${connection.npi}` : undefined, connection.accountNumber ? `Account ${connection.accountNumber}` : undefined, ].filter(Boolean).join(" · ")}

    {sendWords(connection) ? (

    {sendWords(connection)}

    ) : null} {returnWords(connection) ? (

    {returnWords(connection)}

    ) : null}
    {/* How the laboratory wants an order said. The count is the useful thing at a glance: a connection with no profile cannot be sent to however correct its address is. */} {returnWords(connection) ? ( ) : null}
  • ))}
)}

Recording a laboratory prints its account number on the requisition. Each one above says whether its orders go electronically or on paper.

setTarget(undefined)} addConnection={addConnection} saveConnection={saveConnection} /> setDescribing(undefined)} saveProfile={saveProfile} /> setPairing(undefined)} saveTestMappings={saveTestMappings} /> setSigningIn(undefined)} saveCredentials={saveCredentials} removeCredentials={removeCredentials} /> setReturning(undefined)} saveAccountParameter={saveAccountParameter} checkResultReturn={checkResultReturn} readResults={readResults} reload={reload} />
); }; export default LabConnections;