import React, { useState } from 'react'; import { EmptyState } from '../../../components/ui/empty-state'; import { RECORD_ACTIONS } from '../../../utils/recordActions'; import type { ProposalState } from '../../../utils/recordProposals'; // What saving a note offers to put on the patient's record, drawn as the approved encounter deck's // "From your note" card: each item added or declined on its own, and "Add anything else to the // patient's record?" always last - while items wait, once they are done, and when there were none. // // Presentational: it files nothing and reports each decision upward, so a test can assert that no // control here acts on two items at once. interface Props { proposals: ProposalState[]; /** Which visit everything here will be filed to, in words. */ filedTo: string; onAdd: (id: string) => void; onDecline: (id: string) => void; /** * The search for whatever the note did not describe, shown inside the closing disclosure. The note editor draws * that disclosure itself, beside this card, so it is there before any round; left out, this card draws none. */ addSomethingElse?: React.ReactNode; /** The round could not read the note; its empty list is unknown. */ failed?: boolean; onRetry?: () => void; } const kindLabel = (kind: string) => RECORD_ACTIONS.find((action) => action.kind === kind)?.label; /** * "Add anything else to the patient's record?" - the closing disclosure holding manual entry. Its search mounts only * once asked for, so its lookups never load behind a closed line. */ export const AddAnythingElse: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [searchOpen, setSearchOpen] = useState(false); return (
setSearchOpen(event.currentTarget.open)} > Add anything else to the patient’s record? {searchOpen &&
{children}
}
); }; export const RecordProposals: React.FC = ({ proposals, filedTo, onAdd, onDecline, addSomethingElse, failed = false, onRetry, }) => { // A declined item leaves without a trace; added ones stay, marked, in the order the note gave them. const shown = proposals.filter((state) => state.decision !== 'declined'); return (
{/* Which visit, said once above everything, for the clinician writing up after it ended. */}

{filedTo}

{failed && (
Suggestions could not be checked just now. Nothing else was added to the record. {onRetry && ( )}
)} {!failed && shown.length > 0 && (

From your note

Review each item before adding it to the record.

    {shown.map(({ proposal, decision }) => (
  • {/* Wide enough to read before the controls wrap under it on a phone. */} {proposal.title} {/* Why it is offered, not the sentence it came from: the note is on screen. */} {[kindLabel(proposal.kind), proposal.reason].filter(Boolean).join(' ยท ')} {decision === 'added' ? ( Added to record ) : ( // One pair per item and nothing that acts on all of them: Spencer, // "keep it one at a time, no add all." )}
  • ))}
)} {!failed && shown.length === 0 && ( )} {addSomethingElse !== undefined && {addSomethingElse}}
); }; export default RecordProposals;