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

(refactor): Implement json workflow for Service Summary under hct on the patient chart. #1872

Merged
merged 2 commits into from
Jun 17, 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
1 change: 1 addition & 0 deletions packages/esm-commons-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export * from './components/patient-table/patient-table.component';
export * from './hooks/useLastEncounter';
export * from './utils/encounter-list-config-builder';
export * from './utils/summary-card-config-builder';
export * from './utils/encounter-tile-config-builder';
// Workspace registration moved to the index.ts and routes.json
const options = {
featureName: 'ohri-forms-workspace-item',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { getObsFromEncounter, getConceptFromMappings } from './encounter-list-utils';
import { extractSchemaValues, replaceWithConfigDefaults } from './schema-manipulation';

interface MenuCardProps {
menuId: string;
columns: Array<ColumnDefinition>;
}

interface SummaryConcept {
primaryConcept: string;
secondaryConcept?: string;
isDate?: boolean;
hasCalculatedDate?: boolean;
}
interface ColumnDefinition {
id: string;
title: string;
concept: string;
encounterType: string;
isDate?: boolean;
hasSummary?: boolean;
conceptMappings?: Array<string>;
summaryConcept?: SummaryConcept;
}

interface FormattedCardColumn {
key: string;
header: string;
concept: string;
encounterUuid: string;
getObsValue: (encounter: any) => string;
getSummaryObsValue?: (encounter: any) => string;
hasSummary: boolean;
}

const calculateDateDifferenceInDate = (givenDate: string): string => {
const dateDifference = new Date().getTime() - new Date(givenDate).getTime();
const totalDays = Math.floor(dateDifference / (1000 * 3600 * 24));
return `${totalDays} days`;
};

export const getEncounterTileColumns = (schemaConfig: MenuCardProps, config = null) => {
const configDefaults = extractSchemaValues(config);
const transformedSchemaConfig = replaceWithConfigDefaults(schemaConfig, configDefaults);

const columns: Array<FormattedCardColumn> = transformedSchemaConfig.columns?.map((column) => ({
key: column.id,
header: column.title,
concept: column.concept,
encounterUuid: column.encounterType,
hasSummary: column.hasSummary || false,
getObsValue: (encounter) => {
if (column.conceptMappings) {
const concept = getConceptFromMappings(encounter, column.conceptMappings);
return getObsFromEncounter(
encounter,
concept,
column.isDate,
column.isTrueFalseConcept,
column.type,
column.fallbackConcepts,
);
}
return getObsFromEncounter(encounter, column.concept, column.isDate);
},
getSummaryObsValue: column.hasSummary
? (encounter) => {
if (column.summaryConcept.secondaryConcept) {
const primaryConceptType = getObsFromEncounter(encounter, column.summaryConcept.primaryConcept);
if (primaryConceptType !== '--') {
return primaryConceptType;
} else {
return getObsFromEncounter(encounter, column.summaryConcept.secondaryConcept);
}
}

if (column.summaryConcept.hasCalculatedDate) {
const primaryDate = getObsFromEncounter(
encounter,
column.summaryConcept.primaryConcept,
column.summaryConcept.hasDate,
);

if (primaryDate !== '--') {
return calculateDateDifferenceInDate(primaryDate);
} else {
return '--';
}
}

return getObsFromEncounter(encounter, column.summaryConcept.primaryConcept, column.summaryConcept.hasDate);
}
: null,
}));

return columns;
};
5 changes: 4 additions & 1 deletion packages/esm-commons-lib/src/utils/schema-manipulation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export function extractSchemaValues(schema) {
const result = {};
function traverse(obj) {
Object.entries(obj).forEach(([key, value]) => {
if (obj === null || obj === undefined || typeof obj !== 'object') {
return;
}
Object.entries(obj)?.forEach(([key, value]) => {
if (value !== undefined && value !== null) {
if (typeof value === 'object' && !Array.isArray(value)) {
traverse(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"menuId": "serviceSummary",
"columns": [
{
"id": "artCohort",
"title": "ART Cohort",
"encounterType": "art_Therapy_EncounterUUID",
"concept": "artTherapyDateTime_UUID",
"isDate": true,
"conceptMappings": [
"artTherapyDateTime_UUID",
"artStopDateUUID",
"switchDateUUID",
"substitutionDateUUID",
"dateRestartedUUID"
]
},
{
"id": "currentRegimen",
"hasSummary": true,
"title": "Current Regimen",
"encounterType": "art_Therapy_EncounterUUID",
"concept": "regimenConcept",
"summaryConcept": {
"primaryConcept": "regimenLine_UUID"
}
},
{
"id": "dsdModel",
"title": "DSD Model",
"hasSummary": true,
"encounterType": "ServiceDeliveryEncounterType_UUID",
"concept": "CommunityDSDModel_UUID",
"summaryConcept": {
"primaryConcept": "CommunityDSDModel_UUID"
}
},
{
"id": "populationType",
"title": "Population Type",
"encounterType": "careAndTreatmentEncounterType",
"concept": "populationCategoryConcept",
"hasSummary": true,
"summaryConcept": {
"primaryConcept": "keyPopulationTypeConcept",
"secondaryConcept": "priorityPopulationTypeConcept"
}
}
]
}
Loading
Loading