From cc66b9b9956aa5b1469e254aa4d9cf9db7f08c80 Mon Sep 17 00:00:00 2001 From: Rida Abou-Haidar Date: Thu, 10 Aug 2023 17:48:03 -0400 Subject: [PATCH 1/3] [LINST] skip metadatafields for surveys --- php/libraries/NDB_BVL_Instrument.class.inc | 6 +++++- php/libraries/NDB_BVL_Instrument_LINST.class.inc | 4 +++- test/unittests/NDB_BVL_Instrument_Test.php | 9 +++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument.class.inc b/php/libraries/NDB_BVL_Instrument.class.inc index f767c0f97ef..59b983bc42e 100644 --- a/php/libraries/NDB_BVL_Instrument.class.inc +++ b/php/libraries/NDB_BVL_Instrument.class.inc @@ -779,7 +779,11 @@ abstract class NDB_BVL_Instrument extends NDB_Page */ function _saveValues(array $values): void { - if (strrpos($this->testName, "_proband") === false) { + // Surveys do not ask for the metadata informatio nand thus date_taken is + // always null so there is no use in going into the savecandidateage function + if (strrpos($this->testName, "_proband") === false + && $this->DataEntryType === 'normal' + ) { $this->_saveCandidateAge($values); } diff --git a/php/libraries/NDB_BVL_Instrument_LINST.class.inc b/php/libraries/NDB_BVL_Instrument_LINST.class.inc index 495843a4358..71b61d9572d 100644 --- a/php/libraries/NDB_BVL_Instrument_LINST.class.inc +++ b/php/libraries/NDB_BVL_Instrument_LINST.class.inc @@ -556,7 +556,9 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument 'instrument_title', $pieces[1] ); - $this->_addMetadataFields(); + if ($this->DataEntryType!=="DirectEntry") { + $this->_addMetadataFields(); + } } break; case 'begingroup': diff --git a/test/unittests/NDB_BVL_Instrument_Test.php b/test/unittests/NDB_BVL_Instrument_Test.php index e7570e52149..3d648788f91 100644 --- a/test/unittests/NDB_BVL_Instrument_Test.php +++ b/test/unittests/NDB_BVL_Instrument_Test.php @@ -1335,10 +1335,11 @@ function testSaveValueAndSave() { $this->_setUpMockDB(); $this->_setTableData(); - $this->_instrument->commentID = 'commentID1'; - $this->_instrument->table = 'medical_history'; - $this->_instrument->testName = 'Test'; - $this->_instrument->formType = "XIN"; + $this->_instrument->commentID = 'commentID1'; + $this->_instrument->table = 'medical_history'; + $this->_instrument->testName = 'Test'; + $this->_instrument->formType = "XIN"; + $this->_instrument->DataEntryType = "normal"; $values = ['Date_taken' => '2005-06-06', 'arthritis_age' => 2, 'arthritis_age_status' => 'status' From fb05826fec6ebafe112542be14e3b3ed311b217d Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Wed, 15 Nov 2023 18:39:16 -0500 Subject: [PATCH 2/3] set DataEntryType before loadInstrumentFile --- php/libraries/NDB_BVL_Instrument.class.inc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument.class.inc b/php/libraries/NDB_BVL_Instrument.class.inc index 59b983bc42e..52f89196824 100644 --- a/php/libraries/NDB_BVL_Instrument.class.inc +++ b/php/libraries/NDB_BVL_Instrument.class.inc @@ -298,6 +298,12 @@ abstract class NDB_BVL_Instrument extends NDB_Page $base . "project/instruments/$instrument.meta" ); } + // Set DataEntryType to normal or DirectEntry + if (isset($_REQUEST['key'])) { + $obj->DataEntryType = 'DirectEntry'; + } else { + $obj->DataEntryType = 'normal'; + } // Adds all of the form element and form rules to the page after // having instantiated the form above $obj->loadInstrumentFile( @@ -477,10 +483,7 @@ abstract class NDB_BVL_Instrument extends NDB_Page { // ALWAYS INCLUDE THESE! - if (isset($_REQUEST['key'])) { - $this->DataEntryType = 'DirectEntry'; - } else { - $this->DataEntryType = 'normal'; + if ($this->DataEntryType === 'normal') { // These are required for Save Data to work properly, but not when it's // a direct data entry page $this->addHidden( @@ -779,11 +782,7 @@ abstract class NDB_BVL_Instrument extends NDB_Page */ function _saveValues(array $values): void { - // Surveys do not ask for the metadata informatio nand thus date_taken is - // always null so there is no use in going into the savecandidateage function - if (strrpos($this->testName, "_proband") === false - && $this->DataEntryType === 'normal' - ) { + if (strrpos($this->testName, "_proband") === false) { $this->_saveCandidateAge($values); } From 4e6833a95422cd8726fbce417a375d49ab8a6577 Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Mon, 20 Nov 2023 17:58:30 -0500 Subject: [PATCH 3/3] fix test --- test/unittests/NDB_BVL_Instrument_Test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unittests/NDB_BVL_Instrument_Test.php b/test/unittests/NDB_BVL_Instrument_Test.php index 3d648788f91..31946dbd1e6 100644 --- a/test/unittests/NDB_BVL_Instrument_Test.php +++ b/test/unittests/NDB_BVL_Instrument_Test.php @@ -1792,7 +1792,8 @@ function testDisplay() $this->_setUpMockDB(); $this->_setTableData(); $this->_instrument->setup("commentID1", "page"); - $this->_instrument->table = 'medical_history'; + $this->_instrument->table = 'medical_history'; + $this->_instrument->DataEntryType = "normal"; $this->assertStringContainsString( "\n", $this->_instrument->display()