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

add option fields to lock answer group #518

Merged
merged 1 commit into from
Nov 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Field>

export const FieldsValidationSchema = z.object({
healthiePatientId: z.string().min(1),
healthieFormId: z.string().min(1),
lockFormAnswerGroup: z.boolean().optional(),
} satisfies Record<keyof typeof fields, ZodTypeAny>)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Field>

export const FieldsValidationSchema = z.object({
healthiePatientId: z.string().min(1),
healthieFormId: z.string().min(1),
lockFormAnswerGroup: z.boolean().optional(),
} satisfies Record<keyof typeof fields, ZodTypeAny>)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand All @@ -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(
Expand Down
Loading