Skip to content

Commit

Permalink
feat(): data exchange for multiple forms (#471)
Browse files Browse the repository at this point in the history
* feat(): data exchange for multiple forms

* fix(tests): twilio
  • Loading branch information
nckhell authored Oct 1, 2024
1 parent d730697 commit 15e913e
Show file tree
Hide file tree
Showing 44 changed files with 14,245 additions and 12,031 deletions.
2 changes: 2 additions & 0 deletions extensions/healthie/actions/dataExchange/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './pushFormResponseToHealthie'
export * from './pushFormResponsesToHealthie'
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { getLatestFormInCurrentStep } from '../../../../src/lib/awell'
import { getLatestFormInCurrentStep } from '../../../../../src/lib/awell'
import { Category, type Action } from '@awell-health/extensions-core'
import { validatePayloadAndCreateSdk } from '../../lib/sdk/validatePayloadAndCreateSdk'
import { type settings } from '../../settings'
import { validatePayloadAndCreateSdk } from '../../../lib/sdk/validatePayloadAndCreateSdk'
import { type settings } from '../../../settings'
import { datapoints, fields, FieldsValidationSchema } from './config'
import { getSubActivityLogs } from './logs'
import { isEmpty } from 'lodash'
import {
HealthieFormResponseNotCreated,
parseHealthieFormResponseNotCreatedError,
} from './errors'
} from '../shared/errors'
import {
HealthieError,
mapHealthieToActivityError,
} from '../../lib/sdk/graphql-codegen/errors'
} from '../../../lib/sdk/graphql-codegen/errors'

export const pushFormResponseToHealthie: Action<
typeof fields,
Expand All @@ -24,7 +24,7 @@ export const pushFormResponseToHealthie: Action<
title: 'Push form response to Healthie',
description: 'Pushes an Awell form response to a Healthie form',
fields,
previewable: true,
previewable: false,
dataPoints: datapoints,
onEvent: async ({ payload, onComplete, onError, helpers }) => {
const { fields, pathway, activity, healthieSdk } =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export const mockFormDefinitionOneResponse = {
form: {
questions: [
{
options: [],
key: 'PATIENT_FN',
id: 'PSpxniOv52vQ',
definition_id: '4kLSm6MPL4RO',
title: "What's the patient's first name?",
dataPointValueType: 'STRING',
questionType: 'INPUT',
userQuestionType: 'SHORT_TEXT',
metadata: '{"healthieCustomModuleId": "14460375"}',
__typename: 'Question',
},
],
},
}

export const mockFormDefinitionTwoResponse = {
form: {
questions: [
{
options: [],
key: 'PATIENT_LN',
id: 'ABOb9suU2dMc',
definition_id: 'R9EjG3z4Yi3H',
title: "What's the patient's last name?",
dataPointValueType: 'STRING',
questionType: 'INPUT',
userQuestionType: 'SHORT_TEXT',
metadata: '{"healthieCustomModuleId": "14460376"}',
__typename: 'Question',
},
],
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const mockFormResponseOneResponse = {
response: {
answers: [
{
question_id: 'PSpxniOv52vQ',
value: 'Nick',
label: null,
value_type: 'STRING',
__typename: 'Answer',
},
],
},
}

export const mockFormResponseTwoResponse = {
response: {
answers: [
{
question_id: 'ABOb9suU2dMc',
value: 'Hellemans',
label: null,
value_type: 'STRING',
__typename: 'Answer',
},
],
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './formDefinitionResponse'
export * from './formResponseResponse'
export * from './pathwayActivitiesResponse'
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
export const mockPathwayActivitiesResponse = {
success: true,
activities: [
{
id: 'X74HeDQ4N0gtdaSEuzF8s',
status: 'ACTIVE',
date: '2024-09-11T22:56:59.607Z',
object: {
id: 'w1EgLnVu5ApP',
type: 'PLUGIN_ACTION',
},
context: {
step_id: 'Xkn5dkyPA5uW',
},
},
{
id: 'form_acitity_2',
status: 'DONE',
date: '2024-09-11T22:56:08.315Z',
object: {
id: 'form_2',
type: 'FORM',
},
context: {
step_id: 'Xkn5dkyPA5uW',
},
},
{
id: 'form_acitity_1',
status: 'DONE',
date: '2024-09-11T22:56:08.315Z',
object: {
id: 'form_1',
type: 'FORM',
},
context: {
step_id: 'Xkn5dkyPA5uW',
},
},
{
id: 'shkMEWqOzHQMsYrGS6yId',
status: 'DONE',
date: '2024-09-11T22:56:08.113Z',
object: {
id: 'Q3KUacz4qEmn',
type: 'STEP',
},
context: {
step_id: 'Xkn5dkyPA5uW',
},
},
{
id: 'f2IjXGjg7YoHZ7lEF0l5j',
status: 'DONE',
date: '2024-09-11T22:56:07.980Z',
object: {
id: 'Q3KUacz4qEmn',
type: 'STEP',
},
context: {
step_id: 'Xkn5dkyPA5uW',
},
},
{
id: 'IiEYazcYE04vhFiCL9tLG',
status: 'DONE',
date: '2024-09-11T22:56:07.910Z',
object: {
id: 'LTKNrxc5nt9o',
type: 'TRACK',
},
context: {
step_id: null,
},
},
{
id: 'Kp90kFg1PUTkszxVGEmOM',
status: 'DONE',
date: '2024-09-11T22:56:07.736Z',
object: {
id: 'PRjP57V2EA1n',
type: 'PATHWAY',
},
context: {
step_id: null,
},
},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { type DataPointDefinition } from '@awell-health/extensions-core'

export const datapoints = {
formAnswerGroupId: {
key: 'formAnswerGroupId',
valueType: 'string',
},
} satisfies Record<string, DataPointDefinition>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { FieldType, type Field } from '@awell-health/extensions-core'
import z, { type ZodTypeAny } from 'zod'

export const fields = {
healthiePatientId: {
id: 'healthiePatientId',
label: 'Healthie patient ID',
description: 'The ID of the patient in Healthie',
type: FieldType.STRING,
required: true,
},
healthieFormId: {
id: 'healthieFormId',
label: 'Healthie form ID',
description: 'The ID of the form in Healthie',
type: FieldType.STRING,
required: true,
},
} satisfies Record<string, Field>

export const FieldsValidationSchema = z.object({
healthiePatientId: z.string().min(1),
healthieFormId: z.string().min(1),
} satisfies Record<keyof typeof fields, ZodTypeAny>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { fields, FieldsValidationSchema } from './fields'
export { datapoints } from './datapoints'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { pushFormResponsesToHealthie } from './pushFormResponsesToHealthie'
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { getSubActivityLogs, HealthieOmitType } from '.'

describe('getMappingStatus', () => {
beforeEach(() => {
jest.clearAllMocks()
})

test('Should work when there are mapping errors', async () => {
const data = [
{
questionId: 'question_1',
reason:
'No corresponding question definition found in the form definition',
omitType: HealthieOmitType.QUESTION_NOT_FOUND_IN_FORM_DEFINITION,
},
{
questionId: 'question_2',
reason:
'Unable to map this question to a Healthie question because it misses the `healthieCustomModuleId` metadata required for proper integration.',
omitType: HealthieOmitType.MISSING_MAPPING,
},
{
questionId: 'question_3',
reason: 'Unknown error',
omitType: HealthieOmitType.OTHER,
},
{
questionId: 'question_4',
reason:
'Unable to map this question to a Healthie question because it misses the `healthieCustomModuleId` metadata required for proper integration.',
omitType: HealthieOmitType.MISSING_MAPPING,
},
]

const res = getSubActivityLogs(data)

expect(res).toEqual([
{
date: expect.any(String),
text: {
en: 'Missing mapping for the below questions: question_2, question_4',
},
error: {
category: 'MISSING_SETTINGS',
message:
'Missing mapping for the below questions: question_2, question_4',
},
},
{
date: expect.any(String),
text: {
en: 'The following questions in the response could not be linked to a question definition in the form definition: question_1',
},
error: {
category: 'SERVER_ERROR',
message:
'The following questions in the response could not be linked to a question definition in the form definition: question_1',
},
},
{
date: expect.any(String),
text: {
en: 'There was an unexpected error transforming the following Awell form answers to Healthie form answers: question_3: Unknown error',
},
error: {
category: 'SERVER_ERROR',
message:
'There was an unexpected error transforming the following Awell form answers to Healthie form answers: question_3: Unknown error',
},
},
])
})

test('Should work when there are no mapping errors', async () => {
const res = getSubActivityLogs([])

expect(res).toEqual([])
})
})
Loading

0 comments on commit 15e913e

Please sign in to comment.