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.

922 lines
40 KiB

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