Skip to content

Commit 634c91c

Browse files
committed
refactor can update functions
1 parent 0f46bbe commit 634c91c

File tree

4 files changed

+63
-78
lines changed

4 files changed

+63
-78
lines changed

vim--ai-scribe--react/src/components/molecules/SoapSection.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ export const SoapSection = ({
170170
fullWidth
171171
className="py-3 w-2/3 self-center"
172172
disabled={!isWriteAvailable}
173-
tooltip={!isWriteAvailable ? "EHR write access missing" : "" }
173+
tooltip={
174+
!isWriteAvailable ? "Can't write to EHR in current state" : ""
175+
}
174176
>
175177
Push to EHR
176178
</Button>

vim--ai-scribe--react/src/components/organisms/RecordingTab/RecordingTab.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Mic, User } from "lucide-react";
22
import { Button } from "../../atoms/Button";
3-
import { useProviderName } from "../ai-scribe-demo/useProviderName";
3+
import { useProviderName } from "../../../vimOs/useProviderName";
44

55
export const RecordingTab = ({
66
patientName,

vim--ai-scribe--react/src/components/organisms/notes-tab/NotesSections.tsx

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ interface NotePanelProps {
1313
}
1414

1515
const useUpdateSubjective = () => {
16-
const encounterUpdates = useUpdateEncounterSubscription<"subjective">(
17-
{
18-
subjective: {
19-
generalNotes: true,
20-
chiefComplaintNotes: true,
21-
historyOfPresentIllnessNotes: true,
22-
reviewOfSystemsNotes: true,
23-
},
24-
},
16+
const encounterUpdates = useUpdateEncounterSubscription(
2517
"subjective",
2618
{
27-
subjective: ["chiefComplaintNotes", "reviewOfSystemsNotes"],
28-
}
19+
generalNotes: true,
20+
chiefComplaintNotes: true,
21+
historyOfPresentIllnessNotes: true,
22+
reviewOfSystemsNotes: true,
23+
},
24+
["chiefComplaintNotes", "reviewOfSystemsNotes"]
2925
);
3026

3127
const { updateSubscriptionField, canUpdateSubscriptionParams } =
@@ -47,17 +43,13 @@ const useUpdateSubjective = () => {
4743
};
4844

4945
const useUpdateObjective = () => {
50-
const encounterUpdates = useUpdateEncounterSubscription<"objective">(
51-
{
52-
objective: {
53-
generalNotes: true,
54-
physicalExamNotes: true,
55-
},
56-
},
46+
const encounterUpdates = useUpdateEncounterSubscription(
5747
"objective",
5848
{
59-
objective: ["generalNotes", "physicalExamNotes"],
60-
}
49+
generalNotes: true,
50+
physicalExamNotes: true,
51+
},
52+
["generalNotes", "physicalExamNotes"]
6153
);
6254

6355
const { updateSubscriptionField, canUpdateSubscriptionParams } =
@@ -79,16 +71,12 @@ const useUpdateObjective = () => {
7971
};
8072

8173
const useUpdateAssessment = () => {
82-
const encounterUpdates = useUpdateEncounterSubscription<"assessment">(
83-
{
84-
assessment: {
85-
generalNotes: true,
86-
},
87-
},
74+
const encounterUpdates = useUpdateEncounterSubscription(
8875
"assessment",
8976
{
90-
assessment: ["generalNotes"],
91-
}
77+
generalNotes: true,
78+
},
79+
["generalNotes"]
9280
);
9381

9482
const { updateSubscriptionField, canUpdateSubscriptionParams } =
@@ -110,16 +98,12 @@ const useUpdateAssessment = () => {
11098
};
11199

112100
const useUpdatePlan = () => {
113-
const encounterUpdates = useUpdateEncounterSubscription<"plan">(
114-
{
115-
plan: {
116-
generalNotes: true,
117-
},
118-
},
101+
const encounterUpdates = useUpdateEncounterSubscription(
119102
"plan",
120103
{
121-
plan: ["generalNotes"],
122-
}
104+
generalNotes: true,
105+
},
106+
["generalNotes"]
123107
);
124108

125109
const { updateSubscriptionField, canUpdateSubscriptionParams } =
@@ -167,33 +151,31 @@ export const NotesSections = ({
167151
isHighlighted={isHighlighted("subjective")}
168152
isWriteAvailable={canUpdateSubjectiveNote}
169153
renderHighlightedText={renderHighlightedText}
170-
onPushToEHR={() => {
171-
updateSubjectiveNote();
172-
}}
154+
onPushToEHR={updateSubjectiveNote}
173155
/>
174156
<SoapSection
175157
title="Objective"
176158
fieldName="objective"
177159
isHighlighted={isHighlighted("objective")}
178160
isWriteAvailable={canUpdateObjectiveNote}
179161
renderHighlightedText={renderHighlightedText}
180-
onPushToEHR={() => updateObjectiveNote()}
162+
onPushToEHR={updateObjectiveNote}
181163
/>
182164
<SoapSection
183165
title="Assessment"
184166
fieldName="assessment"
185167
isHighlighted={isHighlighted("assessment")}
186168
isWriteAvailable={canUpdateAssessmentNote}
187169
renderHighlightedText={renderHighlightedText}
188-
onPushToEHR={() => updateAssessmentNote()}
170+
onPushToEHR={updateAssessmentNote}
189171
/>
190172
<SoapSection
191173
title="Plan"
192174
fieldName="plan"
193175
isHighlighted={isHighlighted("plan")}
194176
isWriteAvailable={canUpdatePlanNote}
195177
renderHighlightedText={renderHighlightedText}
196-
onPushToEHR={() => updatePlanNote()}
178+
onPushToEHR={updatePlanNote}
197179
/>
198180
</div>
199181
);

vim--ai-scribe--react/src/vimOs/useUpdateEncounter.ts

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,52 @@ import { useEffect, useMemo, useState } from "react";
22
import type { EHR } from "vim-os-js-browser/types";
33
import { useVimOsContext } from "@/providers/VimOSContext";
44

5-
const calcIsUpdatable = (
6-
sectionName: keyof EHR.UpdateEncounterParams,
7-
priorityList: Partial<Record<keyof EHR.UpdateEncounterParams, string[]>>,
5+
type SectionField<T extends keyof EHR.UpdateEncounterParams> =
6+
keyof NonNullable<EHR.UpdateEncounterParams[T]>;
7+
8+
type SectionFields<T extends keyof EHR.UpdateEncounterParams> = Array<
9+
SectionField<T>
10+
>;
11+
12+
const calcIsUpdatable = <T extends keyof EHR.UpdateEncounterParams>(
13+
sectionName: T,
14+
priorityList: SectionFields<T>,
815
details: EHR.CanUpdateEncounterParams
9-
) => {
10-
if (sectionName && priorityList) {
11-
const section = details[sectionName] || {};
12-
const priorities = priorityList[sectionName] || [];
13-
const updatableField = priorities?.find(
14-
(fieldName) => section[fieldName as keyof typeof section] === true
15-
);
16-
17-
return updatableField;
18-
}
16+
): SectionFields<T> => {
17+
const section = details[sectionName] || {};
18+
const updatableFields = priorityList.filter(
19+
(fieldName) => section[fieldName as keyof typeof section] === true
20+
);
21+
22+
return updatableFields;
1923
};
2024

2125
export const useUpdateEncounterSubscription = <
2226
T extends keyof EHR.UpdateEncounterParams
2327
>(
24-
subscriptionParams: EHR.CanUpdateEncounterParams,
2528
sectionName: T,
26-
priorityList: Partial<Record<keyof EHR.UpdateEncounterParams, string[]>> // TODO Support Actual Fieldname // Partial<Record<T, Array<keyof EHR.UpdateEncounterParams[T]>>>
29+
subscriptionParams: EHR.CanUpdateEncounterParams[T],
30+
priorityList: SectionFields<T>
2731
) => {
2832
const vimOS = useVimOsContext();
2933
const [canUpdateSubscriptionParams, setCanUpdateSubscriptionParams] =
3034
useState<boolean>(false);
31-
const [subscriptionUpdatableField, setSubscriptionUpdatableField] =
32-
useState<string>();
35+
const [subscriptionUpdatableFields, setSubscriptionUpdatableFields] =
36+
useState<SectionFields<T>>();
3337

3438
useEffect(() => {
3539
const onUpdate = () => {
36-
if (subscriptionParams) {
37-
const { details } =
38-
vimOS.ehr.resourceUpdater.canUpdateEncounter(subscriptionParams);
39-
if (sectionName && priorityList) {
40-
const updatableField = calcIsUpdatable(
41-
sectionName,
42-
priorityList,
43-
details
44-
);
45-
const canUpdate = updatableField !== undefined;
46-
setCanUpdateSubscriptionParams(canUpdate);
47-
setSubscriptionUpdatableField(updatableField);
48-
}
49-
}
40+
const { details } = vimOS.ehr.resourceUpdater.canUpdateEncounter({
41+
[sectionName]: subscriptionParams,
42+
});
43+
const updatableFields = calcIsUpdatable(
44+
sectionName,
45+
priorityList,
46+
details
47+
);
48+
const canUpdate = updatableFields.length > 0;
49+
setCanUpdateSubscriptionParams(canUpdate);
50+
setSubscriptionUpdatableFields(updatableFields);
5051
};
5152

5253
vimOS.ehr.resourceUpdater.subscribe("encounter", onUpdate);
@@ -63,7 +64,7 @@ export const useUpdateEncounterSubscription = <
6364
return useMemo(
6465
() => ({
6566
canUpdateSubscriptionParams,
66-
subscriptionUpdatableField,
67+
subscriptionUpdatableFields,
6768
updateSubscriptionField: (content: string) => {
6869
if (!sectionName || !canUpdateSubscriptionParams) {
6970
return;
@@ -86,7 +87,7 @@ export const useUpdateEncounterSubscription = <
8687
variant: "destructive",
8788
title: "Uh oh! Something went wrong.",
8889
sectionName,
89-
subscriptionUpdatableField,
90+
subscriptionUpdatableFields,
9091
description: error ? JSON.stringify(error) : "An error occurred.",
9192
});
9293
});
@@ -95,7 +96,7 @@ export const useUpdateEncounterSubscription = <
9596
[
9697
canUpdateSubscriptionParams,
9798
sectionName,
98-
subscriptionUpdatableField,
99+
subscriptionUpdatableFields,
99100
vimOS.ehr.resourceUpdater,
100101
]
101102
);

0 commit comments

Comments
 (0)