From 897680aacad9027144b827e7d75be66444f40461 Mon Sep 17 00:00:00 2001 From: Rida Abou-Haidar Date: Mon, 16 Dec 2024 11:22:00 -0500 Subject: [PATCH] fixed issue --- modules/biobank/jsx/customFields.js | 72 ++++++++++++----------- modules/biobank/jsx/processForm.js | 50 ++++++++-------- modules/biobank/jsx/specimenForm.js | 7 +++ modules/biobank/php/specimendao.class.inc | 59 +++++++++++-------- 4 files changed, 104 insertions(+), 84 deletions(-) diff --git a/modules/biobank/jsx/customFields.js b/modules/biobank/jsx/customFields.js index 6fdaadbe743..0d538b91da9 100644 --- a/modules/biobank/jsx/customFields.js +++ b/modules/biobank/jsx/customFields.js @@ -1,5 +1,12 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { + TextboxElement, + DateElement, + TimeElement, + CheckboxElement, + FileElement +} from 'jsx/Form'; /** * Biobank Custom Attribute Fields @@ -7,23 +14,22 @@ import PropTypes from 'prop-types'; * @param {object} props The component's props. */ function CustomFields(props) { - const {options, errors, fields, object} = props; + const {options, errors, attributes, object} = props; - return Object.keys(fields).map( + return attributes.map( (attribute, key) => { - const datatype = options.specimen.attributeDatatypes[ - fields[attribute]['datatypeId'] - ].datatype; + const datatype = options.specimen.attributeDatatypes[attribute.datatypeId] + .datatype; if (datatype === 'text' || datatype === 'number') { return ( ); } @@ -31,12 +37,12 @@ function CustomFields(props) { return ( ); } @@ -44,42 +50,40 @@ function CustomFields(props) { return ( ); } if (datatype === 'boolean') { - // TODO: delete the following line. - // object[attribute] == null && props.setData(attribute, false); return ( ); } // Do not present the possibility of uploading if file is already set // File must instead be deleted or overwritten. - if (datatype === 'file' && !(props.data||{})[attribute]) { + if (datatype === 'file' && !(props.data||{})[attribute.id]) { return ( ); } @@ -88,7 +92,7 @@ function CustomFields(props) { } CustomFields.propTypes = { - fields: PropTypes.object.isRequired, + attributes: PropTypes.array.isRequired, options: PropTypes.object.isRequired, object: PropTypes.object.isRequired, setData: PropTypes.func.isRequired, diff --git a/modules/biobank/jsx/processForm.js b/modules/biobank/jsx/processForm.js index f946ee4c149..dfd9aa65dd0 100644 --- a/modules/biobank/jsx/processForm.js +++ b/modules/biobank/jsx/processForm.js @@ -63,7 +63,6 @@ const SpecimenProcessForm = (props) => { ); let specimenProtocols = {}; - let specimenProtocolAttributes = {}; Object.entries(options.specimen.protocols).forEach( ([id, protocol]) => { // FIXME: I really don't like 'toLowerCase()' function, but it's the @@ -73,19 +72,17 @@ const SpecimenProcessForm = (props) => { if (typeId == protocol.typeId && process == processStage ) { specimenProtocols[id] = protocol.label; - const attribute = options.specimen.protocolAttributes[id]; - specimenProtocolAttributes[id] = attribute; } } ); const renderProtocolFields = () => { - if (specimenProtocolAttributes[process.protocolId]) { + if (options.specimen.protocolAttributes[process.protocolId]) { if (process.data) { return ; } else { @@ -178,29 +175,28 @@ const SpecimenProcessForm = (props) => { updateButton, ]; } else if (edit === false) { - const protocolStaticFields = process.data && - Object.keys(process.data).map( - (key) => { - let value = process.data[key]; - if (process.data[key] === true) { - value = 'Yes'; - } else if (process.data[key] === false) { - value = 'No'; - } - // FIXME: The label used to be produced in the following way: - // label={options.specimen.protocolAttributes[process.protocolId][key].label} - // However, causes issues when there is data in the data - // object, but the protocolId is not associated with any attributes. - // This is a configuration/importing issue that should be fixed. - return ( - - ); + const protocolAttributes = options.specimen.protocolAttributes[ + process.protocolId + ] || []; + + const protocolStaticFields = protocolAttributes.map((attribute) => { + let value = process.data[attribute.id]; // Fetch the corresponding value from process.data + + // Convert boolean values to "Yes" or "No" + if (value === true) { + value = 'Yes'; + } else if (value === false) { + value = 'No'; } - ); + + return ( + + ); + }); const collectionStaticFields = (processStage === 'collection') && ( db->pselect($query, []); - $pA = []; //protocolAttributes + $protocolAttributes = []; + foreach ($result as $row) { - if (!isset($pA[$row['protocolId']][$row['attributeId']])) { - $pA[$row['protocolId']][$row['attributeId']] = []; + $protocolId = $row['protocolId']; + // Ensure the protocol exists in the array + if (!isset($protocolAttributes[$protocolId])) { + $protocolAttributes[$protocolId] = []; } - $attrib =& $pA[$row['protocolId']][$row['attributeId']]; - - $attrib['label'] = $row['label']; - $attrib['datatypeId'] = $row['datatypeId']; - $attrib['required'] = (int) $row['required']; - $attrib['showInDataTable'] = (int) $row['showInDataTable']; + + // Add the attribute data, keeping the order intact + $protocolAttributes[$protocolId][] = [ + 'id' => $row['attributeId'], + 'label' => $row['label'], + 'datatypeId' => $row['datatypeId'], + 'required' => (int) $row['required'], + 'showInDataTable' => (int) $row['showInDataTable'], + 'orderIndex' => (int) $row['orderIndex'], + ]; } - - return $pA; - } + + return $protocolAttributes; + } /** * Queries all rows from the biobank_specimen_protocol_attribute_rel table