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 allergies to mobile app Health section #10339

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
33 changes: 33 additions & 0 deletions VAMobile/src/api/allergies/getAllergies.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useQuery } from '@tanstack/react-query'

import { AllergyListPayload } from 'api/types'
import { LARGE_PAGE_SIZE } from 'constants/common'
import { get } from 'store/api'

import { allergyKeys } from './queryKeys'

/**
* Fetch user Allergies
*/
const getAllergies = (): Promise<AllergyListPayload | undefined> => {
return get<AllergyListPayload>('/v0/health/allergy-intolerances', {
'page[number]': '1',
'page[size]': LARGE_PAGE_SIZE.toString(),
sort: 'date',
useCache: 'false',
})
}

/**
* Returns a query for user Allergies
*/
export const useAllergies = (options?: { enabled?: boolean }) => {
return useQuery({
...options,
queryKey: [allergyKeys.allergies],
queryFn: () => getAllergies(),
meta: {
errorName: 'getAllergies: Service error',
},
})
}
3 changes: 3 additions & 0 deletions VAMobile/src/api/allergies/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const allergyKeys = {
allergies: ['allergies'] as const,
}
47 changes: 47 additions & 0 deletions VAMobile/src/api/types/AllergyData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
export type AllergyListPayload = {
data: Array<Allergy>
links: {
self: string
first: string
prev: string
next: string
last: string
}
meta: {
pagination: {
currentPage: number
perPage: number
totalPages: number
totalEntries: number
}
dataFromStore: boolean
}
}

export type Allergy = {
id?: string | null
type?: string | null
attributes?: {
code?: {
text?: string | null
} | null
category?: Array<string> | null
recordedDate?: string | null
notes?: Array<NoteText> | null
recorder?: {
display?: string | null
} | null
reactions?: Array<Reaction> | null
}
}

export type Reaction = {
manifestation: Array<ManifestationText> | null
}
export type ManifestationText = {
text: string
}

export type NoteText = {
text: string
}
1 change: 1 addition & 0 deletions VAMobile/src/api/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './PrescriptionData'
export * from './SecureMessagingData'
export * from './ServiceHistoryData'
export * from './VaccineData'
export * from './AllergyData'
5 changes: 5 additions & 0 deletions VAMobile/src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export const Events = {
name: 'vama_af_updated',
}
},
vama_allergy_details: (): Event => {
return {
name: 'vama_allergy_details',
}
},
vama_appt_cancel: (
isPendingAppointment: boolean,
apt_id: string | undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import React from 'react'

import { screen } from '@testing-library/react-native'

import { Allergy } from 'api/types'
// import * as api from 'store/api'
import { context, mockNavProps, render, waitFor, when } from 'testUtils'

Check warning on line 7 in VAMobile/src/screens/HealthScreen/Allergies/AllergyDetails/AllergyDetailsScreen.test.tsx

View workflow job for this annotation

GitHub Actions / lint

'when' is defined but never used

import AllergyDetailsScreen from './AllergyDetailsScreen'

context('AllergyDetailsScreen', () => {
const defaultAllergy = {
id: '4-1abLZzsevfVnWK',
type: 'allergy_intolerance',
attributes: {
resourceType: 'AllergyIntolerance',
type: 'allergy',
clinicalStatus: {
coding: [
{
system: 'http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical',
code: 'active',
},
],
},
category: ['medication'],
code: {
coding: [
{
system: 'http://hl7.org/fhir/ndfrt',
code: 'N0000008048',
display: 'Sulfonamides',
},
],
text: 'Sulfonamides',
},
recordedDate: '2019-03-12T16:30:00Z',
patient: {
reference: 'https://sandbox-api.va.gov/services/fhir/v0/r4/Patient/1013956965V299908',
display: 'DAMASO SUPNICK',
},
notes: [
{
authorReference: {
reference: 'https://sandbox-api.va.gov/services/fhir/v0/r4/Practitioner/4-Nn79MgdlF9vV',
display: 'Dr. Alicia629 Ureña88 MD',
},
time: '2019-03-12T16:30:00Z',
text: 'Sulfonamides',
},
],
recorder: {
reference: 'https://sandbox-api.va.gov/services/fhir/v0/r4/Practitioner/4-Nn79MgdlF9vV',
display: 'Dr. Alicia629 Ureña88 MD',
},
reactions: [],
},
}

const reactions = [
{
substance: {
coding: [],
text: null,
},
manifestation: [
{
coding: [],
text: 'Urticaria (Hives)',
},
],
},
{
substance: {
coding: [],
text: null,
},
manifestation: [
{
coding: [],
text: 'Anaphylaxis',
},
],
},
]

const notes = [
{
authorReference: {
reference: 'https://sandbox-api.va.gov/services/fhir/v0/r4/Practitioner/4-Nn79MgdlF9vV',
display: 'Dr. Alicia629 Ureña88 MD',
},
time: '2019-03-12T16:30:00Z',
text: 'Sulfonamides',
},
{
authorReference: {
reference: 'https://sandbox-api.va.gov/services/fhir/v0/r4/Practitioner/4-Nn79MgdlF9vV',
display: 'Dr. Alicia629 Ureña88 MD',
},
time: '2019-03-13T12:30:00Z',
text: 'Patient has a family history of sulfa allergy',
},
{
authorReference: {
reference: 'https://sandbox-api.va.gov/services/fhir/v0/r4/Practitioner/4-Nn79MgdlF9vV',
display: 'Dr. Alicia629 Ureña88 MD',
},
time: '2020-03-15T16:30:00Z',
text: 'Additional episode of hives',
},
]

const initializeTestInstance = (allergy: Allergy = defaultAllergy) => {
const props = mockNavProps(undefined, undefined, { params: { allergy: allergy } })
render(<AllergyDetailsScreen {...props} />)
}

it('initializes correctly for default allergy', async () => {
initializeTestInstance()
await waitFor(() => expect(screen.getByText('March 12, 2019')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Type')).toBeTruthy())
await waitFor(() => expect(screen.getByText('medication')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Provider')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Dr. Alicia629 Ureña88 MD')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Reaction')).toBeTruthy())
await waitFor(() => expect(screen.getByText('None noted')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Notes')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Sulfonamides')).toBeTruthy())
await waitFor(() =>
expect(
screen.getByText(
'We base this information on your current VA health records. If you have any questions, contact your health care team.',
),
).toBeTruthy(),
)
})

it('initializes correctly for allergy with reactions', async () => {
const allergyWithReactions = {
...defaultAllergy,
attributes: {
...defaultAllergy.attributes,
reactions: reactions,
},
}

initializeTestInstance(allergyWithReactions)
await waitFor(() => expect(screen.getByText('March 12, 2019')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Type')).toBeTruthy())
await waitFor(() => expect(screen.getByText('medication')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Provider')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Dr. Alicia629 Ureña88 MD')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Reaction')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Urticaria (Hives)')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Notes')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Sulfonamides')).toBeTruthy())
await waitFor(() => {
const textElement = screen.queryByText(
'We base this information on your current VA health records. If you have any questions, contact your health care team.',
)
expect(textElement).toBeNull()
})
})

it('initializes correctly for allergy with multiple categories', async () => {
const allergyWithCategories = {
...defaultAllergy,
attributes: {
...defaultAllergy.attributes,
reactions: reactions,
category: ['medication', 'food'],
},
}

initializeTestInstance(allergyWithCategories)
await waitFor(() => expect(screen.getByText('March 12, 2019')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Type')).toBeTruthy())
await waitFor(() => expect(screen.getByText('medication')).toBeTruthy())
await waitFor(() => expect(screen.getByText('food')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Provider')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Dr. Alicia629 Ureña88 MD')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Reaction')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Urticaria (Hives)')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Notes')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Sulfonamides')).toBeTruthy())
await waitFor(() => {
const textElement = screen.queryByText(
'We base this information on your current VA health records. If you have any questions, contact your health care team.',
)
expect(textElement).toBeNull()
})
})

it('initializes correctly for allergy with multiple notes', async () => {
const allergyWithNotes = {
...defaultAllergy,
attributes: {
...defaultAllergy.attributes,
reactions: reactions,
category: ['medication', 'food'],
notes: notes,
},
}

initializeTestInstance(allergyWithNotes)
await waitFor(() => expect(screen.getByText('March 12, 2019')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Type')).toBeTruthy())
await waitFor(() => expect(screen.getByText('medication')).toBeTruthy())
await waitFor(() => expect(screen.getByText('food')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Provider')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Dr. Alicia629 Ureña88 MD')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Reaction')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Urticaria (Hives)')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Notes')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Sulfonamides')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Patient has a family history of sulfa allergy')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Additional episode of hives')).toBeTruthy())
await waitFor(() => {
const textElement = screen.queryByText(
'We base this information on your current VA health records. If you have any questions, contact your health care team.',
)
expect(textElement).toBeNull()
})
})
})
Loading
Loading