@mieweb/forms-renderer 0.1.9 → 0.1.10
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 +58 -36
- package/dist/blaze.js +23418 -0
- package/dist/blaze.js.map +1 -0
- package/dist/blaze.umd.cjs +271 -0
- package/dist/blaze.umd.cjs.map +1 -0
- package/dist/react.js +330 -262
- package/dist/react.js.map +1 -1
- package/dist/standalone.js +9327 -8915
- package/dist/standalone.js.map +1 -1
- package/dist/standalone.umd.cjs +77 -78
- package/dist/standalone.umd.cjs.map +1 -1
- package/package.json +52 -48
- package/dist/web-component.css +0 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ npm install react react-dom
|
|
|
25
25
|
|
|
26
26
|
#### Basic Usage (Custom Submit Button)
|
|
27
27
|
```jsx
|
|
28
|
-
import { QuestionnaireRenderer,
|
|
28
|
+
import { QuestionnaireRenderer, buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
|
|
29
29
|
|
|
30
30
|
function MyForm() {
|
|
31
31
|
const [fields] = React.useState([
|
|
@@ -37,11 +37,11 @@ function MyForm() {
|
|
|
37
37
|
}
|
|
38
38
|
]);
|
|
39
39
|
|
|
40
|
-
const
|
|
40
|
+
const currentFields = useFieldsArray();
|
|
41
41
|
|
|
42
42
|
const handleSubmit = (e) => {
|
|
43
43
|
e.preventDefault();
|
|
44
|
-
const fhirResponse =
|
|
44
|
+
const fhirResponse = buildQuestionnaireResponse(currentFields, 'my-questionnaire', 'patient-123');
|
|
45
45
|
console.log('Submitted:', fhirResponse);
|
|
46
46
|
// Send to your API, etc.
|
|
47
47
|
};
|
|
@@ -61,7 +61,7 @@ function MyForm() {
|
|
|
61
61
|
#### With Sections and Conditional Logic
|
|
62
62
|
From [`example-react.jsx`](./examples/example-react.jsx):
|
|
63
63
|
```jsx
|
|
64
|
-
import { QuestionnaireRenderer,
|
|
64
|
+
import { QuestionnaireRenderer, buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
|
|
65
65
|
|
|
66
66
|
function App() {
|
|
67
67
|
const [fields] = React.useState([
|
|
@@ -90,11 +90,11 @@ function App() {
|
|
|
90
90
|
}
|
|
91
91
|
]);
|
|
92
92
|
|
|
93
|
-
const
|
|
93
|
+
const currentFields = useFieldsArray();
|
|
94
94
|
|
|
95
95
|
const handleSubmit = (e) => {
|
|
96
96
|
e.preventDefault();
|
|
97
|
-
const fhirResponse =
|
|
97
|
+
const fhirResponse = buildQuestionnaireResponse(currentFields, 'demo-1', 'patient-123');
|
|
98
98
|
// Handle submission
|
|
99
99
|
};
|
|
100
100
|
|
|
@@ -107,6 +107,29 @@ function App() {
|
|
|
107
107
|
}
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
+
#### With SurveyJS Schema and Hidden Unsupported Fields
|
|
111
|
+
```jsx
|
|
112
|
+
import { QuestionnaireRenderer } from '@mieweb/forms-renderer';
|
|
113
|
+
|
|
114
|
+
function SurveyForm() {
|
|
115
|
+
const [surveySchema, setSurveySchema] = React.useState(null);
|
|
116
|
+
|
|
117
|
+
React.useEffect(() => {
|
|
118
|
+
fetch('/surveyjs-schema.json')
|
|
119
|
+
.then(r => r.json())
|
|
120
|
+
.then(setSurveySchema);
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<QuestionnaireRenderer
|
|
125
|
+
fields={surveySchema}
|
|
126
|
+
schemaType="surveyjs"
|
|
127
|
+
hideUnsupportedFields={true}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
110
133
|
### 🌐 Standalone Web Component (Framework-Agnostic)
|
|
111
134
|
|
|
112
135
|
✨ Zero dependencies - works with any framework or vanilla JS.
|
|
@@ -165,50 +188,49 @@ React component for rendering questionnaires (no built-in submit button).
|
|
|
165
188
|
|
|
166
189
|
**Props:**
|
|
167
190
|
- `fields` *(array)* - Questionnaire definition array
|
|
191
|
+
- `schemaType` *(string)* - Schema format: `'inhouse'` (default) or `'surveyjs'`
|
|
168
192
|
- `onChange` *(function)* - Callback when answers change: `(updatedFields) => void`
|
|
169
193
|
- `className` *(string)* - Additional CSS classes
|
|
170
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.
|
|
171
196
|
|
|
172
|
-
|
|
173
|
-
Get current questionnaire data and FHIR response builder.
|
|
174
|
-
|
|
175
|
-
**Parameters:**
|
|
176
|
-
- `questionnaireId` *(string)* - FHIR Questionnaire ID (default: `'questionnaire-1'`)
|
|
177
|
-
- `subjectId` *(string, optional)* - Patient/subject ID
|
|
178
|
-
|
|
179
|
-
**Returns:**
|
|
180
|
-
```typescript
|
|
181
|
-
{
|
|
182
|
-
fields: Field[], // Current form fields with answers
|
|
183
|
-
getQuestionnaireResponse: () => Object // Get FHIR QuestionnaireResponse
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
**Example:**
|
|
197
|
+
**Example with hideUnsupportedFields:**
|
|
188
198
|
```jsx
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
};
|
|
199
|
+
<QuestionnaireRenderer
|
|
200
|
+
fields={surveyJsSchema}
|
|
201
|
+
schemaType="surveyjs"
|
|
202
|
+
hideUnsupportedFields={true}
|
|
203
|
+
/>
|
|
195
204
|
```
|
|
196
205
|
|
|
197
|
-
###
|
|
198
|
-
|
|
206
|
+
### Helper Functions
|
|
207
|
+
|
|
208
|
+
#### `buildQuestionnaireResponse(fields, questionnaireId, subjectId)`
|
|
209
|
+
Build FHIR QuestionnaireResponse from fields. Use with `useFieldsArray()`.
|
|
199
210
|
|
|
200
211
|
**Parameters:**
|
|
201
|
-
- `fields` *(array)* - Current form fields
|
|
212
|
+
- `fields` *(array)* - Current form fields (from `useFieldsArray()`)
|
|
202
213
|
- `questionnaireId` *(string)* - FHIR Questionnaire ID
|
|
203
214
|
- `subjectId` *(string, optional)* - Patient/subject ID
|
|
204
|
-
- `onSubmit` *(function)* - Callback with FHIR response
|
|
205
215
|
|
|
206
|
-
**Returns:**
|
|
216
|
+
**Returns:** FHIR QuestionnaireResponse object
|
|
207
217
|
|
|
208
|
-
|
|
209
|
-
|
|
218
|
+
**Example:**
|
|
219
|
+
```jsx
|
|
220
|
+
import { buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
|
|
210
221
|
|
|
211
|
-
|
|
222
|
+
function MyForm() {
|
|
223
|
+
const currentFields = useFieldsArray();
|
|
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
|
+
}
|
|
233
|
+
```
|
|
212
234
|
|
|
213
235
|
### 🌐 Web Component
|
|
214
236
|
- `full-height` - Full viewport height (attribute)
|