Skip to content
Closed
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
338 changes: 267 additions & 71 deletions docs/expandable-data-table-guide.md

Large diffs are not rendered by default.

165 changes: 165 additions & 0 deletions src/__mocks__/allergyMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,168 @@ export const mockAllergyWithEmptyNotes: FhirAllergyIntolerance = {
id: 'allergy-empty-notes',
note: [],
};

/**
* Mock allergy with multiple categories
*/
export const mockAllergyWithMultipleCategories: FhirAllergyIntolerance = {
...mockAllergyIntolerance,
id: 'allergy-multiple-categories',
category: ['food', 'medication', 'environment'],
};

/**
* Mock allergy with different criticality levels
*/
export const mockAllergyWithHighCriticality: FhirAllergyIntolerance = {
...mockAllergyIntolerance,
id: 'allergy-high-criticality',
criticality: 'high',
};

export const mockAllergyWithLowCriticality: FhirAllergyIntolerance = {
...mockAllergyIntolerance,
id: 'allergy-low-criticality',
criticality: 'low',
};

/**
* Mock allergy with specific type
*/
export const mockAllergyWithType: FhirAllergyIntolerance = {
...mockAllergyIntolerance,
id: 'allergy-with-type',
type: 'allergy',
};

export const mockIntoleranceWithType: FhirAllergyIntolerance = {
...mockAllergyIntolerance,
id: 'intolerance-with-type',
type: 'intolerance',
};

/**
* Mock allergy with inactive status
*/
export const mockInactiveAllergy: FhirAllergyIntolerance = {
...mockAllergyIntolerance,
id: 'inactive-allergy',
clinicalStatus: {
coding: [
{
system:
'http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical',
code: 'inactive',
display: 'Inactive',
},
],
},
};

/**
* Mock malformed FHIR bundle
*/
export const mockMalformedFhirBundle = {
resourceType: 'Bundle',
id: 'malformed-bundle',
meta: {
lastUpdated: '2023-01-01T12:00:00Z',
},
// Missing required fields like type, total, link
} as unknown as FhirAllergyIntoleranceBundle;

/**
* Mock bundle with invalid entry structure
*/
export const mockBundleWithInvalidEntry: FhirAllergyIntoleranceBundle = {
resourceType: 'Bundle',
id: 'bundle-invalid-entry',
meta: {
lastUpdated: '2023-01-01T12:00:00Z',
},
type: 'searchset',
total: 1,
link: [
{
relation: 'self',
url: 'http://example.org/fhir/AllergyIntolerance?patient=patient-123',
},
],
entry: [
{
fullUrl: 'http://example.org/fhir/AllergyIntolerance/incomplete-resource',
resource: {
// Incomplete resource
resourceType: 'AllergyIntolerance',
id: 'incomplete-resource',
} as unknown as FhirAllergyIntolerance,
},
],
};

/**
* Mock allergy with invalid coding array
*/
export const mockAllergyWithInvalidCoding: FhirAllergyIntolerance = {
...mockAllergyIntolerance,
id: 'allergy-invalid-coding',
clinicalStatus: {
coding: [], // Empty coding array
},
code: {
coding: [], // Empty coding array
text: 'Allergy with invalid coding',
},
};

/**
* Mock allergy with multiple reactions of different severities
*/
export const mockAllergyWithMultipleSeverities: FhirAllergyIntolerance = {
...mockAllergyIntolerance,
id: 'allergy-multiple-severities',
reaction: [
{
manifestation: [
{
coding: [
{
system: 'http://snomed.info/sct',
code: '247472004',
display: 'Hives',
},
],
},
],
severity: 'mild',
},
{
manifestation: [
{
coding: [
{
system: 'http://snomed.info/sct',
code: '267036007',
display: 'Difficulty breathing',
},
],
},
],
severity: 'severe',
},
{
manifestation: [
{
coding: [
{
system: 'http://snomed.info/sct',
code: '39579001',
display: 'Anaphylaxis',
},
],
},
],
severity: 'severe',
},
],
};
30 changes: 15 additions & 15 deletions src/components/allergies/AllergiesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const AllergiesTable: React.FC = () => {
[],
);

const sortable = useMemo(() => [true, false, false, true, true, true], []);
const sortable = useMemo(() => [true, true, false, true, true, true], []);

// Format allergies for display
const formattedAllergies = useMemo(() => {
Expand All @@ -38,11 +38,15 @@ const AllergiesTable: React.FC = () => {

// Create row class names array for styling rows with severe allergies
const rowClassNames = useMemo(() => {
return formattedAllergies.map((allergy) =>
allergy.reactions?.some((reaction) => reaction.severity === 'severe')
? 'criticalCell'
: '',
);
const classNames: Record<string, string> = {};

formattedAllergies.forEach((allergy) => {
if (allergy.id && allergy.severity && allergy.severity === 'severe') {
classNames[allergy.id] = 'criticalCell';
}
});

return classNames;
}, [formattedAllergies]);

// Function to render cell content based on the cell ID
Expand All @@ -63,17 +67,13 @@ const AllergiesTable: React.FC = () => {
.join(', ')
: 'Not available';
case 'severity':
return allergy.reactions
? allergy.reactions
.map((reaction) => reaction.severity)
.filter((severity): severity is string => !!severity)
.map((severity) => capitalize(severity))
.join(', ')
: 'Not available';
return capitalize(allergy.severity || 'Unknown');
case 'recorder':
return allergy.recorder || 'Not available';
case 'recordedDate':
return formatDateTime(allergy.recordedDate || '');
case 'recordedDate': {
const recordedDate = formatDateTime(allergy.recordedDate || '');
return recordedDate.formattedResult || 'Not available';
}
}
};

Expand Down
Loading