tijian_tieying/web/dccdc/Controllers/SummaryController.cs

721 lines
30 KiB
C#
Raw Normal View History

2025-02-20 12:14:39 +08:00
using dccdc.BLL;
using dccdc.DAL;
using dccdc.Models;
using ICSharpCode.SharpZipLib.GZip;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
namespace dccdc.Controllers
{
public class SummaryController : Controller
{
// GET: Summary
public ActionResult Index()
{
return View();
}
public JsonResult getData(string start, string end, string where, string sort)
{
if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end) || string.IsNullOrEmpty(sort))
return Json(null);
var bll = new occupation_reportBll();
var result = bll.GetAllList(start, end, where, sort);
return Json(new { Rows = result });
}
public ActionResult Add(string id)
{
occupation_reportModel model;
if (string.IsNullOrEmpty(id))
{
//2024-01-06 xulu 添加报告时间,默认当天
model = new occupation_reportModel() { expersion_disease = "0", other_disease = "0", report_status = "已编制", report_date= DateTime.Now.ToString("yyyy-MM-dd") };
}
else
{
model = new occupation_reportBll().GetAllList(id).First();
}
return View(model);
}
[HttpPost]
public ActionResult Add(occupation_reportModel model)
{
ModelState.Remove("id");
occupation_reportBll bll = new occupation_reportBll();
if (!ModelState.IsValid)
{
var errors = ModelState.Values.SelectMany(v => v.Errors);
return View(model);
}
ERPUser user = Session["loginUser"] as Models.ERPUser;
model.report_user_name = user.ID.ToString();
model.report_person = user.UserName;
//20240106 xulu 报告日期根据医生填写保存
//model.report_date = DateTime.Now.ToString("yyyy-MM-dd");
return Json(bll.save(model));
}
public ActionResult Del(string id)
{
occupation_reportBll bll = new occupation_reportBll();
return Json(bll.delete(id));
}
public ActionResult changeStatus(string id, string sort, string descript)
{
occupation_reportBll bll = new occupation_reportBll();
return Json(bll.changeStatus(id, sort, descript, Session["loginUser"] as Models.ERPUser));
}
public string getCount(string personids,string iType)
{
if (string.IsNullOrEmpty(personids))
return "";
//2023-12-11 xulu 无用,暂时注释
//Dictionary<string, int> hazard = new Dictionary<string, int>();
var bll = new occupation_reportBll();
//获取登记(含对应复检)记录
var result = bll.GetRegesite(personids.TrimStart(',').TrimEnd(','));
//获取结果记录
//var result2 = bll.GetRegesiteResult(personids.TrimStart(',').TrimEnd(','));
int sort1 = 0;
int sort2 = 0;
int sort3 = 0;
int sort4 = 0;
int sort5 = 0;
//string zj3 = "";
foreach (ProfessionalExamRegisterModel model in result)
{
//2023-12-11 xulu 无用,暂时注释
//zj3 += model.hazards_alias + "(" + model.status + ")" + "(" + model.hazard_type_names + ")" + "(1人)" + new occupation_reportBll().GetGroups(model.check_item_ids.TrimStart(',').TrimEnd(',')) + "\r\n";
/*if (string.IsNullOrEmpty(model.physical_num_old))
{
string[] key = new string[]{ };
if(!string.IsNullOrEmpty(model.hazards))
key = model.hazards.TrimStart(',').TrimEnd(',').Split(',');
foreach (string h in key)
{
if (hazard.Keys.Contains(h))
hazard[h]++;
else
hazard.Add(h, 1);
}
}*/
if (model.resultids.Contains("1"))
sort1++;
if (model.resultids.Contains("2"))
sort2++;
if (model.resultids.Contains("3"))
sort3++;
if (model.resultids.Contains("4"))
sort4++;
if (model.resultids.Contains("5"))
sort5++;
}
//2023-12-11 xulu 无用,暂时注释
/* string zj1 = "";
string hazards = "";
foreach (string h in hazard.Keys)
{
zj1 += "备注:接触" + h + "的有" + hazard[h] + "人次。\r\n";
hazards += h + ",";
}*/
//体检结果总结
/*string zj2 = "一、本次职业健康检查" + result.Where(t => string.IsNullOrEmpty(t.physical_num_old)).Count() + "人。" +
"\r\n本次职业健康检查未见明显异常" + result.Where(t => t.resultids.Contains("1")).Count() + "人。" +
"\r\n本次职业健康检查发现其他疾病或异常" + result.Where(t => t.resultids.Contains("2")).Count() + "人。" +
"\r\n本次职业健康检查发现与目标疾病相关的异常项目需复查" + result.Where(t => string.IsNullOrEmpty(t.physical_num_old) && t.resultids.Contains("3")).Count() + "人。" +
"\r\n本次职业健康检查发现疑似职业病" + sort4 + "人。" +
"\r\n本次职业健康检查发现职业禁忌证" + sort5 + "人。";*/
string strZY = "。\r\n";
string strZYJJZ = "。\r\n";
string strFC = "。\r\n";
string strQT = "。\r\n";
string strZC = "。\r\n";
string zj2 = "";
//20240106 xulu itype=1职业报告
if (iType == "1")
{
if (sort4 != 0)
{
strZY = "建议单位出具职业史证明到XX职业病诊断机构进行职业病观察和诊断确诊。名单详见附表1及个体报告书。\r\n";
}
zj2 = "1、发现疑似职业病病人" + sort4 + "人" + strZY;
if (sort5 != 0)
{
strZYJJZ = " 建议脱离XX作业。名单详见附表2及个体报告书。\r\n";
}
zj2 += "2、发现职业禁忌证" + sort5 + "人" + strZYJJZ;
if (result.Where(t => !string.IsNullOrEmpty(t.physical_num_old) && t.resultids.Contains("3")).Count() != 0)
{
strFC = ",建议XX时间到XX机构复查XXX项目。名单详见附表3及个体报告书。\r\n";
}
zj2 += "3、发现需要复查人员" + result.Where(t => !string.IsNullOrEmpty(t.physical_num_old) && t.resultids.Contains("3")).Count() + "人" + strFC;
if (result.Where(t => t.resultids.Contains("2")).Count() != 0)
{
strQT = "不属于本次职业健康检查目标疾病建议到相关专科医院诊治。名单详见附表4及个体报告书。\r\n";
}
zj2 += "4、发现其他疾病或异常结果人员" + result.Where(t => t.resultids.Contains("2")).Count() + "人" + strQT;
if (result.Where(t => t.resultids.Contains("1")).Count() != 0)
{
strZC = "。名单详见附表5及个体报告书。\r\n";
}
//不包含复检正常人员
zj2 += "5、本次职业健康检查未见异常" + result.Where(t => t.resultids.Contains("1") && t.register_type.Contains("正常登记")).Count() + "人" + strZC;
}
//itype=2常规报告
else if(iType == "2")
{
if (result.Where(t => t.resultids.Contains("1")).Count() != 0)
{
strZC = "。名单详见附表1及个体报告书。\r\n";
}
//不包含复检正常人员
zj2 += "1、本次健康检查未见异常" + result.Where(t => t.resultids.Contains("1") && t.register_type.Contains("正常登记")).Count() + "人" + strZC;
if (result.Where(t => t.resultids.Contains("2")).Count() != 0)
{
strQT = "建议到相关专科医院诊治。名单详见附表2及个体报告书。\r\n";
}
zj2 += "2、发现其他疾病或异常结果人员" + result.Where(t => t.resultids.Contains("2")).Count() + "人" + strQT;
if (result.Where(t => !string.IsNullOrEmpty(t.physical_num_old) && t.resultids.Contains("3")).Count() != 0)
{
strFC = ",建议XX时间到XX机构复查XXX项目。名单详见附表3及个体报告书。\r\n";
}
zj2 += "3、发现需要复查人员" + result.Where(t => !string.IsNullOrEmpty(t.physical_num_old) && t.resultids.Contains("3")).Count() + "人" + strFC;
}
//2023-10-31 xulu 获取有害因素、体检项目
//List<ProfessionalExamRegisterModel> hazard_factors = new occupation_reportBll().getRegisterById(personids.Trim(','));
string str = "";
string str1 = "";
if (iType == "1")
{
foreach (var r in result)
{
//2023-12-08 xulu 添加不为空判断
if (r.hazards_text != null)
{
r.hazards_text = r.hazards_text.Replace('、', ',');
r.hazards_text = r.hazards_text.Replace('', ',');
str += r.hazards_text + ",";
}
}
var sss = str.Split(',').Distinct().ToArray();
str1 = String.Join(",", sss);
}
List<ExamGroupMaintainModel> list = new occupation_reportDal().getExamGroupByIds(personids.Trim(','));
string items = "";
foreach(var o in list)
{
items += o.team_name + ",";
}
//var aaa = new { zj1 = zj1, zj2 = zj2, zj3 = zj3, hazards = hazards, hazards_text = str1, check_items= items };
var aaa = new { zj2 = zj2, hazards_text = str1, check_items= items };
//return Json(aaa);
/*return new JsonResult()
{
Data = aaa,
MaxJsonLength = int.MaxValue,
ContentType = "application/json"
};*/
return JsonConvert.SerializeObject(aaa, Formatting.None);
}
public ActionResult register()
{
//20240106 xulu 分析常规报告时,不根据在岗状态分析
var items = new List<SelectListItem> { new SelectListItem { Text = "----请选择----", Value = "" } };
List<JobsStateMaintainModel> jobs = new JobsStateMaintainBll().GetAllList("", "是");
items.AddRange(jobs.Select(item => new SelectListItem { Text = item.jobs_state, Value = item.id.ToString() }));
ViewData["jobs"] = new SelectList(items, "Value", "Text");
return View();
}
public string getRegister(string start, string end, string where, string sort)
{
if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end))
return Newtonsoft.Json.JsonConvert.SerializeObject(null);
var bll = new occupation_reportBll();
var result = bll.GetRegesite(start, end, where, sort);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Rows = result });
}
public JsonResult getRegister2(string personids)
{
if (string.IsNullOrEmpty(personids))
return Json(null);
var bll = new occupation_reportBll();
var result = bll.GetRegesite(personids.TrimStart(',').TrimEnd(','));
return Json(new { Rows = result });
}
public string getRegesitePR(string personids)
{
if (string.IsNullOrEmpty(personids))
return "";
var bll = new occupation_reportBll();
//2023-12-12 xulu 获取检查项参考值
var result = bll.GetRegesitePR1(personids.TrimStart(',').TrimEnd(','), true);
return JsonConvert.SerializeObject(new { Rows = result }, Formatting.None);
}
public JsonResult getHazard1(string personids)
{
if (string.IsNullOrEmpty(personids))
return Json(null);
var bll = new occupation_reportBll();
var result = bll.GetTargetFactor(personids.TrimStart(',').TrimEnd(','));
//var jobid = bll.GetJobId(result[0].status);
//foreach (ProfessionalExamRegisterModel model in result)
//{
// model.hazard_ids
//}
return Json(new { Rows = result });
}
public JsonResult getHazard2(string personids)
{
if (string.IsNullOrEmpty(personids))
return Json(null);
var bll = new occupation_reportBll();
var result = bll.GetContraindicatFactor(personids.TrimStart(',').TrimEnd(','));
return Json(new { Rows = result });
}
public string getRegister3(int page, int pagesize, string personids)
{
if (string.IsNullOrEmpty(personids))
return "";
var bll = new occupation_reportBll();
string[] strids = personids.Split(',');
//2023-12-12 xulu 添加分页
var result = bll.GetRegesite(page, pagesize,personids.TrimStart(',').TrimEnd(','));
var result2 = bll.GetRegesitePR(personids.TrimStart(',').TrimEnd(','), false);
foreach (var m in result)
{
if (m.procedure_status == "复检")
{
}
else
{
m.procedure_status = "非复检";
}
if (result2.Where(t => t.qualified == "不合格" && t.person_id.ToString() == m.id).Count() > 0)
{
m.procedure_status += "|有不合格";
}
if (result2.Where(t => t.deficiency == "缺项" && t.person_id.ToString() == m.id).Count() > 0)
{
m.procedure_status += "|有缺项";
}
}
return JsonConvert.SerializeObject(new { Total = strids.Length, Rows = result }, Formatting.None);
}
public JsonResult getRegisterResult(string personids)
{
if (string.IsNullOrEmpty(personids))
return Json(null);
var bll = new occupation_reportBll();
var result = bll.GetRegesiteResult(personids.TrimStart(',').TrimEnd(','));
return Json(new { Rows = result });
}
//检查及评价依据
public ActionResult getYj()
{
return View();
}
public JsonResult getYjData()
{
var bll = new SummaryreportBasisMaintainBll();
var result = bll.GetAllList("", "是");
return Json(new { Rows = result });
}
//处理意见及建议
public ActionResult getJy()
{
return View();
}
public JsonResult getJyData()
{
var bll = new summaryreport_suggest_maintainBll();
var result = bll.GetAllList("", "是");
return Json(new { Rows = result });
}
public string personids = "";
public string hazards = "";
//单项分析
public JsonResult getFx2(string personids, string hazards)
{
System.Web.HttpContext.Current.Session["personids"] = personids;
System.Web.HttpContext.Current.Session["hazards"] = hazards;
ViewData["i"] = 0;
return Json(new { d = "1" });
}
public ActionResult getFx()
{
ViewData["personids"] = Session["personids"];
ViewData["hazards"] = Session["hazards"];
ViewData["i"] = 0;
System.Web.HttpContext.Current.Session["personids"] = null;
System.Web.HttpContext.Current.Session["hazards"] = null;
return View();
}
public JsonResult getFxData(string hazards, string personids)
{
if (string.IsNullOrEmpty(hazards) || string.IsNullOrEmpty(personids))
return Json("");
//return Json(null);
var bll = new occupation_reportBll();
//获取登记记录
var result = bll.GetRegesite(personids.TrimStart(',').TrimEnd(','));
//获取检验项目 结果列表
var result2 = bll.GetRegesitePR(personids.TrimStart(',').TrimEnd(','), false);
Dictionary<string, int> p1 = new Dictionary<string, int>();
Dictionary<string, int> p2 = new Dictionary<string, int>();
Dictionary<string, int> p3 = new Dictionary<string, int>();
Dictionary<string, int> p4 = new Dictionary<string, int>();
Dictionary<string, int> p5 = new Dictionary<string, int>();
Dictionary<string, int> p6 = new Dictionary<string, int>();
int sort0 = 0;
int sort1 = 0;
int sort2 = 0;
int sort3 = 0;
int sort4 = 0;
int sort5 = 0;
foreach (ProfessionalExamRegisterModel model in result)
{
if (!model.hazards.Split(',').Contains(hazards))
continue;
if (string.IsNullOrEmpty(model.physical_num_old))
{
sort0++;
//复查此处貌似bugphysical_num_old为空的不可能是复检。应放到下面zyk 20230621
if (model.resultids.Contains("3"))
sort3++;
}
//目前未见异常
if (model.resultids.Contains("1"))
sort1++;
//其他疾病或异常
if (model.resultids.Contains("2"))
sort2++;
//疑似职业病
if (model.resultids.Contains("4"))
sort4++;
//职业禁忌证
if (model.resultids.Contains("5"))
sort5++;
if (model.otherProject != null)
{
string[] ppss = model.otherProject.Split(new string[] { "###" }, StringSplitOptions.RemoveEmptyEntries);
if (ppss.Length > 0)
{
//此处可能有bugpps[1]不是项目名称,是建议。 zyk 20230621
string[] pps = ppss[0].Split(new char[] { ',', '、' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string key in pps)
if (p3.Keys.Contains(key))
{
p3[key]++;
}
else
{
p3.Add(key, 1);
}
}
}
if (model.fujianProject != null)
{
string[] ppss = model.fujianProject.Split(new string[] { "###" }, StringSplitOptions.RemoveEmptyEntries);
if (ppss.Length > 0)
{
//此处可能有bugpps[1]不是项目名称,是建议。 zyk 20230621
string[] pps = ppss[0].Split(new char[] { ',', '、' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string key in pps)
if (p4.Keys.Contains(key))
{
p4[key]++;
}
else
{
p4.Add(key, 1);
}
}
}
if (model.zhiyeProject != null)
{
string[] ppss = model.zhiyeProject.Split(new string[] { "###" }, StringSplitOptions.RemoveEmptyEntries);
if (ppss.Length > 0)
{
//此处可能有bugpps[1]不是项目名称,是建议。 zyk 20230621
string[] pps = ppss[0].Split(new char[] { ',', '、' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string key in pps)
if (p5.Keys.Contains(key))
{
p5[key]++;
}
else
{
p5.Add(key, 1);
}
}
}
if (model.yisiProject != null)
{
string[] ppss = model.yisiProject.Split(new string[] { "###" }, StringSplitOptions.RemoveEmptyEntries);
if (ppss.Length > 0)
{
//此处可能有bugpps[1]不是项目名称,是建议。 zyk 20230621
string[] pps = ppss[0].Split(new char[] { ',', '、' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string key in pps)
if (p6.Keys.Contains(key))
{
p6[key]++;
}
else
{
p6.Add(key, 1);
}
}
}
List<ProfessionalExamProjectResultModel> result3 = result2.Where(t => t.person_id == Convert.ToInt32(model.id)).ToList();
List<string> have = new List<string>();
//result3是当前体检人员做的所有项目不是异常项目===
foreach (var model2 in result3)
{
//异常项目
if (p1.Keys.Contains(model2.project_name + "-" + model2.team_name))
{
p1[model2.project_name + "-" + model2.team_name]++;
}
else
{
p1.Add(model2.project_name + "-" + model2.team_name, 1);
}
//异常小组
if (p2.Keys.Contains(model2.team_name))
{
if (!have.Contains(model2.team_name))
{
p2[model2.team_name]++;
have.Add(model2.team_name);
}
}
else
{
p2.Add(model2.team_name, 1);
have.Add(model2.team_name);
}
}
}
string sort11 = Convert.ToInt32(sort1 * 100 / sort0).ToString() + "%";
string sort22 = Convert.ToInt32(sort2 * 100 / sort0).ToString() + "%";
string sort33 = Convert.ToInt32(sort3 * 100 / sort0).ToString() + "%";
string sort44 = Convert.ToInt32(sort4 * 100 / sort0).ToString() + "%";
string sort55 = Convert.ToInt32(sort5 * 100 / sort0).ToString() + "%";
List<dicModel> p11 = new List<dicModel>();
List<dicModel> p22 = new List<dicModel>();
List<dicModel> p33 = new List<dicModel>();
List<dicModel> p44 = new List<dicModel>();
List<dicModel> p55 = new List<dicModel>();
List<dicModel> p66 = new List<dicModel>();
foreach (string key in p1.Keys)
{
p11.Add(new dicModel { key = key, value = p1[key].ToString() });
}
foreach (string key in p2.Keys)
{
p22.Add(new dicModel { key = key, value = p2[key].ToString() });
}
foreach (string key in p3.Keys)
{
p33.Add(new dicModel { key = key, value = p3[key].ToString() });
}
foreach (string key in p4.Keys)
{
p44.Add(new dicModel { key = key, value = p4[key].ToString() });
}
foreach (string key in p5.Keys)
{
p55.Add(new dicModel { key = key, value = p5[key].ToString() });
}
foreach (string key in p6.Keys)
{
p66.Add(new dicModel { key = key, value = p6[key].ToString() });
}
var aaa = new { sort0 = sort0, sort1 = sort1, sort2 = sort2, sort3 = sort3, sort4 = sort4, sort5 = sort5, sort11 = sort11, sort22 = sort22, sort33 = sort33, sort44 = sort44, sort55 = sort55, p11 = new { Rows = p11 }, p22 = new { Rows = p22 }, p33 = new { Rows = p33 }, p44 = new { Rows = p44 }, p55 = new { Rows = p55 }, p66 = new { Rows = p66 } };
return Json(aaa);
}
//根据报表编码获取汇总报告数据
[AllowAnonymous]
public JsonResult getReportByNum(string report_num)
{
if (string.IsNullOrEmpty(report_num))
return Json(null);
return Json(new occupation_reportBll().getReportByNum(report_num), JsonRequestBehavior.AllowGet);
}
//根据人员ID获取异常的体检结果
[AllowAnonymous]
public JsonResult getTjjgById(string pid)
{
if (string.IsNullOrEmpty(pid))
return Json(null);
return Json(new occupation_reportBll().getTjjgById(pid), JsonRequestBehavior.AllowGet);
}
//根据人员编码获取人员列表
[AllowAnonymous]
public string getRegisterByReportId(string reportId)
{
//2023-12-08 xulu 先根据report的id查询personids直接返回序列化的string
if (string.IsNullOrEmpty(reportId))
return "";
List<occupation_reportModel> list = new occupation_reportBll().GetAllList(reportId);
string ids = "";
if (list.Count > 0)
{
ids = list[0].person_ids.ToString();
}
return JsonConvert.SerializeObject(new occupation_reportBll().getRegisterById(ids.Trim(',')), Formatting.None);
}
//获取单位信息
[AllowAnonymous]
public JsonResult getDw(string dwmc)
{
if (string.IsNullOrEmpty(dwmc))
return Json(null);
return Json(new occupation_reportBll().getDw(dwmc), JsonRequestBehavior.AllowGet);
}
//获取化验项目参考表
[AllowAnonymous]
public string getHyxm(string reportId)
{
//2023-12-08 xulu 先根据report的id查询personids直接返回序列化的string
if (string.IsNullOrEmpty(reportId))
return "";
List<occupation_reportModel> list = new occupation_reportBll().GetAllList(reportId);
string ids = "";
if (list.Count > 0)
{
ids = list[0].person_ids.ToString();
}
string ss = ids.TrimStart(',').TrimEnd(',');
//string strIds = ids.Substring(1, ids.TrimEnd()).ToString();
//return Json(new occupation_reportBll().getHyxm(ss), JsonRequestBehavior.AllowGet);
return Newtonsoft.Json.JsonConvert.SerializeObject(new occupation_reportBll().getHyxm(ss));
}
//获取职业病危害因素
[AllowAnonymous]
public string getHazards(string reportId)
{
string str = "";
string str1 = "";
DataTable dt = new DataTable();
dt.Columns.Add("Hazards");
//2023-12-08 xulu 先根据report的id查询personids直接返回序列化的string
if (string.IsNullOrEmpty(reportId))
return "";
List<occupation_reportModel> list = new occupation_reportBll().GetAllList(reportId);
string ids = "";
if (list.Count > 0)
{
ids = list[0].person_ids.ToString();
}
var hazards = new occupation_reportBll().getRegisterById(ids.Trim(','));
foreach (var r in hazards)
{
str += r.hazards + ",";
}
var sss = str.Split(',').Distinct().ToArray();
foreach (var o in sss)
{
str1 += o + ',';
}
DataRow dr = dt.NewRow();
dr["Hazards"] = str1.Substring(0, str1.Length - 1).ToString();
dt.Rows.Add(dr);
return Newtonsoft.Json.JsonConvert.SerializeObject(dt);
}
//获取检查项目
[AllowAnonymous]
public string getJcxm(string str)
{
DataTable dt = new DataTable();
dt.Columns.Add("c1");
if (string.IsNullOrEmpty(str))
return "";
var s = str.Split('|');
foreach (var ss in s)
{
DataRow dr = dt.NewRow();
dr["c1"] = ss;
dt.Rows.Add(dr.ItemArray);
}
return new occupation_reportBll().getJcxm(dt.Rows[0]["c1"].ToString(), dt.Rows[1]["c1"].ToString());
}
//获取职业健康检查的目的
[AllowAnonymous]
public string getZyjkjc(string str)
{
if (string.IsNullOrEmpty(str))
return "";
string[] s = str.Split('|');
return new occupation_reportBll().getZyjkjc(s[0], s[1]);
}
}
public class dicModel
{
public string key { get; set; }
public string value { set; get; }
}
}