diff --git a/extensions/healthie/actions/dataExchange/pushFormResponseToHealthie/config/fields.ts b/extensions/healthie/actions/dataExchange/pushFormResponseToHealthie/config/fields.ts index 5e5fac39..b4efd0de 100644 --- a/extensions/healthie/actions/dataExchange/pushFormResponseToHealthie/config/fields.ts +++ b/extensions/healthie/actions/dataExchange/pushFormResponseToHealthie/config/fields.ts @@ -16,9 +16,17 @@ export const fields = { type: FieldType.STRING, required: true, }, + lockFormAnswerGroup: { + id: 'lockFormAnswerGroup', + label: 'Lock form answer group', + description: 'Locking the form will stop any further editing', + type: FieldType.BOOLEAN, + required: false, + }, } satisfies Record export const FieldsValidationSchema = z.object({ healthiePatientId: z.string().min(1), healthieFormId: z.string().min(1), + lockFormAnswerGroup: z.boolean().optional(), } satisfies Record) diff --git a/extensions/healthie/actions/dataExchange/pushFormResponseToHealthie/pushFormResponseToHealthie.ts b/extensions/healthie/actions/dataExchange/pushFormResponseToHealthie/pushFormResponseToHealthie.ts index beee9cc9..006cd625 100644 --- a/extensions/healthie/actions/dataExchange/pushFormResponseToHealthie/pushFormResponseToHealthie.ts +++ b/extensions/healthie/actions/dataExchange/pushFormResponseToHealthie/pushFormResponseToHealthie.ts @@ -4,7 +4,7 @@ import { validatePayloadAndCreateSdk } from '../../../lib/sdk/validatePayloadAnd import { type settings } from '../../../settings' import { datapoints, fields, FieldsValidationSchema } from './config' import { getSubActivityLogs } from './logs' -import { isEmpty } from 'lodash' +import { isEmpty, defaultTo } from 'lodash' import { HealthieFormResponseNotCreated, parseHealthieFormResponseNotCreatedError, @@ -60,6 +60,9 @@ export const pushFormResponseToHealthie: Action< awellFormResponse: formResponse, }) + // indicates whether to make form values editable in Healthie + const lock = defaultTo(fields.lockFormAnswerGroup, false) + try { const res = await healthieSdk.client.mutation({ createFormAnswerGroup: { @@ -83,6 +86,22 @@ export const pushFormResponseToHealthie: Action< if (isEmpty(res?.createFormAnswerGroup?.form_answer_group?.id)) throw new HealthieFormResponseNotCreated(res) + // separate call to lock the form if needed + if (lock) { + await healthieSdk.client.mutation({ + lockFormAnswerGroup: { + __args: { + input: { + id: fields.healthieFormId, + }, + }, + form_answer_group: { + id: true, + }, + }, + }) + } + await onComplete({ data_points: { formAnswerGroupId: String( diff --git a/extensions/healthie/actions/dataExchange/pushFormResponsesToHealthie/config/fields.ts b/extensions/healthie/actions/dataExchange/pushFormResponsesToHealthie/config/fields.ts index 5e5fac39..b4efd0de 100644 --- a/extensions/healthie/actions/dataExchange/pushFormResponsesToHealthie/config/fields.ts +++ b/extensions/healthie/actions/dataExchange/pushFormResponsesToHealthie/config/fields.ts @@ -16,9 +16,17 @@ export const fields = { type: FieldType.STRING, required: true, }, + lockFormAnswerGroup: { + id: 'lockFormAnswerGroup', + label: 'Lock form answer group', + description: 'Locking the form will stop any further editing', + type: FieldType.BOOLEAN, + required: false, + }, } satisfies Record export const FieldsValidationSchema = z.object({ healthiePatientId: z.string().min(1), healthieFormId: z.string().min(1), + lockFormAnswerGroup: z.boolean().optional(), } satisfies Record) diff --git a/extensions/healthie/actions/dataExchange/pushFormResponsesToHealthie/pushFormResponsesToHealthie.ts b/extensions/healthie/actions/dataExchange/pushFormResponsesToHealthie/pushFormResponsesToHealthie.ts index 40942105..883c795b 100644 --- a/extensions/healthie/actions/dataExchange/pushFormResponsesToHealthie/pushFormResponsesToHealthie.ts +++ b/extensions/healthie/actions/dataExchange/pushFormResponsesToHealthie/pushFormResponsesToHealthie.ts @@ -4,7 +4,7 @@ import { validatePayloadAndCreateSdk } from '../../../lib/sdk/validatePayloadAnd import { type settings } from '../../../settings' import { datapoints, fields, FieldsValidationSchema } from './config' import { getSubActivityLogs } from './logs' -import { isEmpty } from 'lodash' +import { isEmpty, defaultTo } from 'lodash' import { HealthieFormResponseNotCreated, parseHealthieFormResponseNotCreatedError, @@ -67,6 +67,9 @@ export const pushFormResponsesToHealthie: Action< ({ omittedFormAnswers }) => omittedFormAnswers ) + // indicates whether to make form values editable in Healthie + const lock = defaultTo(fields.lockFormAnswerGroup, false) + try { const res = await healthieSdk.client.mutation({ createFormAnswerGroup: { @@ -90,6 +93,21 @@ export const pushFormResponsesToHealthie: Action< if (isEmpty(res?.createFormAnswerGroup?.form_answer_group?.id)) throw new HealthieFormResponseNotCreated(res) + // separate call to lock the form if needed + if (lock) { + await healthieSdk.client.mutation({ + lockFormAnswerGroup: { + __args: { + input: { + id: fields.healthieFormId, + }, + }, + form_answer_group: { + id: true, + }, + }, + }) + } await onComplete({ data_points: { formAnswerGroupId: String(