@openmrs/esm-fast-data-entry-app 1.0.0-pre.34 → 1.0.0-pre.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.github/pull_request_template.md +18 -0
  2. package/dist/120.js +2 -0
  3. package/dist/{147.js.LICENSE.txt → 120.js.LICENSE.txt} +6 -0
  4. package/dist/574.js +1 -1
  5. package/dist/595.js +1 -1
  6. package/dist/595.js.LICENSE.txt +0 -2
  7. package/dist/61.js +1 -0
  8. package/dist/804.js +1 -1
  9. package/dist/84.js +1 -0
  10. package/dist/990.js +1 -0
  11. package/dist/openmrs-esm-fast-data-entry-app.js +1 -1
  12. package/dist/openmrs-esm-fast-data-entry-app.js.buildmanifest.json +77 -77
  13. package/dist/openmrs-esm-fast-data-entry-app.old +1 -1
  14. package/package.json +4 -4
  15. package/src/FormBootstrap.tsx +2 -0
  16. package/src/Root.tsx +6 -9
  17. package/src/context/FormWorkflowContext.tsx +43 -15
  18. package/src/context/FormWorkflowReducer.ts +41 -0
  19. package/src/form-entry-workflow/FormEntryWorkflow.tsx +116 -54
  20. package/src/form-entry-workflow/styles.scss +13 -6
  21. package/src/form-review-card/FormReviewCard.tsx +50 -0
  22. package/src/form-review-card/index.ts +3 -0
  23. package/src/form-review-card/styles.scss +38 -0
  24. package/src/forms-table/FormsTable.tsx +3 -5
  25. package/src/hooks/index.ts +3 -1
  26. package/src/hooks/useFormState.ts +23 -0
  27. package/src/hooks/useGetEncounter.ts +22 -0
  28. package/src/patient-banner/PatientBanner.test.tsx +1 -1
  29. package/src/patient-banner/PatientBanner.tsx +51 -105
  30. package/src/patient-banner/styles.scss +13 -28
  31. package/src/patient-card/PatientCard.tsx +2 -2
  32. package/src/patient-card/styles.scss +6 -5
  33. package/src/patient-search-header/PatientSearchHeader.tsx +3 -1
  34. package/src/patient-search-header/styles.scss +6 -2
  35. package/src/workflow-review/WorkflowReview.tsx +36 -0
  36. package/src/workflow-review/index.ts +3 -0
  37. package/src/workflow-review/styles.scss +34 -0
  38. package/translations/en.json +1 -0
  39. package/dist/147.js +0 -2
  40. package/dist/508.js +0 -1
  41. package/dist/634.js +0 -2
  42. package/dist/634.js.LICENSE.txt +0 -5
  43. package/dist/954.js +0 -1
@@ -6,6 +6,7 @@ const reducer = (state, action) => {
6
6
  patientUuids: [...state.patientUuids, action.patientUuid],
7
7
  activePatientUuid: action.patientUuid,
8
8
  activeEncounterUuid: null,
9
+ workflowState: "EDIT_FORM",
9
10
  };
10
11
  case "OPEN_PATIENT_SEARCH":
11
12
  // this will need to be updated once AMPATH hook is available
@@ -13,6 +14,7 @@ const reducer = (state, action) => {
13
14
  ...state,
14
15
  activePatientUuid: null,
15
16
  activeEncounterUuid: null,
17
+ workflowState: "NEW_PATIENT",
16
18
  };
17
19
  case "SAVE_ENCOUNTER":
18
20
  return {
@@ -23,12 +25,51 @@ const reducer = (state, action) => {
23
25
  },
24
26
  activePatientUuid: null,
25
27
  activeEncounterUuid: null,
28
+ workflowState:
29
+ state.workflowState === "SUBMIT_FOR_NEXT"
30
+ ? "NEW_PATIENT"
31
+ : state.workflowState === "SUBMIT_FOR_REVIEW"
32
+ ? "REVIEW"
33
+ : state.workflowState,
26
34
  };
27
35
  case "EDIT_ENCOUNTER":
28
36
  return {
29
37
  ...state,
30
38
  activeEncounterUuid: state.encounters[action.patientUuid],
31
39
  activePatientUuid: action.patientUuid,
40
+ workflowState: "EDIT_FORM",
41
+ };
42
+ case "SUBMIT_FOR_NEXT":
43
+ window.dispatchEvent(
44
+ new CustomEvent("ampath-form-action", {
45
+ detail: { formUuid: state.formUuid, action: "onSubmit" },
46
+ })
47
+ );
48
+ return {
49
+ ...state,
50
+ workflowState: "SUBMIT_FOR_NEXT",
51
+ };
52
+ case "SUBMIT_FOR_REVIEW":
53
+ window.dispatchEvent(
54
+ new CustomEvent("ampath-form-action", {
55
+ detail: { formUuid: state.formUuid, action: "onSubmit" },
56
+ })
57
+ );
58
+ return {
59
+ ...state,
60
+ workflowState: "SUBMIT_FOR_REVIEW",
61
+ };
62
+ case "UPDATE_FORM_UUID":
63
+ return {
64
+ ...state,
65
+ formUuid: action.formUuid,
66
+ };
67
+ case "GO_TO_REVIEW":
68
+ return {
69
+ ...state,
70
+ activeEncounterUuid: null,
71
+ activePatientUuid: null,
72
+ workflowState: "REVIEW",
32
73
  };
33
74
  default:
34
75
  return state;
@@ -1,28 +1,80 @@
1
- import { ExtensionSlot } from "@openmrs/esm-framework";
1
+ import {
2
+ ExtensionSlot,
3
+ getGlobalStore,
4
+ useStore,
5
+ } from "@openmrs/esm-framework";
2
6
  import { Button } from "carbon-components-react";
3
- import React, { useContext, useState } from "react";
4
- import { useHistory, useParams } from "react-router-dom";
7
+ import React, { useContext } from "react";
8
+ import { useHistory } from "react-router-dom";
5
9
  import FormBootstrap from "../FormBootstrap";
6
10
  import PatientCard from "../patient-card/PatientCard";
7
11
  import PatientBanner from "../patient-banner";
8
12
  import styles from "./styles.scss";
9
13
  import PatientSearchHeader from "../patient-search-header";
10
14
  import { useTranslation } from "react-i18next";
11
- import FormWorkflowContext from "../context/FormWorkflowContext";
15
+ import FormWorkflowContext, {
16
+ FormWorkflowProvider,
17
+ } from "../context/FormWorkflowContext";
18
+ import WorkflowReview from "../workflow-review";
12
19
 
13
20
  interface ParamTypes {
14
21
  formUuid: string;
15
22
  }
16
23
 
17
- const FormEntryWorkflow = () => {
18
- const { formUuid } = useParams() as ParamTypes;
24
+ const formStore = getGlobalStore("ampath-form-state");
25
+
26
+ const WorkflowNavigationButtons = () => {
27
+ const {
28
+ formUuid,
29
+ submitForReview,
30
+ submitForNext,
31
+ workflowState,
32
+ goToReview,
33
+ } = useContext(FormWorkflowContext);
19
34
  const history = useHistory();
35
+ const store = useStore(formStore);
36
+ const formState = store[formUuid];
37
+ const navigationDisabled = formState !== "ready";
38
+ const { t } = useTranslation();
39
+
40
+ return (
41
+ <div className={styles.rightPanelActionButtons}>
42
+ <Button
43
+ kind="primary"
44
+ onClick={() => submitForNext()}
45
+ disabled={navigationDisabled || workflowState === "NEW_PATIENT"}
46
+ >
47
+ {t("nextPatient", "Next Patient")}
48
+ </Button>
49
+ <Button
50
+ kind="secondary"
51
+ disabled={navigationDisabled}
52
+ onClick={
53
+ workflowState === "NEW_PATIENT"
54
+ ? () => goToReview()
55
+ : () => submitForReview()
56
+ }
57
+ >
58
+ {t("reviewSave", "Review & Save")}
59
+ </Button>
60
+ <Button
61
+ kind="tertiary"
62
+ onClick={() => history.push("/")}
63
+ disabled={navigationDisabled}
64
+ >
65
+ {t("cancel", "Cancel")}
66
+ </Button>
67
+ </div>
68
+ );
69
+ };
70
+
71
+ const FormWorkspace = () => {
20
72
  const {
21
73
  patientUuids,
22
74
  activePatientUuid,
23
75
  activeEncounterUuid,
24
- openPatientSearch,
25
76
  saveEncounter,
77
+ formUuid,
26
78
  } = useContext(FormWorkflowContext);
27
79
  const { t } = useTranslation();
28
80
 
@@ -33,56 +85,66 @@ const FormEntryWorkflow = () => {
33
85
  };
34
86
 
35
87
  return (
36
- <div>
37
- <div className={styles.breadcrumbsContainer}>
38
- <ExtensionSlot extensionSlotName="breadcrumbs-slot" />
39
- </div>
40
- {!activePatientUuid && <PatientSearchHeader />}
41
- {activePatientUuid && <PatientBanner patientUuid={activePatientUuid} />}
42
- <div className={styles.workspaceWrapper}>
43
- <div className={styles.workspace}>
44
- {!patientUuids.length && (
45
- <div className={styles.selectPatientMessage}>
46
- {t("selectPatientFirst", "Please select a patient first")}
47
- </div>
48
- )}
49
- {!!patientUuids.length && (
50
- <div className={styles.formMainContent}>
51
- <div className={styles.formContainer}>
52
- <FormBootstrap
53
- patientUuid={activePatientUuid}
54
- encounterUuid={activeEncounterUuid}
55
- {...{
56
- formUuid,
57
- handlePostResponse,
58
- }}
59
- />
60
- </div>
61
- <div className={styles.rightPanel}>
62
- <h4>Forms filled</h4>
63
- <div className={styles.patientCardsSection}>
64
- {patientUuids.map((patientUuid) => (
65
- <PatientCard patientUuid={patientUuid} key={patientUuid} />
66
- ))}
67
- </div>
68
- <div className={styles.rightPanelActionButtons}>
69
- <Button kind="primary" onClick={() => openPatientSearch()}>
70
- {t("nextPatient", "Next Patient")}
71
- </Button>
72
- <Button kind="secondary" disabled>
73
- {t("reviewSave", "Review & Save")}
74
- </Button>
75
- <Button kind="tertiary" onClick={() => history.push("/")}>
76
- {t("cancel", "Cancel")}
77
- </Button>
78
- </div>
79
- </div>
88
+ <div className={styles.workspace}>
89
+ {!patientUuids.length && (
90
+ <div className={styles.selectPatientMessage}>
91
+ {t("selectPatientFirst", "Please select a patient first")}
92
+ </div>
93
+ )}
94
+ {!!patientUuids.length && (
95
+ <div className={styles.formMainContent}>
96
+ <div className={styles.formContainer}>
97
+ <FormBootstrap
98
+ patientUuid={activePatientUuid}
99
+ encounterUuid={activeEncounterUuid}
100
+ {...{
101
+ formUuid,
102
+ handlePostResponse,
103
+ }}
104
+ />
105
+ </div>
106
+ <div className={styles.rightPanel}>
107
+ <h4>Forms filled</h4>
108
+ <div className={styles.patientCardsSection}>
109
+ {patientUuids.map((patientUuid) => (
110
+ <PatientCard patientUuid={patientUuid} key={patientUuid} />
111
+ ))}
80
112
  </div>
81
- )}
113
+ <WorkflowNavigationButtons />
114
+ </div>
82
115
  </div>
83
- </div>
116
+ )}
84
117
  </div>
85
118
  );
86
119
  };
87
120
 
88
- export default FormEntryWorkflow;
121
+ const FormEntryWorkflow = () => {
122
+ const { workflowState } = useContext(FormWorkflowContext);
123
+ return (
124
+ <>
125
+ <div className={styles.breadcrumbsContainer}>
126
+ <ExtensionSlot extensionSlotName="breadcrumbs-slot" />
127
+ </div>
128
+ {workflowState === "REVIEW" && <WorkflowReview />}
129
+ {workflowState !== "REVIEW" && (
130
+ <>
131
+ <PatientSearchHeader />
132
+ <PatientBanner />
133
+ <div className={styles.workspaceWrapper}>
134
+ <FormWorkspace />
135
+ </div>
136
+ </>
137
+ )}
138
+ </>
139
+ );
140
+ };
141
+
142
+ const FormEntryWorkflowWrapper = () => {
143
+ return (
144
+ <FormWorkflowProvider>
145
+ <FormEntryWorkflow />
146
+ </FormWorkflowProvider>
147
+ );
148
+ };
149
+
150
+ export default FormEntryWorkflowWrapper;
@@ -4,9 +4,9 @@
4
4
 
5
5
 
6
6
  .breadcrumbsContainer > div > div > nav {
7
- background-color: white;
8
- padding: 0.5rem;
9
- border-bottom: 1px solid $openmrs-background-grey;
7
+ background-color: $ui-02;
8
+ padding: $spacing-04 $spacing-05;
9
+ height: $spacing-08;
10
10
  }
11
11
 
12
12
  .workspaceWrapper {
@@ -27,28 +27,35 @@
27
27
  .formMainContent {
28
28
  display: flex;
29
29
  text-align: center;
30
- margin-top: 1rem;
30
+ margin-top: $spacing-05;
31
+ column-gap: $spacing-05;
31
32
  }
32
33
 
33
34
  .formContainer {
34
35
  flex-grow: 1;
35
36
  max-height: calc(100vh - 14rem);
37
+ overflow-y: scroll;
38
+ }
39
+
40
+ .formContainer :global(.bx--form-item) :global(.question-area) {
41
+ max-width: 100%;
36
42
  }
37
43
 
38
44
  .rightPanel {
39
45
  width: 13rem;
40
46
  text-align: left;
47
+ overflow-y: scroll;
41
48
  }
42
49
 
43
50
  .patientCardsSection {
44
- margin: 1rem 0;
51
+ margin: $spacing-05 0;
45
52
  border-bottom: 1px solid $carbon--gray-10;
46
53
  }
47
54
 
48
55
  .rightPanelActionButtons {
49
56
  display: flex;
50
57
  flex-direction: column;
51
- row-gap: 0.5rem;
58
+ row-gap: $spacing-03;
52
59
  & button {
53
60
  width: 100%;
54
61
  text-decoration: "none";
@@ -0,0 +1,50 @@
1
+ import { Accordion, AccordionItem, Button } from "carbon-components-react";
2
+ import React, { useContext } from "react";
3
+ import { useTranslation } from "react-i18next";
4
+ import FormWorkflowContext from "../context/FormWorkflowContext";
5
+ import { useGetPatient, useGetEncounter } from "../hooks";
6
+ import styles from "./styles.scss";
7
+
8
+ const FormReviewCard = ({ patientUuid }) => {
9
+ const { encounters, editEncounter } = useContext(FormWorkflowContext);
10
+ const patient = useGetPatient(patientUuid);
11
+ const givenName = patient?.name?.[0]?.given?.[0];
12
+ const familyName = patient?.name?.[0]?.family;
13
+ const identifier = patient?.identifier?.[0]?.value;
14
+ const encounterUuid = encounters?.[patientUuid];
15
+ const { encounter } = useGetEncounter(encounterUuid);
16
+ const { t } = useTranslation();
17
+
18
+ return (
19
+ <div className={styles.formReviewCard}>
20
+ <Accordion align="start">
21
+ <AccordionItem
22
+ title={
23
+ <>
24
+ <span className={styles.identifier}>{identifier}</span>
25
+ <span className={styles.displayName}>
26
+ {givenName} {familyName}
27
+ </span>
28
+ </>
29
+ }
30
+ className={styles.accordionItem}
31
+ >
32
+ {encounter && encounter?.obs && encounter.obs?.length && (
33
+ <div className={styles.dataField}>
34
+ <ul>
35
+ {encounter.obs.map((obs, index) => (
36
+ <li key={index}>{obs.display}</li>
37
+ ))}
38
+ </ul>
39
+ </div>
40
+ )}
41
+ <Button kind="primary" onClick={() => editEncounter(patientUuid)}>
42
+ {t("goToForm", "Go To Form")}
43
+ </Button>
44
+ </AccordionItem>
45
+ </Accordion>
46
+ </div>
47
+ );
48
+ };
49
+
50
+ export default FormReviewCard;
@@ -0,0 +1,3 @@
1
+ import FormReviewCard from "./FormReviewCard";
2
+
3
+ export default FormReviewCard;
@@ -0,0 +1,38 @@
1
+ @import "~@openmrs/esm-styleguide/src/vars";
2
+ @import "~carbon-components/src/globals/scss/vars";
3
+ @import "~carbon-components/src/globals/scss/mixins";
4
+
5
+
6
+ .formReviewCard {
7
+ background-color: $ui-02;
8
+ padding: $spacing-02;
9
+ }
10
+
11
+ .formReviewCard :global(.bx--accordion) :global(.bx--accordion__item) {
12
+ border: none;
13
+ }
14
+
15
+ .formReviewCard :global(.bx--accordion__title) {
16
+ display: flex;
17
+ align-items: baseline;
18
+ column-gap: $spacing-05;
19
+ }
20
+
21
+ .formReviewCard :global(.bx--accordion__content) {
22
+ padding: $spacing-03;
23
+ }
24
+
25
+ .dataField {
26
+ @include carbon--type-style('code-02');
27
+ background-color: $ui-01;
28
+ padding: $spacing-03;
29
+ }
30
+
31
+ .displayName {
32
+ @include carbon--type-style('productive-heading-02');
33
+ font-weight: bold;
34
+ }
35
+
36
+ .identifier {
37
+ @include carbon--type-style('body-short-01')
38
+ }
@@ -1,3 +1,4 @@
1
+ import { ErrorState } from "@openmrs/esm-framework";
1
2
  import {
2
3
  DataTable,
3
4
  DataTableSkeleton,
@@ -49,12 +50,9 @@ const FormsTable = ({ rows, error, isLoading }) => {
49
50
  if (isLoading) return <DataTableSkeleton />;
50
51
  if (error) {
51
52
  return (
52
- <EmptyState
53
+ <ErrorState
53
54
  headerTitle={t("errorLoadingData", "Error Loading Data")}
54
- displayText={`${t(
55
- "dataErrorMessage",
56
- "Something went wrong loading data from the server."
57
- )} "${error?.response?.status}: ${error?.response?.statusText}"`}
55
+ error={error}
58
56
  />
59
57
  );
60
58
  }
@@ -1,4 +1,6 @@
1
1
  import useGetAllForms from "./useGetAllForms";
2
2
  import useGetPatient from "./useGetPatient";
3
+ import useFormState from "./useFormState";
4
+ import useGetEncounter from "./useGetEncounter";
3
5
 
4
- export { useGetAllForms, useGetPatient };
6
+ export { useGetAllForms, useGetPatient, useFormState, useGetEncounter };
@@ -0,0 +1,23 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ const useFormState = (formUuid) => {
4
+ const [state, setState] = useState(null);
5
+
6
+ useEffect(() => {
7
+ const handler = (e) => {
8
+ if (e.detail?.formUuid === formUuid) {
9
+ setState(e.detail?.state);
10
+ }
11
+ };
12
+
13
+ window.addEventListener("ampath-form-state", handler);
14
+
15
+ return () => {
16
+ window.removeEventListener("ampath-form-state", handler);
17
+ };
18
+ }, [formUuid]);
19
+
20
+ return state;
21
+ };
22
+
23
+ export default useFormState;
@@ -0,0 +1,22 @@
1
+ import { fetchCurrentPatient, openmrsFetch } from "@openmrs/esm-framework";
2
+ import { useEffect, useState } from "react";
3
+ import useSWR from "swr";
4
+
5
+ const encounterUrl = "/ws/rest/v1/encounter/";
6
+
7
+ const useGetEncounter = (encounterUuid) => {
8
+ const url = `${encounterUrl}${encounterUuid}`;
9
+ const { data, error } = useSWR(url, async () => {
10
+ const res = await openmrsFetch(url);
11
+ const encounter = res.data || null;
12
+ return encounter;
13
+ });
14
+
15
+ return {
16
+ encounter: data,
17
+ isLoading: !error && data,
18
+ error,
19
+ };
20
+ };
21
+
22
+ export default useGetEncounter;
@@ -4,6 +4,6 @@ import PatientBanner from "./PatientBanner";
4
4
 
5
5
  describe("PatientBanner", () => {
6
6
  it("renders placeholder information when no data is present", () => {
7
- render(<PatientBanner patientUuid={null} />);
7
+ render(<PatientBanner />);
8
8
  });
9
9
  });