Skip to content

Commit ea6c680

Browse files
committed
Changed Trials to set a start date when the trial is moved from open to in-progress, and switched any GUI uses of created_date to use started_date instead
1 parent e49f39d commit ea6c680

File tree

7 files changed

+62
-19
lines changed

7 files changed

+62
-19
lines changed

controllers/TrialController.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -214,22 +214,25 @@ public function actionIndex()
214214
$sortBy = 'LOWER(t.name)';
215215
break;
216216
case 1:
217-
$sortBy = 't.created_date';
217+
$sortBy = 't.started_date';
218218
break;
219219
case 2:
220-
$sortBy = "LOWER(u.first_name) $sortDir, LOWER(u.last_name)";
220+
$sortBy = 't.closed_date';
221221
break;
222222
case 3:
223+
$sortBy = "LOWER(u.first_name) $sortDir, LOWER(u.last_name)";
224+
break;
225+
case 4:
223226
$sortBy = 't.status';
224227
break;
225228
default:
226-
$sortBy = 't.status';
229+
$sortBy = 'LOWER(t.name)';
227230
break;
228231
}
229232

230233
$condition = "trial_type = :trialType AND EXISTS (
231234
SELECT * FROM user_trial_permission utp WHERE utp.user_id = :userId AND utp.trial_id = t.id
232-
) ORDER BY $sortBy $sortDir";
235+
) ORDER BY $sortBy $sortDir, LOWER(t.name) ASC";
233236

234237
$interventionTrialDataProvider = new CActiveDataProvider('Trial', array(
235238
'criteria' => array(
@@ -454,11 +457,15 @@ public function actionTransitionState($id, $new_state)
454457
}
455458

456459
if ($new_state == Trial::STATUS_CLOSED || $new_state == Trial::STATUS_CANCELLED) {
457-
$model->closed_date = date('Y-m-d 00:00:00');
460+
$model->closed_date = date('Y-m-d H:i:s');
458461
} else {
459462
$model->closed_date = null;
460463
}
461464

465+
if ($model->status == Trial::STATUS_OPEN && $new_state == Trial::STATUS_IN_PROGRESS) {
466+
$model->started_date = date('Y-m-d H:i:s');
467+
}
468+
462469
$model->status = $new_state;
463470
if (!$model->save()) {
464471
throw new CHttpException(403, 'An error occurred when attempting to change the status');

migrations/m170521_234542_create_trial_table.php

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function up()
1313
'description' => 'text',
1414
'owner_user_id' => 'int(10) unsigned NOT NULL',
1515
'status' => 'int(10) unsigned NOT NULL',
16+
'started_date' => 'datetime',
1617
'closed_date' => 'datetime',
1718
'external_reference' =>'varchar(100) collate utf8_bin',
1819
), self::VERSIONED

models/Trial.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @property integer $owner_user_id
1111
* @property integer $status
1212
* @property integer $trial_type
13+
* @property string $started_date
1314
* @property string $closed_date
1415
* @property string $last_modified_date
1516
* @property string $last_modified_user_id
@@ -171,13 +172,13 @@ public function getStatusString()
171172
}
172173

173174
/**
174-
* Returns the date this trial was created as a string
175+
* Returns the date this trial was started as a string
175176
*
176-
* @return string The created date
177+
* @return string The started date as a string
177178
*/
178-
public function getCreatedDateForDisplay()
179+
public function getStartedDateForDisplay()
179180
{
180-
return Helper::formatFuzzyDate($this->created_date);
181+
return $this->started_date !== null ? Helper::formatFuzzyDate($this->started_date) : 'Pending';
181182
}
182183

183184
/**
@@ -187,7 +188,13 @@ public function getCreatedDateForDisplay()
187188
*/
188189
public function getClosedDateForDisplay()
189190
{
190-
return $this->closed_date ? Helper::formatFuzzyDate($this->closed_date) : 'present';
191+
if ($this->started_date === null) {
192+
return null;
193+
} elseif ($this->closed_date !== null) {
194+
return Helper::formatFuzzyDate($this->closed_date);
195+
} else {
196+
return 'present';
197+
}
191198
}
192199

193200

@@ -389,11 +396,12 @@ public function getPatientDataProvider($patient_status, $sort_by, $sort_dir)
389396
*/
390397
public static function getTrialList($type)
391398
{
392-
if ($type === null || $type === ''){
399+
if ($type === null || $type === '') {
393400
return array();
394401
}
395402

396403
$trialModels = Trial::model()->findAll('trial_type=:type', array(':type' => $type));
404+
397405
return CHtml::listData($trialModels, 'id', 'name');
398406
}
399407
}

tests/unit/models/TrialTest.php

+26-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,33 @@ public function testTitle()
3030
public function testCreatedDate()
3131
{
3232
$trial = new Trial();
33-
$trial->created_date = date('Y-m-d', strtotime('2012-12-21'));
34-
$this->assertEquals($trial->getCreatedDateForDisplay(), '21 Dec 2012');
33+
$trial->started_date = date('Y-m-d', strtotime('2012-12-21'));
34+
$this->assertEquals($trial->getStartedDateForDisplay(), '21 Dec 2012');
3535

36-
$trial->created_date = date('Y-m-d', strtotime('1970-1-1'));
37-
$this->assertEquals($trial->getCreatedDateForDisplay(), '1 Jan 1970');
36+
$trial->started_date = date('Y-m-d', strtotime('1970-1-1'));
37+
$this->assertEquals($trial->getStartedDateForDisplay(), '1 Jan 1970');
38+
39+
$trial->started_date = null;
40+
$this->assertEquals($trial->getStartedDateForDisplay(), 'Pending');
41+
}
42+
43+
public function testClosedDate()
44+
{
45+
$trial = new Trial();
46+
$trial->started_date = date('Y-m-d', strtotime('1970-01-01'));
47+
$trial->closed_date = date('Y-m-d', strtotime('2012-12-21'));
48+
$this->assertEquals($trial->getClosedDateForDisplay(), '21 Dec 2012');
49+
50+
$trial->closed_date = date('Y-m-d', strtotime('1970-1-1'));
51+
$this->assertEquals($trial->getClosedDateForDisplay(), '1 Jan 1970');
52+
53+
$trial->started_date = null;
54+
$trial->closed_date = null;
55+
$this->assertNull($trial->getClosedDateForDisplay());
56+
57+
$trial->started_date = date('Y-m-d', strtotime('1970-01-01'));
58+
$trial->closed_date = null;
59+
$this->assertEquals($trial->getClosedDateForDisplay(), 'present');
3860
}
3961

4062
public function testDataProvidersExist()

views/patientSummary/_patient_trials.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@
4949
echo CHtml::encode($PI->last_name . ', ' . $PI->first_name);
5050
?>
5151
</td>
52+
<td><?php echo $trialPatient->getTreatmentTypeForDisplay(); ?></td>
5253
<td><?php echo $trialPatient->getStatusForDisplay(); ?></td>
5354
<td><?php echo $trialPatient->trial->getTypeString(); ?></td>
54-
<td><?php echo $trialPatient->trial->getCreatedDateForDisplay(); ?></td>
55+
<td><?php echo $trialPatient->trial->getStartedDateForDisplay(); ?></td>
5556
<td><?php echo $trialPatient->trial->getClosedDateForDisplay(); ?></td>
5657
</tr>
5758
<?php endforeach; ?>

views/trial/_trialList.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<table id="patient-grid" class="grid">
3333
<thead>
3434
<tr>
35-
<?php foreach (array('Name', 'Date Created', 'Owner', 'Status') as $i => $field) { ?>
35+
<?php foreach (array('Name', 'Date Started', 'Date Closed', 'Owner', 'Status') as $i => $field) { ?>
3636
<th id="patient-grid_c<?php echo $i; ?>">
3737
<?php
3838
$new_sort_dir = ($i === $sort_by) ? 1 - $sort_dir : 0;
@@ -57,7 +57,8 @@
5757
foreach ($dataProvided as $i => $trial) { ?>
5858
<tr id="r<?php echo $trial->id; ?>" class="clickable">
5959
<td><?php echo CHtml::encode($trial->name); ?></td>
60-
<td><?php echo date('d/m/Y', strtotime($trial->created_date)); ?></td>
60+
<td><?php echo $trial->getStartedDateForDisplay(); ?></td>
61+
<td><?php echo $trial->getClosedDateForDisplay(); ?></td>
6162
<td><?php echo CHtml::encode($trial->ownerUser->getFullName()); ?></td>
6263
<td><?php echo $trial->getStatusString(); ?></td>
6364
</tr>

views/trial/view.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
</h3>
4646
</div>
4747
<div class="large-3 column">
48-
<?php echo $model->getCreatedDateForDisplay(); ?> &mdash; <?php echo $model->getClosedDateForDisplay() ?>
48+
<?php echo $model->getStartedDateForDisplay(); ?>
49+
<?php if ($model->started_date !== null): ?>
50+
&mdash; <?php echo $model->getClosedDateForDisplay() ?>
51+
<?php endif; ?>
4952
</div>
5053
</div>
5154

0 commit comments

Comments
 (0)