You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

904 lines
39 KiB

2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
  1. using Dapper;
  2. using Newtonsoft.Json.Converters;
  3. using Newtonsoft.Json;
  4. using Npgsql;
  5. using NPOI.SS.Formula.Functions;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data.Common;
  9. using System.Linq;
  10. using System.Net.Http.Headers;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Text.RegularExpressions;
  14. using Shentun.Peis.PatientRegisters;
  15. using Shentun.Peis.PersonnelTypes;
  16. using Shentun.Peis.MedicalTypes;
  17. using Shentun.Peis.CustomerOrgs;
  18. using Shentun.Peis.CustomerOrgGroups;
  19. using Shentun.Peis.CustomerReports;
  20. using Shentun.Peis.CustomerOrgGroupDetails;
  21. using Shentun.Peis.CustomerOrgRegisters;
  22. using Shentun.Peis.Enums;
  23. using Shentun.Peis.Patients;
  24. using Shentun.Peis.PlugIns.PatientRegisters;
  25. using Shentun.Peis.PlugIns.ImportPacsResults;
  26. namespace Shentun.Peis.PlugIns.Extensions.PatientRegisters.Qztl
  27. {
  28. public class ImportPatientRegisterPlugInsQztl : ImportPatientRegisterPlugInsBase
  29. {
  30. private string _hospitalId;
  31. private string _aesKEY;
  32. private string _year;
  33. private CustomerOrgDto _customerOrgDto;
  34. private CustomerOrgRegisterDto _customerOrgRegisterDto;
  35. private List<PersonnelTypeDto> _personnelTypes;
  36. private List<CustomerOrgGroupDto> _customerOrgGroupDtos;
  37. private string _answerWebApiUrl;
  38. public ImportPatientRegisterPlugInsQztl(Guid thirdInterfaceId) : base(thirdInterfaceId)
  39. {
  40. }
  41. public ImportPatientRegisterPlugInsQztl(string parmValue) : base(parmValue)
  42. {
  43. }
  44. public override async Task<List<string>> ImportPatientRegisterByCustomerOrgRegisterIdAsync(Guid customerOrgRegisterId)
  45. {
  46. CustomerOrgRegisterId = customerOrgRegisterId;
  47. if(CustomerOrgRegisterId == Guid.Empty)
  48. {
  49. throw new Exception("customerOrgRegisterId参数不能为空");
  50. }
  51. await LoginAsync();
  52. await InitAsync();
  53. var errorList = new List<string>();
  54. var qztlPatientRegisterFromInterface = await CallInterfaceServiceAsync();
  55. if (qztlPatientRegisterFromInterface == null)
  56. {
  57. return errorList;
  58. }
  59. //删除人员
  60. if (qztlPatientRegisterFromInterface.delIds != null)
  61. {
  62. foreach (var deleteUserId in qztlPatientRegisterFromInterface.delIds)
  63. {
  64. var error = deleteUserId;
  65. try
  66. {
  67. var patientRegister = await GetPatientRegisterByPlanUserId(deleteUserId);
  68. if (patientRegister == null)
  69. {
  70. continue;
  71. }
  72. if (patientRegister.CompleteFlag != PatientRegisterCompleteFlag.PreRegistration &&
  73. patientRegister.CompleteFlag != PatientRegisterCompleteFlag.Registration)
  74. {
  75. //已检人员不允许删除
  76. errorList.Add($"姓名:{patientRegister.PatientName},身份证号:{patientRegister.IdNo},已检不能删除");
  77. continue;
  78. }
  79. var patientRegisterInputDto = new PatientRegisterIdInputDto()
  80. {
  81. PatientRegisterId = patientRegister.PatientRegisterId
  82. };
  83. await CallAppServiceAsync<PatientRegisterIdInputDto, object>(
  84. "api/app/PatientRegister/DeleteById", patientRegisterInputDto);
  85. //发送答复通知
  86. var succesIds = new List<string>();
  87. var deleteIds = new List<string>();
  88. deleteIds.Add(deleteUserId);
  89. await AnswerOk(succesIds, deleteIds);
  90. }
  91. catch (Exception ex)
  92. {
  93. errorList.Add(error + ex.Message);
  94. continue;
  95. }
  96. }
  97. }
  98. if (qztlPatientRegisterFromInterface.plans == null)
  99. {
  100. return errorList;
  101. }
  102. //设置导入人员信息
  103. foreach (var patient in qztlPatientRegisterFromInterface.plans)
  104. {
  105. var error = $"姓名:{patient.personName},身份证:{patient.cardId}";
  106. try
  107. {
  108. //婚姻状况
  109. var maritalStatusId = ConvertMaritalStatus(patient.wedding);
  110. //人员类别
  111. var personnelType = ConvertPersonnelType(patient.tjJieduan);
  112. //性别
  113. var sexId = ConvertSex(patient.sex);
  114. //体检类别
  115. var medicalTypeName = patient.tjpcV;
  116. MedicalTypeDto medicalTypeDto = null;
  117. if (!string.IsNullOrWhiteSpace(medicalTypeName))
  118. {
  119. medicalTypeDto = await CallAppServiceAsync<DisplayNameInputDto, MedicalTypeDto>(
  120. "api/app/MedicalType/GetByDisplayName", new DisplayNameInputDto() { DisplayName = medicalTypeName });
  121. if (medicalTypeDto == null)
  122. {
  123. var createMedicalTypeDto = new CreateMedicalTypeDto()
  124. {
  125. DisplayName = medicalTypeName,
  126. };
  127. medicalTypeDto = await CallAppServiceAsync<CreateMedicalTypeDto, MedicalTypeDto>(
  128. "api/app/medical-type", new CreateMedicalTypeDto() { DisplayName = medicalTypeName });
  129. }
  130. }
  131. //职称
  132. var jobTitle = ConvertJobTitle(patient.gradeZwV);
  133. //职务
  134. var jobPost = ConvertJobPost(patient.tjTab1);
  135. string workTypeV = patient.workTypeV;
  136. if (string.IsNullOrWhiteSpace(workTypeV))
  137. {
  138. workTypeV = "";
  139. }
  140. else
  141. {
  142. workTypeV = "," + workTypeV;
  143. }
  144. jobPost = jobPost + workTypeV;
  145. if (!string.IsNullOrWhiteSpace(jobPost) && jobPost.Length >= 10)
  146. {
  147. jobPost = jobPost.Substring(0, 10);//只能存储10个汉字
  148. }
  149. //查找子单位是否存在,如存在获取子单位id,如果不存在这创建子单位
  150. var orgName = patient.orgName;
  151. var pos = orgName.IndexOf("_");
  152. orgName = orgName.Substring(0, pos);
  153. if (string.IsNullOrWhiteSpace(patient.mobile))
  154. {
  155. //青海省第五人民医院要强行设置为 11111111111
  156. }
  157. var customerOrgDtos = await CallAppServiceAsync<CustomerOrgIdInputDto, List<CustomerOrgDto>>(
  158. "api/app/CustomerOrg/GetChildCustomerOrgsById",
  159. new CustomerOrgIdInputDto() { CustomerOrgId = _customerOrgDto.Id });
  160. CustomerOrgDto customerOrgDto = null;
  161. if (customerOrgDtos != null && customerOrgDtos.Any())
  162. {
  163. customerOrgDto = customerOrgDtos.Where(o => o.DisplayName == orgName).FirstOrDefault();
  164. }
  165. if (customerOrgDto == null)
  166. {
  167. customerOrgDto = await CallAppServiceAsync<CreateCustomerOrgDto, CustomerOrgDto>(
  168. "api/app/customerorg/create", new CreateCustomerOrgDto()
  169. {
  170. MedicalCenterId = _customerOrgDto.MedicalCenterId,
  171. ParentId = _customerOrgDto.Id,
  172. DisplayName = orgName,
  173. ShortName = orgName,
  174. IsActive = 'Y',
  175. IsLock = 'Y'
  176. });
  177. }
  178. CustomerOrgGroupDto customerOrgGroupDto;
  179. if (patient.ifFj == 1)
  180. {
  181. //复检
  182. //加载单位分组信息
  183. _customerOrgGroupDtos = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, List<CustomerOrgGroupDto>>(
  184. "api/app/CustomerOrgGroup/GetListByCustomerOrgRegisterId"
  185. , new CustomerOrgRegisterIdInputDto() { CustomerOrgRegisterId = CustomerOrgRegisterId});
  186. customerOrgGroupDto = _customerOrgGroupDtos.Where(o => o.DisplayName == "复检").FirstOrDefault();
  187. if (customerOrgGroupDto == null)
  188. {
  189. throw new Exception("没有复检这个分组");
  190. }
  191. }
  192. else
  193. {
  194. List<string> groupNames = new List<string>();
  195. if (patient.ifGy == 1)
  196. {
  197. groupNames.Add("高原");
  198. }
  199. else if (patient.ifJk == 1)
  200. {
  201. groupNames.Add("健康");
  202. }
  203. else
  204. {
  205. throw new Exception("分组名称必须是高原或健康体检二选一");
  206. }
  207. if (patient.ifGt == 1)
  208. {
  209. groupNames.Add("高铁");
  210. }
  211. if (patient.ifWh == 1)
  212. {
  213. groupNames.Add("职害");
  214. }
  215. if (patient.ifCw == 1)
  216. {
  217. groupNames.Add("普速");
  218. }
  219. if (patient.ifMain == 1)
  220. {
  221. groupNames.Add("行车");
  222. }
  223. if (patient.ifCy == 1)
  224. {
  225. groupNames.Add("从业");
  226. }
  227. customerOrgGroupDto = await GetCustomerOrgGroup(groupNames, sexId, maritalStatusId);
  228. }
  229. //没有planuserid的自动设置planuserid
  230. var patientRegisters = await GetPatientRegisterByCustomerOrgRegisterIdWithIdNo(_customerOrgRegisterDto.Id, patient.cardId);
  231. var succesIds = new List<string>();
  232. var deleteIds = new List<string>();
  233. succesIds.Add(patient.id.ToString());
  234. bool IsNoPlanUserIdComplete = false;
  235. foreach (var patintRegister in patientRegisters)
  236. {
  237. //没有planUserId的更新planUserId
  238. if (string.IsNullOrWhiteSpace(patintRegister.Planuserid) && patintRegister.PatientName == patient.personName)
  239. {
  240. await UpdatePatientRegisterPlanUserId(patintRegister.PatientRegisterId, patient.id.ToString());
  241. await AnswerOk(succesIds, deleteIds);
  242. IsNoPlanUserIdComplete = true;
  243. }
  244. //已经登记了该PlanUserId的不再登记
  245. if (!string.IsNullOrWhiteSpace(patintRegister.Planuserid) && patintRegister.Planuserid == patient.id.ToString())
  246. {
  247. await AnswerOk(succesIds, deleteIds);
  248. IsNoPlanUserIdComplete = true;
  249. }
  250. }
  251. if (IsNoPlanUserIdComplete)
  252. {
  253. continue;
  254. }
  255. //获取病人ID
  256. var patientRegister = new CreatePatientRegisterDto()
  257. {
  258. MedicalCenterId = _customerOrgDto.MedicalCenterId,
  259. //PatientRegisterId = null,
  260. //PatientId = null,
  261. IsMaxMedicalTimes = 'Y',
  262. CompleteFlag = '0',
  263. CustomerOrgId = customerOrgDto.Id,
  264. CustomerOrgRegisterId = _customerOrgRegisterDto.Id,
  265. CustomerOrgGroupId = customerOrgGroupDto.Id,
  266. PatientName = patient.personName,
  267. SexId = sexId,
  268. Age = patient.age,
  269. MaritalStatusId = maritalStatusId,
  270. MobileTelephone = patient.mobile,
  271. Planuserid = patient.id.ToString(),
  272. IdNo = patient.cardId,
  273. //PersonnelTypeId = personnelType.Id,
  274. JobTitle = jobTitle,
  275. Remark = patient.remark,
  276. JobPost = jobPost,
  277. Remark2 = patient.tjOpinion,
  278. Remark3 = patient.fjOpinion,
  279. QztlIsFj = patient.ifFj == 1 ? 'Y' : 'N',
  280. QztlIsGt = patient.ifGt == 1 ? 'Y' : 'N',
  281. QztlIsWh = patient.ifWh == 1 ? 'Y' : 'N',
  282. QztlIsCw = patient.ifCw == 1 ? 'Y' : 'N',
  283. QztlIsMain = patient.ifMain == 1 ? 'Y' : 'N',
  284. QztlIsCy = patient.ifCy == 1 ? 'Y' : 'N',
  285. IsQztlImport = 'Y'
  286. };
  287. if (!string.IsNullOrWhiteSpace(patient.cardId))
  288. {
  289. var patientInfo = await CallAppServiceAsync<IdNoInputDto, PatientDto>(
  290. "api/app/patient/GetByIdNo",
  291. new IdNoInputDto()
  292. {
  293. IdNo = patient.cardId
  294. });
  295. if (patientInfo != null)
  296. {
  297. patientRegister.PatientId = patientInfo.Id;
  298. }
  299. }
  300. if (medicalTypeDto != null)
  301. {
  302. patientRegister.MedicalTypeId = medicalTypeDto.Id;
  303. }
  304. if (personnelType != null)
  305. {
  306. patientRegister.PersonnelTypeId = personnelType.Id;
  307. }
  308. if (patient.ifGy == 1)
  309. {
  310. patientRegister.QztlType = '0';
  311. }
  312. else if (patient.ifJk == 1) { }
  313. {
  314. patientRegister.QztlType = '1';
  315. }
  316. patientRegister.RegisterCheckAsbitems = new List<CreatePatientRegisterRegisterCheckAsbitem>();
  317. //获取分组信息
  318. var customerOrgGroupDetailOrAsbitemDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDetailOrAsbitemDto>>(
  319. "api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=" + customerOrgGroupDto.Id.ToString()
  320. , Guid.Empty, "get");
  321. if (!customerOrgGroupDetailOrAsbitemDtos.Any())
  322. {
  323. throw new Exception($"分组{customerOrgGroupDto.DisplayName}未包含项目");
  324. }
  325. foreach (var asbitem in customerOrgGroupDetailOrAsbitemDtos)
  326. {
  327. patientRegister.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
  328. {
  329. AsbitemId = asbitem.AsbitemId,
  330. StandardPrice = asbitem.Price,
  331. ChargePrice = asbitem.CustomerOrgGroupDetailPrice,
  332. PayTypeFlag = '1',
  333. IsCharge = 'N',
  334. Amount = asbitem.CustomerOrgGroupDetailAmount
  335. });
  336. }
  337. await CallAppServiceAsync<CreatePatientRegisterDto, object>(
  338. "api/PatientRegister/CreatePatientRegister",
  339. patientRegister);
  340. //var succesIds = new List<string>();
  341. //var deleteIds = new List<string>();
  342. //succesIds.Add(patientRegister.Planuserid);
  343. await AnswerOk(succesIds, deleteIds);
  344. }
  345. catch (Exception ex)
  346. {
  347. errorList.Add(error + ",错误信息:"+ex.Message);
  348. continue;
  349. //throw new Exception(error + ex.Message);
  350. //if (ex.Message.Contains("人员信息姓名和性别和原来的信息都不一致") ||
  351. // ex.Message.Contains("身份证号解析出的性别与填入的性别不一致"))
  352. //{
  353. // continue;
  354. //}
  355. //else
  356. //{
  357. // throw ex;
  358. //}
  359. }
  360. }
  361. return errorList;
  362. }
  363. public async Task InitAsync()
  364. {
  365. if (CustomerOrgRegisterId == Guid.Empty)
  366. {
  367. throw new Exception("customerOrgRegisterId参数不能为空");
  368. }
  369. var customerOrgIdStr = InterfaceConfig.GetSection("Interface").GetSection("CustomerOrgId").Value;
  370. _hospitalId = InterfaceConfig.GetSection("Interface").GetSection("HospitalId").Value;
  371. _aesKEY = InterfaceConfig.GetSection("Interface").GetSection("aesKEY").Value;
  372. _answerWebApiUrl = InterfaceConfig.GetSection("Interface").GetSection("AnswerWebApiUrl").Value;
  373. if (string.IsNullOrWhiteSpace(customerOrgIdStr))
  374. {
  375. return;
  376. }
  377. if (string.IsNullOrWhiteSpace(_hospitalId))
  378. {
  379. throw new Exception("HospitalId参数不能为空");
  380. }
  381. if (string.IsNullOrWhiteSpace(_aesKEY))
  382. {
  383. throw new Exception("_aesKEY参数不能为空");
  384. }
  385. Guid customerOrgId;
  386. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  387. {
  388. string sql;
  389. sql = @"
  390. SELECT customer_org.id as customer_org_id,
  391. customer_org.display_name as customer_org_name,
  392. customer_org.parent_id as parent_id,
  393. customer_org.path_code as path_code
  394. from customer_org ,customer_org_register
  395. where customer_org.id = customer_org_register.customer_org_id and
  396. customer_org_register.id = @CustomerOrgRegisterId
  397. ";
  398. var customerOrgForPlugInss = (await conn.QueryAsync<CustomerOrgForPlugIns>(sql,
  399. new { CustomerOrgRegisterId = CustomerOrgRegisterId })).FirstOrDefault();
  400. if (customerOrgForPlugInss == null)
  401. {
  402. throw new Exception("单位登记次数不正确,找不到单位");
  403. }
  404. var year = customerOrgForPlugInss.CustomerOrgName.Substring(
  405. customerOrgForPlugInss.CustomerOrgName.Length - 5
  406. , 4);
  407. if (!int.TryParse(year, out var yearNumber))
  408. {
  409. throw new Exception("单位名称必须是以2000年这样的格式结尾");
  410. }
  411. if (yearNumber < 2024 || yearNumber > 2050)
  412. {
  413. throw new Exception("单位名称年限范围必须在2024-2050之间");
  414. }
  415. _year = year;
  416. customerOrgId = customerOrgForPlugInss.CustomerOrgId;
  417. }
  418. //加载单位信息
  419. _customerOrgDto = await CallAppServiceAsync<CustomerOrgIdInputDto, CustomerOrgDto>(
  420. "api/app/CustomerOrg/GetById", new CustomerOrgIdInputDto()
  421. {
  422. CustomerOrgId = customerOrgId,
  423. });
  424. //加载单位登记信息
  425. _customerOrgRegisterDto = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, CustomerOrgRegisterDto>(
  426. "api/app/CustomerOrgRegister/GetById", new CustomerOrgRegisterIdInputDto()
  427. {
  428. CustomerOrgRegisterId = CustomerOrgRegisterId,
  429. });
  430. //加载人员类别列表
  431. _personnelTypes = await CallAppServiceAsync<string, List<PersonnelTypeDto>>("api/app/PersonnelType/GetAll", "");
  432. }
  433. public async Task<List<PatientRegisterQztl>> GetPatientRegisterByCustomerOrgRegisterIdWithIdNo(Guid customerOrgRegisterId, string idNo)
  434. {
  435. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  436. {
  437. string sql;
  438. sql = @"
  439. SELECT *
  440. from patient_register,patient_register_exter,patient
  441. where patient_register.id = patient_register_exter.patient_register_id and
  442. patient_register.patient_id = patient.id and
  443. customer_org_register_id =@CustomerOrgRegisterId and
  444. patient.id_no =@IdNo
  445. ";
  446. var patientRegisters = (await conn.QueryAsync<PatientRegisterQztl>(sql,
  447. new { CustomerOrgRegisterId = customerOrgRegisterId, IdNo = idNo })).ToList();
  448. return patientRegisters;
  449. }
  450. }
  451. public async Task<PatientRegisterQztl> GetPatientRegisterByPlanUserId(string planUserId)
  452. {
  453. if (string.IsNullOrWhiteSpace(planUserId))
  454. {
  455. throw new Exception("planUserId不能为空");
  456. }
  457. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  458. {
  459. string sql;
  460. sql = @"
  461. SELECT *
  462. from patient_register,patient_register_exter
  463. where patient_register.id = patient_register_exter.patient_register_id and
  464. patient_register_exter.planuserid =@PlanUserId
  465. ";
  466. var patientRegisters = (await conn.QueryAsync<PatientRegisterQztl>(sql,
  467. new { PlanUserId = planUserId })).FirstOrDefault();
  468. return patientRegisters;
  469. }
  470. }
  471. public async Task UpdatePatientRegisterPlanUserId(Guid patientRegisterId, string planUserid)
  472. {
  473. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  474. {
  475. string sql;
  476. sql = @"
  477. update patient_register_exter
  478. set planuserid =@Planuserid
  479. where patient_register_id=@PatientRegisterId
  480. ";
  481. conn.Execute(sql, new { PatientRegisterId = patientRegisterId, Planuserid = planUserid });
  482. return;
  483. }
  484. }
  485. public async Task<QztlPatientRegisterFromInterface?> CallInterfaceServiceAsync()
  486. {
  487. string baseAddress = InterfaceWebApiUrl;
  488. string ary = "HospitalId=" + _hospitalId + (char)38 + "year=" + _year + (char)38 + "AesKey=" + _aesKEY;
  489. baseAddress = baseAddress + ary;
  490. using (var httpClientHandler = new HttpClientHandler())
  491. {
  492. using (var httpClient = new HttpClient(httpClientHandler))
  493. {
  494. httpClient.BaseAddress = new Uri(baseAddress);
  495. httpClient.DefaultRequestHeaders.Accept.Add(
  496. new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//设置accept标头,告诉JSON是可接受的响应类型
  497. //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
  498. IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
  499. timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  500. //var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
  501. using (HttpContent httpContent = new StringContent(""))
  502. {
  503. httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
  504. HttpResponseMessage response = await httpClient.GetAsync("");
  505. string result;
  506. if (!response.IsSuccessStatusCode)
  507. {
  508. result = response.Content.ReadAsStringAsync().Result;
  509. throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
  510. }
  511. result = await response.Content.ReadAsStringAsync();
  512. result = result.Replace(":\"[{", ":[{").Replace("}]\"", "}]").Replace("\\", "");
  513. if (result.IndexOf("status") < 0)
  514. {
  515. throw new Exception($"调用WebApi中无status,返回值:" + result);
  516. }
  517. QztlPatientRegisterFromInterface? resultDto = JsonConvert.DeserializeObject<QztlPatientRegisterFromInterface>(result);
  518. if (resultDto != null)
  519. {
  520. if (resultDto.status != 0)
  521. {
  522. throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.status + resultDto.errorMsg);
  523. }
  524. //插入数据库中备份
  525. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  526. {
  527. string sql;
  528. var qztlImportDataEntity = new QztlImportDataEntity()
  529. {
  530. Id = Guid.NewGuid(),
  531. Data = result,
  532. DataType = '0',
  533. IsComplete = 'Y',
  534. CreationTime = DateTime.Now,
  535. };
  536. sql = @"insert into qztl_import_data(id, data, data_type, is_complete,creation_time)
  537. values(@Id, @Data, @DataType, @IsComplete,@CreationTime)";
  538. conn.Execute(sql, qztlImportDataEntity);
  539. }
  540. return resultDto;
  541. }
  542. return null;
  543. }
  544. }
  545. }
  546. }
  547. public char ConvertMaritalStatus(int maritalStatus)
  548. {
  549. switch (maritalStatus)
  550. {
  551. case 1:
  552. return '0';
  553. case 2:
  554. return '1';
  555. case 3:
  556. return '4';
  557. default:
  558. return '9';
  559. }
  560. }
  561. public char ConvertSex(int sex)
  562. {
  563. switch (sex)
  564. {
  565. case 1:
  566. return 'M';
  567. case 2:
  568. return 'F';
  569. default:
  570. return 'U';
  571. }
  572. }
  573. public string ConvertJobPost(string jobPost)
  574. {
  575. if (string.IsNullOrWhiteSpace(jobPost))
  576. {
  577. return "";
  578. }
  579. switch (jobPost)
  580. {
  581. case "0":
  582. return "普通成员";
  583. case "1":
  584. return "班子成员";
  585. default:
  586. return "";
  587. }
  588. }
  589. public string ConvertJobTitle(string jobTitle)
  590. {
  591. if (string.IsNullOrWhiteSpace(jobTitle))
  592. {
  593. return "无";
  594. }
  595. switch (jobTitle)
  596. {
  597. case "0":
  598. return "无";
  599. case "1":
  600. return "科员";
  601. case "2":
  602. return "副科";
  603. case "3":
  604. return "正科";
  605. case "4":
  606. return "副处";
  607. case "5":
  608. return "正处";
  609. case "6":
  610. return "副局";
  611. case "7":
  612. return "正局";
  613. default:
  614. return "无";
  615. }
  616. }
  617. public PersonnelTypeDto ConvertPersonnelType(int personnelType)
  618. {
  619. string personnelTypeName;
  620. switch (personnelType)
  621. {
  622. case 1:
  623. personnelTypeName = "岗前";
  624. break;
  625. case 2:
  626. personnelTypeName = "岗中";
  627. break;
  628. case 3:
  629. personnelTypeName = "岗后";
  630. break;
  631. default:
  632. personnelTypeName = "";
  633. break;
  634. }
  635. if (string.IsNullOrWhiteSpace(personnelTypeName))
  636. {
  637. return null;
  638. }
  639. var personnelTypeDto = _personnelTypes.Where(o => o.DisplayName == personnelTypeName).FirstOrDefault();
  640. return personnelTypeDto;
  641. }
  642. public async Task<CustomerOrgGroupDto> GetCustomerOrgGroup(List<string> goupNames, char sexId, char maritalStatusId)
  643. {
  644. string sexName = "";
  645. if (sexId == 'M')
  646. {
  647. sexName = "男";
  648. }
  649. else if (sexId == 'F')
  650. {
  651. sexName = "女";
  652. }
  653. string groupName = "";
  654. for (var i = 0; i < goupNames.Count; i++)
  655. {
  656. if (i == 0)
  657. {
  658. groupName = goupNames[i];
  659. }
  660. else
  661. {
  662. groupName += goupNames[i];
  663. }
  664. }
  665. string maritalStatusName;
  666. if (maritalStatusId == '0')
  667. {
  668. maritalStatusName = "未婚";
  669. }
  670. else
  671. {
  672. maritalStatusName = "已婚";
  673. }
  674. if (sexName == "女")
  675. {
  676. groupName += maritalStatusName + sexName;
  677. }
  678. else
  679. {
  680. groupName += sexName;
  681. }
  682. _customerOrgGroupDtos = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, List<CustomerOrgGroupDto>>(
  683. "api/app/CustomerOrgGroup/GetListByCustomerOrgRegisterId"
  684. , new CustomerOrgRegisterIdInputDto() { CustomerOrgRegisterId = CustomerOrgRegisterId});
  685. var customerOrgGroup = _customerOrgGroupDtos.Where(o => o.DisplayName == groupName).FirstOrDefault();
  686. if (customerOrgGroup != null)
  687. {
  688. return customerOrgGroup;
  689. }
  690. //-------------自动创建分组
  691. //检测有没有单个分组
  692. string existGroupName = "";
  693. var createCustomerOrgGroupWithDetailDto = new CreateCustomerOrgGroupWithDetailDto()
  694. {
  695. IsMaxMedicalTimes = 'Y',
  696. CustomerOrgId = _customerOrgDto.Id,
  697. DisplayName = groupName,
  698. ForSexId = sexId,
  699. AgeLowerLimit = 0,
  700. AgeUpperLimit = 200,
  701. MaritalStatusId = 'A'
  702. };
  703. for (var i = 0; i < goupNames.Count; i++)
  704. {
  705. if (i == 0)
  706. {
  707. if (sexName == "女")
  708. {
  709. existGroupName = goupNames[i] + maritalStatusName + sexName;
  710. }
  711. else
  712. {
  713. existGroupName = goupNames[i] + maritalStatusName + sexName;
  714. }
  715. }
  716. else
  717. {
  718. existGroupName = goupNames[i];
  719. }
  720. _customerOrgGroupDtos = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, List<CustomerOrgGroupDto>>(
  721. "api/app/CustomerOrgGroup/GetListByCustomerOrgRegisterId"
  722. , new CustomerOrgRegisterIdInputDto() { CustomerOrgRegisterId = CustomerOrgRegisterId});
  723. customerOrgGroup = _customerOrgGroupDtos.Where(o => o.DisplayName == existGroupName).FirstOrDefault();
  724. if (customerOrgGroup == null)
  725. {
  726. throw new Exception($"分组名{existGroupName}不存在");
  727. }
  728. var customerOrgGroupDetailOrAsbitemDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDetailOrAsbitemDto>>(
  729. "api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=" + customerOrgGroup.Id.ToString()
  730. , Guid.Empty, "get");
  731. foreach (var customerOrgGroupDetailOrAsbitemDto in customerOrgGroupDetailOrAsbitemDtos)
  732. {
  733. if (!createCustomerOrgGroupWithDetailDto.Details.
  734. Where(o => o.AsbitemId == customerOrgGroupDetailOrAsbitemDto.AsbitemId).ToList().Any())
  735. {
  736. createCustomerOrgGroupWithDetailDto.Details.Add(new CreateCustomerOrgGroupDetail_Detail()
  737. {
  738. AsbitemId = customerOrgGroupDetailOrAsbitemDto.AsbitemId,
  739. Amount = customerOrgGroupDetailOrAsbitemDto.CustomerOrgGroupDetailAmount,
  740. Price = customerOrgGroupDetailOrAsbitemDto.Price,
  741. });
  742. }
  743. }
  744. }
  745. customerOrgGroup = await CallAppServiceAsync<CreateCustomerOrgGroupWithDetailDto, CustomerOrgGroupDto>(
  746. "api/app/CustomerOrgGroup/CreateCustomerOrgGroupWithDetail", createCustomerOrgGroupWithDetailDto);
  747. return customerOrgGroup;
  748. }
  749. public async Task AnswerOk(List<string> successIds, List<string> deleteIds)
  750. {
  751. if (successIds == null || deleteIds == null)
  752. {
  753. return;
  754. }
  755. if (successIds.Count == 0 && deleteIds.Count == 0)
  756. {
  757. return;
  758. }
  759. string successIdStr = "";
  760. for (var i = 0; i < successIds.Count; i++)
  761. {
  762. if (i == 0)
  763. {
  764. successIdStr = successIds[i];
  765. }
  766. else
  767. {
  768. successIdStr += "," + successIds[i];
  769. }
  770. }
  771. string deleteIdStr = "";
  772. for (var i = 0; i < deleteIds.Count; i++)
  773. {
  774. if (i == 0)
  775. {
  776. deleteIdStr = deleteIds[i];
  777. }
  778. else
  779. {
  780. deleteIdStr += "," + deleteIds[i];
  781. }
  782. }
  783. string baseAddress = _answerWebApiUrl;// "http://62.156.10.237:8005/health/values/SetPlanOK?";
  784. string ary = "HospitalId=" + _hospitalId + (char)38 +
  785. "ids=" + successIdStr + (char)38 + "delids=" + deleteIdStr + (char)38 + "AesKey=" + _aesKEY;
  786. baseAddress = baseAddress + ary;
  787. using (var httpClientHandler = new HttpClientHandler())
  788. {
  789. using (var httpClient = new HttpClient(httpClientHandler))
  790. {
  791. httpClient.BaseAddress = new Uri(baseAddress);
  792. httpClient.DefaultRequestHeaders.Accept.Add(
  793. new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//设置accept标头,告诉JSON是可接受的响应类型
  794. //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
  795. IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
  796. timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  797. //var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
  798. using (HttpContent httpContent = new StringContent(""))
  799. {
  800. httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
  801. HttpResponseMessage response = await httpClient.GetAsync("");
  802. string result;
  803. if (!response.IsSuccessStatusCode)
  804. {
  805. result = response.Content.ReadAsStringAsync().Result;
  806. throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
  807. }
  808. result = await response.Content.ReadAsStringAsync();
  809. result = result.Replace(":\"[{", ":[{").Replace("}]\"", "}]").Replace("\\", "");
  810. if (result.IndexOf("更新ok") >= 0 || result.IndexOf("更新OK") >= 0 || result.IndexOf("更新Ok") >= 0)
  811. {
  812. return;
  813. }
  814. dynamic? resultDto = JsonConvert.DeserializeObject(result);
  815. if (resultDto != null)
  816. {
  817. if (resultDto.status != 0)
  818. {
  819. throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.status + resultDto.errorMsg);
  820. }
  821. //插入数据库中备份
  822. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  823. {
  824. string sql;
  825. var qztlImportDataEntity = new QztlImportDataEntity()
  826. {
  827. Id = Guid.NewGuid(),
  828. Data = result,
  829. DataType = '0',
  830. IsComplete = 'Y',
  831. CreationTime = DateTime.Now,
  832. };
  833. sql = @"insert into qztl_import_data(id, data, data_type, is_complete,creation_time)
  834. values(@Id, @Data, @DataType, @IsComplete,@CreationTime)";
  835. conn.Execute(sql, qztlImportDataEntity);
  836. }
  837. return;
  838. }
  839. return;
  840. }
  841. }
  842. }
  843. }
  844. }
  845. }