@medplum/react 0.9.20 → 0.9.21
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/dist/cjs/index.js +59 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.min.js +1 -1
- package/dist/cjs/index.min.js.map +1 -1
- package/dist/esm/index.js +59 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.min.js +1 -1
- package/dist/esm/index.min.js.map +1 -1
- package/dist/types/stories/QuestionnaireForm.stories.d.ts +2 -0
- package/package.json +5 -5
package/dist/cjs/index.js
CHANGED
|
@@ -2184,8 +2184,7 @@
|
|
|
2184
2184
|
setHistory({});
|
|
2185
2185
|
return;
|
|
2186
2186
|
}
|
|
2187
|
-
|
|
2188
|
-
medplum.post('fhir/R4', batchRequest).then(handleBatchResponse);
|
|
2187
|
+
medplum.executeBatch(buildSearchRequests(resource)).then(handleBatchResponse);
|
|
2189
2188
|
}, [medplum, resource, buildSearchRequests]);
|
|
2190
2189
|
React.useEffect(() => {
|
|
2191
2190
|
loadTimeline();
|
|
@@ -4613,31 +4612,64 @@
|
|
|
4613
4612
|
return (React__default["default"].createElement(TextArea, { name: name, defaultValue: initial === null || initial === void 0 ? void 0 : initial.valueString, onChange: (newValue) => onChangeAnswer({ valueString: newValue }) }));
|
|
4614
4613
|
case exports.QuestionnaireItemType.url:
|
|
4615
4614
|
return (React__default["default"].createElement(Input, { type: "url", name: name, defaultValue: initial === null || initial === void 0 ? void 0 : initial.valueUri, onChange: (newValue) => onChangeAnswer({ valueUri: newValue }) }));
|
|
4616
|
-
case exports.QuestionnaireItemType.choice:
|
|
4617
|
-
case exports.QuestionnaireItemType.openChoice:
|
|
4618
|
-
return (React__default["default"].createElement("div", null, item.answerOption &&
|
|
4619
|
-
item.answerOption.map((option, index) => {
|
|
4620
|
-
const valueElementDefinition = core.globalSchema.types['QuestionnaireItemAnswerOption'].properties['value[x]'];
|
|
4621
|
-
const optionValue = core.getTypedPropertyValue({ type: 'QuestionnaireItemAnswerOption', value: option }, 'value');
|
|
4622
|
-
const initialValue = core.getTypedPropertyValue({ type: 'QuestionnaireItemInitial', value: initial }, 'value');
|
|
4623
|
-
const propertyName = 'value' + core.capitalize(optionValue.type);
|
|
4624
|
-
const optionName = `${name}-option-${index}`;
|
|
4625
|
-
return (React__default["default"].createElement("div", { key: optionName, className: "medplum-questionnaire-option-row" },
|
|
4626
|
-
React__default["default"].createElement("div", { className: "medplum-questionnaire-option-checkbox" },
|
|
4627
|
-
React__default["default"].createElement("input", { type: "radio", id: optionName, name: name, value: optionValue.value, defaultChecked: initialValue && core.stringify(optionValue) === core.stringify(initialValue), onChange: () => onChangeAnswer({ [propertyName]: optionValue.value }) })),
|
|
4628
|
-
React__default["default"].createElement("div", null,
|
|
4629
|
-
React__default["default"].createElement("label", { htmlFor: optionName },
|
|
4630
|
-
React__default["default"].createElement(ResourcePropertyDisplay, { property: valueElementDefinition, propertyType: optionValue.type, value: optionValue.value })))));
|
|
4631
|
-
})));
|
|
4632
4615
|
case exports.QuestionnaireItemType.attachment:
|
|
4633
4616
|
return (React__default["default"].createElement(AttachmentInput, { name: name, defaultValue: initial === null || initial === void 0 ? void 0 : initial.valueAttachment, onChange: (newValue) => onChangeAnswer({ valueAttachment: newValue }) }));
|
|
4634
4617
|
case exports.QuestionnaireItemType.reference:
|
|
4635
4618
|
return (React__default["default"].createElement(ReferenceInput, { name: name, defaultValue: initial === null || initial === void 0 ? void 0 : initial.valueReference, onChange: (newValue) => onChangeAnswer({ valueReference: newValue }) }));
|
|
4636
4619
|
case exports.QuestionnaireItemType.quantity:
|
|
4637
4620
|
return (React__default["default"].createElement(QuantityInput, { name: name, defaultValue: initial === null || initial === void 0 ? void 0 : initial.valueQuantity, onChange: (newValue) => onChangeAnswer({ valueQuantity: newValue }) }));
|
|
4621
|
+
case exports.QuestionnaireItemType.choice:
|
|
4622
|
+
case exports.QuestionnaireItemType.openChoice:
|
|
4623
|
+
if (isDropDownChoice(item)) {
|
|
4624
|
+
return (React__default["default"].createElement(QuestionnaireChoiceDropDownInput, { name: name, item: item, initial: initial, onChangeAnswer: onChangeAnswer }));
|
|
4625
|
+
}
|
|
4626
|
+
else {
|
|
4627
|
+
return (React__default["default"].createElement(QuestionnaireChoiceRadioInput, { name: name, item: item, initial: initial, onChangeAnswer: onChangeAnswer }));
|
|
4628
|
+
}
|
|
4638
4629
|
}
|
|
4639
4630
|
return null;
|
|
4640
4631
|
}
|
|
4632
|
+
function QuestionnaireChoiceDropDownInput(props) {
|
|
4633
|
+
const { name, item, initial } = props;
|
|
4634
|
+
const valueElementDefinition = core.globalSchema.types['QuestionnaireItemAnswerOption'].properties['value[x]'];
|
|
4635
|
+
const initialValue = core.getTypedPropertyValue({ type: 'QuestionnaireItemInitial', value: initial }, 'value');
|
|
4636
|
+
return (React__default["default"].createElement("select", { id: name, name: name, className: "medplum-select", onChange: (e) => {
|
|
4637
|
+
const index = e.currentTarget.selectedIndex;
|
|
4638
|
+
if (index === 0) {
|
|
4639
|
+
props.onChangeAnswer({});
|
|
4640
|
+
return;
|
|
4641
|
+
}
|
|
4642
|
+
const option = item.answerOption[index - 1];
|
|
4643
|
+
const optionValue = core.getTypedPropertyValue({ type: 'QuestionnaireItemAnswerOption', value: option }, 'value');
|
|
4644
|
+
const propertyName = 'value' + core.capitalize(optionValue.type);
|
|
4645
|
+
props.onChangeAnswer({ [propertyName]: optionValue.value });
|
|
4646
|
+
} },
|
|
4647
|
+
React__default["default"].createElement("option", null),
|
|
4648
|
+
item.answerOption &&
|
|
4649
|
+
item.answerOption.map((option, index) => {
|
|
4650
|
+
const optionValue = core.getTypedPropertyValue({ type: 'QuestionnaireItemAnswerOption', value: option }, 'value');
|
|
4651
|
+
const optionName = `${name}-option-${index}`;
|
|
4652
|
+
return (React__default["default"].createElement("option", { key: optionName, value: optionValue.value, selected: initialValue && core.stringify(optionValue) === core.stringify(initialValue) },
|
|
4653
|
+
React__default["default"].createElement(ResourcePropertyDisplay, { property: valueElementDefinition, propertyType: optionValue.type, value: optionValue.value })));
|
|
4654
|
+
})));
|
|
4655
|
+
}
|
|
4656
|
+
function QuestionnaireChoiceRadioInput(props) {
|
|
4657
|
+
const { name, item, initial, onChangeAnswer } = props;
|
|
4658
|
+
const valueElementDefinition = core.globalSchema.types['QuestionnaireItemAnswerOption'].properties['value[x]'];
|
|
4659
|
+
const initialValue = core.getTypedPropertyValue({ type: 'QuestionnaireItemInitial', value: initial }, 'value');
|
|
4660
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null, item.answerOption &&
|
|
4661
|
+
item.answerOption.map((option, index) => {
|
|
4662
|
+
const optionValue = core.getTypedPropertyValue({ type: 'QuestionnaireItemAnswerOption', value: option }, 'value');
|
|
4663
|
+
const propertyName = 'value' + core.capitalize(optionValue.type);
|
|
4664
|
+
const optionName = `${name}-option-${index}`;
|
|
4665
|
+
return (React__default["default"].createElement("div", { key: optionName, className: "medplum-questionnaire-option-row" },
|
|
4666
|
+
React__default["default"].createElement("div", { className: "medplum-questionnaire-option-checkbox" },
|
|
4667
|
+
React__default["default"].createElement("input", { type: "radio", id: optionName, name: name, value: optionValue.value, defaultChecked: initialValue && core.stringify(optionValue) === core.stringify(initialValue), onChange: () => onChangeAnswer({ [propertyName]: optionValue.value }) })),
|
|
4668
|
+
React__default["default"].createElement("div", null,
|
|
4669
|
+
React__default["default"].createElement("label", { htmlFor: optionName },
|
|
4670
|
+
React__default["default"].createElement(ResourcePropertyDisplay, { property: valueElementDefinition, propertyType: optionValue.type, value: optionValue.value })))));
|
|
4671
|
+
})));
|
|
4672
|
+
}
|
|
4641
4673
|
function buildInitialResponse(questionnaire) {
|
|
4642
4674
|
const response = {
|
|
4643
4675
|
resourceType: 'QuestionnaireResponse',
|
|
@@ -4663,6 +4695,14 @@
|
|
|
4663
4695
|
// have the same properties.
|
|
4664
4696
|
return Object.assign({}, answer);
|
|
4665
4697
|
}
|
|
4698
|
+
function isDropDownChoice(item) {
|
|
4699
|
+
var _a;
|
|
4700
|
+
return !!((_a = item.extension) === null || _a === void 0 ? void 0 : _a.some((e) => {
|
|
4701
|
+
var _a, _b, _c;
|
|
4702
|
+
return e.url === 'http://hl7.org/fhir/StructureDefinition/questionnaire-itemControl' &&
|
|
4703
|
+
((_c = (_b = (_a = e.valueCodeableConcept) === null || _a === void 0 ? void 0 : _a.coding) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.code) === 'drop-down';
|
|
4704
|
+
}));
|
|
4705
|
+
}
|
|
4666
4706
|
|
|
4667
4707
|
function QuestionnaireBuilder(props) {
|
|
4668
4708
|
const medplum = useMedplum();
|
|
@@ -4876,7 +4916,7 @@
|
|
|
4876
4916
|
const [responseBundle, setResponseBundle] = React.useState();
|
|
4877
4917
|
React.useEffect(() => {
|
|
4878
4918
|
if (requestGroup && !startedLoading) {
|
|
4879
|
-
medplum.
|
|
4919
|
+
medplum.executeBatch(buildBatchRequest(requestGroup)).then(setResponseBundle);
|
|
4880
4920
|
setStartedLoading(true);
|
|
4881
4921
|
}
|
|
4882
4922
|
}, [medplum, requestGroup, startedLoading]);
|