@openmrs/esm-form-engine-lib 2.1.0-pre.1529 → 2.1.0-pre.1531

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.
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "Test read only",
3
+ "pages": [
4
+ {
5
+ "label": "1",
6
+ "sections": [
7
+ {
8
+ "label": "1",
9
+ "isExpanded": "true",
10
+ "questions": [
11
+ {
12
+ "label": "Visit punctuality",
13
+ "type": "obs",
14
+ "required": false,
15
+ "id": "visitPunctuality",
16
+ "readonly": "true",
17
+ "questionOptions": {
18
+ "rendering": "text",
19
+ "concept": "160632AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
20
+ "conceptMappings": [
21
+ {
22
+ "relationship": "SAME-AS",
23
+ "type": "CIEL",
24
+ "value": "160632"
25
+ },
26
+ {
27
+ "relationship": "SAME-AS",
28
+ "type": "AMPATH",
29
+ "value": "1915"
30
+ },
31
+ {
32
+ "relationship": "BROADER-THAN",
33
+ "type": "LOINC",
34
+ "value": "48767-8"
35
+ }
36
+ ]
37
+ },
38
+ "validators": []
39
+ },
40
+ {
41
+ "label": "Visit notes",
42
+ "type": "obs",
43
+ "required": false,
44
+ "id": "visitNotes",
45
+ "readonly": "true",
46
+ "questionOptions": {
47
+ "rendering": "text",
48
+ "concept": "1066AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
49
+ "conceptMappings": []
50
+ },
51
+ "validators": []
52
+ }
53
+ ]
54
+ }
55
+ ]
56
+ }
57
+ ],
58
+ "processor": "EncounterFormProcessor",
59
+ "encounterType": "",
60
+ "referencedForms": [],
61
+ "uuid": "",
62
+ "description": "Test read only"
63
+ }
@@ -1,91 +1,96 @@
1
1
  {
2
- "name": "Test HTS POC",
3
- "pages": [
2
+ "name": "Test HTS POC",
3
+ "pages": [
4
+ {
5
+ "label": "Screening",
6
+ "sections": [
4
7
  {
5
- "label": "Screening",
6
- "sections": [
8
+ "label": "Testing history",
9
+ "isExpanded": "true",
10
+ "questions": [
11
+ {
12
+ "label": "When was the HIV test conducted?",
13
+ "type": "obs",
14
+ "questionOptions": {
15
+ "rendering": "date",
16
+ "concept": "164400AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
17
+ "weeksList": ""
18
+ },
19
+ "required": "true",
20
+ "unspecified": "true",
21
+ "hide": {
22
+ "hideWhenExpression": "false"
23
+ },
24
+ "validators": [
7
25
  {
8
- "label": "Testing history",
9
- "isExpanded": "true",
10
- "questions": [
11
- {
12
- "label": "When was the HIV test conducted?",
13
- "type": "obs",
14
- "questionOptions": {
15
- "rendering": "date",
16
- "concept": "164400AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
17
- "weeksList": ""
18
- },
19
- "required": "true",
20
- "unspecified": "true",
21
- "hide": {
22
- "hideWhenExpression": "false"
23
- },
24
- "validators": [
25
- {
26
- "type": "date",
27
- "allowFutureDates": "false"
28
- },
29
- {
30
- "type": "js_expression",
31
- "failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
32
- }
33
- ],
34
- "behaviours": [
35
- {
36
- "intent": "HTS_RETROSPECTIVE",
37
- "required": "true",
38
- "unspecified": "true",
39
- "hide": {
40
- "hideWhenExpression": "false"
41
- },
42
- "validators": [
43
- {
44
- "type": "date",
45
- "allowFutureDates": "false"
46
- },
47
- {
48
- "type": "js_expression",
49
- "failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
50
- }
51
- ]
52
- },
53
- {
54
- "intent": "HTS_HIVTEST",
55
- "required": "true"
56
- },
57
- {
58
- "intent": "",
59
- "required": "false",
60
- "hide": {
61
- "hideWhenExpression": "hivTestConducted !== 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3'"
62
- },
63
- "validators": [
64
- {
65
- "type": "date",
66
- "allowFutureDates": "false"
67
- },
68
- {
69
- "type": "js_expression",
70
- "failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
71
- }
72
- ]
73
- }
74
- ],
75
- "id": "dateTestPerformed"
76
- }
77
- ]
26
+ "type": "date",
27
+ "allowFutureDates": "false"
28
+ },
29
+ {
30
+ "type": "js_expression",
31
+ "failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
32
+ }
33
+ ],
34
+ "behaviours": [
35
+ {
36
+ "intent": "HTS_RETROSPECTIVE",
37
+ "required": "true",
38
+ "unspecified": "true",
39
+ "hide": {
40
+ "hideWhenExpression": "false"
41
+ },
42
+ "validators": [
43
+ {
44
+ "type": "date",
45
+ "allowFutureDates": "false"
46
+ },
47
+ {
48
+ "type": "js_expression",
49
+ "failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
50
+ }
51
+ ]
52
+ },
53
+ {
54
+ "intent": "HTS_HIVTEST",
55
+ "required": "true"
56
+ },
57
+ {
58
+ "intent": "",
59
+ "required": "false",
60
+ "hide": {
61
+ "hideWhenExpression": "hivTestConducted !== 'cf82933b-3f3f-45e7-a5ab-5d31aaee3da3'"
62
+ },
63
+ "validators": [
64
+ {
65
+ "type": "date",
66
+ "allowFutureDates": "false"
67
+ },
68
+ {
69
+ "type": "js_expression",
70
+ "failsWhenExpression": "myValue < '1/1/1980' || myValue > today()"
71
+ }
72
+ ]
78
73
  }
79
- ]
74
+ ],
75
+ "id": "dateTestPerformed"
76
+ },
77
+ {
78
+ "label": "Question title",
79
+ "type": "obs",
80
+ "questionOptions": {
81
+ "rendering": "text",
82
+ "concept": "193e8a03-1581-46e9-b0a4-17c55fa2649f"
83
+ },
84
+ "id": "sampleQuestion"
85
+ }
86
+ ]
80
87
  }
81
- ],
82
- "availableIntents": [
83
- "HTS_RETROSPECTIVE",
84
- "HTS_HIVTEST",
85
- "*"
86
- ],
87
- "processor": "EncounterFormProcessor",
88
- "uuid": "da24c540-cc83-43bc-978f-c1ef180a497f",
89
- "referencedForms": [],
90
- "encounterType": "79c1f50f-f77d-42e2-ad2a-d29304dde2fe"
91
- }
88
+ ]
89
+ }
90
+ ],
91
+ "availableIntents": ["HTS_RETROSPECTIVE", "HTS_HIVTEST", "*"],
92
+ "processor": "EncounterFormProcessor",
93
+ "uuid": "da24c540-cc83-43bc-978f-c1ef180a497f",
94
+ "referencedForms": [],
95
+ "encounterType": "79c1f50f-f77d-42e2-ad2a-d29304dde2fe"
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-form-engine-lib",
3
- "version": "2.1.0-pre.1529",
3
+ "version": "2.1.0-pre.1531",
4
4
  "description": "React Form Engine for O3",
5
5
  "browser": "dist/openmrs-esm-form-engine-lib.js",
6
6
  "main": "src/index.ts",
@@ -89,7 +89,7 @@
89
89
  "sass": "^1.77.2",
90
90
  "swc-loader": "^0.2.6",
91
91
  "swr": "^2.2.5",
92
- "turbo": "^2.0.6",
92
+ "turbo": "^2.2.3",
93
93
  "typescript": "^4.9.5",
94
94
  "webpack": "^5.91.0",
95
95
  "webpack-bundle-analyzer": "^4.10.2",
@@ -41,8 +41,10 @@ import externalDataSourceForm from '__mocks__/forms/rfe-forms/external_data_sour
41
41
  import monthsOnArtForm from '__mocks__/forms/rfe-forms/months-on-art-form.json';
42
42
  import nextVisitForm from '__mocks__/forms/rfe-forms/next-visit-test-form.json';
43
43
  import viralLoadStatusForm from '__mocks__/forms/rfe-forms/viral-load-status-form.json';
44
+ import readOnlyValidationForm from '__mocks__/forms/rfe-forms/read-only-validation-form.json';
44
45
 
45
46
  import FormEngine from './form-engine.component';
47
+ import { type SessionMode } from './types';
46
48
 
47
49
  const patientUUID = '8673ee4f-e2ab-4077-ba55-4980f408773e';
48
50
  const visit = mockVisit;
@@ -842,7 +844,48 @@ describe('Form engine component', () => {
842
844
  });
843
845
  });
844
846
 
845
- function renderForm(formUUID, formJson, intent?: string) {
847
+ describe('Read only mode', () => {
848
+ it('should ensure that each read-only field is not editable', async () => {
849
+ await act(async () => {
850
+ renderForm(null, readOnlyValidationForm);
851
+ });
852
+
853
+ const visitPunctualityTextbox = screen.getByLabelText(/visit punctuality/i);
854
+ expect(visitPunctualityTextbox).toHaveAttribute('readonly');
855
+
856
+ const visitNotesTextbox = screen.getByLabelText(/visit notes/i);
857
+ expect(visitNotesTextbox).toHaveAttribute('readonly');
858
+ });
859
+ });
860
+
861
+ describe('Form view mode', () => {
862
+ it('should ensure that the form is not editable in view mode', async () => {
863
+ await act(async () => {
864
+ renderForm(null, htsPocForm, null, 'view');
865
+ });
866
+ const testingHistoryButton = screen.getByRole('button', { name: /Testing history/i });
867
+ expect(testingHistoryButton).toBeInTheDocument();
868
+
869
+ const hivTestButton = screen.getByRole('button', { name: /When was the HIV test conducted\?:/i });
870
+ expect(hivTestButton).toBeInTheDocument();
871
+
872
+ const blankFields = screen.getAllByText(/\(Blank\)/i);
873
+ blankFields.forEach((blankField) => {
874
+ expect(blankField).toBeInTheDocument();
875
+ });
876
+
877
+ const inputs = screen.queryAllByRole('textbox');
878
+ inputs.forEach((input) => {
879
+ expect(input).toHaveAttribute('readonly');
880
+ });
881
+
882
+ const interactiveElements = screen.queryAllByRole('textbox', { hidden: false });
883
+ expect(interactiveElements).toHaveLength(0);
884
+ expect(screen.queryByRole('button', { name: /save/i })).toBeDisabled();
885
+ });
886
+ });
887
+
888
+ function renderForm(formUUID, formJson, intent?: string, mode?: SessionMode) {
846
889
  render(
847
890
  <FormEngine
848
891
  formJson={formJson}
@@ -850,7 +893,7 @@ describe('Form engine component', () => {
850
893
  patientUUID={patientUUID}
851
894
  formSessionIntent={intent}
852
895
  visit={visit}
853
- mode="enter"
896
+ mode={mode ? mode : 'enter'}
854
897
  />,
855
898
  );
856
899
  }
@@ -127,6 +127,15 @@ describe('Forms loader - getForm', () => {
127
127
  ],
128
128
  id: 'dateTestPerformed',
129
129
  },
130
+ {
131
+ id: 'sampleQuestion',
132
+ label: 'Question title',
133
+ questionOptions: {
134
+ concept: '193e8a03-1581-46e9-b0a4-17c55fa2649f',
135
+ rendering: 'text',
136
+ },
137
+ type: 'obs',
138
+ },
130
139
  ],
131
140
  },
132
141
  ],
@@ -246,6 +255,15 @@ describe('Forms loader - getForm', () => {
246
255
  ],
247
256
  id: 'dateTestPerformed',
248
257
  },
258
+ {
259
+ id: 'sampleQuestion',
260
+ label: 'Question title',
261
+ questionOptions: {
262
+ concept: '193e8a03-1581-46e9-b0a4-17c55fa2649f',
263
+ rendering: 'text',
264
+ },
265
+ type: 'obs',
266
+ },
249
267
  ],
250
268
  },
251
269
  ],