mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Quota priority feature added including auto priority calculation (Sponsor: Zimi)
This commit is contained in:
@@ -67,6 +67,46 @@ include("../functions/functions.operator.php");
|
||||
*/
|
||||
include("../functions/functions.limesurvey.php");
|
||||
|
||||
|
||||
if (isset($_POST['submit']))
|
||||
{
|
||||
$questionnaire_id = bigintval($_POST['questionnaire_id']);
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
$sql = "UPDATE questionnaire_sample_quota_row
|
||||
SET autoprioritise = 0
|
||||
WHERE questionnaire_id = '$questionnaire_id'";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
foreach($_POST as $key => $val)
|
||||
{
|
||||
$qsqr = bigintval(substr($key,1));
|
||||
if (substr($key,0,1) == 'a')
|
||||
{
|
||||
$sql = "UPDATE questionnaire_sample_quota_row
|
||||
SET autoprioritise = 1
|
||||
WHERE questionnaire_sample_quota_row_id = $qsqr";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
else if (substr($key,0,1) == 'p')
|
||||
{
|
||||
$val = intval($val);
|
||||
|
||||
$sql = "UPDATE questionnaire_sample_quota_row
|
||||
SET priority = '$val'
|
||||
WHERE questionnaire_sample_quota_row_id = $qsqr";
|
||||
|
||||
$db->Execute($sql);
|
||||
}
|
||||
}
|
||||
update_quota_priorities($questionnaire_id);
|
||||
|
||||
$db->CompleteTrans();
|
||||
}
|
||||
|
||||
xhtml_head(T_("Quota report"),true,array("../css/table.css"),array("../js/window.js"));
|
||||
|
||||
print "<h2>" . T_("Select a questionnaire from the list below") . "</h2>";
|
||||
@@ -140,7 +180,7 @@ if ($questionnaire_id)
|
||||
|
||||
//a. (Standard quota) Monitor outcomes of questions in completed questionnaires, and exclude selected sample records when completion limit is reached
|
||||
//b. (Replicate quota) Exclude selected sample records (where lime_sgqa == -1)
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id,lime_sgqa,value,completions,quota_reached,lime_sid,comparison,exclude_var,exclude_val,qsq.description,current_completions
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id,lime_sgqa,value,completions,quota_reached,lime_sid,comparison,exclude_var,exclude_val,qsq.description,current_completions, priority, autoprioritise
|
||||
FROM questionnaire_sample_quota_row as qsq, questionnaire as q
|
||||
WHERE qsq.questionnaire_id = '$questionnaire_id'
|
||||
AND qsq.sample_import_id = '$sample_import_id'
|
||||
@@ -151,6 +191,12 @@ if ($questionnaire_id)
|
||||
foreach ($r as $v)
|
||||
{
|
||||
$completions = $v['current_completions'];
|
||||
$priority = $v['priority'];
|
||||
$autoprioritise = $v['autoprioritise'];
|
||||
$checked = "";
|
||||
if ($autoprioritise) $checked = "checked='checked'";
|
||||
$qsqr = $v['questionnaire_sample_quota_row_id'];
|
||||
|
||||
|
||||
if ($v['lime_sgqa'] == -1)
|
||||
{
|
||||
@@ -185,9 +231,9 @@ if ($questionnaire_id)
|
||||
if ($completions < $v['completions'] || $v['lime_sgqa'] == -1) //if completions less than the quota, allow for closing/opening
|
||||
{
|
||||
if ($v['quota_reached'] == 1)
|
||||
$status = "<a href='?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id&rowquota={$v['questionnaire_sample_quota_row_id']}&open=open'>" . T_("closed") . "</a>";
|
||||
$status = "<a href='?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id&rowquota=$qsqr&open=open'>" . T_("closed") . "</a>";
|
||||
else
|
||||
$status = "<a href='?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id&rowquota={$v['questionnaire_sample_quota_row_id']}&close=close'>" . T_("open") . "</a>";
|
||||
$status = "<a href='?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id&rowquota=$qsqr&close=close'>" . T_("open") . "</a>";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -197,7 +243,7 @@ if ($questionnaire_id)
|
||||
$status = T_("open");
|
||||
}
|
||||
|
||||
$report[] = array("strata" => "<a href='quotarow.php?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id'>" . $v['description'] . "</a>", "status" => $status, "quota" => $v['completions'], "sample" => $drawn + $remain, "sampleused" => $drawn, "sampleremain" => $remain, "completions" => $completions, "perc" => $perc);
|
||||
$report[] = array("strata" => "<a href='quotarow.php?questionnaire_id=$questionnaire_id&sample_import_id=$sample_import_id'>" . $v['description'] . "</a>", "status" => $status, "quota" => $v['completions'], "sample" => $drawn + $remain, "sampleused" => $drawn, "sampleremain" => $remain, "completions" => $completions, "perc" => $perc, "priority" => "<input type='text' size='3' value='$priority' id='p$qsqr' name='p$qsqr' />", "autoprioritise" => "<input type='checkbox' id='a$qsqr' name='a$qsqr' $checked />");
|
||||
}
|
||||
|
||||
//c. (Questionnaire quota) Monitor outcomes of questions in completed questionnaires, and abort interview when completion limit is reached
|
||||
@@ -235,8 +281,11 @@ if ($questionnaire_id)
|
||||
$report[] = array("strata" => "<a href='" . LIME_URL . "/admin/admin.php?action=quotas&sid={$r['sid']}"a_id={$r['id']}&subaction=quota_editquota'>" . $r['name'] . "</a>", "quota" => $r['qlimit'], "completions" => $completions, "perc" => $perc);
|
||||
}
|
||||
|
||||
xhtml_table($report,array("strata","status","quota","sample","sampleused","sampleremain","completions","perc"),array(T_("Strata"),T_("Status"),T_("Quota"),T_("Sample"),T_("Sample Used"),T_("Sample Remaining"),T_("Completions"),T_("% Complete")),"tclass",false,false);
|
||||
print "<form action='' method='post'>";
|
||||
xhtml_table($report,array("strata","status","quota","sample","sampleused","sampleremain","completions","perc","priority","autoprioritise"),array(T_("Strata"),T_("Status"),T_("Quota"),T_("Sample"),T_("Sample Used"),T_("Sample Remaining"),T_("Completions"),T_("% Complete"),T_("Set priority"),T_("Auto prioritise")),"tclass",false,false);
|
||||
print "<p><input type='hidden' name='questionnaire_id' id='questionnaire_id' value='$questionnaire_id'/><input type='submit' id='submit' name='submit' value='" . T_("Update priorities") . "'/></p></form>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
xhtml_foot();
|
||||
|
||||
@@ -76,7 +76,11 @@ if (isset($_GET['questionnaire_id']) && isset($_GET['sgqa']) && isset($_GET['va
|
||||
$comparison = -1;
|
||||
$completions = -1;
|
||||
$sgqa = -1;
|
||||
$autoprioritise = 0;
|
||||
|
||||
if (isset($_GET['autoprioritise'])) $autoprioritise = 1;
|
||||
|
||||
$priority = intval($_GET['priority']);
|
||||
$questionnaire_id = bigintval($_GET['questionnaire_id']);
|
||||
$sample_import_id = bigintval($_GET['sample_import_id']);
|
||||
if ($_GET['sgqa'] != -1)
|
||||
@@ -90,8 +94,8 @@ if (isset($_GET['questionnaire_id']) && isset($_GET['sgqa']) && isset($_GET['va
|
||||
$exclude_var = $db->quote($_GET['exclude_var']);
|
||||
$description = $db->quote($_GET['description']);
|
||||
|
||||
$sql = "INSERT INTO questionnaire_sample_quota_row(questionnaire_id, sample_import_id, lime_sgqa,value,completions,comparison,exclude_var,exclude_val,description)
|
||||
VALUES ($questionnaire_id, $sample_import_id, $sgqa, $value, $completions, $comparison, $exclude_var, $exclude_val, $description)";
|
||||
$sql = "INSERT INTO questionnaire_sample_quota_row(questionnaire_id, sample_import_id, lime_sgqa,value,completions,comparison,exclude_var,exclude_val,description, priority, autoprioritise)
|
||||
VALUES ($questionnaire_id, $sample_import_id, $sgqa, $value, $completions, $comparison, $exclude_var, $exclude_val, $description, $priority, $autoprioritise)";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
@@ -263,6 +267,8 @@ if ($questionnaire_id != false)
|
||||
<form action="" method="get">
|
||||
<p>
|
||||
<label for="description"><? echo T_("Describe this quota"); ?> </label><input type="text" name="description" id="description"/> <br/>
|
||||
<label for="priority"><? echo T_("Quota priority (50 is default, 100 highest, 0 lowest)"); ?> </label><input type="text" name="priority" id="priority" value="50"/> <br/>
|
||||
<label for="autoprioritise"><? echo T_("Should the priority be automatically updated based on the number of completions in this quota?"); ?> </label><input type="checkbox" name="autoprioritise" id="autoprioritise"/> <br/>
|
||||
<? if ($sgqa != -1) { ?>
|
||||
<label for="value"><? echo T_("The code value to compare"); ?> </label><input type="text" name="value" id="value"/> <br/>
|
||||
<label for="comparison"><? echo T_("The type of comparison"); ?></label><select name="comparison" id="comparison"><option value="LIKE">LIKE</option><option value="NOT LIKE">NOT LIKE</option><option value="=">=</option><option value="!=">!=</option><option value="<"><</option><option value=">">></option><option value="<="><=</option><option value=">=">>=</option></select><br/>
|
||||
|
||||
@@ -563,6 +563,8 @@ CREATE TABLE IF NOT EXISTS `questionnaire_sample_quota_row` (
|
||||
`quota_reached` tinyint(1) NOT NULL default '0',
|
||||
`current_completions` int(11) NOT NULL default '0',
|
||||
`description` text collate utf8_unicode_ci NOT NULL,
|
||||
`priority` tinyint(3) NOT NULL default '50' COMMENT 'Priority from 0 - 100',
|
||||
`autoprioritise` tinyint(1) NOT NULL default '0' COMMENT 'Should this row have it''s priority automatically adjusted to 100 - (completions %)',
|
||||
PRIMARY KEY (`questionnaire_sample_quota_row_id`),
|
||||
KEY `questionnaire_id` (`questionnaire_id`),
|
||||
KEY `sample_import_id` (`sample_import_id`),
|
||||
|
||||
@@ -330,11 +330,10 @@ function get_case_id($operator_id, $create = false)
|
||||
AND ((apn.appointment_id IS NOT NULL) or qs.call_attempt_max = 0 or ((SELECT count(*) FROM call_attempt WHERE case_id = c.case_id) < qs.call_attempt_max))
|
||||
AND ((apn.appointment_id IS NOT NULL) or qs.call_max = 0 or ((SELECT count(*) FROM `call` WHERE case_id = c.case_id) < qs.call_max))
|
||||
AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = c.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0
|
||||
ORDER BY apn.start DESC, a.start ASC
|
||||
ORDER BY apn.start DESC, a.start ASC, qsep.priority DESC
|
||||
LIMIT 1";
|
||||
|
||||
//apn.appointment_id contains the id of an appointment if we are calling on an appointment
|
||||
|
||||
$r2 = $db->GetRow($sql);
|
||||
|
||||
if (empty($r2))
|
||||
@@ -367,7 +366,7 @@ function get_case_id($operator_id, $create = false)
|
||||
AND !(q.restrict_work_shifts = 1 AND sh.shift_id IS NULL)
|
||||
AND !(si.call_restrict = 1 AND cr.day_of_week IS NULL)
|
||||
AND (SELECT count(*) FROM `questionnaire_sample_quota` WHERE questionnaire_id = qs.questionnaire_id AND sample_import_id = s.import_id AND quota_reached = 1) = 0
|
||||
ORDER BY rand() * qs.random_select, s.sample_id
|
||||
ORDER BY qsep.priority DESC, rand() * qs.random_select, s.sample_id
|
||||
LIMIT 1";
|
||||
|
||||
|
||||
@@ -1219,6 +1218,7 @@ function copy_row_quota($questionnaire_id,$sample_import_id,$copy_sample_import_
|
||||
* Update the row quota table
|
||||
*
|
||||
* @param int $questionnaire_id The questionnaire ID to update
|
||||
* @param int|bool $case_id The case id if known to limit the scope of the search
|
||||
*/
|
||||
function update_row_quota($questionnaire_id,$case_id = false)
|
||||
{
|
||||
@@ -1228,7 +1228,7 @@ function update_row_quota($questionnaire_id,$case_id = false)
|
||||
|
||||
$db->StartTrans();
|
||||
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id,q.questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,quota_reached,q.lime_sid,qsq.exclude_var,qsq.exclude_val,qsq.current_completions
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id,q.questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,quota_reached,q.lime_sid,qsq.exclude_var,qsq.exclude_val,qsq.current_completions,qsq.priority,qsq.autoprioritise
|
||||
FROM questionnaire_sample_quota_row as qsq, questionnaire as q
|
||||
WHERE qsq.questionnaire_id = '$questionnaire_id'
|
||||
AND q.questionnaire_id = '$questionnaire_id'
|
||||
@@ -1245,6 +1245,7 @@ function update_row_quota($questionnaire_id,$case_id = false)
|
||||
//update all row quotas for this questionnaire
|
||||
foreach($rs as $r)
|
||||
{
|
||||
//whether a completion was changed for this quota
|
||||
$updatequota = false;
|
||||
|
||||
//if a case_Id is specified, we can just check if this case matches
|
||||
@@ -1290,11 +1291,26 @@ function update_row_quota($questionnaire_id,$case_id = false)
|
||||
else
|
||||
{
|
||||
$sql = "UPDATE questionnaire_sample_quota_row
|
||||
SET current_completions = '$completions'
|
||||
WHERE questionnaire_sample_quota_row_id = {$r['questionnaire_sample_quota_row_id']}";
|
||||
SET current_completions = '$completions' ";
|
||||
|
||||
//If autopriority is set update it here
|
||||
if ($r['autoprioritise'] == 1)
|
||||
{
|
||||
//priority is 100 - the percentage of completions
|
||||
$pr = 100 - round(100 * ($completions / $r['completions']));
|
||||
$sql .= ", priority = '$pr' ";
|
||||
|
||||
//need to update quotas now
|
||||
$update = true;
|
||||
}
|
||||
|
||||
$sql .= " WHERE questionnaire_sample_quota_row_id = {$r['questionnaire_sample_quota_row_id']}";
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1348,6 +1364,44 @@ function update_quota_priorities($questionnaire_id)
|
||||
|
||||
if ($db->HasFailedTrans()) die ($sql);
|
||||
|
||||
//Update the priority record
|
||||
|
||||
//Select all quota rows that are open, and have a priority != 50
|
||||
$sql = "SELECT questionnaire_sample_quota_row_id, priority
|
||||
FROM questionnaire_sample_quota_row
|
||||
WHERE questionnaire_id = '$questionnaire_id'
|
||||
AND quota_reached = 0
|
||||
AND priority != 50
|
||||
ORDER BY priority ASC";
|
||||
|
||||
$rs = $db->GetAll($sql);
|
||||
|
||||
if ($db->HasFailedTrans()) die ($sql);
|
||||
|
||||
if (!empty($rs)) foreach ($rs as $r)
|
||||
{
|
||||
$qsqri = $r['questionnaire_sample_quota_row_id'];
|
||||
$priority = $r['priority'];
|
||||
|
||||
//find all cases that match this quota, and update it to the new priority
|
||||
$sql = "UPDATE sample as s, sample_var as sv, questionnaire_sample_quota_row as qs, questionnaire_sample_exclude_priority as qsep
|
||||
SET qsep.priority = '$priority'
|
||||
WHERE s.import_id = qs.sample_import_id
|
||||
AND qs.questionnaire_sample_quota_row_id = '$qsqri'
|
||||
AND s.sample_id = sv.sample_id
|
||||
AND sv.var = qs.exclude_var
|
||||
AND qs.exclude_val LIKE sv.val
|
||||
AND qsep.questionnaire_id = qs.questionnaire_id
|
||||
AND qsep.sample_id = s.sample_id";
|
||||
|
||||
|
||||
$db->Execute($sql);
|
||||
|
||||
|
||||
if ($db->HasFailedTrans()) die ($sql);
|
||||
}
|
||||
|
||||
|
||||
//Update the exclusion record to be 1 where exists in the qsqre table
|
||||
|
||||
$sql = "SELECT questionnaire_id,sample_id
|
||||
|
||||
Reference in New Issue
Block a user