@mieweb/forms-renderer 0.1.10 → 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 +155 -191
- package/dist/blaze.js +11219 -9008
- package/dist/blaze.js.map +1 -1
- package/dist/blaze.umd.cjs +2032 -76
- package/dist/blaze.umd.cjs.map +1 -1
- package/dist/react.js +228 -228
- package/dist/react.js.map +1 -1
- package/dist/standalone.js +11414 -9209
- package/dist/standalone.js.map +1 -1
- package/dist/standalone.umd.cjs +2031 -75
- package/dist/standalone.umd.cjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
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
|
-
|
|
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
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
- [`example-react.jsx`](./examples/example-react.jsx) - ⚛️ React component usage
|
|
15
|
-
- [`example-standalone.html`](./examples/example-standalone.html) - 🌐 Web Component usage
|
|
13
|
+
Choose the method that fits your stack:
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
### 1. React Component (for React apps)
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Requires React peer dependencies:
|
|
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
24
|
import { QuestionnaireRenderer, buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
|
|
29
25
|
|
|
@@ -31,7 +27,7 @@ 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
|
}
|
|
@@ -41,61 +37,7 @@ function MyForm() {
|
|
|
41
37
|
|
|
42
38
|
const handleSubmit = (e) => {
|
|
43
39
|
e.preventDefault();
|
|
44
|
-
const
|
|
45
|
-
console.log('Submitted:', fhirResponse);
|
|
46
|
-
// Send to your API, etc.
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<form onSubmit={handleSubmit}>
|
|
51
|
-
<QuestionnaireRenderer
|
|
52
|
-
fields={fields}
|
|
53
|
-
onChange={(updated) => console.log('Changed:', updated)}
|
|
54
|
-
/>
|
|
55
|
-
<button type="submit">Submit Questionnaire</button>
|
|
56
|
-
</form>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
#### With Sections and Conditional Logic
|
|
62
|
-
From [`example-react.jsx`](./examples/example-react.jsx):
|
|
63
|
-
```jsx
|
|
64
|
-
import { QuestionnaireRenderer, buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
|
|
65
|
-
|
|
66
|
-
function App() {
|
|
67
|
-
const [fields] = React.useState([
|
|
68
|
-
{
|
|
69
|
-
id: 'sec-1',
|
|
70
|
-
fieldType: 'section',
|
|
71
|
-
title: 'Personal Information',
|
|
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
|
-
}
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
]);
|
|
92
|
-
|
|
93
|
-
const currentFields = useFieldsArray();
|
|
94
|
-
|
|
95
|
-
const handleSubmit = (e) => {
|
|
96
|
-
e.preventDefault();
|
|
97
|
-
const fhirResponse = buildQuestionnaireResponse(currentFields, 'demo-1', 'patient-123');
|
|
98
|
-
// Handle submission
|
|
40
|
+
const fhir = buildQuestionnaireResponse(currentFields, 'my-questionnaire', 'patient-123');
|
|
99
41
|
};
|
|
100
42
|
|
|
101
43
|
return (
|
|
@@ -107,18 +49,19 @@ function App() {
|
|
|
107
49
|
}
|
|
108
50
|
```
|
|
109
51
|
|
|
110
|
-
|
|
52
|
+
**With SurveyJS Schema:**
|
|
111
53
|
```jsx
|
|
112
54
|
import { QuestionnaireRenderer } from '@mieweb/forms-renderer';
|
|
113
55
|
|
|
114
56
|
function SurveyForm() {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
57
|
+
const surveySchema = {
|
|
58
|
+
pages: [{
|
|
59
|
+
elements: [
|
|
60
|
+
{ type: 'text', name: 'firstName', title: 'First Name' },
|
|
61
|
+
{ type: 'text', name: 'lastName', title: 'Last Name' }
|
|
62
|
+
]
|
|
63
|
+
}]
|
|
64
|
+
};
|
|
122
65
|
|
|
123
66
|
return (
|
|
124
67
|
<QuestionnaireRenderer
|
|
@@ -130,127 +73,158 @@ function SurveyForm() {
|
|
|
130
73
|
}
|
|
131
74
|
```
|
|
132
75
|
|
|
133
|
-
|
|
76
|
+
---
|
|
134
77
|
|
|
135
|
-
|
|
78
|
+
### 2. Standalone Web Component (framework-agnostic)
|
|
79
|
+
|
|
80
|
+
**Install:**
|
|
81
|
+
```bash
|
|
82
|
+
npm install @mieweb/forms-renderer
|
|
83
|
+
```
|
|
84
|
+
No peer dependencies required - bundles React internally.
|
|
136
85
|
|
|
137
|
-
|
|
86
|
+
**Usage:**
|
|
138
87
|
```html
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
</
|
|
177
|
-
|
|
178
|
-
<form id="myForm">
|
|
179
|
-
<questionnaire-renderer full-height></questionnaire-renderer>
|
|
180
|
-
<button type="submit">Submit</button>
|
|
181
|
-
</form>
|
|
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>
|
|
182
127
|
```
|
|
183
128
|
|
|
184
|
-
|
|
129
|
+
---
|
|
185
130
|
|
|
186
|
-
###
|
|
187
|
-
React component for rendering questionnaires (no built-in submit button).
|
|
131
|
+
### 3. Blaze Component (for Meteor apps)
|
|
188
132
|
|
|
189
|
-
**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
- `className` *(string)* - Additional CSS classes
|
|
194
|
-
- `fullHeight` *(boolean)* - Full viewport height mode
|
|
195
|
-
- `hideUnsupportedFields` *(boolean)* - Hide unsupported field types instead of showing placeholders. Useful when importing schemas from external sources like SurveyJS that may contain field types not yet supported by this renderer.
|
|
133
|
+
**Install:**
|
|
134
|
+
```bash
|
|
135
|
+
meteor npm install @mieweb/forms-renderer
|
|
136
|
+
```
|
|
196
137
|
|
|
197
|
-
**
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
138
|
+
**Usage:**
|
|
139
|
+
```javascript
|
|
140
|
+
// In your Meteor client code
|
|
141
|
+
import '@mieweb/forms-renderer/blaze';
|
|
142
|
+
|
|
143
|
+
// If the above doesn't work in your Meteor version, try:
|
|
144
|
+
// import '@mieweb/forms-renderer/dist/blaze.js';
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**In your Blaze template:**
|
|
148
|
+
```handlebars
|
|
149
|
+
{{> questionnaireRenderer
|
|
150
|
+
fields=myFields
|
|
151
|
+
schemaType="surveyjs"
|
|
152
|
+
hideUnsupportedFields=true
|
|
153
|
+
onChange=handleChange}}
|
|
154
|
+
```
|
|
155
|
+
|
|
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
|
+
});
|
|
204
170
|
```
|
|
205
171
|
|
|
206
|
-
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## API Reference
|
|
207
175
|
|
|
208
|
-
|
|
209
|
-
Build FHIR QuestionnaireResponse from fields. Use with `useFieldsArray()`.
|
|
176
|
+
### React Component Props
|
|
210
177
|
|
|
211
|
-
|
|
212
|
-
- `
|
|
213
|
-
- `
|
|
214
|
-
- `
|
|
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
|
|
215
184
|
|
|
216
|
-
|
|
185
|
+
### React Helpers
|
|
186
|
+
|
|
187
|
+
**`buildQuestionnaireResponse(fields, questionnaireId, subjectId)`**
|
|
188
|
+
|
|
189
|
+
Returns FHIR QuestionnaireResponse. Use with `useFieldsArray()` to get current form state:
|
|
217
190
|
|
|
218
|
-
**Example:**
|
|
219
191
|
```jsx
|
|
220
192
|
import { buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
|
|
221
193
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const handleSubmit = (e) => {
|
|
226
|
-
e.preventDefault();
|
|
227
|
-
const fhirResponse = buildQuestionnaireResponse(currentFields, 'q-1', 'patient-123');
|
|
228
|
-
// Send to API, save to database, etc.
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
return <form onSubmit={handleSubmit}>...</form>;
|
|
232
|
-
}
|
|
194
|
+
const currentFields = useFieldsArray();
|
|
195
|
+
const fhir = buildQuestionnaireResponse(currentFields, 'q-1', 'patient-123');
|
|
233
196
|
```
|
|
234
197
|
|
|
235
|
-
###
|
|
236
|
-
|
|
237
|
-
- `fields` -
|
|
238
|
-
- `onChange` -
|
|
239
|
-
- `
|
|
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)
|
|
240
205
|
|
|
241
|
-
|
|
206
|
+
### Blaze Component Data Context
|
|
242
207
|
|
|
243
|
-
- `
|
|
244
|
-
- `
|
|
245
|
-
- `
|
|
246
|
-
- `
|
|
247
|
-
- `
|
|
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
|
|
248
213
|
|
|
249
|
-
##
|
|
214
|
+
## Field Types
|
|
250
215
|
|
|
251
|
-
|
|
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
|
|
252
224
|
|
|
253
|
-
|
|
225
|
+
## Conditional Logic
|
|
226
|
+
|
|
227
|
+
Show/hide fields based on other answers:
|
|
254
228
|
```javascript
|
|
255
229
|
{
|
|
256
230
|
id: 'sec-pregnancy',
|
|
@@ -265,7 +239,7 @@ From [`example-react.jsx`](./examples/example-react.jsx):
|
|
|
265
239
|
fields: [
|
|
266
240
|
{
|
|
267
241
|
id: 'q-weeks',
|
|
268
|
-
fieldType: '
|
|
242
|
+
fieldType: 'text',
|
|
269
243
|
question: 'Weeks gestation (if known)',
|
|
270
244
|
answer: '',
|
|
271
245
|
enableWhen: {
|
|
@@ -279,9 +253,9 @@ From [`example-react.jsx`](./examples/example-react.jsx):
|
|
|
279
253
|
}
|
|
280
254
|
```
|
|
281
255
|
|
|
282
|
-
##
|
|
256
|
+
## FHIR Output
|
|
283
257
|
|
|
284
|
-
|
|
258
|
+
FHIR QuestionnaireResponse format:
|
|
285
259
|
|
|
286
260
|
```javascript
|
|
287
261
|
{
|
|
@@ -297,14 +271,4 @@ The `onSubmit` callback receives a FHIR QuestionnaireResponse:
|
|
|
297
271
|
}
|
|
298
272
|
]
|
|
299
273
|
}
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
## 📊 Bundle Sizes
|
|
303
|
-
|
|
304
|
-
- **⚛️ React version**: ~24 KB (requires peer deps)
|
|
305
|
-
- **🌐 Standalone version**: ~819 KB (zero dependencies)
|
|
306
|
-
|
|
307
|
-
## 📚 Documentation
|
|
308
|
-
|
|
309
|
-
- [⚛️ React Component Example](./examples/example-react.jsx)
|
|
310
|
-
- [🌐 Web Component Example](./examples/example-standalone.html)
|
|
274
|
+
```
|