예제 #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;
            }
        }
예제 #2
0
        public bool GetInfo(int tpr_id)
        {
            try
            {
                using (InhCheckupDataContext cdc = new InhCheckupDataContext())
                {
                    trn_patient_regi patient_regis = cdc.trn_patient_regis.Where(x => x.tpr_id == tpr_id).FirstOrDefault();
                    string           hn            = patient_regis.trn_patient.tpt_hn_no;
                    using (Service.WS_TrakcareCls ws_trak = new Service.WS_TrakcareCls())
                    {
                        var info = ws_trak.GetPTInfoByHN(hn).AsEnumerable()
                                   .Select(x => new
                        {
                            PAPMI_No              = x.Field <string>("PAPMI_No"),
                            PAPMI_DOB             = x.Field <DateTime>("PAPMI_DOB"),
                            PAPMI_Name            = x.Field <string>("PAPMI_Name"),
                            PAPMI_Name2           = x.Field <string>("PAPMI_Name2"),
                            PAPMI_Name3           = x.Field <string>("PAPMI_Name3"),
                            PAPMI_Name5           = x.Table.Columns.Contains("PAPMI_Name5") ? x.Field <string>("PAPMI_Name5") : "",
                            PAPMI_Name6           = x.Table.Columns.Contains("PAPMI_Name6") ? x.Field <string>("PAPMI_Name6") : "",
                            PAPMI_Name7           = x.Table.Columns.Contains("PAPMI_Name7") ? x.Field <string>("PAPMI_Name7") : "",
                            PAPER_PrefLanguage_DR = x.Field <int>("PAPER_PrefLanguage_DR"),
                            PAPER_AgeYr           = x.Field <string>("PAPER_AgeYr"),
                            PAPER_AgeMth          = x.Field <string>("PAPER_AgeMth"),
                            PAPER_AgeDay          = x.Field <string>("PAPER_AgeDay"),
                            TTL_Desc              = x.Field <string>("TTL_Desc"),
                            CTSEX_Code            = x.Field <string>("CTSEX_Code"),
                            CTSEX_Desc            = x.Field <string>("CTSEX_Desc"),
                            PAPMI_DOB1            = x.Field <DateTime>("PAPMI_DOB1"),
                            PAPMI_DOB_TEXT        = x.Field <string>("papmi_dob_text"),
                            PAPER_StName          = x.Field <string>("PAPER_StName"),
                            CTZIP_Code            = x.Field <string>("CTZIP_Code"),
                            CTZIP_Desc            = x.Field <string>("CTZIP_Desc"),
                            CTNAT_Desc            = x.Field <string>("CTNAT_Desc"),
                            //addby  Artist 18/01/2016
                            Area     = x.Field <string>("Area"),
                            City     = x.Field <string>("City"),
                            Province = x.Field <string>("Province")
                        }).FirstOrDefault();

                        string[] dobText   = info.PAPMI_DOB_TEXT.Split('-');
                        string   dobString = "";
                        if (dobText.Count() == 3)
                        {
                            dobString = dobText[2] + "/" + dobText[1] + "/" + dobText[0];
                        }

                        patient_regis.trn_patient.tpt_dob_text    = dobString;
                        patient_regis.trn_patient.tpt_hn_no       = info.PAPMI_No;
                        patient_regis.trn_patient.tpt_dob         = info.PAPMI_DOB;
                        patient_regis.trn_patient.tpt_pre_name    = info.TTL_Desc;
                        patient_regis.trn_patient.tpt_first_name  = info.PAPMI_Name;
                        patient_regis.trn_patient.tpt_last_name   = info.PAPMI_Name2;
                        patient_regis.trn_patient.tpt_gender      = info.CTSEX_Code == "M" ? 'M' : 'F';
                        patient_regis.trn_patient.tpt_nation_desc = info.CTNAT_Desc;
                        //addby  Artist 18/01/2016
                        patient_regis.tpr_main_address   = info.PAPER_StName;
                        patient_regis.tpr_main_tumbon    = info.Area;
                        patient_regis.tpr_main_amphur    = info.City;
                        patient_regis.tpr_main_province  = info.Province;
                        patient_regis.tpr_other_address  = info.PAPER_StName;
                        patient_regis.tpr_other_tumbon   = info.Area;
                        patient_regis.tpr_other_amphur   = info.City;
                        patient_regis.tpr_other_province = info.Province;
                        //
                        patient_regis.tpr_main_zip_code  = info.CTZIP_Code;
                        patient_regis.tpr_other_zip_code = info.CTZIP_Code;

                        patient_regis.trn_patient.tpt_en_name1 = info.PAPMI_Name5;
                        patient_regis.trn_patient.tpt_en_name2 = info.PAPMI_Name6;
                        patient_regis.trn_patient.tpt_en_name3 = info.PAPMI_Name7;
                        //update image  add by m 08/05/2017 dd/mm/yyyy

                        patient_regis.trn_patient.tpt_image = new APITrakcare.GetPatientImageCls().GetImageByWS(info.PAPMI_No);
                        try
                        {
                            string tname    = string.IsNullOrEmpty(info.TTL_Desc) ? "" : info.TTL_Desc.Trim();
                            string fname    = string.IsNullOrEmpty(info.PAPMI_Name) ? "" : " " + info.PAPMI_Name.Trim();
                            string mname    = string.IsNullOrEmpty(info.PAPMI_Name3) ? "" : " " + info.PAPMI_Name3.Trim();
                            string lname    = string.IsNullOrEmpty(info.PAPMI_Name2) ? "" : " " + info.PAPMI_Name2.Trim();
                            string fullname = (tname + fname + mname + lname).Trim();
                            patient_regis.trn_patient.tpt_fullname  = fullname;
                            patient_regis.trn_patient.tpt_othername = fullname;
                        }
                        catch (Exception ex)
                        {
                            try
                            {
                                string tname    = string.IsNullOrEmpty(info.TTL_Desc) ? "" : info.TTL_Desc.Trim();
                                string fname    = string.IsNullOrEmpty(info.PAPMI_Name) ? "" : " " + info.PAPMI_Name.Trim();
                                string lname    = string.IsNullOrEmpty(info.PAPMI_Name2) ? "" : " " + info.PAPMI_Name2.Trim();
                                string fullname = (tname + fname + lname).Trim();
                                patient_regis.trn_patient.tpt_othername = fullname;
                            }
                            catch
                            {
                            }
                            Program.MessageError("GetDataFromTrakCare", "tpt_fullname", ex, false);
                        }

                        cdc.SubmitChanges();
                    }
                }
                return(true);
            }
            catch
            {
            }
            return(false);
        }