Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy-up-the-action #515

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions extensions/elation/actions/addVitals/addVitals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod'
import { omitBy, isEmpty } from 'lodash'
import { isEmpty } from 'lodash'
import { type Action, Category, validate } from '@awell-health/extensions-core'
import { SettingsValidationSchema, type settings } from '../../settings'
import { makeAPIClient } from '../../client'
Expand All @@ -17,7 +17,7 @@ import {
const createMeasurement = (
value?: number,
note?: string
): Array<z.infer<typeof measurementInputSchema>> | undefined => {
): Array<z.infer<typeof measurementInputSchema>> => {
// the undefined check is stupid but otherwise the build is failing
if (value !== undefined && !isEmpty(value)) {
return isEmpty(note)
Expand All @@ -32,7 +32,7 @@ const createMeasurement = (
>,
]
}
return undefined
return []
}

export const addVitals: Action<
Expand All @@ -58,7 +58,12 @@ export const addVitals: Action<

const api = makeAPIClient(settings)

const measurements = {
const body: AddVitalsInputType = {
patient: fields.patientId,
practice: fields.practiceId,
visit_note: fields?.visitNoteId,
non_visit_note: fields?.nonVisitNoteId,
bmi: fields.bmi,
height: createMeasurement(fields.height, fields.heightNote),
weight: createMeasurement(fields.weight, fields.weightNote),
oxygen: createMeasurement(fields.oxygen, fields.oxygenNote),
Expand All @@ -75,17 +80,6 @@ export const addVitals: Action<
bfm: createMeasurement(fields.bfm, fields.bfmNote),
wc: createMeasurement(fields.wc, fields.wcNote),
}
// remove empty measurements
const validMeasurements = omitBy(measurements, isEmpty)

const body: AddVitalsInputType = {
patient: fields.patientId,
practice: fields.practiceId,
visit_note: fields?.visitNoteId,
non_visit_note: fields?.nonVisitNoteId,
bmi: fields.bmi,
...validMeasurements,
}

const { id } = await api.addVitals(body)

Expand Down
14 changes: 7 additions & 7 deletions extensions/elation/actions/addVitals/config/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const fields = {
},
rr: {
id: 'rr',
label: 'Respiratory Rate',
label: 'Respiratory Rate (rr)',
description: 'Respiratory rate',
type: FieldType.NUMERIC,
required: false,
Expand All @@ -103,7 +103,7 @@ export const fields = {
},
hr: {
id: 'hr',
label: 'Heart Rate',
label: 'Heart Rate (hr)',
description: 'Heart rate',
type: FieldType.NUMERIC,
required: false,
Expand All @@ -117,7 +117,7 @@ export const fields = {
},
hc: {
id: 'hc',
label: 'Head Circumference',
label: 'Head Circumference (hc)',
description: 'Head circumference',
type: FieldType.NUMERIC,
required: false,
Expand Down Expand Up @@ -145,7 +145,7 @@ export const fields = {
},
bp: {
id: 'bp',
label: 'Blood Pressure',
label: 'Blood Pressure (bp)',
description: 'Blood pressure',
type: FieldType.NUMERIC,
required: false,
Expand Down Expand Up @@ -173,7 +173,7 @@ export const fields = {
},
dlm: {
id: 'dlm',
label: 'Dry Lean Mass',
label: 'Dry Lean Mass (dlm)',
description: 'Dry lean mass',
type: FieldType.NUMERIC,
required: false,
Expand All @@ -187,7 +187,7 @@ export const fields = {
},
bfm: {
id: 'bfm',
label: 'Body Fat Mass',
label: 'Body Fat Mass (bfm)',
description: 'Body fat mass',
type: FieldType.NUMERIC,
required: false,
Expand All @@ -201,7 +201,7 @@ export const fields = {
},
wc: {
id: 'wc',
label: 'Waist Circumference',
label: 'Waist Circumference (wc)',
description: 'Waist circumference',
type: FieldType.NUMERIC,
required: false,
Expand Down
11 changes: 0 additions & 11 deletions extensions/elation/types/vitals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,30 @@ export const AddVitalsInputSchema = z
bmi: z.number().optional(),
height: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Height; only one item allowed'),
weight: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Weight; only one item allowed'),
oxygen: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Oxygen; only one item allowed'),
rr: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Respiratory rate; only one item allowed'),
hr: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Heart rate; only one item allowed'),
hc: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Head circumference; only one item allowed'),
temperature: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Temperature; only one item allowed'),
bp: z
Expand All @@ -64,22 +57,18 @@ export const AddVitalsInputSchema = z
// ketone: z.array(measurementInputSchema).optional().describe("Optional ketone; see Vital Object Definition for supported observations"),
bodyfat: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Optional body fat; only one item allowed'),
dlm: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Optional DLM; only one item allowed'),
bfm: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Optional BFM; only one item allowed'),
wc: z
.array(measurementInputSchema)
.length(1)
.optional()
.describe('Optional WC; only one item allowed'),
})
Expand Down