@mieweb/forms-renderer 0.1.9 → 0.1.11
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/README.md +165 -179
- package/dist/blaze.js +25629 -0
- package/dist/blaze.js.map +1 -0
- package/dist/blaze.umd.cjs +2227 -0
- package/dist/blaze.umd.cjs.map +1 -0
- package/dist/react.js +321 -253
- package/dist/react.js.map +1 -1
- package/dist/standalone.js +13127 -10510
- package/dist/standalone.js.map +1 -1
- package/dist/standalone.umd.cjs +2032 -77
- package/dist/standalone.umd.cjs.map +1 -1
- package/package.json +52 -48
- package/dist/web-component.css +0 -1
package/README.md
CHANGED
|
@@ -1,234 +1,230 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mieweb/forms-renderer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Questionnaire renderer with three distribution options: React component, standalone Web Component, or Blaze component for Meteor.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Examples
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## 🚀 Examples
|
|
7
|
+
- [`example-react.jsx`](./examples/example-react.jsx) - React component
|
|
8
|
+
- [`example-standalone.html`](./examples/example-standalone.html) - Web Component
|
|
9
|
+
- [`blaze-example.html`](./examples/blaze-example.html) - Blaze/Meteor
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
- [`example-react.jsx`](./examples/example-react.jsx) - ⚛️ React component usage
|
|
15
|
-
- [`example-standalone.html`](./examples/example-standalone.html) - 🌐 Web Component usage
|
|
11
|
+
## Usage
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
Choose the method that fits your stack:
|
|
18
14
|
|
|
19
|
-
###
|
|
15
|
+
### 1. React Component (for React apps)
|
|
20
16
|
|
|
21
|
-
|
|
17
|
+
**Install:**
|
|
22
18
|
```bash
|
|
23
|
-
npm install react react-dom
|
|
19
|
+
npm install @mieweb/forms-renderer react react-dom
|
|
24
20
|
```
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
**Basic Usage:**
|
|
27
23
|
```jsx
|
|
28
|
-
import { QuestionnaireRenderer,
|
|
24
|
+
import { QuestionnaireRenderer, buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
|
|
29
25
|
|
|
30
26
|
function MyForm() {
|
|
31
27
|
const [fields] = React.useState([
|
|
32
28
|
{
|
|
33
29
|
id: 'q-name',
|
|
34
|
-
fieldType: '
|
|
30
|
+
fieldType: 'text',
|
|
35
31
|
question: 'What is your full name?',
|
|
36
32
|
answer: ''
|
|
37
33
|
}
|
|
38
34
|
]);
|
|
39
35
|
|
|
40
|
-
const
|
|
36
|
+
const currentFields = useFieldsArray();
|
|
41
37
|
|
|
42
38
|
const handleSubmit = (e) => {
|
|
43
39
|
e.preventDefault();
|
|
44
|
-
const
|
|
45
|
-
console.log('Submitted:', fhirResponse);
|
|
46
|
-
// Send to your API, etc.
|
|
40
|
+
const fhir = buildQuestionnaireResponse(currentFields, 'my-questionnaire', 'patient-123');
|
|
47
41
|
};
|
|
48
42
|
|
|
49
43
|
return (
|
|
50
44
|
<form onSubmit={handleSubmit}>
|
|
51
|
-
<QuestionnaireRenderer
|
|
52
|
-
|
|
53
|
-
onChange={(updated) => console.log('Changed:', updated)}
|
|
54
|
-
/>
|
|
55
|
-
<button type="submit">Submit Questionnaire</button>
|
|
45
|
+
<QuestionnaireRenderer fields={fields} />
|
|
46
|
+
<button type="submit">Submit</button>
|
|
56
47
|
</form>
|
|
57
48
|
);
|
|
58
49
|
}
|
|
59
50
|
```
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
From [`example-react.jsx`](./examples/example-react.jsx):
|
|
52
|
+
**With SurveyJS Schema:**
|
|
63
53
|
```jsx
|
|
64
|
-
import { QuestionnaireRenderer
|
|
65
|
-
|
|
66
|
-
function
|
|
67
|
-
const
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
fields: [
|
|
73
|
-
{
|
|
74
|
-
id: 'q-name',
|
|
75
|
-
fieldType: 'input',
|
|
76
|
-
question: 'What is your full name?',
|
|
77
|
-
answer: ''
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
id: 'q-gender',
|
|
81
|
-
fieldType: 'radio',
|
|
82
|
-
question: 'Biological sex',
|
|
83
|
-
options: [
|
|
84
|
-
{ id: 'gender-male', value: 'Male' },
|
|
85
|
-
{ id: 'gender-female', value: 'Female' }
|
|
86
|
-
],
|
|
87
|
-
selected: null
|
|
88
|
-
}
|
|
54
|
+
import { QuestionnaireRenderer } from '@mieweb/forms-renderer';
|
|
55
|
+
|
|
56
|
+
function SurveyForm() {
|
|
57
|
+
const surveySchema = {
|
|
58
|
+
pages: [{
|
|
59
|
+
elements: [
|
|
60
|
+
{ type: 'text', name: 'firstName', title: 'First Name' },
|
|
61
|
+
{ type: 'text', name: 'lastName', title: 'Last Name' }
|
|
89
62
|
]
|
|
90
|
-
}
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
const { fields: currentFields, getQuestionnaireResponse } = useQuestionnaireData('demo-1');
|
|
94
|
-
|
|
95
|
-
const handleSubmit = (e) => {
|
|
96
|
-
e.preventDefault();
|
|
97
|
-
const fhirResponse = getQuestionnaireResponse();
|
|
98
|
-
// Handle submission
|
|
63
|
+
}]
|
|
99
64
|
};
|
|
100
65
|
|
|
101
66
|
return (
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
67
|
+
<QuestionnaireRenderer
|
|
68
|
+
fields={surveySchema}
|
|
69
|
+
schemaType="surveyjs"
|
|
70
|
+
hideUnsupportedFields={true}
|
|
71
|
+
/>
|
|
106
72
|
);
|
|
107
73
|
}
|
|
108
74
|
```
|
|
109
75
|
|
|
110
|
-
|
|
76
|
+
---
|
|
111
77
|
|
|
112
|
-
|
|
78
|
+
### 2. Standalone Web Component (framework-agnostic)
|
|
113
79
|
|
|
114
|
-
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
import './package/dist/standalone.js';
|
|
118
|
-
|
|
119
|
-
const renderer = document.querySelector('questionnaire-renderer');
|
|
120
|
-
renderer.fields = [
|
|
121
|
-
{
|
|
122
|
-
id: 'sec-1',
|
|
123
|
-
fieldType: 'section',
|
|
124
|
-
title: 'Patient Information',
|
|
125
|
-
fields: [
|
|
126
|
-
{
|
|
127
|
-
id: 'q-name',
|
|
128
|
-
fieldType: 'input',
|
|
129
|
-
question: 'Full Name',
|
|
130
|
-
answer: ''
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
id: 'q-gender',
|
|
134
|
-
fieldType: 'radio',
|
|
135
|
-
question: 'Biological sex',
|
|
136
|
-
options: [
|
|
137
|
-
{ id: 'gender-male', value: 'Male' },
|
|
138
|
-
{ id: 'gender-female', value: 'Female' }
|
|
139
|
-
],
|
|
140
|
-
selected: null
|
|
141
|
-
}
|
|
142
|
-
]
|
|
143
|
-
}
|
|
144
|
-
];
|
|
145
|
-
|
|
146
|
-
// Handle form submission
|
|
147
|
-
const form = document.getElementById('myForm');
|
|
148
|
-
form.addEventListener('submit', (e) => {
|
|
149
|
-
e.preventDefault();
|
|
150
|
-
const fhirResponse = renderer.getQuestionnaireResponse('q-1', 'patient-123');
|
|
151
|
-
console.log('Form submitted:', fhirResponse);
|
|
152
|
-
});
|
|
153
|
-
</script>
|
|
154
|
-
|
|
155
|
-
<form id="myForm">
|
|
156
|
-
<questionnaire-renderer full-height></questionnaire-renderer>
|
|
157
|
-
<button type="submit">Submit</button>
|
|
158
|
-
</form>
|
|
80
|
+
**Install:**
|
|
81
|
+
```bash
|
|
82
|
+
npm install @mieweb/forms-renderer
|
|
159
83
|
```
|
|
84
|
+
No peer dependencies required - bundles React internally.
|
|
160
85
|
|
|
161
|
-
|
|
86
|
+
**Usage:**
|
|
87
|
+
```html
|
|
88
|
+
<!DOCTYPE html>
|
|
89
|
+
<html>
|
|
90
|
+
<head>
|
|
91
|
+
<script type="module">
|
|
92
|
+
import '@mieweb/forms-renderer/standalone';
|
|
93
|
+
</script>
|
|
94
|
+
</head>
|
|
95
|
+
<body>
|
|
96
|
+
<form id="myForm">
|
|
97
|
+
<questionnaire-renderer></questionnaire-renderer>
|
|
98
|
+
<button type="submit">Submit</button>
|
|
99
|
+
</form>
|
|
100
|
+
|
|
101
|
+
<script>
|
|
102
|
+
const renderer = document.querySelector('questionnaire-renderer');
|
|
103
|
+
|
|
104
|
+
// Set schema type for SurveyJS schemas
|
|
105
|
+
renderer.schemaType = 'surveyjs';
|
|
106
|
+
|
|
107
|
+
// Hide unsupported field types
|
|
108
|
+
renderer.hideUnsupportedFields = true;
|
|
109
|
+
|
|
110
|
+
renderer.fields = [
|
|
111
|
+
{
|
|
112
|
+
id: 'q-name',
|
|
113
|
+
fieldType: 'text',
|
|
114
|
+
question: 'Full Name',
|
|
115
|
+
answer: ''
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
document.getElementById('myForm').addEventListener('submit', (e) => {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
const fhir = renderer.getQuestionnaireResponse('q-1', 'patient-123');
|
|
122
|
+
console.log(fhir);
|
|
123
|
+
});
|
|
124
|
+
</script>
|
|
125
|
+
</body>
|
|
126
|
+
</html>
|
|
127
|
+
```
|
|
162
128
|
|
|
163
|
-
|
|
164
|
-
React component for rendering questionnaires (no built-in submit button).
|
|
129
|
+
---
|
|
165
130
|
|
|
166
|
-
|
|
167
|
-
- `fields` *(array)* - Questionnaire definition array
|
|
168
|
-
- `onChange` *(function)* - Callback when answers change: `(updatedFields) => void`
|
|
169
|
-
- `className` *(string)* - Additional CSS classes
|
|
170
|
-
- `fullHeight` *(boolean)* - Full viewport height mode
|
|
131
|
+
### 3. Blaze Component (for Meteor apps)
|
|
171
132
|
|
|
172
|
-
|
|
173
|
-
|
|
133
|
+
**Install:**
|
|
134
|
+
```bash
|
|
135
|
+
meteor npm install @mieweb/forms-renderer
|
|
136
|
+
```
|
|
174
137
|
|
|
175
|
-
**
|
|
176
|
-
|
|
177
|
-
|
|
138
|
+
**Usage:**
|
|
139
|
+
```javascript
|
|
140
|
+
// In your Meteor client code
|
|
141
|
+
import '@mieweb/forms-renderer/blaze';
|
|
178
142
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{
|
|
182
|
-
fields: Field[], // Current form fields with answers
|
|
183
|
-
getQuestionnaireResponse: () => Object // Get FHIR QuestionnaireResponse
|
|
184
|
-
}
|
|
143
|
+
// If the above doesn't work in your Meteor version, try:
|
|
144
|
+
// import '@mieweb/forms-renderer/dist/blaze.js';
|
|
185
145
|
```
|
|
186
146
|
|
|
187
|
-
**
|
|
188
|
-
```
|
|
189
|
-
|
|
147
|
+
**In your Blaze template:**
|
|
148
|
+
```handlebars
|
|
149
|
+
{{> questionnaireRenderer
|
|
150
|
+
fields=myFields
|
|
151
|
+
schemaType="surveyjs"
|
|
152
|
+
hideUnsupportedFields=true
|
|
153
|
+
onChange=handleChange}}
|
|
154
|
+
```
|
|
190
155
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
156
|
+
**Helper example:**
|
|
157
|
+
```javascript
|
|
158
|
+
Template.myTemplate.helpers({
|
|
159
|
+
myFields() {
|
|
160
|
+
return [
|
|
161
|
+
{ id: 'q1', fieldType: 'text', question: 'Name?', answer: '' }
|
|
162
|
+
];
|
|
163
|
+
},
|
|
164
|
+
handleChange() {
|
|
165
|
+
return (updatedFields) => {
|
|
166
|
+
console.log('Fields changed:', updatedFields);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
});
|
|
195
170
|
```
|
|
196
171
|
|
|
197
|
-
|
|
198
|
-
*(Legacy)* Pre-built submit handler.
|
|
172
|
+
---
|
|
199
173
|
|
|
200
|
-
|
|
201
|
-
- `fields` *(array)* - Current form fields
|
|
202
|
-
- `questionnaireId` *(string)* - FHIR Questionnaire ID
|
|
203
|
-
- `subjectId` *(string, optional)* - Patient/subject ID
|
|
204
|
-
- `onSubmit` *(function)* - Callback with FHIR response
|
|
174
|
+
## API Reference
|
|
205
175
|
|
|
206
|
-
|
|
176
|
+
### React Component Props
|
|
207
177
|
|
|
208
|
-
|
|
209
|
-
|
|
178
|
+
- `fields` - Questionnaire definition array
|
|
179
|
+
- `schemaType` - `'inhouse'` (default) or `'surveyjs'`
|
|
180
|
+
- `onChange` - Callback when answers change
|
|
181
|
+
- `className` - Additional CSS classes
|
|
182
|
+
- `fullHeight` - Full viewport height mode
|
|
183
|
+
- `hideUnsupportedFields` - Hide unsupported field types
|
|
210
184
|
|
|
211
|
-
|
|
185
|
+
### React Helpers
|
|
212
186
|
|
|
213
|
-
|
|
214
|
-
- `full-height` - Full viewport height (attribute)
|
|
215
|
-
- `fields` - Questionnaire definition (property)
|
|
216
|
-
- `onChange` - Change callback (property)
|
|
217
|
-
- `getQuestionnaireResponse(questionnaireId, subjectId)` - Get FHIR response (method)
|
|
187
|
+
**`buildQuestionnaireResponse(fields, questionnaireId, subjectId)`**
|
|
218
188
|
|
|
219
|
-
|
|
189
|
+
Returns FHIR QuestionnaireResponse. Use with `useFieldsArray()` to get current form state:
|
|
220
190
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
191
|
+
```jsx
|
|
192
|
+
import { buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
|
|
193
|
+
|
|
194
|
+
const currentFields = useFieldsArray();
|
|
195
|
+
const fhir = buildQuestionnaireResponse(currentFields, 'q-1', 'patient-123');
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Web Component API
|
|
199
|
+
|
|
200
|
+
- `renderer.fields` - Set/get questionnaire definition (property)
|
|
201
|
+
- `renderer.onChange` - Set change callback (property)
|
|
202
|
+
- `renderer.schemaType` - Set to `'surveyjs'` for SurveyJS schemas (property)
|
|
203
|
+
- `renderer.hideUnsupportedFields` - Boolean to hide unsupported types (property)
|
|
204
|
+
- `renderer.getQuestionnaireResponse(id, subjectId)` - Get FHIR response (method)
|
|
205
|
+
|
|
206
|
+
### Blaze Component Data Context
|
|
207
|
+
|
|
208
|
+
- `fields` - Questionnaire definition array
|
|
209
|
+
- `schemaType` - `'inhouse'` or `'surveyjs'`
|
|
210
|
+
- `onChange` - Change callback function
|
|
211
|
+
- `hideUnsupportedFields` - Boolean to hide unsupported types
|
|
212
|
+
- `fullHeight` - Boolean for full height mode
|
|
226
213
|
|
|
227
|
-
##
|
|
214
|
+
## Field Types
|
|
228
215
|
|
|
229
|
-
|
|
216
|
+
- `text` - Single-line text input
|
|
217
|
+
- `longtext` - Multi-line text area
|
|
218
|
+
- `multitext` - Multiple labeled text inputs
|
|
219
|
+
- `boolean` - Yes/No button selection
|
|
220
|
+
- `radio` - Single selection
|
|
221
|
+
- `check` - Multiple selection
|
|
222
|
+
- `dropdown` - Dropdown selection
|
|
223
|
+
- `section` - Container for grouping
|
|
230
224
|
|
|
231
|
-
|
|
225
|
+
## Conditional Logic
|
|
226
|
+
|
|
227
|
+
Show/hide fields based on other answers:
|
|
232
228
|
```javascript
|
|
233
229
|
{
|
|
234
230
|
id: 'sec-pregnancy',
|
|
@@ -243,7 +239,7 @@ From [`example-react.jsx`](./examples/example-react.jsx):
|
|
|
243
239
|
fields: [
|
|
244
240
|
{
|
|
245
241
|
id: 'q-weeks',
|
|
246
|
-
fieldType: '
|
|
242
|
+
fieldType: 'text',
|
|
247
243
|
question: 'Weeks gestation (if known)',
|
|
248
244
|
answer: '',
|
|
249
245
|
enableWhen: {
|
|
@@ -257,9 +253,9 @@ From [`example-react.jsx`](./examples/example-react.jsx):
|
|
|
257
253
|
}
|
|
258
254
|
```
|
|
259
255
|
|
|
260
|
-
##
|
|
256
|
+
## FHIR Output
|
|
261
257
|
|
|
262
|
-
|
|
258
|
+
FHIR QuestionnaireResponse format:
|
|
263
259
|
|
|
264
260
|
```javascript
|
|
265
261
|
{
|
|
@@ -275,14 +271,4 @@ The `onSubmit` callback receives a FHIR QuestionnaireResponse:
|
|
|
275
271
|
}
|
|
276
272
|
]
|
|
277
273
|
}
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
## 📊 Bundle Sizes
|
|
281
|
-
|
|
282
|
-
- **⚛️ React version**: ~24 KB (requires peer deps)
|
|
283
|
-
- **🌐 Standalone version**: ~819 KB (zero dependencies)
|
|
284
|
-
|
|
285
|
-
## 📚 Documentation
|
|
286
|
-
|
|
287
|
-
- [⚛️ React Component Example](./examples/example-react.jsx)
|
|
288
|
-
- [🌐 Web Component Example](./examples/example-standalone.html)
|
|
274
|
+
```
|