public List <CheckupLab> Get(string hn, DateTime dateFrom, DateTime dateTo) { try { using (Service.WS_TrakcareCls ws = new Service.WS_TrakcareCls()) { var result = ws.GetCheckupLab(hn, dateFrom.ToString("yyyy-MM-dd"), dateTo.ToString("yyyy-MM-dd")).AsEnumerable(); return(result.Select(x => new CheckupLab { rowid = x.Field <string>("EPVISVisitNumber"), hn = x.Field <string>("DBT_CDE"), en = x.Field <string>("EPI_NO"), age = Convert.ToInt32(x.Field <string>("EPVIS_AGE")), sex = x.Field <string>("EPVIS_SEX") == "Male" ? "M" : x.Field <string>("EPVIS_SEX") == "Female" ? "F" : "", lab_date = new DateTime( Convert.ToInt32(x.Field <string>("EPIVISDateOfCollection").Substring(0, 4)), Convert.ToInt32(x.Field <string>("EPIVISDateOfCollection").Substring(5, 2)), Convert.ToInt32(x.Field <string>("EPIVISDateOfCollection").Substring(8, 2)), (int)(Convert.ToInt32(x.Field <string>("EPIVISTimeOfCollection")) / 60), (int)(Convert.ToInt32(x.Field <string>("EPIVISTimeOfCollection")) % 60), 0 ), head_lab_code = x.Field <string>("CTTS_CDE"), head_lab_desc = x.Field <string>("CTTS_NME"), lab_code = x.Field <string>("CTTC_CDE"), lab_desc = x.Field <string>("CTTC_DES"), lab_value_number = x.Field <string>("CTTC_RSL_FMT").Contains("N") && x.Field <string>("TST_DTA").Trim().Length > 0 ? x.Field <string>("TST_DTA").Trim().Substring(0, 1) == "." ? "0" + x.Field <string>("TST_DTA") : x.Field <string>("TST_DTA") : x.Field <string>("TST_DTA"), lab_value_string = x.Field <string>("RSL") == null || x.Field <string>("RSL").Trim() == "" ? null : x.Field <string>("RSL").Trim(), lab_unit = x.Field <string>("CTTC_UNT"), lab_range = x.Field <string>("NML"), lab_hl = x.Field <string>("HL") == "H" ? 1 : x.Field <string>("HL") == "L" ? -1 : 0, lab_frs = x.Field <string>("CTTC_RSL_FMT").Contains("N") ? 1 : x.Field <string>("CTTC_RSL_FMT") == "S" ? 2 : x.Field <string>("CTTC_RSL_FMT") == "X" ? 0 : -1, status = x.Field <string>("Status") == "Executed" ? 'E' : 'I', site_code = x.Field <string>("CTHOS_CDE"), lab_seq = (x.Field <string>("Sequen") == null || x.Field <string>("Sequen") == "") ? (int?)null : !IsNumeric(x.Field <string>("Sequen")) ? (int?)null : Convert.ToInt32(x.Field <string>("Sequen")) }).ToList()); } } catch (Exception ex) { throw ex; } }
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; } }
public static void retrieveLabToPatientLab(List <string> LabCode, int tpr_id) { try { using (InhCheckupDataContext cdt = new InhCheckupDataContext()) { trn_patient_regi tpr = cdt.trn_patient_regis.Where(x => x.tpr_id == tpr_id).FirstOrDefault(); using (Service.WS_TrakcareCls ws = new Service.WS_TrakcareCls()) { // get lab code ที่ไม่มีใน trn_patient_lab check by en var _labCode = LabCode.Where(x => !(tpr.trn_patient_labs.Where(y => y.tpl_en_no == tpr.tpr_en_no && LabCode.Contains(y.tpl_lab_no)) .Select(y => y.tpl_lab_no)).Contains(x)); // // get จาก web service แล้ว insert to trn_patient_lab ตรงๆ ไม่ผ่าน tmp // insert เฉพาะ lab ที่ต้องการและ ยังไม่เคย insert to trn_patient_lab DateTime date = Program.GetServerDateTime(); var result = ws.GetCheckupLab(tpr.trn_patient.tpt_hn_no, date.AddMonths(-1).ToString("yyyy-MM-dd"), date.ToString("yyyy-MM-dd")).AsEnumerable(); List <trn_patient_lab> tpl = result.Where(x => x.Field <string>("EPI_NO") == tpr.tpr_en_no && _labCode.Contains(x.Field <string>("CTTC_CDE"))) .Select(x => new trn_patient_lab { tpr_id = tpr_id, tpl_rowid = x.Field <string>("EPVISVisitNumber"), tpl_hn_no = x.Field <string>("DBT_CDE"), tpl_en_no = x.Field <string>("EPI_NO"), tpl_patient_age = Convert.ToInt32(x.Field <string>("EPVIS_AGE")), tpl_patient_sex = x.Field <string>("EPVIS_SEX") == "Male" ? "M" : x.Field <string>("EPVIS_SEX") == "Female" ? "F" : "", tpl_lab_date = new DateTime( Convert.ToInt32(x.Field <string>("EPIVISDateOfCollection").Substring(0, 4)), Convert.ToInt32(x.Field <string>("EPIVISDateOfCollection").Substring(5, 2)), Convert.ToInt32(x.Field <string>("EPIVISDateOfCollection").Substring(8, 2)), (Convert.ToInt32(x.Field <string>("EPIVISTimeOfCollection")) / 60), (Convert.ToInt32(x.Field <string>("EPIVISTimeOfCollection")) % 60), 0 ), tpl_head_lab_no = x.Field <string>("CTTS_CDE"), tpl_head_lab = x.Field <string>("CTTS_NME"), tpl_lab_no = x.Field <string>("CTTC_CDE"), tpl_lab_name = x.Field <string>("CTTC_DES"), tpl_lab_value = x.Field <string>("TST_DTA"), tpl_lab_unit = x.Field <string>("CTTC_UNT"), tpl_lab_range = x.Field <string>("NML"), tpl_lab_rsl = x.Field <string>("RSL"), tpl_lab_hl = x.Field <string>("HL") == "H" ? 1 : x.Field <string>("HL") == "L" ? -1 : 0, tpl_lab_frs = x.Field <string>("CTTC_RSL_FMT") == "N" ? 1 : x.Field <string>("CTTC_RSL_FMT") == "S" ? 2 : -1, tpl_status = x.Field <string>("Status") == "" ? 'E' : 'I', tpl_mhs_id = cdt.mst_hpc_sites.Where(y => y.mhs_code == x.Field <string>("CTHOS_CDE")).Select(y => y.mhs_id).FirstOrDefault(), tpl_mhs_tname = cdt.mst_hpc_sites.Where(y => y.mhs_code == x.Field <string>("CTHOS_CDE")).Select(y => y.mhs_tname).FirstOrDefault(), tpl_mhs_ename = cdt.mst_hpc_sites.Where(y => y.mhs_code == x.Field <string>("CTHOS_CDE")).Select(y => y.mhs_ename).FirstOrDefault(), tpl_create_date = Program.GetServerDateTime(), tpl_update_date = Program.GetServerDateTime(), tpl_lab_result_seq = x.Field <int>("sequen") }).ToList(); if (tpl.Count > 0) { cdt.trn_patient_labs.InsertAllOnSubmit(tpl); cdt.SubmitChanges(); } } } } catch (Exception ex) { throw new Exception(ex.Message); } }