public bool InsertByVitalSignResult(int tpr_id, string user) { try { using (InhCheckupDataContext cdc = new InhCheckupDataContext()) { DateTime dateNow = Class.globalCls.GetServerDateTime(); var pregis = cdc.trn_patient_regis.Where(x => x.tpr_id == tpr_id).FirstOrDefault(); if (pregis != null) { int enrowid; int.TryParse(pregis.tpr_en_rowid, out enrowid); var vs = new APITrakcare.GetVitalSignCls().ByGetVitalSignByHN(pregis.trn_patient.tpt_hn_no); var vs3time = new Class.VitalSignCls().Get3time(vs, enrowid); var vsunits = new Class.VitalSignUnitCls().Get(); var visitdate = pregis.trn_patient_regis_detail != null && pregis.trn_patient_regis_detail.tpr_real_arrived_date != null ? pregis.trn_patient_regis_detail.tpr_real_arrived_date.Value.Date : pregis.tpr_arrive_date != null ? pregis.tpr_arrive_date.Value.Date : dateNow; InsertByVitalSignResult(ref pregis, vs3time, dateNow, user); var hdr = pregis.trn_basic_measure_hdrs.FirstOrDefault(); for (int i = vs3time.Count; i < hdr.trn_basic_measure_dtls.Count; i++) { if (hdr.trn_basic_measure_dtls[i].tbd_id == 0) { hdr.trn_basic_measure_dtls.Remove(hdr.trn_basic_measure_dtls[i]); } else { cdc.trn_basic_measure_dtls.DeleteOnSubmit(hdr.trn_basic_measure_dtls[i]); } } var sex = (char)pregis.trn_patient.tpt_gender; var ages = new LabClass.InterpretLabCls().calAge(pregis.trn_patient.tpt_dob.Value.Date, visitdate); var labvitalsigns = cdc.mst_labs.Where(x => x.mlb_type == 'C' && x.mlb_status == 'A').ToList(); var labconfig = new LabClass.GetLabConfigCls().GetByPaientLab(tpr_id); foreach (var lab in labvitalsigns) { var maplabspecial = new LabClass.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 = new LabClass.InterpretLabCls().GetResult(maplabspecial, labconfig, ages, sex); var rslab = new LabClass.InterpretLab { setcode = lab.mlb_lab_set, code = lab.mlb_code, name_en = lab.mlb_ename, name_th = lab.mlb_tname, seq = lab.mlb_chart_seq, mlr_id = rs.mlr_id, summary = rs.summary, result_en = rs.result_en, result_th = rs.result_th, result_jp = rs.result_jp, normalrange = rs.normalrange, unit = rs.unit, status = rs.status }; InsertLabVs(ref pregis, rslab, vs3time, vsunits, dateNow, user); } cdc.SubmitChanges(); new Class.GetVitalSignCLs().GetEyeExam(tpr_id, "TESTVS"); return(true); } else { return(false); } } } catch (Exception ex) { Class.globalCls.MessageError("VitalSignCls", "InsertByVitalSignResult", ex.Message); return(false); } }
public void GetEyeExam(int tpr_id, string username) { using (InhCheckupDataContext dbc = new InhCheckupDataContext()) { DateTime dateNow = globalCls.GetServerDateTime(); trn_patient_regi tpr = dbc.trn_patient_regis.Where(x => x.tpr_id == tpr_id).FirstOrDefault(); if (tpr != null) { var visitdate = tpr.trn_patient_regis_detail != null && tpr.trn_patient_regis_detail.tpr_real_arrived_date != null ? tpr.trn_patient_regis_detail.tpr_real_arrived_date.Value.Date : tpr.tpr_arrive_date != null ? tpr.tpr_arrive_date.Value.Date : dateNow; trn_eye_exam_hdr teh = dbc.trn_eye_exam_hdrs.Where(x => x.tpr_id == tpr_id).FirstOrDefault(); trn_basic_measure_hdr hdr = dbc.trn_basic_measure_hdrs.Where(x => x.tpr_id == tpr_id).FirstOrDefault(); trn_patient_event mvt = dbc.trn_patient_events.Where(x => x.tpr_id == tpr_id && x.mst_event.mvt_code == "EM").FirstOrDefault(); if (mvt != null) { hdr.tbm_glass_or_contact = string.IsNullOrEmpty(teh.teh_vision_le) == true && string.IsNullOrEmpty(teh.teh_vision_out_le) == false ? 'Y' : 'N'; hdr.tbm_color_blind = teh.teh_color_vision == null ? (char?)null : (char?)teh.teh_color_vision; //tbm_vision_lvisual_with_lens if (teh.teh_vision_le == null && teh.teh_vision_out_llens == null) { hdr.tbm_vision_lvisual_with_lens = null; } else if (teh.teh_vision_le != null) { if (teh.teh_vision_le.Contains("20/")) { hdr.tbm_vision_lvisual_with_lens = findEyeValue(teh.teh_vision_le); } else { hdr.tbm_vision_lvisual_with_lens = teh.teh_vision_le; } } else if (teh.teh_vision_out_llens != null) { if (teh.teh_vision_out_llens.Contains("20/")) { hdr.tbm_vision_lvisual_with_lens = findEyeValue(teh.teh_vision_out_llens); } else { hdr.tbm_vision_lvisual_with_lens = teh.teh_vision_out_llens.ToString(); } } //tbm_vision_rvisual_with_lens if (teh.teh_vision_re == null && teh.teh_vision_out_rlens == null) { hdr.tbm_vision_rvisual_with_lens = null; } else if (teh.teh_vision_re != null) { if (teh.teh_vision_re.Contains("20/")) { hdr.tbm_vision_rvisual_with_lens = findEyeValue(teh.teh_vision_re); } else { hdr.tbm_vision_rvisual_with_lens = teh.teh_vision_re; } } else if (teh.teh_vision_out_llens != null) { if (teh.teh_vision_out_rlens.Contains("20/")) { hdr.tbm_vision_rvisual_with_lens = findEyeValue(teh.teh_vision_out_rlens); } else { hdr.tbm_vision_rvisual_with_lens = teh.teh_vision_out_rlens.ToString(); } } hdr.tbm_vision_lvisual_out_lens = teh.teh_vision_out_le == null ? null : teh.teh_vision_out_le.Contains("20/") ? findEyeValue(teh.teh_vision_out_le) : null; hdr.tbm_vision_rvisual_out_lens = teh.teh_vision_out_re == null ? null : teh.teh_vision_out_re.Contains("20/") ? findEyeValue(teh.teh_vision_out_re) : null; // } dbc.SubmitChanges(); var labconfig = new LabClass.GetLabConfigCls().GetByPaientLab(tpr_id); trn_patient tpt = dbc.trn_patients.Where(x => x.tpt_id == tpr.tpt_id).FirstOrDefault(); var ages = new LabClass.InterpretLabCls().calAge(tpt.tpt_dob.Value.Date, visitdate); var sex = Convert.ToChar(tpt.tpt_gender.ToString()); mst_lab lab = dbc.mst_labs.Where(x => x.mlb_type == 'C' && x.mlb_status == 'A' && x.mlb_code == "VS001").FirstOrDefault(); var maplabspecial = new LabClass.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 = false, valuetype = lab.mlb_value_type, status = 'E' }; var rs = new LabClass.InterpretLabCls().GetResult(maplabspecial, labconfig, ages, sex); var rslab = new LabClass.InterpretLab { setcode = lab.mlb_lab_set, code = lab.mlb_code, name_en = lab.mlb_ename, name_th = lab.mlb_tname, seq = lab.mlb_chart_seq, mlr_id = rs.mlr_id, summary = rs.summary, result_en = rs.result_en, result_th = rs.result_th, result_jp = rs.result_jp, normalrange = rs.normalrange, unit = rs.unit, status = rs.status }; var labvs = tpr.trn_patient_lab_vitalsigns.Where(x => x.tplv_lab_code == maplabspecial.code && x.tpr_id == tpr_id).FirstOrDefault(); if (labvs != null) { labvs.tplv_summary = rslab.summary == null ? null : rslab.summary.ToString(); labvs.tplv_lab_name_th = rslab.name_th; labvs.tplv_lab_name_en = rslab.name_en; labvs.tplv_lab_result_th = rslab.result_th; labvs.tplv_lab_result_en = rslab.result_en; labvs.tplv_lab_result_jp = rslab.result_jp; labvs.tplv_normal_range = rslab.normalrange; labvs.tplv_update_by = username; labvs.tplv_update_date = dateNow; } } try { dbc.SubmitChanges(); } catch (Exception ex) { Class.globalCls.MessageError("GetVitalSignCls", "GetEyeExam", ex.Message); throw ex; } // } } } }