@openmrs/esm-fast-data-entry-app 1.0.1-pre.180 → 1.0.1-pre.183
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/dist/101.js +1 -1
- package/dist/101.js.map +1 -1
- package/dist/188.js +1 -1
- package/dist/188.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 -1
- package/src/group-form-entry-workflow/SessionDetailsForm.tsx +1 -1
- package/src/group-form-entry-workflow/configurable-questions/ConfigurableQuestionsSection.tsx +4 -0
- package/src/hooks/index.ts +2 -2
- package/src/hooks/useSpecificQuestions.ts +68 -0
- package/src/types.ts +4 -0
- package/src/hooks/useForm.ts +0 -56
package/dist/routes.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.2.0"},"pages":[{"component":"root","routeRegex":"forms","online":true,"offline":true}],"extensions":[{"name":"forms-app-link","slot":"app-menu-slot","component":"formsAppMenuLink","online":true,"offline":true}],"version":"1.0.1-pre.
|
|
1
|
+
{"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"fhir2":">=1.2","webservices.rest":"^2.2.0"},"pages":[{"component":"root","routeRegex":"forms","online":true,"offline":true}],"extensions":[{"name":"forms-app-link","slot":"app-menu-slot","component":"formsAppMenuLink","online":true,"offline":true}],"version":"1.0.1-pre.183"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import { AttendanceTable } from './attendance-table';
|
|
|
9
9
|
import GroupFormWorkflowContext from '../context/GroupFormWorkflowContext';
|
|
10
10
|
import useGetPatients from '../hooks/useGetPatients';
|
|
11
11
|
import ConfigurableQuestionsSection from './configurable-questions/ConfigurableQuestionsSection';
|
|
12
|
-
import useSpecificQuestions from '../hooks/
|
|
12
|
+
import useSpecificQuestions from '../hooks/useSpecificQuestions';
|
|
13
13
|
|
|
14
14
|
interface ParamTypes {
|
|
15
15
|
formUuid?: string;
|
package/src/group-form-entry-workflow/configurable-questions/ConfigurableQuestionsSection.tsx
CHANGED
|
@@ -18,6 +18,8 @@ const ConfigurableQuestionsSection: React.FC<ConfigurableQuestionsSectionProps>
|
|
|
18
18
|
{...register(specificQuestion.question.id, { required: false })}
|
|
19
19
|
id={specificQuestion.question.id}
|
|
20
20
|
labelText={specificQuestion.question.display}
|
|
21
|
+
readOnly={!!specificQuestion.question.disabled}
|
|
22
|
+
defaultValue={specificQuestion.question.defaultAnswer}
|
|
21
23
|
>
|
|
22
24
|
<SelectItem value="" text="" />
|
|
23
25
|
{specificQuestion.answers.map((answer) => (
|
|
@@ -30,6 +32,8 @@ const ConfigurableQuestionsSection: React.FC<ConfigurableQuestionsSectionProps>
|
|
|
30
32
|
{...register(specificQuestion.question.id, { required: false })}
|
|
31
33
|
type="text"
|
|
32
34
|
labelText={specificQuestion.question.display}
|
|
35
|
+
readOnly={!!specificQuestion.question.disabled}
|
|
36
|
+
defaultValue={specificQuestion.question.defaultAnswer}
|
|
33
37
|
/>
|
|
34
38
|
)}
|
|
35
39
|
</div>
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import useGetAllForms from './useGetAllForms';
|
|
|
2
2
|
import useGetPatient from './useGetPatient';
|
|
3
3
|
import useFormState from './useFormState';
|
|
4
4
|
import useGetEncounter from './useGetEncounter';
|
|
5
|
-
import
|
|
5
|
+
import useSpecificQuestions from './useSpecificQuestions';
|
|
6
6
|
|
|
7
|
-
export { useGetAllForms, useGetPatient, useFormState, useGetEncounter,
|
|
7
|
+
export { useGetAllForms, useGetPatient, useFormState, useGetEncounter, useSpecificQuestions };
|
|
8
8
|
export * from './usePostEndpoint';
|
|
@@ -0,0 +1,68 @@
|
|
|
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';
|
|
5
|
+
|
|
6
|
+
const formUrl = `${restBaseUrl}/o3/forms`;
|
|
7
|
+
|
|
8
|
+
export const useSpecificQuestions = (formUuid: string, specificQuestionConfig: Array<SpecificQuestionConfig>) => {
|
|
9
|
+
const specificQuestionsToLoad = useMemo(
|
|
10
|
+
() => getQuestionByFormId(formUuid, specificQuestionConfig),
|
|
11
|
+
[formUuid, specificQuestionConfig],
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const { data, error } = useSWR<FetchResponse, Error>(
|
|
15
|
+
specificQuestionsToLoad ? `${formUrl}/${formUuid}` : null,
|
|
16
|
+
openmrsFetch,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const specificQuestions = getQuestions(specificQuestionsToLoad, data?.data);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
questions: specificQuestions || null,
|
|
23
|
+
isError: error,
|
|
24
|
+
isLoading: !data && !error,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function getQuestionByFormId(formUuid: string, specificQuestionConfig: Array<SpecificQuestionConfig>) {
|
|
29
|
+
return specificQuestionConfig.filter((question) => question.forms.includes(formUuid));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getQuestions(specificQuestions: Array<SpecificQuestionConfig>, formSchema): Array<SpecificQuestion> {
|
|
33
|
+
if (!formSchema || specificQuestions.length <= 0) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const specificQuestionsMap = new Map<string, SpecificQuestionConfig>(
|
|
38
|
+
specificQuestions.map((sq) => [sq.questionId, sq]),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const questionIds = new Set(specificQuestionsMap.keys());
|
|
42
|
+
const conceptLabels = formSchema.conceptReferences;
|
|
43
|
+
|
|
44
|
+
return formSchema.pages.flatMap((page) =>
|
|
45
|
+
page.sections.flatMap((section) =>
|
|
46
|
+
section.questions
|
|
47
|
+
.filter((question) => questionIds.has(question.id))
|
|
48
|
+
.map((question) => {
|
|
49
|
+
const specificQuestion = specificQuestionsMap.get(question.id) || {};
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
question: {
|
|
53
|
+
display: question.label ?? conceptLabels[question.questionOptions.concept]?.display,
|
|
54
|
+
id: question.id,
|
|
55
|
+
disabled: (specificQuestion as SpecificQuestionConfig).disabled,
|
|
56
|
+
defaultAnswer: (specificQuestion as SpecificQuestionConfig).defaultAnswer,
|
|
57
|
+
},
|
|
58
|
+
answers: (question.questionOptions.answers ?? []).map((answer) => ({
|
|
59
|
+
value: answer.concept,
|
|
60
|
+
display: answer.label ?? conceptLabels[answer.concept]?.display,
|
|
61
|
+
})),
|
|
62
|
+
};
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default useSpecificQuestions;
|
package/src/types.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface SpecificQuestion {
|
|
|
7
7
|
question: {
|
|
8
8
|
id: string;
|
|
9
9
|
display: string;
|
|
10
|
+
defaultAnswer?: string;
|
|
11
|
+
disabled?: boolean;
|
|
10
12
|
};
|
|
11
13
|
answers: Array<{
|
|
12
14
|
value: string;
|
|
@@ -17,4 +19,6 @@ export interface SpecificQuestion {
|
|
|
17
19
|
export interface SpecificQuestionConfig {
|
|
18
20
|
forms: Array<string>;
|
|
19
21
|
questionId: string;
|
|
22
|
+
defaultAnswer?: string;
|
|
23
|
+
disabled?: boolean;
|
|
20
24
|
}
|
package/src/hooks/useForm.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
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';
|
|
5
|
-
|
|
6
|
-
const formUrl = `${restBaseUrl}/o3/forms`;
|
|
7
|
-
|
|
8
|
-
export const useSpecificQuestions = (formUuid: string, specificQuestionConfig: Array<SpecificQuestionConfig>) => {
|
|
9
|
-
const specificQuestionsToLoad = useMemo(
|
|
10
|
-
() => getQuestionIdsByFormId(formUuid, specificQuestionConfig),
|
|
11
|
-
[formUuid, specificQuestionConfig],
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const { data, error } = useSWR<FetchResponse, Error>(
|
|
15
|
-
specificQuestionsToLoad ? `${formUrl}/${formUuid}` : null,
|
|
16
|
-
openmrsFetch,
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const specificQuestions = getQuestionsByIds(specificQuestionsToLoad, data?.data);
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
questions: specificQuestions || null,
|
|
23
|
-
isError: error,
|
|
24
|
-
isLoading: !data && !error,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function getQuestionIdsByFormId(formUuid: string, specificQuestionConfig: Array<SpecificQuestionConfig>) {
|
|
29
|
-
const matchingQuestions = specificQuestionConfig.filter((question) => question.forms.includes(formUuid));
|
|
30
|
-
return matchingQuestions.map((question) => question.questionId);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function getQuestionsByIds(questionIds, formSchema): Array<SpecificQuestion> {
|
|
34
|
-
if (!formSchema || questionIds.lenght <= 0) {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
const conceptLabels = formSchema.conceptReferences;
|
|
38
|
-
return formSchema.pages.flatMap((page) =>
|
|
39
|
-
page.sections.flatMap((section) =>
|
|
40
|
-
section.questions
|
|
41
|
-
.filter((question) => questionIds.includes(question.id))
|
|
42
|
-
.map((question) => ({
|
|
43
|
-
question: {
|
|
44
|
-
display: question.label ?? conceptLabels[question.questionOptions.concept]?.display,
|
|
45
|
-
id: question.id,
|
|
46
|
-
},
|
|
47
|
-
answers: (question.questionOptions.answers ?? []).map((answer) => ({
|
|
48
|
-
value: answer.concept,
|
|
49
|
-
display: answer.label ?? conceptLabels[answer.concept]?.display,
|
|
50
|
-
})),
|
|
51
|
-
})),
|
|
52
|
-
),
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default useSpecificQuestions;
|