diff --git a/src/config/patient-chart-widgets.schema.ts b/src/config/programs.schema.ts similarity index 61% rename from src/config/patient-chart-widgets.schema.ts rename to src/config/programs.schema.ts index 5f24ded..cb9b06f 100644 --- a/src/config/patient-chart-widgets.schema.ts +++ b/src/config/programs.schema.ts @@ -1,6 +1,6 @@ import { validators } from "@openmrs/esm-module-config"; -export const esmPatientChartWidgetsSchema = { +export const programsConfigSchema = { programs: { arrayElements: { programUuid: { validators: [validators.isString] }, @@ -16,3 +16,18 @@ export const esmPatientChartWidgetsSchema = { default: [] } }; + +export type ProgramFormsConfig = { + programUuid: string; + programName: string; + forms: Array; +}; + +export interface ProgramConfig { + programs: ProgramFormsConfig[]; +} + +export type FormSelector = { + encounterTypeUuid: string; + formUuid?: string; +}; diff --git a/src/config/use-widget-config.ts b/src/config/use-widget-config.ts new file mode 100644 index 0000000..514684c --- /dev/null +++ b/src/config/use-widget-config.ts @@ -0,0 +1,8 @@ +import React from "react"; +import { useConfig, validateConfig } from "@openmrs/esm-module-config"; + +export default function useWidgetConfig(key: string, schema: any): T { + const config = useConfig()[key] as T; + validateConfig(schema, config); + return config; +} diff --git a/src/forms/form-grouper.test.ts b/src/forms/form-grouper.test.ts index 4ef9178..d810b81 100644 --- a/src/forms/form-grouper.test.ts +++ b/src/forms/form-grouper.test.ts @@ -1,10 +1,7 @@ -import { - ProgramFormsConfig, - ProgramForms, - groupFormsByProgram -} from "./form-grouper"; +import { ProgramForms, groupFormsByProgram } from "./form-grouper"; import { Form } from "../openmrs-resource/form.resource"; import { Encounter } from "../openmrs-resource/encounter.resource"; +import { ProgramFormsConfig } from "../config/programs.schema"; describe("Form Grouper", () => { const programFormsConfig: Array = [ { diff --git a/src/forms/form-grouper.ts b/src/forms/form-grouper.ts index deb5dd0..38e5def 100644 --- a/src/forms/form-grouper.ts +++ b/src/forms/form-grouper.ts @@ -1,6 +1,7 @@ import { Form } from "../openmrs-resource/form.resource"; import { FormsFilter, areFormsEqual } from "./form-list-filter"; import { Encounter } from "../openmrs-resource/encounter.resource"; +import { ProgramFormsConfig } from "../config/programs.schema"; export function groupFormsByProgram( forms: Array
, @@ -67,18 +68,3 @@ export type ProgramForms = { availableForms?: Array; completedForms?: Array; }; - -export type ProgramFormsConfig = { - programUuid: string; - programName: string; - forms: Array; -}; - -export type ProgramConfig = { - programs: ProgramFormsConfig[]; -}; - -export type FormSelector = { - encounterTypeUuid: string; - formUuid?: string; -}; diff --git a/src/forms/forms-list.component.tsx b/src/forms/forms-list.component.tsx index 2dd5965..f5524ef 100644 --- a/src/forms/forms-list.component.tsx +++ b/src/forms/forms-list.component.tsx @@ -13,8 +13,15 @@ import { filterAvailableCompletedForms } from "./form-grouper"; import Parcel from "single-spa-react/parcel"; import { Link } from "react-router-dom"; import { Subscription } from "rxjs"; +import { ProgramConfig, programsConfigSchema } from "../config/programs.schema"; +import useWidgetConfig from "../config/use-widget-config"; export default function FormsList(props: FormsListProps) { + const config = useWidgetConfig( + "externalPatientChartConfigs", + programsConfigSchema + ); + // console.log("config", config); // console.log("props", props); const baseChartUrl = `${props.match.url.substr( 0, diff --git a/src/visit/start-visit.component.tsx b/src/visit/start-visit.component.tsx index 389b310..f57a913 100644 --- a/src/visit/start-visit.component.tsx +++ b/src/visit/start-visit.component.tsx @@ -7,12 +7,8 @@ import { FetchResponse } from "@openmrs/esm-api/dist/openmrs-fetch"; import styles from "./start-visit.component.css"; import LocationSelectComponent from "../widgets/location-select.component"; import { toOmrsDateString } from "../utils/omrs-dates"; -import { ProgramConfig } from "../forms/form-grouper"; -import { useConfig } from "@openmrs/esm-module-config"; export default function StartVisitComponent(props: StartVisitProps) { - const config: ProgramConfig = useConfig(); - const [patientUuid, setPatientUuid] = React.useState(); const [visitStartDate, setVisitStartDate] = React.useState( diff --git a/src/visit/visit-summary.component.tsx b/src/visit/visit-summary.component.tsx index e9a8003..46d7314 100644 --- a/src/visit/visit-summary.component.tsx +++ b/src/visit/visit-summary.component.tsx @@ -8,14 +8,8 @@ import StartVisitComponent from "./start-visit.component"; import StartedVisitComponent from "./started-visit.component"; import useStartedVisit from "./use-started-visit"; import styles from "../summary-card.css"; -import { esmPatientChartWidgetsSchema } from "../config/patient-chart-widgets.schema"; export default function VisitSummaryComponent(props: any) { - defineConfigSchema( - "@ampath/esm-patient-chart-widgets", - esmPatientChartWidgetsSchema - ); - const visitToStart: VisitTypeProp = { // Intentional: useful for switching between openmrs-spa and ampath environment for testing // visitTypeUuid: "7b0f5697-27e3-40c4-8bae-f4049abfb4ed", @@ -43,72 +37,68 @@ export default function VisitSummaryComponent(props: any) { }; return ( - +
+
+
+

+ {startedVisit + ? "Today's Outpatient Visit" + : "Start New Clinical Visit"} +

+
+
-
-
-

- {startedVisit - ? "Today's Outpatient Visit" - : "Start New Clinical Visit"} -

-
-
-
- {!startingVisit && startedVisit === undefined && ( -
Loading...
- )} - {startingVisit && ( - - )} - {!startingVisit && startedVisit === null && ( + {!startingVisit && startedVisit === undefined &&
Loading...
} + {startingVisit && ( + + )} + {!startingVisit && startedVisit === null && ( +
+
+ +
-
- -
-
- - - -
+ +
- )} +
+ )} - {startedVisit && } -
+ {startedVisit && }
- +
); }