mirror of
https://github.com/ACSPRI/queXS
synced 2024-04-02 12:12:16 +00:00
Sort on a questionnaire by questionnaire basis
This commit is contained in:
@@ -88,8 +88,11 @@ register_shutdown_function('disable_systemsort');
|
|||||||
//all output send to database instead of stdout
|
//all output send to database instead of stdout
|
||||||
ob_start('update_callback',2);
|
ob_start('update_callback',2);
|
||||||
|
|
||||||
|
$closecasescounter = 0;
|
||||||
|
|
||||||
print T_("Sorting cases process starting");
|
print T_("Sorting cases process starting");
|
||||||
|
|
||||||
|
$closecasesinterval = (24 * 60) / SYSTEM_SORT_MINUTES; //check for closed cases once every day
|
||||||
$sleepinterval = 10; // in seconds so we can monitor if the process has been killed
|
$sleepinterval = 10; // in seconds so we can monitor if the process has been killed
|
||||||
|
|
||||||
while (!is_process_killed($process_id)) //check if process killed every $sleepinterval
|
while (!is_process_killed($process_id)) //check if process killed every $sleepinterval
|
||||||
@@ -97,10 +100,12 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin
|
|||||||
//Make sure that the system knows we are system sorting
|
//Make sure that the system knows we are system sorting
|
||||||
set_setting('systemsort',true);
|
set_setting('systemsort',true);
|
||||||
|
|
||||||
print T_("Sorting cases");
|
if ($closecasescounter == 0 || $closecasescounter > $closecasesinterval)
|
||||||
|
{
|
||||||
$time_start = microtime(true);
|
$time_start = microtime(true);
|
||||||
|
print T_("Checking for cases open for more than 24 hours");
|
||||||
|
|
||||||
|
$closecasescounter = 0;
|
||||||
$db->StartTrans();
|
$db->StartTrans();
|
||||||
|
|
||||||
//find all call attempts without an end that started more than 24 hours ago
|
//find all call attempts without an end that started more than 24 hours ago
|
||||||
@@ -180,34 +185,57 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin
|
|||||||
print T_("System automatically closed case as not closed for more than 24 hours") . " - " . T_("Case id") . ": {$r['case_id']}";
|
print T_("System automatically closed case as not closed for more than 24 hours") . " - " . T_("Case id") . ": {$r['case_id']}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = $db->CompleteTrans();
|
||||||
|
|
||||||
//Set all cases as unavailable
|
$time_end = microtime(true);
|
||||||
$sql = "UPDATE `case`
|
$timer = $time_end - $time_start;
|
||||||
SET sortorder = NULL
|
|
||||||
WHERE sortorder IS NOT NULL";
|
|
||||||
|
|
||||||
$db->Execute($sql);
|
if ($result)
|
||||||
|
print T_("Completed case closing") . ". " . T_("This task took") . ": $timer " . T_("seconds");
|
||||||
|
else
|
||||||
|
print T_("Failed to complete caes closing") . ". " . T_("This task took") . ": $timer " . T_("seconds");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Update quotas for all enabled questionnaires
|
$closecasescounter++;
|
||||||
$sql = "SELECT questionnaire_id
|
|
||||||
|
//Sort cases on a questionnaire by questionnaire basis
|
||||||
|
$sql = "SELECT questionnaire_id, description
|
||||||
FROM questionnaire
|
FROM questionnaire
|
||||||
WHERE enabled = 1";
|
WHERE enabled = 1";
|
||||||
|
|
||||||
$qs = $db->GetAll($sql);
|
$qs = $db->GetAll($sql);
|
||||||
|
|
||||||
foreach($qs as $q)
|
foreach($qs as $q)
|
||||||
update_quotas($q['questionnaire_id']);
|
{
|
||||||
|
print T_("Sorting cases for ") . $q['description'];
|
||||||
|
|
||||||
|
$questionnaire_id = $q['questionnaire_id'];
|
||||||
|
|
||||||
|
$time_start = microtime(true);
|
||||||
|
|
||||||
|
$db->StartTrans();
|
||||||
|
|
||||||
|
//Set all cases as unavailable
|
||||||
|
$sql = "UPDATE `case`
|
||||||
|
SET sortorder = NULL
|
||||||
|
WHERE sortorder IS NOT NULL
|
||||||
|
AND questionnaire_id = '$questionnaire_id'";
|
||||||
|
|
||||||
|
$db->Execute($sql);
|
||||||
|
|
||||||
|
|
||||||
//Sort current cases for all enabled questionnaires
|
//update quotas
|
||||||
|
update_quotas($questionnaire_id);
|
||||||
|
|
||||||
|
|
||||||
|
//Sort current cases for this questionnaire
|
||||||
|
|
||||||
$sql = "SELECT c.case_id
|
$sql = "SELECT c.case_id
|
||||||
FROM `case` as c
|
FROM `case` as c
|
||||||
LEFT JOIN `call` as a on (a.call_id = c.last_call_id)
|
LEFT JOIN `call` as a on (a.call_id = c.last_call_id)
|
||||||
JOIN (sample as s, sample_import as si) on (s.sample_id = c.sample_id and si.sample_import_id = s.import_id)
|
JOIN (sample as s, sample_import as si) on (s.sample_id = c.sample_id and si.sample_import_id = s.import_id)
|
||||||
JOIN (questionnaire_sample as qs, questionnaire as q, outcome as ou) on (c.questionnaire_id = q.questionnaire_id and qs.sample_import_id = s.import_id and ou.outcome_id = c.current_outcome_id and q.enabled = 1 and qs.questionnaire_id = c.questionnaire_id)
|
JOIN (questionnaire_sample as qs, questionnaire as q, outcome as ou) on (c.questionnaire_id = q.questionnaire_id and qs.sample_import_id = s.import_id and ou.outcome_id = c.current_outcome_id and q.questionnaire_id = '$questionnaire_id' and qs.questionnaire_id = c.questionnaire_id)
|
||||||
LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))
|
LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))
|
||||||
LEFT JOIN appointment as ap on (ap.case_id = c.case_id AND ap.completed_call_id is NULL AND (ap.start > CONVERT_TZ(NOW(),'System','UTC')))
|
LEFT JOIN appointment as ap on (ap.case_id = c.case_id AND ap.completed_call_id is NULL AND (ap.start > CONVERT_TZ(NOW(),'System','UTC')))
|
||||||
LEFT JOIN appointment as apn on (apn.case_id = c.case_id AND apn.completed_call_id is NULL AND (CONVERT_TZ(NOW(),'System','UTC') >= apn.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= apn.end))
|
LEFT JOIN appointment as apn on (apn.case_id = c.case_id AND apn.completed_call_id is NULL AND (CONVERT_TZ(NOW(),'System','UTC') >= apn.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= apn.end))
|
||||||
@@ -216,6 +244,7 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin
|
|||||||
LEFT JOIN case_availability AS casa ON (casa.case_id = c.case_id)
|
LEFT JOIN case_availability AS casa ON (casa.case_id = c.case_id)
|
||||||
LEFT JOIN availability AS ava ON (ava.availability_group_id = casa.availability_group_id)
|
LEFT JOIN availability AS ava ON (ava.availability_group_id = casa.availability_group_id)
|
||||||
WHERE c.current_operator_id IS NULL
|
WHERE c.current_operator_id IS NULL
|
||||||
|
AND c.questionnaire_id = '$questionnaire_id'
|
||||||
AND (casa.case_id IS NULL OR (ava.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(),'System',s.Time_zone_name)) AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= ava.start AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= ava.end ))
|
AND (casa.case_id IS NULL OR (ava.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(),'System',s.Time_zone_name)) AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= ava.start AND TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= ava.end ))
|
||||||
AND (a.call_id is NULL or (a.end < CONVERT_TZ(DATE_SUB(NOW(), INTERVAL ou.default_delay_minutes MINUTE),'System','UTC')))
|
AND (a.call_id is NULL or (a.end < CONVERT_TZ(DATE_SUB(NOW(), INTERVAL ou.default_delay_minutes MINUTE),'System','UTC')))
|
||||||
AND ap.case_id is NULL
|
AND ap.case_id is NULL
|
||||||
@@ -245,17 +274,17 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin
|
|||||||
//First set all sample records as unavailable
|
//First set all sample records as unavailable
|
||||||
$sql = "UPDATE `questionnaire_sample_exclude_priority`
|
$sql = "UPDATE `questionnaire_sample_exclude_priority`
|
||||||
SET sortorder = NULL
|
SET sortorder = NULL
|
||||||
WHERE sortorder IS NOT NULL";
|
WHERE sortorder IS NOT NULL
|
||||||
|
AND questionnaire_id = '$questionnaire_id'";
|
||||||
|
|
||||||
$db->Execute($sql);
|
$db->Execute($sql);
|
||||||
|
|
||||||
|
|
||||||
|
//Sort sample list where attached to this questionnaire
|
||||||
//Sort sample list where attached to an enabled questionnaire
|
|
||||||
|
|
||||||
$sql = "SELECT s.sample_id as sample_id,qs.questionnaire_id as questionnaire_id
|
$sql = "SELECT s.sample_id as sample_id,qs.questionnaire_id as questionnaire_id
|
||||||
FROM sample as s
|
FROM sample as s
|
||||||
JOIN (questionnaire_sample as qs, questionnaire as q, sample_import as si) on (qs.sample_import_id = s.import_id and si.sample_import_id = s.import_id and q.questionnaire_id = qs.questionnaire_id AND q.enabled = 1)
|
JOIN (questionnaire_sample as qs, questionnaire as q, sample_import as si) on (qs.sample_import_id = s.import_id and si.sample_import_id = s.import_id and q.questionnaire_id = qs.questionnaire_id AND q.questionnaire_id = '$questionnaire_id')
|
||||||
LEFT JOIN `case` as c on (c.sample_id = s.sample_id and c.questionnaire_id = qs.questionnaire_id)
|
LEFT JOIN `case` as c on (c.sample_id = s.sample_id and c.questionnaire_id = qs.questionnaire_id)
|
||||||
LEFT JOIN call_restrict as cr on (cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)
|
LEFT JOIN call_restrict as cr on (cr.day_of_week = DAYOFWEEK(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) >= cr.start and TIME(CONVERT_TZ(NOW(), 'System' , s.Time_zone_name)) <= cr.end)
|
||||||
LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))
|
LEFT JOIN shift as sh on (sh.questionnaire_id = q.questionnaire_id and (CONVERT_TZ(NOW(),'System','UTC') >= sh.start) AND (CONVERT_TZ(NOW(),'System','UTC') <= sh.end))
|
||||||
@@ -282,8 +311,6 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$result = $db->CompleteTrans();
|
$result = $db->CompleteTrans();
|
||||||
|
|
||||||
$time_end = microtime(true);
|
$time_end = microtime(true);
|
||||||
@@ -293,6 +320,7 @@ while (!is_process_killed($process_id)) //check if process killed every $sleepin
|
|||||||
print T_("Completed sort") . ". " . T_("This task took") . ": $timer " . T_("seconds");
|
print T_("Completed sort") . ". " . T_("This task took") . ": $timer " . T_("seconds");
|
||||||
else
|
else
|
||||||
print T_("Failed to complete sort") . ". " . T_("This task took") . ": $timer " . T_("seconds");
|
print T_("Failed to complete sort") . ". " . T_("This task took") . ": $timer " . T_("seconds");
|
||||||
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < (SYSTEM_SORT_MINUTES * 60); $i += $sleepinterval)
|
for ($i = 0; $i < (SYSTEM_SORT_MINUTES * 60); $i += $sleepinterval)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user