Beispiel #1
0
        public InterpretAllLabResult GetAllLabResult(APITrakcare.Episode episode, LabConfigResult labconfig, DateTime dob, char sex)
        {
            try
            {
                var maplab    = new LabClass.MapLabEmrCheckupCls().Mapping(episode);
                var visitdate = episode.labdates.Select(x => x.labdate).FirstOrDefault();

                return(GetAllLabResult(visitdate, maplab, labconfig, dob, sex));
            }
            catch (Exception ex)
            {
                Class.globalCls.MessageError("InterpretLabCls", "GetAllLabResult", ex.Message);
                throw ex;
            }
        }
Beispiel #2
0
        public InterpretAllLabResult GetAllLabResult(DateTime visitdate, List <LabClass.MapLabEmrCheckupResult> maplab, LabConfigResult labconfig, DateTime dob, char sex)
        {
            try
            {
                InterpretAllLabResult result = new InterpretAllLabResult
                {
                    groups = new List <InterpretGroupLab>()
                };

                foreach (var date in maplab)
                {
                    var ages = calAge(dob, date.labdate);
                    foreach (var grp in date.labgroups)
                    {
                        var rsgrp = result.groups.Where(x => x.code == grp.code).LastOrDefault();
                        if (rsgrp == null)
                        {
                            rsgrp = new InterpretGroupLab
                            {
                                code    = grp.code,
                                name_en = grp.nameen,
                                name_th = grp.nameth,
                                labs    = new List <InterpretLab>()
                            };
                            result.groups.Add(rsgrp);
                        }
                        foreach (var lab in grp.labs)
                        {
                            var rslab = new InterpretLab();
                            // if (lab.status == 'E')
                            if (lab.status != 'D')
                            {
                                var lab_date_nrange = new DateTime(2017, 11, 01);
                                if (visitdate < lab_date_nrange)     // use get lab old
                                {
                                    var rs = GetResult_old(lab, labconfig, ages, sex);
                                    rslab.setcode     = lab.setcode;
                                    rslab.code        = lab.code;
                                    rslab.name_en     = lab.nameen;
                                    rslab.name_th     = lab.nameth;
                                    rslab.seq         = lab.seq;
                                    rslab.value       = lab.valuedisplay;
                                    rslab.mlr_id      = rs.mlr_id;
                                    rslab.summary     = rs.summary;
                                    rslab.result_en   = rs.result_en;
                                    rslab.result_th   = rs.result_th;
                                    rslab.result_jp   = rs.result_jp;
                                    rslab.normalrange = rs.normalrange;
                                    rslab.unit        = rs.unit;
                                    rslab.status      = lab.status;
                                    if (lab.usechart)
                                    {
                                        var chartrs = new LabClass.GetChartCls().GetID(lab.code, rs.chartmin, rs.chartmax, rs.normalmin, rs.normalmax, rs.interpretvalue, rs.displayvalue, (rs.summary == null ? "" : rs.summary.ToString()));
                                        if (chartrs != null)
                                        {
                                            rslab.chartid   = chartrs.chartid;
                                            rslab.chartpath = chartrs.chartpath;
                                        }
                                    }
                                }
                                else
                                {
                                    // var rs = GetResult(lab, labconfig, ages, sex); // use get lab old
                                    var rs = GetResult_Special(lab, labconfig, ages, sex);     // use test get lab test  //  lab Royallife
                                    rslab.setcode     = lab.setcode;
                                    rslab.code        = lab.code;
                                    rslab.name_en     = lab.nameen;
                                    rslab.name_th     = lab.nameth;
                                    rslab.seq         = lab.seq;
                                    rslab.value       = lab.valuedisplay;
                                    rslab.mlr_id      = rs.mlr_id;
                                    rslab.summary     = rs.summary;
                                    rslab.result_en   = rs.result_en;
                                    rslab.result_th   = rs.result_th;
                                    rslab.result_jp   = rs.result_jp;
                                    rslab.normalrange = rs.normalrange;
                                    rslab.unit        = rs.unit;
                                    rslab.status      = lab.status;

                                    rslab.result_sp     = rs.result_sp;
                                    rslab.result_sp_con = rs.result_sp_con;

                                    if (lab.usechart)
                                    {
                                        var chartrs = new LabClass.GetChartCls().GetID(lab.code, rs.chartmin, rs.chartmax, rs.normalmin, rs.normalmax, rs.interpretvalue, rs.displayvalue, (rs.summary == null ? "" : rs.summary.ToString()));
                                        if (chartrs != null)
                                        {
                                            rslab.chartid   = chartrs.chartid;
                                            rslab.chartpath = chartrs.chartpath;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                rslab.setcode = lab.setcode;
                                rslab.code    = lab.code;
                                rslab.name_en = lab.nameen;
                                rslab.name_th = lab.nameth;
                                rslab.seq     = lab.seq;
                                rslab.value   = lab.valuedisplay;
                                rslab.status  = lab.status; //  m Add 18/08/2017
                            }
                            rsgrp.labs.Add(rslab);
                        }
                    }
                }

                //using (InhCheckupDataContext cdc = new InhCheckupDataContext())
                //{
                //    var ages = calAge(dob, visitdate);
                //    var labspecials = cdc.mst_labs.Where(x => (x.mlb_type == 'S' || x.mlb_type == 'C') && x.mlb_status == 'A').ToList();
                //    foreach (var lab in labspecials)
                //    {
                //        var rsgrp = result.groups.Where(x => x.code == lab.mst_lab_group.mlg_code).FirstOrDefault();
                //        if (rsgrp == null)
                //        {
                //            rsgrp = new InterpretGroupLab
                //            {
                //                code = lab.mst_lab_group.mlg_code,
                //                name_en = lab.mst_lab_group.mlg_ename,
                //                name_th = lab.mst_lab_group.mlg_tname,
                //                labs = new List<InterpretLab>()
                //            };
                //            result.groups.Add(rsgrp);
                //        }
                //        var maplabspecial = new MapLab
                //        {
                //            code = lab.mlb_code,
                //            id = lab.mlb_id,
                //            nameen = lab.mlb_ename,
                //            nameth = lab.mlb_tname,
                //            seq = lab.mlb_chart_seq,
                //            setcode = lab.mlb_lab_set,
                //            usechart = lab.mlb_use_chart == true ? true : false,
                //            valuetype = lab.mlb_value_type,
                //            status = 'E'
                //        };
                //        //var rs = GetResult(maplabspecial, labconfig, ages, sex); // use get lab old

                //         var lab_date_nrange = new DateTime(2017,11,01);
                //         if (visitdate < lab_date_nrange) // use get lab old
                //         {
                //             var rs = GetResult_old(maplabspecial, labconfig, ages, sex);
                //             var rslab = new InterpretLab();
                //             if (lab.mlb_type == 'C' || rs.mlr_id != null)
                //             {
                //                 rslab.setcode = lab.mlb_lab_set;
                //                 rslab.code = lab.mlb_code;
                //                 rslab.name_en = lab.mlb_ename;
                //                 rslab.name_th = lab.mlb_tname;
                //                 rslab.seq = lab.mlb_chart_seq;
                //                 rslab.mlr_id = rs.mlr_id;
                //                 rslab.summary = rs.summary;
                //                 rslab.result_en = rs.result_en;
                //                 rslab.result_th = rs.result_th;
                //                 rslab.result_jp = rs.result_jp;
                //                 rslab.normalrange = rs.normalrange;
                //                 rslab.unit = rs.unit;
                //                 rslab.status = rs.status;

                //                 if (lab.mlb_use_chart == true)
                //                 {
                //                     var chartrs = new LabClass.GetChartCls().GetID(lab.mlb_code, rs.chartmin, rs.chartmax, rs.normalmin, rs.normalmax, rs.interpretvalue, rs.displayvalue, (rs.summary == null ? "" : rs.summary.ToString()));
                //                     if (chartrs != null)
                //                     {
                //                         rslab.chartid = chartrs.chartid;
                //                         rslab.chartpath = chartrs.chartpath;
                //                     }
                //                 }
                //                 rsgrp.labs.Add(rslab);

                //             }
                //         }
                //         else {

                //             var rs = GetResult(maplabspecial, labconfig, ages, sex);
                //             var rslab = new InterpretLab();
                //             if (lab.mlb_type == 'C' || rs.mlr_id != null)
                //             {
                //                 rslab.setcode = lab.mlb_lab_set;
                //                 rslab.code = lab.mlb_code;
                //                 rslab.name_en = lab.mlb_ename;
                //                 rslab.name_th = lab.mlb_tname;
                //                 rslab.seq = lab.mlb_chart_seq;
                //                 rslab.mlr_id = rs.mlr_id;
                //                 rslab.summary = rs.summary;
                //                 rslab.result_en = rs.result_en;
                //                 rslab.result_th = rs.result_th;
                //                 rslab.result_jp = rs.result_jp;
                //                 rslab.normalrange = rs.normalrange;
                //                 rslab.unit = rs.unit;
                //                 rslab.status = rs.status;

                //                 if (lab.mlb_use_chart == true)
                //                 {
                //                     var chartrs = new LabClass.GetChartCls().GetID(lab.mlb_code, rs.chartmin, rs.chartmax, rs.normalmin, rs.normalmax, rs.interpretvalue, rs.displayvalue, (rs.summary == null ? "" : rs.summary.ToString()));
                //                     if (chartrs != null)
                //                     {
                //                         rslab.chartid = chartrs.chartid;
                //                         rslab.chartpath = chartrs.chartpath;
                //                     }
                //                 }
                //                 rsgrp.labs.Add(rslab);

                //             }

                //             // Royal
                //             if (lab.mlb_code == "N0140")
                //             {
                //                 var rsRoyal = GetResult_Special(maplabspecial, labconfig, ages, sex);
                //                 var rslabRoyal = new InterpretLab();
                //                 if (lab.mlb_type == 'C' || rs.mlr_id != null)
                //                 {
                //                     rslabRoyal.setcode = lab.mlb_lab_set;
                //                     rslabRoyal.code = lab.mlb_code;
                //                     rslabRoyal.name_en = lab.mlb_ename;
                //                     rslabRoyal.name_th = lab.mlb_tname;
                //                     rslabRoyal.seq = lab.mlb_chart_seq;
                //                     rslabRoyal.mlr_id = rs.mlr_id;
                //                     rslabRoyal.summary = rs.summary;
                //                     rslabRoyal.result_en = rs.result_en;
                //                     rslabRoyal.result_th = rs.result_th;
                //                     rslabRoyal.result_jp = rs.result_jp;
                //                     rslabRoyal.normalrange = rs.normalrange;
                //                     rslabRoyal.unit = rs.unit;
                //                     rslabRoyal.status = rs.status;

                //                     if (lab.mlb_use_chart == true)
                //                     {
                //                         //var chartrs = new LabClass.GetChartCls().GetID_Royal(lab.mlb_code, rs.chartmin, rs.chartmax, rs.normalmin, rs.normalmax, rs.interpretvalue, rs.displayvalue, (rs.summary == null ? "" : rs.summary.ToString()));
                //                         var chartrs = new LabClass.GetChartCls().GetID(lab.mlb_code, rs.chartmin, rs.chartmax, rs.normalmin, rs.normalmax, rs.interpretvalue, rs.displayvalue, (rs.summary == null ? "" : rs.summary.ToString()));

                //                         if (chartrs != null)
                //                         {
                //                             rslab.chartid = chartrs.chartid;
                //                             rslab.chartpath = chartrs.chartpath;
                //                         }
                //                     }
                //                     rsgrp.labs.Add(rslab);

                //                 }
                //             }
                //         }
                //    }
                //}


                foreach (var grp in result.groups)
                {
                    grp.labs    = grp.labs.OrderBy(x => x.seq).ToList();
                    grp.status  = grp.labs.Any(x => x.status == 'I') ? 'I' : 'E';
                    grp.summary = grp.labs.Any(x => x.summary == 'A') ? 'A' : 'N';
                    var edu = grp.labs.Where(x => x.summary == 'A' && !string.IsNullOrEmpty(x.result_th)).Select(x => x.result_th).ToList();
                    grp.education = string.Join(", ", edu);
                }
                return(result);
            }
            catch (Exception ex)
            {
                Class.globalCls.MessageError("InterpretLabCls", "GetAllLabResult", ex.Message);
                throw ex;
            }
        }
Beispiel #3
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;
            }
        }
Beispiel #4
0
        public LabConfigResult Get(QuestionnaireResult questionnaire, List <MapLabEmrCheckupResult> maplabs, APITrakcare.VitalSignResult vsresult)
        {
            try
            {
                LabConfigResult result = new LabConfigResult();
                result.labconfigs = new List <LabConfig>();

                result.labconfigs.Add(new LabConfig {
                    code = "|PREG|", value = questionnaire.pregnancy == 'P' ? @"""True""" : @"""False"""
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|SMOKE|", value = questionnaire.pregnancy == 'S' ? @"""True""" : @"""False"""
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|DM|", value = questionnaire.diabetes == true ? @"""True""" : @"""False"""
                });

                result.labconfigs.Add(new LabConfig {
                    code = "|VLEFT|", value = vsresult.visionLeft
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|VRIGHT|", value = vsresult.visionRight
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|PULSE|", value = vsresult.pulse
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|BMI|", value = vsresult.bmi
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|SYS|", value = vsresult.systolic
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|DIA|", value = vsresult.diastolic
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|RP|", value = vsresult.respirationrate
                });
                result.labconfigs.Add(new LabConfig {
                    code = "|TP|", value = vsresult.temperature
                });

                using (InhCheckupDataContext cdc = new InhCheckupDataContext())
                {
                    var mst = cdc.mst_lab_configs
                              .Where(x => x.mlc_status == 'A' &&
                                     x.mlc_table.Trim() == "trn_patient_lab")
                              .Select(x => new
                    {
                        mlc_code     = x.mlc_code,
                        mlc_lab_code = x.mlc_lab_code
                    }).ToList();
                    foreach (var lc in mst)
                    {
                        var codes = lc.mlc_lab_code.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                        foreach (var code in codes)
                        {
                            foreach (var maplab in maplabs)
                            {
                                foreach (var grp in maplab.labgroups)
                                {
                                    var lab = grp.labs.Where(x => x.code == code.Trim() && x.status == 'E').FirstOrDefault();
                                    if (lab != null)
                                    {
                                        result.labconfigs.Add(new LabConfig {
                                            code = lab.code, value = lab.valueinterpret
                                        });
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                Class.globalCls.MessageError("GetLabConfigCls", "Get", ex.Message);
                throw ex;
            }
        }