diff --git a/src/assets/possibleValues.json b/src/assets/possibleValues.json new file mode 100644 index 00000000..740a1a52 --- /dev/null +++ b/src/assets/possibleValues.json @@ -0,0 +1,97 @@ +[ + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--0", + "http://www.w3.org/2000/01/rdf-schema#comment": [ + { + "@value": "Fully active, able to carry on all pre-disease performance without restriction." + } + ], + "http://www.w3.org/2000/01/rdf-schema#label": [ + { + "@value": "0" + } + ] + }, + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--1", + "http://www.w3.org/2000/01/rdf-schema#comment": [ + { + "@value": "Restricted in physically strenuous activity but ambulatory and able to carry out work of a light or sedentary nature, e.g. light house work, office work." + } + ], + "http://www.w3.org/2000/01/rdf-schema#label": [ + { + "@value": "1" + } + ] + }, + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--2", + "http://www.w3.org/2000/01/rdf-schema#comment": [ + { + "@value": "Ambulatory and capable of all selfcare but unable to carry out any work activities. Up and about more than 50% of waking hours." + } + ], + "http://www.w3.org/2000/01/rdf-schema#label": [ + { + "@value": "2" + } + ] + }, + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--3", + "http://www.w3.org/2000/01/rdf-schema#comment": [ + { + "@value": "Capable of only limited selfcare, confined to bed or chair more than 50% of waking hours." + } + ], + "http://www.w3.org/2000/01/rdf-schema#label": [ + { + "@value": "3" + } + ] + }, + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--4", + "http://www.w3.org/2000/01/rdf-schema#comment": [ + { + "@value": "Completely disabled. Cannot carry on selfcare. Totally confined to bed or chair." + } + ], + "http://www.w3.org/2000/01/rdf-schema#label": [ + { + "@value": "4" + } + ] + }, + { + "@id": "http://vfn.cz/ontologies/study-model/answer-value--na", + "http://onto.fel.cvut.cz/ontologies/form/has-preceding-value": [ + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--3" + }, + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--0" + }, + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--1" + }, + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--4" + }, + { + "@id": "http://vfn.cz/ontologies/abrax-study-model/ecog-status--2" + } + ], + "http://www.w3.org/2000/01/rdf-schema#comment": [ + { + "@value": "Not available value" + } + ], + "http://www.w3.org/2000/01/rdf-schema#label": [ + { + "@value": "Not available" + } + ] + } +] diff --git a/src/components/record/Record.jsx b/src/components/record/Record.jsx index 81c2058b..9839ac9b 100644 --- a/src/components/record/Record.jsx +++ b/src/components/record/Record.jsx @@ -38,6 +38,9 @@ class Record extends React.Component { _onChange = (e) => { const change = {}; change[e.target.name] = e.target.value; + if (e.formTemplateVersion) { + change.formTemplateVersion = e.formTemplateVersion; + } this.props.handlers.onChange(change); }; @@ -121,6 +124,7 @@ class Record extends React.Component { if (!record?.formTemplate) { if (formTemplate) { record.formTemplate = formTemplate; + record.formTemplateVersion = this._getFormTemplateVersion(); } } @@ -297,6 +301,20 @@ class Record extends React.Component { ); } + _getFormTemplateVersion() { + const { formTemplatesLoaded, record } = this.props; + const formTemplate = this.props.formTemplate || record?.formTemplate; + try { + if (formTemplate && formTemplatesLoaded) { + return formTemplatesLoaded.formTemplates.find((t) => t["@id"] === formTemplate)[ + "http://purl.org/dc/terms/hasVersion" + ][0]["@id"]; + } + } catch (e) { + return ""; + } + } + _getFormTemplateName() { const { formTemplatesLoaded, record, intl } = this.props; const formTemplate = this.props.formTemplate || record?.formTemplate; diff --git a/src/components/record/RecordController.jsx b/src/components/record/RecordController.jsx index 9ef2b463..e8e86e12 100644 --- a/src/components/record/RecordController.jsx +++ b/src/components/record/RecordController.jsx @@ -121,6 +121,9 @@ class RecordController extends React.Component { _onChange = (change) => { const update = { ...this.state.record, ...change }; + if (change.formTemplateVersion) { + update.formTemplateVersion = change.formTemplateVersion; + } if (RecordValidator.isComplete(update)) { update.state.recordComplete(); } else { diff --git a/src/components/record/RecordForm.jsx b/src/components/record/RecordForm.jsx index b33f6056..e13af1f3 100644 --- a/src/components/record/RecordForm.jsx +++ b/src/components/record/RecordForm.jsx @@ -10,6 +10,7 @@ import { axiosBackend } from "../../actions"; import { API_URL } from "../../../config"; import * as Logger from "../../utils/Logger"; import * as I18nStore from "../../stores/I18nStore"; +import possibleValues from "../../assets/possibleValues.json"; // TODO enable s-forms-components // import SmartComponents from "s-forms-components"; @@ -27,6 +28,9 @@ class RecordForm extends React.Component { this.form = this.props.form; this.updateForm = this.props.updateForm; this.refForm = React.createRef(); + this.state = { + validTypeaheadEndpoint: true, + }; } componentDidMount() { @@ -65,8 +69,23 @@ class RecordForm extends React.Component { fetchTypeAheadValues = async (query) => { const FORM_GEN_POSSIBLE_VALUES_URL = `${API_URL}/rest/formGen/possibleValues`; - const result = await axiosBackend.get(`${FORM_GEN_POSSIBLE_VALUES_URL}?query=${encodeURIComponent(query)}`); - return result.data; + if (this.state.validTypeaheadEndpoint) { + try { + const result = await axiosBackend.get(`${FORM_GEN_POSSIBLE_VALUES_URL}?query=${encodeURIComponent(query)}`); + return result.data; + } catch (e) { + this.setState({ validTypeaheadEndpoint: false }, () => { + // Fallback logic after state update + return new Promise((resolve) => { + setTimeout(() => resolve(possibleValues), 1000); + }); + }); + } + } else { + return new Promise((resolve) => { + setTimeout(() => resolve(possibleValues), 1000); + }); + } }; _getUsersOptions() { diff --git a/src/components/record/RecordProvenance.jsx b/src/components/record/RecordProvenance.jsx index 87e79443..f2d2fc3e 100644 --- a/src/components/record/RecordProvenance.jsx +++ b/src/components/record/RecordProvenance.jsx @@ -12,10 +12,15 @@ const RecordProvenance = (props) => { } const author = record.author ? record.author.firstName + " " + record.author.lastName : "", created = formatDate(new Date(record.dateCreated)); + + const version = record.formTemplateVersion?.substring(record.formTemplateVersion?.lastIndexOf("/") + 1); + if (!record.lastModified) { return (