Esempio n. 1
0
        //Get labSpecail  //  lab Royallife
        public InterpretResult GetResult_Special(MapLab lab, LabConfigResult labconfig, double ages, char sex)
        {
            try
            {
                InterpretResult result = new InterpretResult();
                if (lab.id != null)
                {
                    using (InhCheckupDataContext cdc = new InhCheckupDataContext())
                    {
                        var mla = cdc.mst_lab_ages
                                  .Where(x => x.mlb_id == lab.id &&
                                         x.mla_max_age.Value + (x.mla_max_day.Value / 365) >= ages &&
                                         x.mla_min_age.Value + (x.mla_min_day.Value / 365) <= ages &&
                                         x.mla_sex == sex &&
                                         x.mla_status == 'A')
                                  .FirstOrDefault();

                        if (mla != null)
                        {
                            result.unit = mla.mla_vstand_unit;


                            if (!new List <string> {
                                "N7007", "N0390"
                            }.Contains(lab.code))                                          //CEA
                            {
                                result.normalrange = mla.mla_vstand_nrange;
                            }
                            else
                            {
                                var smoke = labconfig.labconfigs.Where(x => x.code == "|SMOKE|").Select(x => x.value).FirstOrDefault();
                                if (smoke == @"""True""")
                                {
                                    result.normalrange = "Smoke(0-5.5)";
                                }
                                else
                                {
                                    result.normalrange = mla.mla_vstand_nrange;
                                }
                            }

                            if (lab.usechart)
                            {
                                result.displayvalue = lab.valuedisplay;
                                result.chartmin     = mla.mla_value_min;
                                result.chartmax     = mla.mla_value_max;
                                result.normalmin    = mla.mla_vstand_min;
                                result.normalmax    = mla.mla_vstand_max;

                                if (!new List <string> {
                                    "N7007", "N0390"
                                }.Contains(lab.code))                                          //CEA
                                {
                                    result.normalrange = mla.mla_vstand_nrange;
                                }
                                else
                                {
                                    var smoke = labconfig.labconfigs.Where(x => x.code == "|SMOKE|").Select(x => x.value).FirstOrDefault();
                                    if (smoke == @"""True""")
                                    {
                                        result.normalmin = mla.mla_vstand_min;
                                        result.normalmax = mla.mla_vstand_max;
                                    }
                                    else
                                    {
                                        result.normalmin = 0;
                                        result.normalmax = 3.8;
                                    }
                                }


                                double o;
                                if (double.TryParse(lab.valueinterpret, out o))
                                {
                                    result.interpretvalue = o;
                                }
                                else
                                {
                                    if (lab.valuedisplay.Trim().Substring(0, 1) == "<")
                                    {
                                        result.interpretvalue = Convert.ToDouble(lab.valuedisplay.Replace("<", "0"));
                                    }
                                    if (lab.valuedisplay.Trim().Substring(0, 1) == ">")
                                    {
                                        result.interpretvalue = Convert.ToDouble(lab.valuedisplay.Replace(">", "0"));
                                    }
                                }
                            }
                            // Get Result lab EMR
                            var mlps = mla.mst_lab_results.Where(x => x.mlp_status == 'A' && x.mlp_flag_special == false).OrderBy(x => x.mlp_cond_seq).ToList();
                            foreach (var mlp in mlps)
                            {
                                string condition = mlp.mlp_condition;
                                foreach (var config in labconfig.labconfigs)
                                {
                                    condition = condition.Replace(config.code, config.value);
                                }
                                if (!string.IsNullOrEmpty(lab.valueinterpret))
                                {
                                    condition = condition = condition.Replace("?", lab.valueinterpret);
                                }
                                condition = condition = condition.Replace("\"", "'");
                                //bool val = CompilerStringCls.CheckCondition(condition);
                                bool?val = cdc.emrCalculateCondition(condition).Select(x => x.rs).FirstOrDefault();
                                if ((bool)val)
                                {
                                    result.mlr_id  = mlp.mlr_id;
                                    result.summary = mlp.mlp_summary;
                                    if (result.mlr_id != null)
                                    {
                                        var recom = cdc.mst_lab_recoms
                                                    .Where(x => x.mlr_id == result.mlr_id)
                                                    .Select(x => new
                                        {
                                            en = x.mlr_en_name,
                                            th = x.mlr_th_name,
                                            jp = x.mlr_jp_name,
                                            //sp = x.
                                        }).FirstOrDefault();
                                        if (recom != null)
                                        {
                                            result.result_en = recom.en;
                                            result.result_th = recom.th;
                                            result.result_jp = recom.jp;
                                        }
                                    }
                                    break;
                                }
                            }// end Get Result lab EMR

                            // Get Result lab Royallife
                            List <string> labcode_royallife = new List <string>
                            {
                                "S0721", "S0723", "S0725", "S0727", "S0729", "S0731", "S0733", "S0735", "S0420", "S0380", "S0472", "S0551", "C0280", "N0140", "N0150", "N0130"
                            };
                            if (labcode_royallife.Contains(lab.code))
                            {
                                var mlpsp = mla.mst_lab_results.Where(x => x.mlp_status == 'A' && x.mlp_flag_special == true).OrderBy(x => x.mlp_cond_seq).ToList();
                                foreach (var mlp in mlpsp)
                                {
                                    string condition = mlp.mlp_condition;
                                    foreach (var config in labconfig.labconfigs)
                                    {
                                        condition = condition.Replace(config.code, config.value);
                                    }
                                    if (!string.IsNullOrEmpty(lab.valueinterpret))
                                    {
                                        condition = condition = condition.Replace("?", lab.valueinterpret);
                                    }
                                    condition = condition = condition.Replace("\"", "'");
                                    //bool val = CompilerStringCls.CheckCondition(condition);
                                    bool?val = cdc.emrCalculateCondition(condition).Select(x => x.rs).FirstOrDefault();
                                    if ((bool)val)
                                    {
                                        result.mlr_id  = mlp.mlr_id;
                                        result.summary = mlp.mlp_summary;
                                        if (result.mlr_id != null)
                                        {
                                            var recom = cdc.mst_lab_recoms
                                                        .Where(x => x.mlr_id == result.mlr_id)
                                                        .Select(x => new
                                            {
                                                //en = x.mlr_en_name,
                                                //th = x.mlr_th_name,
                                                //jp = x.mlr_jp_name,
                                                sp = x.mlr_en_name
                                            }).FirstOrDefault();
                                            if (recom != null)
                                            {
                                                result.result_sp     = recom.sp;
                                                result.result_sp_con = mlp.mlp_cond_special;
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                Class.globalCls.MessageError("InterpretLabCls", "GetResults", ex.Message);
                throw ex;
            }
        }