Beispiel #1
0
        public CheckupLabResult ByGetCheckupLab(string hn, DateTime startDate, DateTime endDate, string enCurrent = "")//add enCurrent suriya 30/06/2017
        {
            try
            {
                string enHomer = string.Empty;//add  suriya 30/06/2017
                using (Service.WS_TrakcareCls ws = new Service.WS_TrakcareCls())
                {
                    //add  suriya 30/06/2017
                    if (enCurrent.ToUpper().Contains("I"))
                    {
                        DataTable ENDetails = ws.GetEPIRowIDByEN(enCurrent);
                        enHomer = ENDetails.Rows[0]["PAADM_HomerID"].ToString();
                    }
                    System.Threading.Thread.CurrentThread.CurrentCulture
                        = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

                    //end  suriya 30/06/2017
                    var RawMateWS = ws.GetCheckupLab(hn, startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd")).AsEnumerable();
                    // var RawMateWS = ws.GetCheckupLab(hn, "2018-02-01", endDate.ToString("yyyy-MM-dd")).AsEnumerable();
                    var RawMateGroups = RawMateWS.Where(x => x.Field <string>("EPI_NO").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Count() > 0)
                                        .GroupBy(x => x.Field <string>("EPI_NO").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)[0]).ToList();

                    var result = ws.GetPTInfoByHN(hn).AsEnumerable()
                                 .Select(x => new CheckupLabResult
                    {
                        hn  = hn,
                        sex = x.Field <string>("CTSEX_Code"),
                        dob = x.Field <DateTime>("PAPMI_DOB")
                    }).FirstOrDefault();
                    if (result != null)
                    {
                        using (InhCheckupDataContext cdc = new InhCheckupDataContext())
                        {
                            //var DateRaw = RawMateGroups.Select(z =>  z.Field<string>("EPIVISDateOfCollection") );


                            result.episodes = RawMateGroups.Select(x => new Episode
                            {
                                //en = x.Key, del suriya 30/06/2017
                                en = enHomer == x.Key ? enCurrent : x.Key, //add suriya 30/06/2017


                                //labdates = x.GroupBy(y => new DateTime(
                                //                        Convert.ToInt32( y.Field<string>("EPIVISDateOfCollection").Substring(0, 4)  ),
                                //                        Convert.ToInt32( y.Field<string>("EPIVISDateOfCollection").Substring(5, 2)   ),
                                //                        Convert.ToInt32(  y.Field<string>("EPIVISDateOfCollection").Substring(8, 2) )  )
                                //2017-07-19



                                //   change EPIVISDateOfCollection -> DTE_OF_RCV artist.su 24/08/2017
                                //labdates = x.GroupBy(y => new DateTime(
                                //                        Convert.ToInt32(y.Field<string>("DTE_OF_RCV").Substring(0, 4) == "1840" ? y.Field<string>("EPIVISDateOfCollection").Substring(0, 4) : y.Field<string>("DTE_OF_RCV").Substring(0, 4)),
                                //                        Convert.ToInt32(y.Field<string>("DTE_OF_RCV").Substring(0, 4) == "1840" ? y.Field<string>("EPIVISDateOfCollection").Substring(5, 2) : y.Field<string>("DTE_OF_RCV").Substring(5, 2)),
                                //                        Convert.ToInt32(y.Field<string>("DTE_OF_RCV").Substring(0, 4) == "1840" ? y.Field<string>("EPIVISDateOfCollection").Substring(8, 2) : y.Field<string>("DTE_OF_RCV").Substring(8, 2))
                                //                        )

                                //     labdates = x.GroupBy(y => new DateTime(Convert.ToInt32("2017"), Convert.ToInt32("07"), Convert.ToInt32("19"))
                                //2017-10-30  labdate แก้ 1840 / lab  ผิดพลาด
                                labdates = x.GroupBy(y => new DateTime(
                                                         Convert.ToInt32(y.Field <string>("VISTSDateOfReceive").Substring(0, 4)),
                                                         Convert.ToInt32(y.Field <string>("VISTSDateOfReceive").Substring(5, 2)),
                                                         Convert.ToInt32(y.Field <string>("VISTSDateOfReceive").Substring(8, 2)))

                                                     ).Select(y => new LabDate
                                {
                                    labdate = y.Key,
                                    labs    = (from lab in y
                                               join mhs in new LabClass.MappingLocationCls().Mapping()
                                               on lab.Field <string>("CTHOS_CDE") equals mhs.subcode into l
                                               from m in l.DefaultIfEmpty()
                                               select new Lab
                                    {
                                        rowid = lab.Field <string>("EPVISVisitNumber"),
                                        age = lab.Field <string>("EPVIS_AGE") == null
                                                                 ? (int?)null
                                                                 : !IsNumeric(lab.Field <string>("EPVIS_AGE"))
                                                                 ? (int?)null
                                                                 : Convert.ToInt32(lab.Field <string>("EPVIS_AGE")),
                                        headcode = lab.Field <string>("CTTS_CDE"),
                                        headdesc = lab.Field <string>("CTTS_NME"),
                                        code = lab.Field <string>("CTTC_CDE"),
                                        labname = lab.Field <string>("CTTC_DES"),
                                        //valuenumber = (string.IsNullOrWhiteSpace(lab.Field<string>("TST_DTA")) || string.IsNullOrEmpty(lab.Field<string>("TST_DTA"))) && string.IsNullOrEmpty(lab.Field<string>("VISTD_CMM"))
                                        //              ? null
                                        //              :  string.IsNullOrEmpty(lab.Field<string>("VISTD_CMM")) == false  ?  lab.Field<string>("VISTD_CMM").Trim()
                                        //              : string.IsNullOrWhiteSpace(lab.Field<string>("TST_DTA")) || string.IsNullOrEmpty(lab.Field<string>("TST_DTA")) ? null
                                        //              : lab.Field<string>("TST_DTA").Trim().Substring(0, 1) == "."
                                        //              ? "0" + lab.Field<string>("TST_DTA").Trim()

                                        //              : lab.Field<string>("TST_DTA").Trim(),


                                        //                var tmbLength = tmbPlus < 1 && tmbDiv < 1 ? value.Length - 3 :
                                        //                tmbPlus > 1 ? value.Length - tmbPlus :
                                        //                tmbDiv > 1 ? value.Length - tmbDiv : value.Length - 3;
                                        //               var tmbReturn = value.Substring(3, tmbLength);
                                        valuenumber = string.IsNullOrWhiteSpace(lab.Field <string>("TST_DTA")) || string.IsNullOrEmpty(lab.Field <string>("TST_DTA"))
                                                                         ? null
                                                                         : lab.Field <string>("TST_DTA").Trim().Substring(0, 1) == "."
                                                                         ? "0" + lab.Field <string>("TST_DTA").Trim()
                                                                         : lab.Field <string>("TST_DTA").Trim().Contains("<.")
                                                                         ? lab.Field <string>("TST_DTA").Trim().Replace("<.", "<0.")
                                                                         : lab.Field <string>("TST_DTA").Trim().Contains(">.")
                                                                         ? lab.Field <string>("TST_DTA").Trim().Replace(">.", ">0.")
                                                                         : lab.Field <string>("TST_DTA").Trim().Substring(0, 1).IsNormalized() == false
                                                                         ? lab.Field <string>("TST_DTA").Trim().Substring(1, lab.Field <string>("TST_DTA").Trim().Length - 1)
                                                                         : lab.Field <string>("TST_DTA").Trim(),
                                        valuestring = lab.Field <string>("RSL") == null && lab.Field <string>("TST_DTA") == null
                                                                         ? null
                                                                         : string.IsNullOrEmpty(lab.Field <string>("RSL")) == false ? lab.Field <string>("RSL").Trim()
                                                                         : string.IsNullOrEmpty(lab.Field <string>("TST_DTA")) == false ? lab.Field <string>("TST_DTA").Trim()
                                                                         : string.IsNullOrEmpty(lab.Field <string>("RSL")) ? null
                                                                         : lab.Field <string>("RSL").Trim(),
                                        unit = lab.Field <string>("CTTC_UNT"),
                                        range = lab.Field <string>("NML"),
                                        hl = lab.Field <string>("HL") == "H" ? 1 : lab.Field <string>("HL") == "L" ? -1 : 0,
                                        frs = lab.Field <string>("CTTC_RSL_FMT") == null ? -1
                                                                 : lab.Field <string>("CTTC_RSL_FMT").Contains("N") ? 1
                                                                 : lab.Field <string>("CTTC_RSL_FMT") == "S" ? 2
                                                                 : lab.Field <string>("CTTC_RSL_FMT") == "X" ? 0
                                                                 : -1,
                                        seq = lab.Field <string>("Sequen") == null || lab.Field <string>("Sequen") == ""
                                                                 ? (int?)null
                                                                 : !IsNumeric(lab.Field <string>("Sequen")) ? (int?)null
                                                                 : Convert.ToInt32(lab.Field <string>("Sequen")),
                                        location = lab.Field <string>("CTHOS_CDE"),
                                        status = lab.Field <string>("Status") == "Executed" ? 'E'
                                                                    : lab.Field <string>("Status") == "D/C (Discontinued)" ? 'D'
                                                                    : 'I',
                                        mhs_id = m == null ? (int?)null : m.mainid,
                                        mhs_ename = m == null ? null : m.maindesc,
                                        mhs_tname = m == null ? null : m.maindesc
                                    }).ToList()
                                }).ToList()
                            }).ToList();
                        }
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                Class.globalCls.MessageError("GetCheckupLabCls", "ByGetCheckupLab", ex.Message);
                throw ex;
            }
        }