@openmrs/esm-fast-data-entry-app 1.0.1-pre.171 → 1.0.1-pre.176
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.
- package/__mocks__/react-i18next.js +9 -14
- package/dist/101.js.map +1 -1
- package/dist/188.js.map +1 -1
- package/dist/219.js.map +1 -1
- package/dist/326.js.map +1 -1
- package/dist/564.js.map +1 -1
- package/dist/91.js.map +1 -1
- package/dist/99.js.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/openmrs-esm-fast-data-entry-app.js.buildmanifest.json +8 -8
- package/dist/routes.json +1 -1
- package/package.json +1 -3
- package/prettier.config.js +8 -0
- package/src/CancelModal.tsx +9 -15
- package/src/CompleteModal.tsx +7 -18
- package/src/FormBootstrap.tsx +9 -9
- package/src/Root.tsx +7 -12
- package/src/add-group-modal/AddGroupModal.tsx +46 -109
- package/src/config-schema.ts +35 -36
- package/src/constant.ts +1 -1
- package/src/context/FormWorkflowContext.tsx +26 -39
- package/src/context/FormWorkflowReducer.ts +50 -74
- package/src/context/GroupFormWorkflowContext.tsx +36 -61
- package/src/context/GroupFormWorkflowReducer.ts +69 -105
- package/src/declarations.d.ts +3 -3
- package/src/empty-state/EmptyDataIllustration.tsx +4 -16
- package/src/empty-state/EmptyState.tsx +8 -13
- package/src/form-entry-workflow/FormEntryWorkflow.tsx +26 -44
- package/src/form-entry-workflow/form-review-card/FormReviewCard.tsx +7 -7
- package/src/form-entry-workflow/form-review-card/index.ts +1 -1
- package/src/form-entry-workflow/index.ts +1 -1
- package/src/form-entry-workflow/patient-banner/PatientBanner.test.tsx +5 -5
- package/src/form-entry-workflow/patient-banner/PatientBanner.tsx +14 -27
- package/src/form-entry-workflow/patient-banner/index.ts +1 -1
- package/src/form-entry-workflow/patient-search-header/PatientSearchHeader.tsx +17 -26
- package/src/form-entry-workflow/patient-search-header/index.ts +1 -1
- package/src/form-entry-workflow/workflow-review/WorkflowReview.tsx +12 -12
- package/src/form-entry-workflow/workflow-review/index.ts +1 -1
- package/src/forms-app-menu-link.tsx +4 -6
- package/src/forms-page/FormsPage.tsx +22 -50
- package/src/forms-page/forms-table/FormsTable.tsx +22 -42
- package/src/forms-page/forms-table/index.ts +1 -1
- package/src/forms-page/index.ts +1 -1
- package/src/group-form-entry-workflow/GroupFormEntryWorkflow.tsx +8 -8
- package/src/group-form-entry-workflow/GroupSessionWorkspace.tsx +27 -58
- package/src/group-form-entry-workflow/SessionDetailsForm.tsx +43 -66
- package/src/group-form-entry-workflow/SessionMetaWorkspace.tsx +20 -28
- package/src/group-form-entry-workflow/attendance-table/AttendanceTable.tsx +13 -27
- package/src/group-form-entry-workflow/attendance-table/index.ts +1 -1
- package/src/group-form-entry-workflow/configurable-questions/ConfigurableQuestionsSection.tsx +6 -12
- package/src/group-form-entry-workflow/group-display-header/GroupDisplayHeader.test.tsx +5 -5
- package/src/group-form-entry-workflow/group-display-header/GroupDisplayHeader.tsx +13 -21
- package/src/group-form-entry-workflow/group-display-header/index.ts +1 -1
- package/src/group-form-entry-workflow/group-search/CompactGroupResults.tsx +24 -35
- package/src/group-form-entry-workflow/group-search/CompactGroupSearch.tsx +13 -15
- package/src/group-form-entry-workflow/group-search/GroupSearch.tsx +22 -38
- package/src/group-form-entry-workflow/group-search-header/GroupSearchHeader.tsx +18 -25
- package/src/group-form-entry-workflow/group-search-header/index.ts +1 -1
- package/src/group-form-entry-workflow/index.ts +1 -1
- package/src/hooks/index.ts +7 -13
- package/src/hooks/useForm.ts +13 -30
- package/src/hooks/useFormState.ts +3 -3
- package/src/hooks/useGetAllForms.ts +5 -14
- package/src/hooks/useGetEncounter.ts +2 -2
- package/src/hooks/useGetPatient.ts +2 -2
- package/src/hooks/useGetPatients.ts +4 -6
- package/src/hooks/useGetSystemSetting.ts +3 -5
- package/src/hooks/useKeyPress.ts +5 -5
- package/src/hooks/usePostEndpoint.ts +8 -8
- package/src/hooks/useSearchEndpoint.ts +15 -38
- package/src/hooks/useStartVisit.ts +16 -27
- package/src/index.ts +8 -20
- package/src/patient-card/PatientCard.tsx +8 -20
- package/src/patient-card/index.ts +1 -1
- package/src/setup-tests.ts +1 -1
- package/tools/i18next-parser.config.js +19 -19
- package/webpack.config.js +1 -1
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
import React, { useState } from
|
|
2
|
-
import { type GroupType } from
|
|
3
|
-
import styles from
|
|
4
|
-
import GroupSearch from
|
|
5
|
-
import { Button, Search } from
|
|
6
|
-
import { useTranslation } from
|
|
7
|
-
import debounce from
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { type GroupType } from '../../context/GroupFormWorkflowContext';
|
|
3
|
+
import styles from './compact-group-search.scss';
|
|
4
|
+
import GroupSearch from './GroupSearch';
|
|
5
|
+
import { Button, Search } from '@carbon/react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import debounce from 'lodash-es/debounce';
|
|
8
8
|
|
|
9
9
|
interface CompactGroupSearchProps {
|
|
10
10
|
selectGroupAction?: (group: GroupType) => void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const CompactGroupSearch: React.FC<CompactGroupSearchProps> = ({
|
|
14
|
-
selectGroupAction,
|
|
15
|
-
}) => {
|
|
13
|
+
const CompactGroupSearch: React.FC<CompactGroupSearchProps> = ({ selectGroupAction }) => {
|
|
16
14
|
const { t } = useTranslation();
|
|
17
|
-
const [query, setQuery] = useState(
|
|
15
|
+
const [query, setQuery] = useState('');
|
|
18
16
|
const [dropdownShown, setDropdownShown] = useState(false);
|
|
19
17
|
|
|
20
18
|
const onGroupSelect = (group) => {
|
|
21
19
|
selectGroupAction(group);
|
|
22
20
|
setDropdownShown(false);
|
|
23
|
-
setQuery(
|
|
21
|
+
setQuery('');
|
|
24
22
|
};
|
|
25
23
|
|
|
26
24
|
const handleSearchChange = (e) => {
|
|
@@ -42,18 +40,18 @@ const CompactGroupSearch: React.FC<CompactGroupSearchProps> = ({
|
|
|
42
40
|
<Search
|
|
43
41
|
autoFocus
|
|
44
42
|
className={styles.patientSearchInput}
|
|
45
|
-
closeButtonLabelText={t(
|
|
43
|
+
closeButtonLabelText={t('clearSearch', 'Clear')}
|
|
46
44
|
labelText=""
|
|
47
45
|
onChange={(event) => {
|
|
48
46
|
handleSearchChange(event.target.value);
|
|
49
47
|
}}
|
|
50
48
|
onClear={() => undefined}
|
|
51
|
-
placeholder={t(
|
|
49
|
+
placeholder={t('searchForGroup', 'Search for a group by name')}
|
|
52
50
|
size="sm"
|
|
53
51
|
value={query}
|
|
54
52
|
/>
|
|
55
53
|
<Button kind="secondary" size="sm">
|
|
56
|
-
{t(
|
|
54
|
+
{t('search', 'Search')}
|
|
57
55
|
</Button>
|
|
58
56
|
</div>
|
|
59
57
|
{dropdownShown && (
|
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
import React, { useCallback, useRef } from
|
|
2
|
-
import { useTranslation } from
|
|
3
|
-
import { Layer, Tile, Loading } from
|
|
4
|
-
import styles from
|
|
5
|
-
import { EmptyDataIllustration } from
|
|
6
|
-
import CompactGroupResults, {
|
|
7
|
-
|
|
8
|
-
} from
|
|
9
|
-
import { type GroupType } from "../../context/GroupFormWorkflowContext";
|
|
10
|
-
import { useSearchCohortInfinite } from "../../hooks/useSearchEndpoint";
|
|
1
|
+
import React, { useCallback, useRef } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { Layer, Tile, Loading } from '@carbon/react';
|
|
4
|
+
import styles from './group-search.scss';
|
|
5
|
+
import { EmptyDataIllustration } from '../../empty-state/EmptyDataIllustration';
|
|
6
|
+
import CompactGroupResults, { SearchResultSkeleton } from './CompactGroupResults';
|
|
7
|
+
import { type GroupType } from '../../context/GroupFormWorkflowContext';
|
|
8
|
+
import { useSearchCohortInfinite } from '../../hooks/useSearchEndpoint';
|
|
11
9
|
|
|
12
10
|
interface GroupSearchProps {
|
|
13
11
|
query: string;
|
|
14
12
|
selectGroupAction?: (group: GroupType) => void;
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
const GroupSearch: React.FC<GroupSearchProps> = ({
|
|
18
|
-
query = "",
|
|
19
|
-
selectGroupAction,
|
|
20
|
-
}) => {
|
|
15
|
+
const GroupSearch: React.FC<GroupSearchProps> = ({ query = '', selectGroupAction }) => {
|
|
21
16
|
const { t } = useTranslation();
|
|
22
17
|
const {
|
|
23
18
|
isLoading,
|
|
@@ -31,7 +26,7 @@ const GroupSearch: React.FC<GroupSearchProps> = ({
|
|
|
31
26
|
searchTerm: query,
|
|
32
27
|
searching: !!query,
|
|
33
28
|
parameters: {
|
|
34
|
-
v:
|
|
29
|
+
v: 'full',
|
|
35
30
|
},
|
|
36
31
|
});
|
|
37
32
|
|
|
@@ -53,13 +48,13 @@ const GroupSearch: React.FC<GroupSearchProps> = ({
|
|
|
53
48
|
},
|
|
54
49
|
{
|
|
55
50
|
threshold: 0.75,
|
|
56
|
-
}
|
|
51
|
+
},
|
|
57
52
|
);
|
|
58
53
|
if (node) {
|
|
59
54
|
observer.current.observe(node);
|
|
60
55
|
}
|
|
61
56
|
},
|
|
62
|
-
[loadingNewData, hasMore, setPage]
|
|
57
|
+
[loadingNewData, hasMore, setPage],
|
|
63
58
|
);
|
|
64
59
|
|
|
65
60
|
if (error) {
|
|
@@ -69,11 +64,11 @@ const GroupSearch: React.FC<GroupSearchProps> = ({
|
|
|
69
64
|
<Tile className={styles.emptySearchResultsTile}>
|
|
70
65
|
<EmptyDataIllustration />
|
|
71
66
|
<div>
|
|
72
|
-
<p className={styles.errorMessage}>{t(
|
|
67
|
+
<p className={styles.errorMessage}>{t('error', 'Error')}</p>
|
|
73
68
|
<p className={styles.errorCopy}>
|
|
74
69
|
{t(
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
'errorCopy',
|
|
71
|
+
'Sorry, there was an error. You can try to reload this page, or contact the site administrator and quote the error code above.',
|
|
77
72
|
)}
|
|
78
73
|
</p>
|
|
79
74
|
</div>
|
|
@@ -101,18 +96,11 @@ const GroupSearch: React.FC<GroupSearchProps> = ({
|
|
|
101
96
|
<Layer>
|
|
102
97
|
<Tile className={styles.emptySearchResultsTile}>
|
|
103
98
|
<EmptyDataIllustration />
|
|
104
|
-
<p className={styles.emptyResultText}>
|
|
105
|
-
{t("noGroupsFoundMessage", "Sorry, no groups have been found")}
|
|
106
|
-
</p>
|
|
99
|
+
<p className={styles.emptyResultText}>{t('noGroupsFoundMessage', 'Sorry, no groups have been found')}</p>
|
|
107
100
|
<p className={styles.actionText}>
|
|
108
|
-
<span>
|
|
109
|
-
{t(
|
|
110
|
-
"trySearchWithPatientUniqueID",
|
|
111
|
-
"Try searching with the cohort's description"
|
|
112
|
-
)}
|
|
113
|
-
</span>
|
|
101
|
+
<span>{t('trySearchWithPatientUniqueID', "Try searching with the cohort's description")}</span>
|
|
114
102
|
<br />
|
|
115
|
-
<span>{t(
|
|
103
|
+
<span>{t('orLabelName', 'OR label name')}</span>
|
|
116
104
|
</p>
|
|
117
105
|
</Tile>
|
|
118
106
|
</Layer>
|
|
@@ -125,21 +113,17 @@ const GroupSearch: React.FC<GroupSearchProps> = ({
|
|
|
125
113
|
<div
|
|
126
114
|
className={styles.searchResults}
|
|
127
115
|
style={{
|
|
128
|
-
maxHeight:
|
|
116
|
+
maxHeight: '22rem',
|
|
129
117
|
}}
|
|
130
118
|
>
|
|
131
119
|
<p className={styles.resultsText}>
|
|
132
|
-
{totalResults} {t(
|
|
120
|
+
{totalResults} {t('searchResultsText', 'search result(s)')}
|
|
133
121
|
</p>
|
|
134
|
-
<CompactGroupResults
|
|
135
|
-
groups={results}
|
|
136
|
-
selectGroupAction={selectGroupAction}
|
|
137
|
-
lastRef={lastItem}
|
|
138
|
-
/>
|
|
122
|
+
<CompactGroupResults groups={results} selectGroupAction={selectGroupAction} lastRef={lastItem} />
|
|
139
123
|
<div ref={lastItem}>
|
|
140
124
|
<div className={styles.lastItem} ref={loadingRef}>
|
|
141
125
|
{hasMore && <Loading withOverlay={false} small />}
|
|
142
|
-
{!hasMore && <p>{t(
|
|
126
|
+
{!hasMore && <p>{t('noMoreResults', 'End of search results')}</p>}
|
|
143
127
|
</div>
|
|
144
128
|
</div>
|
|
145
129
|
</div>
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
import { Close, Add } from
|
|
2
|
-
import { Button } from
|
|
3
|
-
import React, { useCallback, useContext, useState } from
|
|
4
|
-
import GroupFormWorkflowContext from
|
|
5
|
-
import styles from
|
|
6
|
-
import { useTranslation } from
|
|
7
|
-
import CompactGroupSearch from
|
|
8
|
-
import AddGroupModal from
|
|
1
|
+
import { Close, Add } from '@carbon/react/icons';
|
|
2
|
+
import { Button } from '@carbon/react';
|
|
3
|
+
import React, { useCallback, useContext, useState } from 'react';
|
|
4
|
+
import GroupFormWorkflowContext from '../../context/GroupFormWorkflowContext';
|
|
5
|
+
import styles from './styles.scss';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import CompactGroupSearch from '../group-search/CompactGroupSearch';
|
|
8
|
+
import AddGroupModal from '../../add-group-modal/AddGroupModal';
|
|
9
9
|
|
|
10
10
|
const GroupSearchHeader = () => {
|
|
11
11
|
const { t } = useTranslation();
|
|
12
|
-
const { activeGroupUuid, setGroup, destroySession } = useContext(
|
|
13
|
-
GroupFormWorkflowContext
|
|
14
|
-
);
|
|
12
|
+
const { activeGroupUuid, setGroup, destroySession } = useContext(GroupFormWorkflowContext);
|
|
15
13
|
const [isOpen, setOpen] = useState(false);
|
|
16
14
|
const handleSelectGroup = (group) => {
|
|
17
15
|
group.cohortMembers.sort((a, b) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
16
|
+
const aName = a?.patient?.person?.names?.[0]?.display;
|
|
17
|
+
const bName = b?.patient?.person?.names?.[0]?.display;
|
|
18
|
+
return aName.localeCompare(bName, undefined, { sensitivity: 'base' });
|
|
19
|
+
});
|
|
23
20
|
setGroup(group);
|
|
24
21
|
};
|
|
25
22
|
|
|
@@ -39,18 +36,14 @@ const GroupSearchHeader = () => {
|
|
|
39
36
|
|
|
40
37
|
return (
|
|
41
38
|
<div className={styles.searchHeaderContainer}>
|
|
42
|
-
<span className={styles.padded}>{t(
|
|
39
|
+
<span className={styles.padded}>{t('findGroup', 'Find group')}:</span>
|
|
43
40
|
<span className={styles.searchBarWrapper}>
|
|
44
41
|
<CompactGroupSearch selectGroupAction={handleSelectGroup} />
|
|
45
42
|
</span>
|
|
46
|
-
<span className={styles.padded}>{t(
|
|
43
|
+
<span className={styles.padded}>{t('or', 'or')}</span>
|
|
47
44
|
<span>
|
|
48
|
-
<Button
|
|
49
|
-
|
|
50
|
-
renderIcon={Add}
|
|
51
|
-
iconDescription="Add"
|
|
52
|
-
>
|
|
53
|
-
{t("createNewGroup", "Create New Group")}
|
|
45
|
+
<Button onClick={handleOpenClick} renderIcon={Add} iconDescription="Add">
|
|
46
|
+
{t('createNewGroup', 'Create New Group')}
|
|
54
47
|
</Button>
|
|
55
48
|
<AddGroupModal
|
|
56
49
|
{...{
|
|
@@ -69,7 +62,7 @@ const GroupSearchHeader = () => {
|
|
|
69
62
|
destroySession();
|
|
70
63
|
}}
|
|
71
64
|
>
|
|
72
|
-
{t(
|
|
65
|
+
{t('cancel', 'Cancel')} <Close size={20} />
|
|
73
66
|
</Button>
|
|
74
67
|
</span>
|
|
75
68
|
</div>
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import useGetAllForms from
|
|
2
|
-
import useGetPatient from
|
|
3
|
-
import useFormState from
|
|
4
|
-
import useGetEncounter from
|
|
5
|
-
import useForm from
|
|
1
|
+
import useGetAllForms from './useGetAllForms';
|
|
2
|
+
import useGetPatient from './useGetPatient';
|
|
3
|
+
import useFormState from './useFormState';
|
|
4
|
+
import useGetEncounter from './useGetEncounter';
|
|
5
|
+
import useForm from './useForm';
|
|
6
6
|
|
|
7
|
-
export {
|
|
8
|
-
|
|
9
|
-
useGetPatient,
|
|
10
|
-
useFormState,
|
|
11
|
-
useGetEncounter,
|
|
12
|
-
useForm,
|
|
13
|
-
};
|
|
14
|
-
export * from "./usePostEndpoint";
|
|
7
|
+
export { useGetAllForms, useGetPatient, useFormState, useGetEncounter, useForm };
|
|
8
|
+
export * from './usePostEndpoint';
|
package/src/hooks/useForm.ts
CHANGED
|
@@ -1,32 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "@openmrs/esm-framework";
|
|
6
|
-
import useSWR from "swr";
|
|
7
|
-
import { type SpecificQuestion, type SpecificQuestionConfig } from "../types";
|
|
8
|
-
import { useMemo } from "react";
|
|
1
|
+
import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
|
2
|
+
import useSWR from 'swr';
|
|
3
|
+
import { type SpecificQuestion, type SpecificQuestionConfig } from '../types';
|
|
4
|
+
import { useMemo } from 'react';
|
|
9
5
|
|
|
10
6
|
const formUrl = `${restBaseUrl}/o3/forms`;
|
|
11
7
|
|
|
12
|
-
export const useSpecificQuestions = (
|
|
13
|
-
formUuid: string,
|
|
14
|
-
specificQuestionConfig: Array<SpecificQuestionConfig>
|
|
15
|
-
) => {
|
|
8
|
+
export const useSpecificQuestions = (formUuid: string, specificQuestionConfig: Array<SpecificQuestionConfig>) => {
|
|
16
9
|
const specificQuestionsToLoad = useMemo(
|
|
17
10
|
() => getQuestionIdsByFormId(formUuid, specificQuestionConfig),
|
|
18
|
-
[formUuid, specificQuestionConfig]
|
|
11
|
+
[formUuid, specificQuestionConfig],
|
|
19
12
|
);
|
|
20
13
|
|
|
21
14
|
const { data, error } = useSWR<FetchResponse, Error>(
|
|
22
15
|
specificQuestionsToLoad ? `${formUrl}/${formUuid}` : null,
|
|
23
|
-
openmrsFetch
|
|
16
|
+
openmrsFetch,
|
|
24
17
|
);
|
|
25
18
|
|
|
26
|
-
const specificQuestions = getQuestionsByIds(
|
|
27
|
-
specificQuestionsToLoad,
|
|
28
|
-
data?.data
|
|
29
|
-
);
|
|
19
|
+
const specificQuestions = getQuestionsByIds(specificQuestionsToLoad, data?.data);
|
|
30
20
|
|
|
31
21
|
return {
|
|
32
22
|
questions: specificQuestions || null,
|
|
@@ -35,13 +25,8 @@ export const useSpecificQuestions = (
|
|
|
35
25
|
};
|
|
36
26
|
};
|
|
37
27
|
|
|
38
|
-
function getQuestionIdsByFormId(
|
|
39
|
-
formUuid
|
|
40
|
-
specificQuestionConfig: Array<SpecificQuestionConfig>
|
|
41
|
-
) {
|
|
42
|
-
const matchingQuestions = specificQuestionConfig.filter((question) =>
|
|
43
|
-
question.forms.includes(formUuid)
|
|
44
|
-
);
|
|
28
|
+
function getQuestionIdsByFormId(formUuid: string, specificQuestionConfig: Array<SpecificQuestionConfig>) {
|
|
29
|
+
const matchingQuestions = specificQuestionConfig.filter((question) => question.forms.includes(formUuid));
|
|
45
30
|
return matchingQuestions.map((question) => question.questionId);
|
|
46
31
|
}
|
|
47
32
|
|
|
@@ -56,17 +41,15 @@ function getQuestionsByIds(questionIds, formSchema): Array<SpecificQuestion> {
|
|
|
56
41
|
.filter((question) => questionIds.includes(question.id))
|
|
57
42
|
.map((question) => ({
|
|
58
43
|
question: {
|
|
59
|
-
display:
|
|
60
|
-
question.label ??
|
|
61
|
-
conceptLabels[question.questionOptions.concept]?.display,
|
|
44
|
+
display: question.label ?? conceptLabels[question.questionOptions.concept]?.display,
|
|
62
45
|
id: question.id,
|
|
63
46
|
},
|
|
64
47
|
answers: (question.questionOptions.answers ?? []).map((answer) => ({
|
|
65
48
|
value: answer.concept,
|
|
66
49
|
display: answer.label ?? conceptLabels[answer.concept]?.display,
|
|
67
50
|
})),
|
|
68
|
-
}))
|
|
69
|
-
)
|
|
51
|
+
})),
|
|
52
|
+
),
|
|
70
53
|
);
|
|
71
54
|
}
|
|
72
55
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
const useFormState = (formUuid) => {
|
|
4
4
|
const [state, setState] = useState(null);
|
|
@@ -10,10 +10,10 @@ const useFormState = (formUuid) => {
|
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
window.addEventListener(
|
|
13
|
+
window.addEventListener('ampath-form-state', handler);
|
|
14
14
|
|
|
15
15
|
return () => {
|
|
16
|
-
window.removeEventListener(
|
|
16
|
+
window.removeEventListener('ampath-form-state', handler);
|
|
17
17
|
};
|
|
18
18
|
}, [formUuid]);
|
|
19
19
|
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
userHasAccess,
|
|
4
|
-
useSession,
|
|
5
|
-
restBaseUrl,
|
|
6
|
-
} from "@openmrs/esm-framework";
|
|
7
|
-
import useSWR from "swr";
|
|
1
|
+
import { openmrsFetch, userHasAccess, useSession, restBaseUrl } from '@openmrs/esm-framework';
|
|
2
|
+
import useSWR from 'swr';
|
|
8
3
|
|
|
9
4
|
const customFormRepresentation =
|
|
10
|
-
|
|
5
|
+
'(uuid,name,display,encounterType:(uuid,name,viewPrivilege,editPrivilege),version,published,retired,resources:(uuid,name,dataType,valueReference))';
|
|
11
6
|
|
|
12
7
|
const formEncounterUrl = `${restBaseUrl}/form?v=custom:${customFormRepresentation}`;
|
|
13
8
|
const formEncounterUrlPoc = `${restBaseUrl}/form?v=custom:${customFormRepresentation}&q=poc`;
|
|
@@ -25,7 +20,7 @@ export function useGetAllForms(cachedOfflineFormsOnly = false) {
|
|
|
25
20
|
// forms should be published
|
|
26
21
|
form.published &&
|
|
27
22
|
// forms should not be component forms
|
|
28
|
-
!/component/i.test(form.name)
|
|
23
|
+
!/component/i.test(form.name),
|
|
29
24
|
// user should have privileges to edit forms
|
|
30
25
|
) ?? [];
|
|
31
26
|
|
|
@@ -33,11 +28,7 @@ export function useGetAllForms(cachedOfflineFormsOnly = false) {
|
|
|
33
28
|
});
|
|
34
29
|
|
|
35
30
|
return {
|
|
36
|
-
forms: data?.filter((form) =>
|
|
37
|
-
Boolean(
|
|
38
|
-
userHasAccess(form.encounterType?.editPrivilege?.display, session?.user)
|
|
39
|
-
)
|
|
40
|
-
),
|
|
31
|
+
forms: data?.filter((form) => Boolean(userHasAccess(form.encounterType?.editPrivilege?.display, session?.user))),
|
|
41
32
|
isLoading: !error && !data,
|
|
42
33
|
error,
|
|
43
34
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { fetchCurrentPatient } from
|
|
2
|
-
import { useEffect, useState } from
|
|
1
|
+
import { fetchCurrentPatient } from '@openmrs/esm-framework';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
const useGetPatient = (patientUuid) => {
|
|
5
5
|
const [patient, setPatient] = useState(null);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { fetchCurrentPatient } from
|
|
2
|
-
import { useEffect, useState } from
|
|
1
|
+
import { fetchCurrentPatient } from '@openmrs/esm-framework';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
const useGetPatients = (patientUuids) => {
|
|
5
5
|
const [patients, setPatients] = useState([]);
|
|
@@ -17,13 +17,11 @@ const useGetPatients = (patientUuids) => {
|
|
|
17
17
|
const getPatients = async (uuids) => {
|
|
18
18
|
try {
|
|
19
19
|
setIsLoading(true);
|
|
20
|
-
const results = await Promise.all(
|
|
21
|
-
uuids.map(async (uuid) => await fetchCurrentPatient(uuid))
|
|
22
|
-
);
|
|
20
|
+
const results = await Promise.all(uuids.map(async (uuid) => await fetchCurrentPatient(uuid)));
|
|
23
21
|
setPatients(results);
|
|
24
22
|
setIsLoading(false);
|
|
25
23
|
} catch (error) {
|
|
26
|
-
console.error(
|
|
24
|
+
console.error('Error fetching patients:', error);
|
|
27
25
|
setIsLoading(false);
|
|
28
26
|
}
|
|
29
27
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from
|
|
2
|
-
import { openmrsFetch, restBaseUrl } from
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
|
3
3
|
|
|
4
4
|
const useGetSystemSetting = (settingId) => {
|
|
5
5
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
@@ -19,9 +19,7 @@ const useGetSystemSetting = (settingId) => {
|
|
|
19
19
|
}, []);
|
|
20
20
|
|
|
21
21
|
const getSetting = useCallback(() => {
|
|
22
|
-
openmrsFetch(`${restBaseUrl}/systemsetting?q=${settingId}&v=default`)
|
|
23
|
-
.then(onResult)
|
|
24
|
-
.catch(onError);
|
|
22
|
+
openmrsFetch(`${restBaseUrl}/systemsetting?q=${settingId}&v=default`).then(onResult).catch(onError);
|
|
25
23
|
}, [onError, onResult, settingId]);
|
|
26
24
|
|
|
27
25
|
useEffect(() => {
|
package/src/hooks/useKeyPress.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
const useKeyPress = (targetKey) => {
|
|
4
4
|
const [keyPressed, setKeyPressed] = useState(false);
|
|
@@ -16,12 +16,12 @@ const useKeyPress = (targetKey) => {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
window.addEventListener(
|
|
20
|
-
window.addEventListener(
|
|
19
|
+
window.addEventListener('keydown', downHandler);
|
|
20
|
+
window.addEventListener('keyup', upHandler);
|
|
21
21
|
|
|
22
22
|
return () => {
|
|
23
|
-
window.removeEventListener(
|
|
24
|
-
window.removeEventListener(
|
|
23
|
+
window.removeEventListener('keydown', downHandler);
|
|
24
|
+
window.removeEventListener('keyup', upHandler);
|
|
25
25
|
};
|
|
26
26
|
}, [targetKey]);
|
|
27
27
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { openmrsFetch, restBaseUrl } from
|
|
2
|
-
import { useCallback, useState } from
|
|
1
|
+
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
|
2
|
+
import { useCallback, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
const usePostEndpoint = ({ endpointUrl }) => {
|
|
5
5
|
const [submissionInProgress, setSubmissionInProgress] = useState(null);
|
|
@@ -14,7 +14,7 @@ const usePostEndpoint = ({ endpointUrl }) => {
|
|
|
14
14
|
}
|
|
15
15
|
setResult(result.data);
|
|
16
16
|
},
|
|
17
|
-
[error]
|
|
17
|
+
[error],
|
|
18
18
|
);
|
|
19
19
|
|
|
20
20
|
const onError = useCallback(
|
|
@@ -25,7 +25,7 @@ const usePostEndpoint = ({ endpointUrl }) => {
|
|
|
25
25
|
}
|
|
26
26
|
setError(error?.responseBody?.error ?? error?.responseBody ?? error);
|
|
27
27
|
},
|
|
28
|
-
[result]
|
|
28
|
+
[result],
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
const post = useCallback(
|
|
@@ -34,20 +34,20 @@ const usePostEndpoint = ({ endpointUrl }) => {
|
|
|
34
34
|
|
|
35
35
|
let path = endpointUrl;
|
|
36
36
|
if (data.uuid) {
|
|
37
|
-
path +=
|
|
37
|
+
path += '/' + data.uuid;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
return openmrsFetch(path, {
|
|
41
|
-
method:
|
|
41
|
+
method: 'POST',
|
|
42
42
|
headers: {
|
|
43
|
-
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
44
|
},
|
|
45
45
|
body: data,
|
|
46
46
|
})
|
|
47
47
|
.then(onFormPosted)
|
|
48
48
|
.catch(onError);
|
|
49
49
|
},
|
|
50
|
-
[endpointUrl, onError, onFormPosted]
|
|
50
|
+
[endpointUrl, onError, onFormPosted],
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
const reset = () => {
|