@openmrs/esm-fast-data-entry-app 1.0.1-pre.10 → 1.0.1-pre.17

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 (61) hide show
  1. package/dist/132.js +1 -0
  2. package/dist/247.js +1 -0
  3. package/dist/255.js +1 -0
  4. package/dist/294.js +2 -0
  5. package/dist/294.js.LICENSE.txt +9 -0
  6. package/dist/32.js +1 -0
  7. package/dist/327.js +1 -0
  8. package/dist/403.js +2 -0
  9. package/dist/403.js.LICENSE.txt +14 -0
  10. package/dist/553.js +2 -0
  11. package/dist/553.js.LICENSE.txt +14 -0
  12. package/dist/569.js +2 -0
  13. package/dist/569.js.LICENSE.txt +27 -0
  14. package/dist/574.js +1 -0
  15. package/dist/595.js +2 -0
  16. package/dist/595.js.LICENSE.txt +1 -0
  17. package/dist/617.js +1 -0
  18. package/dist/68.js +2 -0
  19. package/dist/68.js.LICENSE.txt +21 -0
  20. package/dist/776.js +1 -0
  21. package/dist/804.js +1 -0
  22. package/dist/820.js +1 -0
  23. package/dist/906.js +1 -0
  24. package/dist/935.js +2 -0
  25. package/dist/935.js.LICENSE.txt +19 -0
  26. package/dist/main.js +1 -0
  27. package/dist/openmrs-esm-fast-data-entry-app.js +1 -1
  28. package/dist/openmrs-esm-fast-data-entry-app.js.buildmanifest.json +544 -0
  29. package/dist/openmrs-esm-fast-data-entry-app.old +1 -0
  30. package/package.json +5 -3
  31. package/src/add-group-modal/AddGroupModal.tsx +80 -27
  32. package/src/add-group-modal/styles.scss +14 -4
  33. package/src/context/GroupFormWorkflowContext.tsx +2 -0
  34. package/src/context/GroupFormWorkflowReducer.ts +26 -2
  35. package/src/group-form-entry-workflow/GroupFormEntryWorkflow.tsx +2 -2
  36. package/src/group-form-entry-workflow/{group-banner/GroupBanner.test.tsx → group-display-header/GroupDisplayHeader.test.tsx} +2 -2
  37. package/src/group-form-entry-workflow/{group-banner/GroupBanner.tsx → group-display-header/GroupDisplayHeader.tsx} +31 -5
  38. package/src/group-form-entry-workflow/group-display-header/index.ts +3 -0
  39. package/src/group-form-entry-workflow/{group-banner → group-display-header}/styles.scss +0 -0
  40. package/src/group-form-entry-workflow/group-search/CompactGroupResults.tsx +61 -28
  41. package/src/group-form-entry-workflow/group-search/CompactGroupSearch.tsx +5 -0
  42. package/src/group-form-entry-workflow/group-search/GroupSearch.tsx +65 -8
  43. package/src/group-form-entry-workflow/group-search/group-search.scss +8 -6
  44. package/src/group-form-entry-workflow/group-search-header/GroupSearchHeader.tsx +14 -7
  45. package/src/group-form-entry-workflow/styles.scss +10 -0
  46. package/src/hooks/index.ts +1 -0
  47. package/src/hooks/usePostEndpoint.ts +70 -0
  48. package/src/hooks/useSearchEndpoint.ts +120 -0
  49. package/translations/en.json +6 -1
  50. package/.editorconfig +0 -12
  51. package/.eslintignore +0 -2
  52. package/.eslintrc.js +0 -10
  53. package/.husky/pre-push +0 -1
  54. package/.prettierignore +0 -14
  55. package/.tx/config +0 -9
  56. package/.yarn/plugins/@yarnpkg/plugin-version.cjs +0 -550
  57. package/.yarn/versions/45b499b6.yml +0 -0
  58. package/src/group-form-entry-workflow/group-banner/index.ts +0 -3
  59. package/src/group-form-entry-workflow/group-search/mock-group-data.ts +0 -79
  60. package/src/group-form-entry-workflow/group-search/useGroupSearch.ts +0 -14
  61. package/src/hooks/usePostCohort.ts +0 -18
@@ -4,3 +4,4 @@ import useFormState from "./useFormState";
4
4
  import useGetEncounter from "./useGetEncounter";
5
5
 
6
6
  export { useGetAllForms, useGetPatient, useFormState, useGetEncounter };
7
+ export * from "./usePostEndpoint";
@@ -0,0 +1,70 @@
1
+ import { openmrsFetch } from "@openmrs/esm-framework";
2
+ import { useCallback, useState } from "react";
3
+
4
+ const usePostEndpoint = ({ endpointUrl }) => {
5
+ const [submissionInProgress, setSubmissionInProgress] = useState(null);
6
+ const [result, setResult] = useState(null);
7
+ const [error, setError] = useState(null);
8
+
9
+ const onFormPosted = useCallback(
10
+ (result) => {
11
+ setSubmissionInProgress(false);
12
+ if (error) {
13
+ setError(null);
14
+ }
15
+ setResult(result.data);
16
+ },
17
+ [error]
18
+ );
19
+
20
+ const onError = useCallback(
21
+ (error) => {
22
+ setSubmissionInProgress(false);
23
+ if (result) {
24
+ setResult(null);
25
+ }
26
+ setError(error?.responseBody?.error ?? error?.responseBody ?? error);
27
+ },
28
+ [result]
29
+ );
30
+
31
+ const post = useCallback(
32
+ async (data) => {
33
+ setSubmissionInProgress(true);
34
+ return openmrsFetch(endpointUrl, {
35
+ method: "POST",
36
+ headers: {
37
+ "Content-Type": "application/json",
38
+ },
39
+ body: data,
40
+ })
41
+ .then(onFormPosted)
42
+ .catch(onError);
43
+ },
44
+ [endpointUrl, onError, onFormPosted]
45
+ );
46
+
47
+ const reset = () => {
48
+ setSubmissionInProgress(null);
49
+ setResult(null);
50
+ setError(null);
51
+ };
52
+
53
+ return {
54
+ post,
55
+ isPosting: submissionInProgress,
56
+ result,
57
+ error,
58
+ reset,
59
+ };
60
+ };
61
+
62
+ const usePostVisit = () => {
63
+ return usePostEndpoint({ endpointUrl: "/ws/rest/v1/visit" });
64
+ };
65
+
66
+ const usePostCohort = () => {
67
+ return usePostEndpoint({ endpointUrl: "/ws/rest/v1/cohortm/cohort" });
68
+ };
69
+
70
+ export { usePostEndpoint, usePostVisit, usePostCohort };
@@ -0,0 +1,120 @@
1
+ import { openmrsFetch, FetchResponse } from "@openmrs/esm-framework";
2
+ import { useCallback, useMemo } from "react";
3
+ import useSWRInfinite from "swr/infinite";
4
+
5
+ export interface SearchResponse {
6
+ data: Array<Record<string, unknown>> | null;
7
+ isLoading: boolean;
8
+ error: Error;
9
+ loadingNewData: boolean;
10
+ hasMore: boolean;
11
+ currentPage: number;
12
+ totalResults: number;
13
+ setPage: (size: number | ((_size: number) => number)) => Promise<
14
+ FetchResponse<{
15
+ results: Array<Record<string, unknown>>;
16
+ links: Array<{
17
+ rel: "prev" | "next";
18
+ }>;
19
+ }>[]
20
+ >;
21
+ }
22
+
23
+ interface SearchInfiniteProps {
24
+ baseUrl?: string;
25
+ searchTerm: string;
26
+ parameters?: Record<string, unknown> | undefined;
27
+ searching: boolean;
28
+ resultsToFetch?: number;
29
+ }
30
+
31
+ const useSearchEndpointInfinite = (
32
+ arg0: SearchInfiniteProps
33
+ ): SearchResponse => {
34
+ const {
35
+ baseUrl,
36
+ searchTerm,
37
+ parameters,
38
+ searching = true,
39
+ resultsToFetch = 10,
40
+ } = arg0;
41
+
42
+ const getUrl = useCallback(
43
+ (
44
+ page: number,
45
+ prevPageData: FetchResponse<{
46
+ results: Array<Record<string, unknown>>;
47
+ links: Array<{ rel: "prev" | "next" }>;
48
+ }>
49
+ ) => {
50
+ if (
51
+ prevPageData &&
52
+ !prevPageData?.data?.links.some((link) => link.rel === "next")
53
+ ) {
54
+ return null;
55
+ }
56
+ let url = `${baseUrl}?q=${searchTerm}`;
57
+ const params = {
58
+ // merge passed parameters and default parameters
59
+ // this way the defaults can be overriden if needed
60
+ totalCount: true,
61
+ limit: resultsToFetch,
62
+ ...parameters,
63
+ };
64
+ Object.entries(params).forEach(([key, value]) => {
65
+ // don't send null parmeters
66
+ if (value !== null && value !== undefined) {
67
+ url += `&${key}=${value}`;
68
+ }
69
+ });
70
+ if (page) {
71
+ url += `&startIndex=${page * resultsToFetch}`;
72
+ }
73
+ return url;
74
+ },
75
+ [baseUrl, searchTerm, parameters, resultsToFetch]
76
+ );
77
+
78
+ const { data, isValidating, setSize, error, size } = useSWRInfinite<
79
+ FetchResponse<{
80
+ results: Array<Record<string, unknown>>;
81
+ links: Array<{ rel: "prev" | "next" }>;
82
+ totalCount: number;
83
+ }>,
84
+ Error
85
+ >(searching ? getUrl : null, openmrsFetch);
86
+
87
+ const results = useMemo(
88
+ () => ({
89
+ data: data
90
+ ? [].concat(...(data?.map((resp) => resp?.data?.results) ?? []))
91
+ : null,
92
+ isLoading: !data && !error,
93
+ error,
94
+ hasMore: data?.length
95
+ ? !!data[data.length - 1].data?.links?.some(
96
+ (link) => link.rel === "next"
97
+ )
98
+ : false,
99
+ loadingNewData: isValidating,
100
+ setPage: setSize,
101
+ currentPage: size,
102
+ totalResults: data?.[0]?.data?.totalCount,
103
+ }),
104
+ [data, isValidating, error, setSize, size]
105
+ );
106
+
107
+ return results;
108
+ };
109
+
110
+ const useSearchCohortInfinite = ({
111
+ ...props
112
+ }: SearchInfiniteProps): SearchResponse => {
113
+ return useSearchEndpointInfinite({
114
+ baseUrl: "/ws/rest/v1/cohortm/cohort",
115
+ resultsToFetch: 10,
116
+ ...props,
117
+ });
118
+ };
119
+
120
+ export { useSearchEndpointInfinite, useSearchCohortInfinite };
@@ -4,6 +4,7 @@
4
4
  "areYouSure": "Are you sure?",
5
5
  "cancel": "Cancel",
6
6
  "cancelExplanation": "You will lose any unsaved changes on the current form. Do you want to discard the current session?",
7
+ "changeGroup": "Choose a different group",
7
8
  "chooseGroupError": "Please choose a group.",
8
9
  "createNewPatient": "Create new patient",
9
10
  "createGroup": "Create Group",
@@ -27,10 +28,13 @@
27
28
  "nextPatient": "Next Patient",
28
29
  "noFormsFound": "No Forms To Show",
29
30
  "noFormsFoundMessage": "No forms could be found for this category. Please double check the form concept uuids and access permissions.",
31
+ "noMoreResults": "End of search results",
30
32
  "noGroupsFoundMessage": "Sorry, no groups have been found",
31
33
  "noPatientError": "Please enter at least one patient.",
32
34
  "or": "or",
33
35
  "orLabelName": "OR label name",
36
+ "patientsInGroup": "Patients in group",
37
+ "postError": "POST Error",
34
38
  "practitionerName": "Practitioner Name",
35
39
  "remove": "Remove",
36
40
  "resumeSession": "Resume Session",
@@ -45,5 +49,6 @@
45
49
  "sessionName": "Session Name",
46
50
  "sessionNotes": "Session Notes",
47
51
  "startGroupSession": "Start Group Session",
48
- "trySearchWithPatientUniqueID": "Try searching with the cohort's description"
52
+ "trySearchWithPatientUniqueID": "Try searching with the cohort's description",
53
+ "unknownPostError": "An unknown error occured while saving data"
49
54
  }
package/.editorconfig DELETED
@@ -1,12 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 2
6
- charset = utf-8
7
- trim_trailing_whitespace = true
8
- insert_final_newline = true
9
- end_of_line = lf
10
-
11
- [*.md]
12
- trim_trailing_whitespace = false
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- src/**/*.test.tsx
2
- **/*.d.tsx
package/.eslintrc.js DELETED
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- "extends": [
3
- "eslint:recommended",
4
- "ts-react-important-stuff",
5
- "plugin:prettier/recommended",
6
- 'react-app',
7
- 'plugin:@typescript-eslint/recommended',
8
- ],
9
- "parser": "@typescript-eslint/parser",
10
- }
package/.husky/pre-push DELETED
@@ -1 +0,0 @@
1
- yarn verify
package/.prettierignore DELETED
@@ -1,14 +0,0 @@
1
- # directories
2
- .husky/
3
- dist/
4
- node_modules/
5
-
6
- # dotfiles and generated
7
- .*
8
- yarn.lock
9
-
10
- # by file type
11
- **/*.css
12
- **/*.scss
13
- **/*.md
14
- **/*.json
package/.tx/config DELETED
@@ -1,9 +0,0 @@
1
- [main]
2
- host = https://www.transifex.com
3
-
4
- [openmrs-esm-fast-data-entry-app.esm-fast-data-entry-app]
5
- file_filter = translations/<lang>.json
6
- minimum_perc = 0
7
- source_file = translations/en.json
8
- source_lang = en
9
- type = KEYVALUEJSON