@mieweb/forms-renderer 0.1.8 → 0.1.9
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 +117 -33
- package/dist/react.js +272 -339
- package/dist/react.js.map +1 -1
- package/dist/standalone.js +3641 -3666
- package/dist/standalone.js.map +1 -1
- package/dist/standalone.umd.cjs +56 -56
- package/dist/standalone.umd.cjs.map +1 -1
- package/package.json +48 -48
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ npm install @mieweb/forms-renderer
|
|
|
11
11
|
## 🚀 Examples
|
|
12
12
|
|
|
13
13
|
See the complete working examples in this package:
|
|
14
|
-
- [`example-react.jsx`](./example-react.jsx) - ⚛️ React component usage
|
|
15
|
-
- [`example-standalone.html`](./example-standalone.html) - 🌐 Web Component usage
|
|
14
|
+
- [`example-react.jsx`](./examples/example-react.jsx) - ⚛️ React component usage
|
|
15
|
+
- [`example-standalone.html`](./examples/example-standalone.html) - 🌐 Web Component usage
|
|
16
16
|
|
|
17
17
|
## 💻 Usage
|
|
18
18
|
|
|
@@ -23,9 +23,45 @@ Requires React peer dependencies:
|
|
|
23
23
|
npm install react react-dom
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
#### Basic Usage (Custom Submit Button)
|
|
27
27
|
```jsx
|
|
28
|
-
import { QuestionnaireRenderer } from '@mieweb/forms-renderer';
|
|
28
|
+
import { QuestionnaireRenderer, useQuestionnaireData } from '@mieweb/forms-renderer';
|
|
29
|
+
|
|
30
|
+
function MyForm() {
|
|
31
|
+
const [fields] = React.useState([
|
|
32
|
+
{
|
|
33
|
+
id: 'q-name',
|
|
34
|
+
fieldType: 'input',
|
|
35
|
+
question: 'What is your full name?',
|
|
36
|
+
answer: ''
|
|
37
|
+
}
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
const { getQuestionnaireResponse } = useQuestionnaireData('my-questionnaire', 'patient-123');
|
|
41
|
+
|
|
42
|
+
const handleSubmit = (e) => {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
const fhirResponse = getQuestionnaireResponse();
|
|
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, useQuestionnaireData } from '@mieweb/forms-renderer';
|
|
29
65
|
|
|
30
66
|
function App() {
|
|
31
67
|
const [fields] = React.useState([
|
|
@@ -53,14 +89,20 @@ function App() {
|
|
|
53
89
|
]
|
|
54
90
|
}
|
|
55
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
|
|
99
|
+
};
|
|
56
100
|
|
|
57
101
|
return (
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
onSubmit={(fhirResponse) => console.log('Submitted:', fhirResponse)}
|
|
63
|
-
/>
|
|
102
|
+
<form onSubmit={handleSubmit}>
|
|
103
|
+
<QuestionnaireRenderer fields={fields} />
|
|
104
|
+
<button type="submit">Submit</button>
|
|
105
|
+
</form>
|
|
64
106
|
);
|
|
65
107
|
}
|
|
66
108
|
```
|
|
@@ -69,7 +111,7 @@ function App() {
|
|
|
69
111
|
|
|
70
112
|
✨ Zero dependencies - works with any framework or vanilla JS.
|
|
71
113
|
|
|
72
|
-
From [`example-standalone.html`](./example-standalone.html):
|
|
114
|
+
From [`example-standalone.html`](./examples/example-standalone.html):
|
|
73
115
|
```html
|
|
74
116
|
<script type="module">
|
|
75
117
|
import './package/dist/standalone.js';
|
|
@@ -101,34 +143,78 @@ From [`example-standalone.html`](./example-standalone.html):
|
|
|
101
143
|
}
|
|
102
144
|
];
|
|
103
145
|
|
|
104
|
-
|
|
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');
|
|
105
151
|
console.log('Form submitted:', fhirResponse);
|
|
106
|
-
};
|
|
152
|
+
});
|
|
107
153
|
</script>
|
|
108
154
|
|
|
109
|
-
<
|
|
110
|
-
questionnaire-
|
|
111
|
-
|
|
112
|
-
</
|
|
155
|
+
<form id="myForm">
|
|
156
|
+
<questionnaire-renderer full-height></questionnaire-renderer>
|
|
157
|
+
<button type="submit">Submit</button>
|
|
158
|
+
</form>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## ⚙️ API Reference
|
|
162
|
+
|
|
163
|
+
### `<QuestionnaireRenderer>` Component
|
|
164
|
+
React component for rendering questionnaires (no built-in submit button).
|
|
165
|
+
|
|
166
|
+
**Props:**
|
|
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
|
|
171
|
+
|
|
172
|
+
### `useQuestionnaireData(questionnaireId, subjectId)` Hook
|
|
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
|
+
}
|
|
113
185
|
```
|
|
114
186
|
|
|
115
|
-
|
|
187
|
+
**Example:**
|
|
188
|
+
```jsx
|
|
189
|
+
const { fields, getQuestionnaireResponse } = useQuestionnaireData('q-1', 'patient-123');
|
|
190
|
+
|
|
191
|
+
const handleSubmit = () => {
|
|
192
|
+
const fhirResponse = getQuestionnaireResponse();
|
|
193
|
+
// fhirResponse is a FHIR QuestionnaireResponse object
|
|
194
|
+
};
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### `useQuestionnaireSubmit(fields, questionnaireId, subjectId, onSubmit)` Hook
|
|
198
|
+
*(Legacy)* Pre-built submit handler.
|
|
199
|
+
|
|
200
|
+
**Parameters:**
|
|
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
|
|
205
|
+
|
|
206
|
+
**Returns:** `(event) => void` - Form submit handler
|
|
207
|
+
|
|
208
|
+
### `buildQuestionnaireResponse(fields, questionnaireId, subjectId)` Utility
|
|
209
|
+
Build FHIR QuestionnaireResponse from fields.
|
|
116
210
|
|
|
117
|
-
|
|
118
|
-
- `fields` - Questionnaire definition array
|
|
119
|
-
- `onChange` - Callback when answers change
|
|
120
|
-
- `onSubmit` - Callback on form submit
|
|
121
|
-
- `questionnaireId` - FHIR Questionnaire ID
|
|
122
|
-
- `subjectId` - Patient/subject ID
|
|
123
|
-
- `className` - CSS classes
|
|
124
|
-
- `fullHeight` - Full viewport height
|
|
211
|
+
**Returns:** FHIR QuestionnaireResponse object
|
|
125
212
|
|
|
126
213
|
### 🌐 Web Component
|
|
127
|
-
- `questionnaire-id` - FHIR Questionnaire ID (attribute)
|
|
128
214
|
- `full-height` - Full viewport height (attribute)
|
|
129
215
|
- `fields` - Questionnaire definition (property)
|
|
130
216
|
- `onChange` - Change callback (property)
|
|
131
|
-
- `
|
|
217
|
+
- `getQuestionnaireResponse(questionnaireId, subjectId)` - Get FHIR response (method)
|
|
132
218
|
|
|
133
219
|
## 🔧 Field Types
|
|
134
220
|
|
|
@@ -142,7 +228,7 @@ From [`example-standalone.html`](./example-standalone.html):
|
|
|
142
228
|
|
|
143
229
|
Fields can be shown/hidden based on other field values. Both examples include conditional logic:
|
|
144
230
|
|
|
145
|
-
From [`example-react.jsx`](./example-react.jsx):
|
|
231
|
+
From [`example-react.jsx`](./examples/example-react.jsx):
|
|
146
232
|
```javascript
|
|
147
233
|
{
|
|
148
234
|
id: 'sec-pregnancy',
|
|
@@ -198,7 +284,5 @@ The `onSubmit` callback receives a FHIR QuestionnaireResponse:
|
|
|
198
284
|
|
|
199
285
|
## 📚 Documentation
|
|
200
286
|
|
|
201
|
-
- [
|
|
202
|
-
- [
|
|
203
|
-
- [🌐 Web Component Summary](./docs/WEB-COMPONENT-SUMMARY.md)
|
|
204
|
-
- [🏗️ Architecture](./docs/ARCHITECTURE.md)
|
|
287
|
+
- [⚛️ React Component Example](./examples/example-react.jsx)
|
|
288
|
+
- [🌐 Web Component Example](./examples/example-standalone.html)
|