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.

913 lines
40 KiB

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