/** * function to retrieve the result */ function getVLResult($machineType,$worksheetID,$sampleID,$factor) { global $default_resultFailureNewSampleMessage; $result=0; //first check if any result overrides are in place if($worksheetID && getDetailedTableInfo2("vl_results_override","sampleID='$sampleID' and worksheetID='$worksheetID'","id")) { $result=getDetailedTableInfo2("vl_results_override","sampleID='$sampleID' and worksheetID='$worksheetID'","result"); return $result; } elseif(!$worksheetID && getDetailedTableInfo2("vl_results_override","sampleID='$sampleID'","id")) { $result=getDetailedTableInfo2("vl_results_override","sampleID='$sampleID'","result"); return $result; } else { $rocheFailedResult=0; $rocheFailedResult="Invalid Test Result. Insufficient sample remained to repeat the assay."; $abbottFailedResult=0; $abbottFailedResult="Failed."; if($machineType=="roche") { if(isResultFailed($machineType,($worksheetID?$worksheetID:""),$sampleID)) { /* * 15/Sept/14: * Hellen (hnansumba@gmail.com, CPHL) requested that once a sample has failed more than once, * there is insufficient sample left for a re-run hence; * Change result to read "invalid test result. Insufficient sample remained to repeat the assay" */ if(getDetailedTableInfo3("vl_results_merged","lower(machine)='".strtolower($machineType)."' and vlSampleID='$sampleID'","count(id)","num")>1 && getDetailedTableInfo2("vl_results_merged","lower(machine)='".strtolower($machineType)."' and vlSampleID='$sampleID' order by created limit 1","resultAlphanumeric")==$rocheFailedResult) { /* * 21/Jan/15: * (sewyisaac@yahoo.co.uk) * Regarding the report where we do not have results, this is the massage to I propose. * There is No Result Given. The Test Failed the Quality Control Criteria. We advise you send a a new sample. * * 23/Dec/2015 * Request from Joseph Kibirige (joseph.kibirige@yahoo.com, CPHL) and Prossy Mbabazi (pronam2000@yahoo.com, CPHL) * when a sample has failed twice, automatically override the 2nd result with * "There is No Result Given. The Test Failed the Quality Control Criteria. We advise you send a a new sample." */ logResultOverride($sampleID,$worksheetID,$default_resultFailureNewSampleMessage); //return return $default_resultFailureNewSampleMessage; } else { //return return $rocheFailedResult; } } else { $result=getDetailedTableInfo2("vl_results_roche",($worksheetID?"worksheetID='$worksheetID' and ":"")."SampleID='$sampleID' order by created desc limit 1","Result"); $result=getVLNumericResult($result,$machineType,$factor); return $result; } } elseif($machineType=="abbott") { if(isResultFailed($machineType,($worksheetID?$worksheetID:""),$sampleID)) { /* * 15/Sept/14: * Hellen (hnansumba@gmail.com, CPHL) requested that once a sample has failed more than once, * there is insufficient sample left for a re-run hence; * Change result to read "invalid test result. Insufficient sample remained to repeat the assay" * * 22/Sept/14 * Adjustment made to recognize both samples as failures */ if(getDetailedTableInfo3("vl_results_merged","lower(machine)='".strtolower($machineType)."' and vlSampleID='$sampleID'","count(id)","num")>1 && getDetailedTableInfo2("vl_results_merged","lower(machine)='".strtolower($machineType)."' and vlSampleID='$sampleID' order by created limit 1","resultAlphanumeric")==$abbottFailedResult) { /* * 21/Jan/15: * (sewyisaac@yahoo.co.uk) * Regarding the report where we do not have results, this is the massage to I propose. * There is No Result Given. The Test Failed the Quality Control Criteria. We advise you send a a new sample. * * 23/Dec/2015 * Request from Joseph Kibirige (joseph.kibirige@yahoo.com, CPHL) and Prossy Mbabazi (pronam2000@yahoo.com, CPHL) * when a sample has failed twice, automatically override the 2nd result with * "There is No Result Given. The Test Failed the Quality Control Criteria. We advise you send a a new sample." */ logResultOverride($sampleID,$worksheetID,$default_resultFailureNewSampleMessage); //return return $default_resultFailureNewSampleMessage; } else { //return return $abbottFailedResult; } } else { $result=getDetailedTableInfo2("vl_results_abbott",($worksheetID?"worksheetID='$worksheetID' and ":"")."sampleID='$sampleID' order by created desc limit 1","result"); $result=getVLNumericResult($result,$machineType,$factor); return $result; } } } }
/** * function to log whether this sample should be repeated */ function logRepeat($machineType,$sampleID,$worksheetID,$result,$flags) { global $datetime,$user; //result and flags should all be lower caps for easier comparison $result=trim(strtolower($result)); $flags=trim(strtolower($flags)); //avoid duplicates $id=0; $id=getDetailedTableInfo2("vl_logs_samplerepeats","sampleID='$sampleID' limit 1","id"); if(!$id) { //first time, and sample qualifies for an automatic repeat? if(($machineType=="roche" && isResultFailed($machineType,($worksheetID?$worksheetID:""),getDetailedTableInfo2("vl_samples","id='$sampleID' limit 1","vlSampleID"))) || ($machineType=="abbott" && isResultFailed($machineType,($worksheetID?$worksheetID:""),getDetailedTableInfo2("vl_samples","id='$sampleID' limit 1","vlSampleID")))) { mysqlquery("insert into vl_logs_samplerepeats (sampleID,oldWorksheetID,created,createdby) values ('$sampleID','$worksheetID','$datetime','$user')"); } } else { //get last worksheetID this sample was entered with $oldWorksheetID=0; $oldWorksheetID=getDetailedTableInfo2("vl_logs_samplerepeats","sampleID='$sampleID' and oldWorksheetID!='' and withWorksheetID='' and created<'$datetime' order by created desc limit 1","oldWorksheetID"); $withWorksheetID=0; $withWorksheetID=getDetailedTableInfo2("vl_logs_samplerepeats","sampleID='$sampleID' and oldWorksheetID!='' and withWorksheetID!='' and created<'$datetime' order by created desc limit 1","withWorksheetID"); if($oldWorksheetID!=$worksheetID) { //log changes $modifyID=0; $modifyID=getDetailedTableInfo2("vl_logs_samplerepeats","sampleID='$sampleID' and oldWorksheetID='$oldWorksheetID' order by created limit 1","id"); logTableChange("vl_logs_samplerepeats","repeatedOn",$modifyID,getDetailedTableInfo2("vl_logs_samplerepeats","id='$modifyID'","repeatedOn"),$datetime); logTableChange("vl_logs_samplerepeats","withWorksheetID",$modifyID,getDetailedTableInfo2("vl_logs_samplerepeats","id='$modifyID'","withWorksheetID"),$worksheetID); //modify the db mysqlquery("update vl_logs_samplerepeats set repeatedOn='$datetime',withWorksheetID='$worksheetID' where sampleID='$sampleID' and oldWorksheetID='$oldWorksheetID'"); } elseif($withWorksheetID==$worksheetID) { /* * this is a new repeat, which has failed and needs to be re-run * e.g row 1, 193 (under withWorksheetID column) was a repeat which also failed and * ended up being repeated +----+----------+----------------+---------------------+-----------------+ | id | sampleID | oldWorksheetID | repeatedOn | withWorksheetID | +----+----------+----------------+---------------------+-----------------+ | 37 | 4794 | 192 | 2014-11-17 10:06:58 | 193 | | 40 | 4794 | 193 | 2014-11-18 10:07:59 | 203 | +----+----------+----------------+---------------------+-----------------+ */ if(($machineType=="roche" && isResultFailed($machineType,($worksheetID?$worksheetID:""),getDetailedTableInfo2("vl_samples","id='$sampleID' limit 1","vlSampleID"))) || ($machineType=="abbott" && isResultFailed($machineType,($worksheetID?$worksheetID:""),getDetailedTableInfo2("vl_samples","id='$sampleID' limit 1","vlSampleID")))) { mysqlquery("insert into vl_logs_samplerepeats (sampleID,oldWorksheetID,created,createdby) values ('$sampleID','$worksheetID','$datetime','$user')"); } } } }