From 5de27d5f315ae64d732e5e87694e57064dea2dfd Mon Sep 17 00:00:00 2001 From: zainvirani Date: Fri, 18 Aug 2017 13:50:23 -0400 Subject: [PATCH 1/9] get proper context --- .../NDB_BVL_Instrument_JSON.class.inc | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index 178fa2d2e4d..87f86d43b9a 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -46,18 +46,38 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument * @return array containing context variables */ function _getContext() { + $timepoint = \TimePoint::singleton($this->getSessionID()); + $candID = $timepoint->getCandID(); + $candidate = \Candidate::singleton($candID); + $dob = $candidate->getCandidateDoB(); + $dobDT = new \DateTime($dob); + $curDate = new \DateTime("now"); + $interval = date_diff($curDate, $dobDT, true); + $ageM = ($interval->format("%y")*12 + +$interval->format("%m") + +$interval->format("%d")/30.44); + $gender = $candidate->getCandidateGender(); return array( - "t1_arm_1" => array( - "age_mths" => 200 - ) + "context" => array( + "age_mths" => $ageM, + "dob" => $dob, + "gender" => $gender + ), + "age_mths" => $ageM, + "dob" => $dob ); } function _getLang() { - // This should grab lang from the timepoint associated with this instrument instance - return 'en-ca'; + //$timepoint = \TimePoint::singleton($this->getSessionID()); + //$candID = $timepoint->getCandID(); + //$candidate = \Candidate::singleton($candID); + //$lang = $candidate->getCandidateLanguage(); + $lang = "en-ca"; + return $lang ? $lang : "en-ca"; } + function _getInstrumentData($db) { $result = $db->pselect( "SELECT * FROM $this->table WHERE CommentID=:CID", From 72a9df193930e6e6f42c133c48ba5909d9faeeda Mon Sep 17 00:00:00 2001 From: zainvirani Date: Fri, 18 Aug 2017 13:56:47 -0400 Subject: [PATCH 2/9] call parent setup --- php/libraries/NDB_BVL_Instrument_JSON.class.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index 87f86d43b9a..3308050786c 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -37,6 +37,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument { $this->commentID = $commentID; $this->page = $page; + parent::setup($commentID, $page); } /** From 28af09a424a81ab29c184ea1679e33da9e233467 Mon Sep 17 00:00:00 2001 From: zainvirani Date: Fri, 18 Aug 2017 14:03:38 -0400 Subject: [PATCH 3/9] testing timepoint --- php/libraries/NDB_BVL_Instrument_JSON.class.inc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index 3308050786c..6648ab04ff9 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -47,7 +47,8 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument * @return array containing context variables */ function _getContext() { - $timepoint = \TimePoint::singleton($this->getSessionID()); + echo $this->getSessionID(); + /*$timepoint = \TimePoint::singleton($this->getSessionID()); $candID = $timepoint->getCandID(); $candidate = \Candidate::singleton($candID); $dob = $candidate->getCandidateDoB(); @@ -66,7 +67,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument ), "age_mths" => $ageM, "dob" => $dob - ); + );*/ } function _getLang() { From 43ba17c22fc2a232539e74b3d02a7a5b931e7ff1 Mon Sep 17 00:00:00 2001 From: zainvirani Date: Fri, 18 Aug 2017 14:06:51 -0400 Subject: [PATCH 4/9] retrieve correct candidate info --- htdocs/survey-react.php | 1 + php/libraries/NDB_BVL_Instrument_JSON.class.inc | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/survey-react.php b/htdocs/survey-react.php index ec6246e740f..010168c04ea 100644 --- a/htdocs/survey-react.php +++ b/htdocs/survey-react.php @@ -243,6 +243,7 @@ function display() $factory = \NDB_Factory::singleton(); $config = $factory->config(); $json_class = new NDB_BVL_Instrument_JSON(); + $json_class->setup($this->CommentID); $base = $config->getSetting('base'); $json = file_get_contents($base."project/instruments/$this->TestName.json"); $this->updateStatus('In Progress'); diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index 6648ab04ff9..3308050786c 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -47,8 +47,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument * @return array containing context variables */ function _getContext() { - echo $this->getSessionID(); - /*$timepoint = \TimePoint::singleton($this->getSessionID()); + $timepoint = \TimePoint::singleton($this->getSessionID()); $candID = $timepoint->getCandID(); $candidate = \Candidate::singleton($candID); $dob = $candidate->getCandidateDoB(); @@ -67,7 +66,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument ), "age_mths" => $ageM, "dob" => $dob - );*/ + ); } function _getLang() { From 22b2f1c8775ba13ef425b6a61ab5d84c307ce1e8 Mon Sep 17 00:00:00 2001 From: Zain Virani Date: Tue, 29 Aug 2017 12:27:03 -0400 Subject: [PATCH 5/9] Update NDB_BVL_Instrument_JSON.class.inc --- php/libraries/NDB_BVL_Instrument_JSON.class.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index ca8a68d7e61..cff7242977b 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -60,7 +60,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument $gender = $candidate->getCandidateGender(); return array( "age_mths" => $ageM, - "dob" => $dob + "dob" => $dob, "gender" => $gender ); } From 1a4da04d426f36587000fef3fc681af1674ce84a Mon Sep 17 00:00:00 2001 From: Zain Virani Date: Tue, 29 Aug 2017 12:43:07 -0400 Subject: [PATCH 6/9] Update NDB_BVL_Instrument_JSON.class.inc --- php/libraries/NDB_BVL_Instrument_JSON.class.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index cff7242977b..1b0f48755ed 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -54,9 +54,9 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument $dobDT = new \DateTime($dob); $curDate = new \DateTime("now"); $interval = date_diff($curDate, $dobDT, true); - $ageM = ($interval->format("%y")*12 - +$interval->format("%m") - +$interval->format("%d")/30.44); + $ageM = calculateAgeMonths(array('year' => $interval->format("%y"), + 'mon' => $interval->format("%m"), + 'day' => $interval->format("%d"))); $gender = $candidate->getCandidateGender(); return array( "age_mths" => $ageM, From 10712c0e1fad665375f5c1bc8410dacd06cbe72a Mon Sep 17 00:00:00 2001 From: zainvirani Date: Tue, 29 Aug 2017 13:03:08 -0400 Subject: [PATCH 7/9] use proper age method --- php/libraries/NDB_BVL_Instrument_JSON.class.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index 1b0f48755ed..c7274163cf3 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -54,7 +54,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument $dobDT = new \DateTime($dob); $curDate = new \DateTime("now"); $interval = date_diff($curDate, $dobDT, true); - $ageM = calculateAgeMonths(array('year' => $interval->format("%y"), + $ageM = $this->calculateAgeMonths(array('year' => $interval->format("%y"), 'mon' => $interval->format("%m"), 'day' => $interval->format("%d"))); $gender = $candidate->getCandidateGender(); From 7a3fca50c9a7a2eb75d1fe5c8ac583daa54ffba4 Mon Sep 17 00:00:00 2001 From: zainvirani Date: Tue, 29 Aug 2017 13:24:33 -0400 Subject: [PATCH 8/9] age --- htdocs/survey-react.php | 1 + php/libraries/NDB_BVL_Instrument_JSON.class.inc | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/htdocs/survey-react.php b/htdocs/survey-react.php index 010168c04ea..82fc70a32be 100644 --- a/htdocs/survey-react.php +++ b/htdocs/survey-react.php @@ -246,6 +246,7 @@ function display() $json_class->setup($this->CommentID); $base = $config->getSetting('base'); $json = file_get_contents($base."project/instruments/$this->TestName.json"); + //$json = $json_class->loadInstrumentFile($base."project/instruments/$this->TestName.json"); //TODO $this->updateStatus('In Progress'); $this->tpl_data['lang'] = $json_class->_getLang(); $this->tpl_data['json'] = htmlspecialchars($json); diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index c7274163cf3..542d2d64f90 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -57,6 +57,9 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument $ageM = $this->calculateAgeMonths(array('year' => $interval->format("%y"), 'mon' => $interval->format("%m"), 'day' => $interval->format("%d"))); + //$ageTEST = $this->getCandidateAge($curDate); //TODO replace the hacky age function with this + echo $ageM; + echo $ageTEST; $gender = $candidate->getCandidateGender(); return array( "age_mths" => $ageM, @@ -102,6 +105,7 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument $this->instrument = json_decode($json, true); $this->instrument["Elements"] = self::inlineCalcFormulas($this->instrument["Elements"]); $this->table = $this->instrument['Meta']['ShortName']; + $this->testName = $this->table; return $json; } } From dac666056ab855339fe2c839312550583773af23 Mon Sep 17 00:00:00 2001 From: zainvirani Date: Tue, 29 Aug 2017 13:25:21 -0400 Subject: [PATCH 9/9] age --- php/libraries/NDB_BVL_Instrument_JSON.class.inc | 2 -- 1 file changed, 2 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument_JSON.class.inc b/php/libraries/NDB_BVL_Instrument_JSON.class.inc index 542d2d64f90..fbcc234fa79 100644 --- a/php/libraries/NDB_BVL_Instrument_JSON.class.inc +++ b/php/libraries/NDB_BVL_Instrument_JSON.class.inc @@ -58,8 +58,6 @@ class NDB_BVL_Instrument_JSON extends \NDB_BVL_Instrument 'mon' => $interval->format("%m"), 'day' => $interval->format("%d"))); //$ageTEST = $this->getCandidateAge($curDate); //TODO replace the hacky age function with this - echo $ageM; - echo $ageTEST; $gender = $candidate->getCandidateGender(); return array( "age_mths" => $ageM,