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.

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