@mieweb/forms-renderer 0.1.8 → 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 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
- From [`example-react.jsx`](./example-react.jsx):
26
+ #### Basic Usage (Custom Submit Button)
27
27
  ```jsx
28
- import { QuestionnaireRenderer } from '@mieweb/forms-renderer';
28
+ import { QuestionnaireRenderer, buildQuestionnaireResponse, useFieldsArray } 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 currentFields = useFieldsArray();
41
+
42
+ const handleSubmit = (e) => {
43
+ e.preventDefault();
44
+ const fhirResponse = buildQuestionnaireResponse(currentFields, 'my-questionnaire', 'patient-123');
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';
29
65
 
30
66
  function App() {
31
67
  const [fields] = React.useState([
@@ -53,13 +89,42 @@ function App() {
53
89
  ]
54
90
  }
55
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
99
+ };
56
100
 
57
101
  return (
58
- <QuestionnaireRenderer
59
- questionnaireId="demo-questionnaire"
60
- fields={fields}
61
- onChange={(updatedFields) => console.log('Changed:', updatedFields)}
62
- onSubmit={(fhirResponse) => console.log('Submitted:', fhirResponse)}
102
+ <form onSubmit={handleSubmit}>
103
+ <QuestionnaireRenderer fields={fields} />
104
+ <button type="submit">Submit</button>
105
+ </form>
106
+ );
107
+ }
108
+ ```
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}
63
128
  />
64
129
  );
65
130
  }
@@ -69,7 +134,7 @@ function App() {
69
134
 
70
135
  ✨ Zero dependencies - works with any framework or vanilla JS.
71
136
 
72
- From [`example-standalone.html`](./example-standalone.html):
137
+ From [`example-standalone.html`](./examples/example-standalone.html):
73
138
  ```html
74
139
  <script type="module">
75
140
  import './package/dist/standalone.js';
@@ -101,34 +166,77 @@ From [`example-standalone.html`](./example-standalone.html):
101
166
  }
102
167
  ];
103
168
 
104
- renderer.onSubmit = (fhirResponse) => {
169
+ // Handle form submission
170
+ const form = document.getElementById('myForm');
171
+ form.addEventListener('submit', (e) => {
172
+ e.preventDefault();
173
+ const fhirResponse = renderer.getQuestionnaireResponse('q-1', 'patient-123');
105
174
  console.log('Form submitted:', fhirResponse);
106
- };
175
+ });
107
176
  </script>
108
177
 
109
- <questionnaire-renderer
110
- questionnaire-id="standalone-demo"
111
- full-height>
112
- </questionnaire-renderer>
178
+ <form id="myForm">
179
+ <questionnaire-renderer full-height></questionnaire-renderer>
180
+ <button type="submit">Submit</button>
181
+ </form>
113
182
  ```
114
183
 
115
- ## ⚙️ Props/Attributes
184
+ ## ⚙️ API Reference
185
+
186
+ ### `<QuestionnaireRenderer>` Component
187
+ React component for rendering questionnaires (no built-in submit button).
188
+
189
+ **Props:**
190
+ - `fields` *(array)* - Questionnaire definition array
191
+ - `schemaType` *(string)* - Schema format: `'inhouse'` (default) or `'surveyjs'`
192
+ - `onChange` *(function)* - Callback when answers change: `(updatedFields) => void`
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.
196
+
197
+ **Example with hideUnsupportedFields:**
198
+ ```jsx
199
+ <QuestionnaireRenderer
200
+ fields={surveyJsSchema}
201
+ schemaType="surveyjs"
202
+ hideUnsupportedFields={true}
203
+ />
204
+ ```
116
205
 
117
- ### ⚛️ React Component
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
206
+ ### Helper Functions
207
+
208
+ #### `buildQuestionnaireResponse(fields, questionnaireId, subjectId)`
209
+ Build FHIR QuestionnaireResponse from fields. Use with `useFieldsArray()`.
210
+
211
+ **Parameters:**
212
+ - `fields` *(array)* - Current form fields (from `useFieldsArray()`)
213
+ - `questionnaireId` *(string)* - FHIR Questionnaire ID
214
+ - `subjectId` *(string, optional)* - Patient/subject ID
215
+
216
+ **Returns:** FHIR QuestionnaireResponse object
217
+
218
+ **Example:**
219
+ ```jsx
220
+ import { buildQuestionnaireResponse, useFieldsArray } from '@mieweb/forms-renderer';
221
+
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
+ ```
125
234
 
126
235
  ### 🌐 Web Component
127
- - `questionnaire-id` - FHIR Questionnaire ID (attribute)
128
236
  - `full-height` - Full viewport height (attribute)
129
237
  - `fields` - Questionnaire definition (property)
130
238
  - `onChange` - Change callback (property)
131
- - `onSubmit` - Submit callback (property)
239
+ - `getQuestionnaireResponse(questionnaireId, subjectId)` - Get FHIR response (method)
132
240
 
133
241
  ## 🔧 Field Types
134
242
 
@@ -142,7 +250,7 @@ From [`example-standalone.html`](./example-standalone.html):
142
250
 
143
251
  Fields can be shown/hidden based on other field values. Both examples include conditional logic:
144
252
 
145
- From [`example-react.jsx`](./example-react.jsx):
253
+ From [`example-react.jsx`](./examples/example-react.jsx):
146
254
  ```javascript
147
255
  {
148
256
  id: 'sec-pregnancy',
@@ -198,7 +306,5 @@ The `onSubmit` callback receives a FHIR QuestionnaireResponse:
198
306
 
199
307
  ## 📚 Documentation
200
308
 
201
- - [📖 Migration Guide](./docs/MIGRATION.md)
202
- - [🚀 Meteor/Blaze Guide](./docs/METEOR-BLAZE-GUIDE.md)
203
- - [🌐 Web Component Summary](./docs/WEB-COMPONENT-SUMMARY.md)
204
- - [🏗️ Architecture](./docs/ARCHITECTURE.md)
309
+ - [⚛️ React Component Example](./examples/example-react.jsx)
310
+ - [🌐 Web Component Example](./examples/example-standalone.html)