--- a/application/p/logic/EquipmentRecord.php +++ b/application/p/logic/EquipmentRecord.php @@ -84,7 +84,7 @@ //9 51 kx21n //21 66 西门子 //7100 80 日立 - $where['a.relation_type'] = ['in',[9,21,7100]]; + $where['a.relation_type'] = ['in',[1,2,3,4,9,10,21,7100]]; $res = Db::name('equipment_result') ->alias('a') ->join('staff b','a.staff_uuid = b.uuid','left') @@ -107,7 +107,7 @@ //9 51 kx21n //21 66 西门子 //7100 80 日立 - $where['a.relation_type'] = ['in',[9,21,7100]]; + $where['a.relation_type'] = ['in',[1,2,3,4,9,10,21,7100]]; return Db::name('equipment_result') ->alias('a') ->join('staff b','a.staff_uuid = b.uuid','left') @@ -2314,7 +2314,7 @@ $test_result = 2; $test_value = ''; // if(isset($result[$value['k']]) && !empty($result[$value['k']]) && is_numeric($result[$value['k']])){ - if(isset($result[$value['k']]) && !empty($result[$value['k']])){ + if(isset($result[$value['k']]) && $result[$value['k']] !== ''){ $test_value = $result[$value['k']]; if($value['upper_limit'] != $value['lower_limit']){ if($test_value > $value['upper_limit']){ @@ -2615,8 +2615,8 @@ $department_name = $staff_info[$value['staff_uuid']]['department_name']; $center_res[$center_name][$value['test_date']][] = $value['staff_uuid']; //详细表格数据 - $relation_type = $value['relation_type']; - if(in_array($relation_type,array(9,21,7100))){ + $relation_type = $this->canonicalFunctionalRelationType($value['relation_type']); + if($relation_type !== null){ $table_middle[$center_name][$department_name][$value['test_date']]['sum'][] = $value['staff_uuid']; $table_middle[$center_name][$department_name][$value['test_date']][$relation_type][] = $value['staff_uuid']; } @@ -2703,6 +2703,25 @@ 'table_arr' => $table_res, ); return $res; + } + + /** + * Collapse device-specific functional types into the three groups exposed + * by the analysis and export UI. + */ + private function canonicalFunctionalRelationType($relationType) + { + $relationType = (int)$relationType; + if (in_array($relationType, [1, 9], true)) { + return 9; + } + if (in_array($relationType, [4, 21], true)) { + return 21; + } + if (in_array($relationType, [2, 3, 10, 7100], true)) { + return 7100; + } + return null; } /** @@ -3006,15 +3025,19 @@ //西门子 'COR','TSTII', //kx21n 'WBC','RBC','PLT','HCT','HGB','LYM#','LYM%','MCH','BT','CT','MCHC','MCV','MPV','MXD#','MXD%','NEUT#','NEUT%','PDW','P-LCR','RDW-SD','RDW-CV','RDW-SD' //$head_arr = ['BUN','CK','COR','TSTII','WBC','RBC','PLT','HCT','HGB','LYM#','LYM%','MCH','BT','CT','MCHC','MCV','MPV','MXD#','MXD%','NEUT#','NEUT%','PDW','P-LCR','RDW-SD','RDW-CV','RDW-SD']; - $head_arr = [ - '7100'=>['BUN','CK'], - '21'=>['COR','TSTII'], - '9'=>['WBC','RBC','PLT','HCT','HGB','LYM#','LYM%','MCH','MCHC','MCV','MPV','MXD#','MXD%','NEUT#','NEUT%','PDW','P-LCR','RDW-SD','RDW-CV','RDW-SD']]; + $head_arr = ['7100'=>[],'21'=>[],'9'=>[]]; $k_arr = array(); if(isset($where['a.relation_type'])){ - $item_res = Db::name('equipment_relation')->where(['type'=>$where['a.relation_type']])->select(); + $item_res = Db::name('equipment_relation') + ->where(['type'=>$where['a.relation_type'], 'is_del'=>0, 'is_norm'=>1]) + ->order('type asc,id asc') + ->select(); foreach ($item_res as $value){ - $k_arr[$value['type']][$value['k']] = $value['v']; + $k_arr[(int)$value['type']][$value['k']] = $value['v']; + $canonical_type = $this->canonicalFunctionalRelationType($value['type']); + if ($canonical_type !== null && !in_array($value['k'], $head_arr[$canonical_type], true)) { + $head_arr[$canonical_type][] = $value['k']; + } } } // @@ -3024,9 +3047,7 @@ foreach ($head_arr as $head_key => $head_value){ foreach ($head_value as $head_val){ $output_head[] = $head_val; - if(isset($k_arr[$head_key][$head_val])){ - $head_key_arr[$head_key][] = $k_arr[$head_key][$head_val]; - } + $head_key_arr[$head_key][] = $head_val; } } $res_arr[] = $output_head; @@ -3043,22 +3064,23 @@ $output_arr[] = $staff_info[$middle_val_val_val[0]['staff_uuid']]['sex'] == 1 ? '男' : '女'; $output_arr[] = $test_date; foreach ($head_key_arr as $head_key => $head_value){ - $is_input = 1; - foreach ($middle_val_val_val as $item){ - $type = $item['relation_type']; - if($head_key == $type && isset($result[$item['id']])){ - $is_input = 0; - $result_all = $result[$item['id']]; - foreach ($head_value as $head_key){ - $output_arr[] = isset($result_all[$head_key]) ? $result_all[$head_key] : '/'; + foreach ($head_value as $metric){ + $metric_value = '/'; + foreach ($middle_val_val_val as $item){ + $type = $this->canonicalFunctionalRelationType($item['relation_type']); + if($head_key == $type && isset($result[$item['id']])){ + $result_all = $result[$item['id']]; + $value_key = isset($k_arr[(int)$item['relation_type']][$metric]) + ? $k_arr[(int)$item['relation_type']][$metric] + : null; + if ($value_key !== null && isset($result_all[$value_key]) && $result_all[$value_key] !== '') { + $metric_value = $result_all[$value_key]; + break; + } } } + $output_arr[] = $metric_value; } - if($is_input){ - foreach ($head_value as $head_key){ - $output_arr[] = '/'; - } - } } $res_arr[] = $output_arr; } @@ -3088,8 +3110,3 @@ // return $res; } } - - - - -