-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate hiv program management to JSON config workflow
- Loading branch information
1 parent
02b422a
commit 990cfc2
Showing
11 changed files
with
705 additions
and
720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/esm-commons-lib/src/utils/encounter-list-builder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { getObsFromEncounter, findObs } from './encounter-list-utils'; | ||
|
||
interface MenuProps { | ||
menuId: string; | ||
tabDefinitions: Array<TabSchema>; | ||
} | ||
interface ActionProps { | ||
mode: string; | ||
label: string; | ||
package: string; | ||
formName: string; | ||
} | ||
interface ColumnDefinition { | ||
id: string; | ||
title: string; | ||
isComplex?: boolean; | ||
concept?: string; | ||
fallbackConcepts?: Array<string>; | ||
actionOptions?: Array<ActionProps>; | ||
isDate?: boolean; | ||
isTrueFalseConcept?: boolean; | ||
type?: string; | ||
} | ||
|
||
interface LaunchOptions { | ||
displayText: string; | ||
moduleName: string; | ||
} | ||
interface TabSchema { | ||
tabName: string; | ||
headerTitle: string; | ||
displayText: string; | ||
encounterType: string; | ||
columns: Array<ColumnDefinition>; | ||
formList: Array<{ name: string; uuid: string }>; | ||
launchOptions: LaunchOptions; | ||
} | ||
|
||
interface FormattedColumn { | ||
key: string; | ||
header: string; | ||
getValue: (encounter: any) => string; | ||
link?: any; | ||
} | ||
export const getTabColumns = (columnsDefinition: Array<ColumnDefinition>) => { | ||
const columns: Array<FormattedColumn> = columnsDefinition.map((column: ColumnDefinition) => ({ | ||
key: column.id, | ||
header: column.title, | ||
getValue: (encounter) => { | ||
if (column.id === 'actions') { | ||
return column.actionOptions.map((action: ActionProps) => ({ | ||
form: { name: action.formName, package: action.package }, | ||
encounterUuid: encounter.uuid, | ||
intent: '*', | ||
label: action.label, | ||
mode: action.mode, | ||
})); | ||
} else { | ||
return getObsFromEncounter( | ||
encounter, | ||
column.concept, | ||
column.isDate, | ||
column.isTrueFalseConcept, | ||
column.type, | ||
column.fallbackConcepts, | ||
); | ||
} | ||
}, | ||
})); | ||
|
||
return columns; | ||
}; | ||
|
||
export const getMenuItemTabConfiguration = (schemaConfig: MenuProps) => { | ||
const tabs = schemaConfig.tabDefinitions.map((tab) => { | ||
return { | ||
name: tab.tabName, | ||
encounterType: tab.encounterType, | ||
headerTitle: tab.headerTitle, | ||
description: tab.displayText, | ||
formList: tab.formList, | ||
columns: getTabColumns(tab.columns), | ||
launchOptions: tab.launchOptions, | ||
}; | ||
}); | ||
|
||
return tabs; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.