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.

912 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. 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. };
  294. if (!string.IsNullOrWhiteSpace(patient.cardId))
  295. {
  296. var patientInfo = await CallAppServiceAsync<IdNoInputDto, PatientDto>(
  297. "api/app/patient/GetByIdNo",
  298. new IdNoInputDto()
  299. {
  300. IdNo = patient.cardId
  301. });
  302. if (patientInfo != null)
  303. {
  304. patientRegister.PatientId = patientInfo.Id;
  305. }
  306. }
  307. if (medicalTypeDto != null)
  308. {
  309. patientRegister.MedicalTypeId = medicalTypeDto.Id;
  310. }
  311. if (personnelType != null)
  312. {
  313. patientRegister.PersonnelTypeId = personnelType.Id;
  314. }
  315. if (patient.ifGy == 1)
  316. {
  317. patientRegister.QztlType = '0';
  318. }
  319. else if (patient.ifJk == 1) { }
  320. {
  321. patientRegister.QztlType = '1';
  322. }
  323. patientRegister.RegisterCheckAsbitems = new List<CreatePatientRegisterRegisterCheckAsbitem>();
  324. //获取分组信息
  325. var customerOrgGroupDetailOrAsbitemDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDetailOrAsbitemDto>>(
  326. "api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=" + customerOrgGroupDto.Id.ToString()
  327. , Guid.Empty, "get");
  328. if (!customerOrgGroupDetailOrAsbitemDtos.Any() && customerOrgGroupDto.DisplayName!= "复检")
  329. {
  330. throw new Exception($"分组{customerOrgGroupDto.DisplayName}未包含项目");
  331. }
  332. foreach (var asbitem in customerOrgGroupDetailOrAsbitemDtos)
  333. {
  334. patientRegister.RegisterCheckAsbitems.Add(new CreatePatientRegisterRegisterCheckAsbitem()
  335. {
  336. AsbitemId = asbitem.AsbitemId,
  337. StandardPrice = asbitem.Price,
  338. ChargePrice = asbitem.CustomerOrgGroupDetailPrice,
  339. PayTypeFlag = '1',
  340. IsCharge = 'N',
  341. Amount = asbitem.CustomerOrgGroupDetailAmount
  342. });
  343. }
  344. await CallAppServiceAsync<CreatePatientRegisterDto, object>(
  345. "api/PatientRegister/CreatePatientRegister",
  346. patientRegister);
  347. await AnswerOk(succesIds, deleteIds);
  348. returnDto.ImportSuccessNum++;
  349. }
  350. catch (Exception ex)
  351. {
  352. returnDto.ImportErrorNum++;
  353. returnDto.ImportErrorMessages.Add(error + ",错误信息:" + ex.Message);
  354. continue;
  355. //throw new Exception(error + ex.Message);
  356. //if (ex.Message.Contains("人员信息姓名和性别和原来的信息都不一致") ||
  357. // ex.Message.Contains("身份证号解析出的性别与填入的性别不一致"))
  358. //{
  359. // continue;
  360. //}
  361. //else
  362. //{
  363. // throw ex;
  364. //}
  365. }
  366. }
  367. return returnDto;
  368. }
  369. public async Task InitAsync()
  370. {
  371. if (CustomerOrgRegisterId == Guid.Empty)
  372. {
  373. throw new Exception("customerOrgRegisterId参数不能为空");
  374. }
  375. var customerOrgIdStr = InterfaceConfig.GetSection("Interface").GetSection("CustomerOrgId").Value;
  376. _hospitalId = InterfaceConfig.GetSection("Interface").GetSection("HospitalId").Value;
  377. _aesKEY = InterfaceConfig.GetSection("Interface").GetSection("aesKEY").Value;
  378. _answerWebApiUrl = InterfaceConfig.GetSection("Interface").GetSection("AnswerWebApiUrl").Value;
  379. if (string.IsNullOrWhiteSpace(customerOrgIdStr))
  380. {
  381. return;
  382. }
  383. if (string.IsNullOrWhiteSpace(_hospitalId))
  384. {
  385. throw new Exception("HospitalId参数不能为空");
  386. }
  387. if (string.IsNullOrWhiteSpace(_aesKEY))
  388. {
  389. throw new Exception("_aesKEY参数不能为空");
  390. }
  391. Guid customerOrgId;
  392. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  393. {
  394. string sql;
  395. sql = @"
  396. SELECT customer_org.id as customer_org_id,
  397. customer_org.display_name as customer_org_name,
  398. customer_org.parent_id as parent_id,
  399. customer_org.path_code as path_code
  400. from customer_org ,customer_org_register
  401. where customer_org.id = customer_org_register.customer_org_id and
  402. customer_org_register.id = @CustomerOrgRegisterId
  403. ";
  404. var customerOrgForPlugInss = (await conn.QueryAsync<CustomerOrgForPlugIns>(sql,
  405. new { CustomerOrgRegisterId = CustomerOrgRegisterId })).FirstOrDefault();
  406. if (customerOrgForPlugInss == null)
  407. {
  408. throw new Exception("单位登记次数不正确,找不到单位");
  409. }
  410. var year = customerOrgForPlugInss.CustomerOrgName.Substring(
  411. customerOrgForPlugInss.CustomerOrgName.Length - 5
  412. , 4);
  413. if (!int.TryParse(year, out var yearNumber))
  414. {
  415. throw new Exception("单位名称必须是以2000年这样的格式结尾");
  416. }
  417. if (yearNumber < 2024 || yearNumber > 2050)
  418. {
  419. throw new Exception("单位名称年限范围必须在2024-2050之间");
  420. }
  421. _year = year;
  422. customerOrgId = customerOrgForPlugInss.CustomerOrgId;
  423. }
  424. //加载单位信息
  425. _customerOrgDto = await CallAppServiceAsync<CustomerOrgIdInputDto, CustomerOrgDto>(
  426. "api/app/CustomerOrg/GetById", new CustomerOrgIdInputDto()
  427. {
  428. CustomerOrgId = customerOrgId,
  429. });
  430. //加载单位登记信息
  431. _customerOrgRegisterDto = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, CustomerOrgRegisterDto>(
  432. "api/app/CustomerOrgRegister/GetById", new CustomerOrgRegisterIdInputDto()
  433. {
  434. CustomerOrgRegisterId = CustomerOrgRegisterId,
  435. });
  436. //加载人员类别列表
  437. _personnelTypes = await CallAppServiceAsync<string, List<PersonnelTypeDto>>("api/app/PersonnelType/GetAll", "");
  438. }
  439. public async Task<List<PatientRegisterQztl>> GetPatientRegisterByCustomerOrgRegisterIdWithIdNo(Guid customerOrgRegisterId, string idNo)
  440. {
  441. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  442. {
  443. string sql;
  444. sql = @"
  445. SELECT *
  446. from patient_register,patient_register_exter,patient
  447. where patient_register.id = patient_register_exter.patient_register_id and
  448. patient_register.patient_id = patient.id and
  449. customer_org_register_id =@CustomerOrgRegisterId and
  450. patient.id_no =@IdNo
  451. ";
  452. var patientRegisters = (await conn.QueryAsync<PatientRegisterQztl>(sql,
  453. new { CustomerOrgRegisterId = customerOrgRegisterId, IdNo = idNo })).ToList();
  454. return patientRegisters;
  455. }
  456. }
  457. public async Task<PatientRegisterQztl> GetPatientRegisterByPlanUserId(string planUserId)
  458. {
  459. if (string.IsNullOrWhiteSpace(planUserId))
  460. {
  461. throw new Exception("planUserId不能为空");
  462. }
  463. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  464. {
  465. string sql;
  466. sql = @"
  467. SELECT *
  468. from patient_register,patient_register_exter
  469. where patient_register.id = patient_register_exter.patient_register_id and
  470. patient_register_exter.planuserid =@PlanUserId
  471. ";
  472. var patientRegisters = (await conn.QueryAsync<PatientRegisterQztl>(sql,
  473. new { PlanUserId = planUserId })).FirstOrDefault();
  474. return patientRegisters;
  475. }
  476. }
  477. public async Task UpdatePatientRegisterPlanUserId(Guid patientRegisterId, string planUserid)
  478. {
  479. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  480. {
  481. string sql;
  482. sql = @"
  483. update patient_register_exter
  484. set planuserid =@Planuserid
  485. where patient_register_id=@PatientRegisterId
  486. ";
  487. conn.Execute(sql, new { PatientRegisterId = patientRegisterId, Planuserid = planUserid });
  488. return;
  489. }
  490. }
  491. public async Task<QztlPatientRegisterFromInterface?> CallInterfaceServiceAsync()
  492. {
  493. string baseAddress = InterfaceWebApiUrl;
  494. string ary = "HospitalId=" + _hospitalId + (char)38 + "year=" + _year + (char)38 + "AesKey=" + _aesKEY;
  495. baseAddress = baseAddress + ary;
  496. using (var httpClientHandler = new HttpClientHandler())
  497. {
  498. using (var httpClient = new HttpClient(httpClientHandler))
  499. {
  500. httpClient.BaseAddress = new Uri(baseAddress);
  501. httpClient.DefaultRequestHeaders.Accept.Add(
  502. new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//设置accept标头,告诉JSON是可接受的响应类型
  503. //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
  504. IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
  505. timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  506. //var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
  507. using (HttpContent httpContent = new StringContent(""))
  508. {
  509. httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
  510. HttpResponseMessage response = await httpClient.GetAsync("");
  511. string result;
  512. if (!response.IsSuccessStatusCode)
  513. {
  514. result = response.Content.ReadAsStringAsync().Result;
  515. throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
  516. }
  517. result = await response.Content.ReadAsStringAsync();
  518. result = result.Replace(":\"[{", ":[{").Replace("}]\"", "}]").Replace("\\", "");
  519. if (result.IndexOf("status") < 0)
  520. {
  521. throw new Exception($"调用WebApi中无status,返回值:" + result);
  522. }
  523. QztlPatientRegisterFromInterface? resultDto = JsonConvert.DeserializeObject<QztlPatientRegisterFromInterface>(result);
  524. if (resultDto != null)
  525. {
  526. if (resultDto.status != 0)
  527. {
  528. throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.status + resultDto.errorMsg);
  529. }
  530. //插入数据库中备份
  531. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  532. {
  533. string sql;
  534. var qztlImportDataEntity = new QztlImportDataEntity()
  535. {
  536. Id = Guid.NewGuid(),
  537. Data = result,
  538. DataType = '0',
  539. IsComplete = 'Y',
  540. CreationTime = DateTime.Now,
  541. };
  542. sql = @"insert into qztl_import_data(id, data, data_type, is_complete,creation_time)
  543. values(@Id, @Data, @DataType, @IsComplete,@CreationTime)";
  544. conn.Execute(sql, qztlImportDataEntity);
  545. }
  546. return resultDto;
  547. }
  548. return null;
  549. }
  550. }
  551. }
  552. }
  553. public char ConvertMaritalStatus(int maritalStatus)
  554. {
  555. switch (maritalStatus)
  556. {
  557. case 1:
  558. return '0';
  559. case 2:
  560. return '1';
  561. case 3:
  562. return '4';
  563. default:
  564. return '9';
  565. }
  566. }
  567. public char ConvertSex(int sex)
  568. {
  569. switch (sex)
  570. {
  571. case 1:
  572. return 'M';
  573. case 2:
  574. return 'F';
  575. default:
  576. return 'U';
  577. }
  578. }
  579. public string ConvertJobPost(string jobPost)
  580. {
  581. if (string.IsNullOrWhiteSpace(jobPost))
  582. {
  583. return "";
  584. }
  585. switch (jobPost)
  586. {
  587. case "0":
  588. return "普通成员";
  589. case "1":
  590. return "班子成员";
  591. default:
  592. return "";
  593. }
  594. }
  595. public string ConvertJobTitle(string jobTitle)
  596. {
  597. if (string.IsNullOrWhiteSpace(jobTitle))
  598. {
  599. return "无";
  600. }
  601. switch (jobTitle)
  602. {
  603. case "0":
  604. return "无";
  605. case "1":
  606. return "科员";
  607. case "2":
  608. return "副科";
  609. case "3":
  610. return "正科";
  611. case "4":
  612. return "副处";
  613. case "5":
  614. return "正处";
  615. case "6":
  616. return "副局";
  617. case "7":
  618. return "正局";
  619. default:
  620. return "无";
  621. }
  622. }
  623. public PersonnelTypeDto ConvertPersonnelType(int personnelType)
  624. {
  625. string personnelTypeName;
  626. switch (personnelType)
  627. {
  628. case 1:
  629. personnelTypeName = "岗前";
  630. break;
  631. case 2:
  632. personnelTypeName = "岗中";
  633. break;
  634. case 3:
  635. personnelTypeName = "岗后";
  636. break;
  637. default:
  638. personnelTypeName = "";
  639. break;
  640. }
  641. if (string.IsNullOrWhiteSpace(personnelTypeName))
  642. {
  643. return null;
  644. }
  645. var personnelTypeDto = _personnelTypes.Where(o => o.DisplayName == personnelTypeName).FirstOrDefault();
  646. return personnelTypeDto;
  647. }
  648. public async Task<CustomerOrgGroupDto> GetCustomerOrgGroup(List<string> goupNames, char sexId, char maritalStatusId)
  649. {
  650. string sexName = "";
  651. if (sexId == 'M')
  652. {
  653. sexName = "男";
  654. }
  655. else if (sexId == 'F')
  656. {
  657. sexName = "女";
  658. }
  659. string groupName = "";
  660. for (var i = 0; i < goupNames.Count; i++)
  661. {
  662. if (i == 0)
  663. {
  664. groupName = goupNames[i];
  665. }
  666. else
  667. {
  668. groupName += goupNames[i];
  669. }
  670. }
  671. string maritalStatusName;
  672. if (maritalStatusId == '0')
  673. {
  674. maritalStatusName = "未婚";
  675. }
  676. else
  677. {
  678. maritalStatusName = "已婚";
  679. }
  680. if (sexName == "女")
  681. {
  682. groupName += maritalStatusName + sexName;
  683. }
  684. else
  685. {
  686. groupName += sexName;
  687. }
  688. _customerOrgGroupDtos = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, List<CustomerOrgGroupDto>>(
  689. "api/app/CustomerOrgGroup/GetListByCustomerOrgRegisterId"
  690. , new CustomerOrgRegisterIdInputDto() { CustomerOrgRegisterId = CustomerOrgRegisterId});
  691. var customerOrgGroup = _customerOrgGroupDtos.Where(o => o.DisplayName == groupName).FirstOrDefault();
  692. if (customerOrgGroup != null)
  693. {
  694. return customerOrgGroup;
  695. }
  696. //-------------自动创建分组
  697. //检测有没有单个分组
  698. string existGroupName = "";
  699. var createCustomerOrgGroupWithDetailDto = new CreateCustomerOrgGroupWithDetailDto()
  700. {
  701. IsMaxMedicalTimes = 'Y',
  702. CustomerOrgId = _customerOrgDto.Id,
  703. DisplayName = groupName,
  704. ForSexId = sexId,
  705. AgeLowerLimit = 0,
  706. AgeUpperLimit = 200,
  707. MaritalStatusId = 'A'
  708. };
  709. for (var i = 0; i < goupNames.Count; i++)
  710. {
  711. if (i == 0)
  712. {
  713. if (sexName == "女")
  714. {
  715. existGroupName = goupNames[i] + maritalStatusName + sexName;
  716. }
  717. else
  718. {
  719. existGroupName = goupNames[i] + maritalStatusName + sexName;
  720. }
  721. }
  722. else
  723. {
  724. existGroupName = goupNames[i];
  725. }
  726. _customerOrgGroupDtos = await CallAppServiceAsync<CustomerOrgRegisterIdInputDto, List<CustomerOrgGroupDto>>(
  727. "api/app/CustomerOrgGroup/GetListByCustomerOrgRegisterId"
  728. , new CustomerOrgRegisterIdInputDto() { CustomerOrgRegisterId = CustomerOrgRegisterId});
  729. customerOrgGroup = _customerOrgGroupDtos.Where(o => o.DisplayName == existGroupName).FirstOrDefault();
  730. if (customerOrgGroup == null)
  731. {
  732. throw new Exception($"分组名{existGroupName}不存在");
  733. }
  734. var customerOrgGroupDetailOrAsbitemDtos = await CallAppServiceAsync<Guid, List<CustomerOrgGroupDetailOrAsbitemDto>>(
  735. "api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=" + customerOrgGroup.Id.ToString()
  736. , Guid.Empty, "get");
  737. foreach (var customerOrgGroupDetailOrAsbitemDto in customerOrgGroupDetailOrAsbitemDtos)
  738. {
  739. if (!createCustomerOrgGroupWithDetailDto.Details.
  740. Where(o => o.AsbitemId == customerOrgGroupDetailOrAsbitemDto.AsbitemId).ToList().Any())
  741. {
  742. createCustomerOrgGroupWithDetailDto.Details.Add(new CreateCustomerOrgGroupDetail_Detail()
  743. {
  744. AsbitemId = customerOrgGroupDetailOrAsbitemDto.AsbitemId,
  745. Amount = customerOrgGroupDetailOrAsbitemDto.CustomerOrgGroupDetailAmount,
  746. Price = customerOrgGroupDetailOrAsbitemDto.Price,
  747. });
  748. }
  749. }
  750. }
  751. customerOrgGroup = await CallAppServiceAsync<CreateCustomerOrgGroupWithDetailDto, CustomerOrgGroupDto>(
  752. "api/app/CustomerOrgGroup/CreateCustomerOrgGroupWithDetail", createCustomerOrgGroupWithDetailDto);
  753. return customerOrgGroup;
  754. }
  755. public async Task AnswerOk(List<string> successIds, List<string> deleteIds)
  756. {
  757. if (successIds == null || deleteIds == null)
  758. {
  759. return;
  760. }
  761. if (successIds.Count == 0 && deleteIds.Count == 0)
  762. {
  763. return;
  764. }
  765. string successIdStr = "";
  766. for (var i = 0; i < successIds.Count; i++)
  767. {
  768. if (i == 0)
  769. {
  770. successIdStr = successIds[i];
  771. }
  772. else
  773. {
  774. successIdStr += "," + successIds[i];
  775. }
  776. }
  777. string deleteIdStr = "";
  778. for (var i = 0; i < deleteIds.Count; i++)
  779. {
  780. if (i == 0)
  781. {
  782. deleteIdStr = deleteIds[i];
  783. }
  784. else
  785. {
  786. deleteIdStr += "," + deleteIds[i];
  787. }
  788. }
  789. string baseAddress = _answerWebApiUrl;// "http://62.156.10.237:8005/health/values/SetPlanOK?";
  790. string ary = "HospitalId=" + _hospitalId + (char)38 +
  791. "ids=" + successIdStr + (char)38 + "delids=" + deleteIdStr + (char)38 + "AesKey=" + _aesKEY;
  792. baseAddress = baseAddress + ary;
  793. using (var httpClientHandler = new HttpClientHandler())
  794. {
  795. using (var httpClient = new HttpClient(httpClientHandler))
  796. {
  797. httpClient.BaseAddress = new Uri(baseAddress);
  798. httpClient.DefaultRequestHeaders.Accept.Add(
  799. new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));//设置accept标头,告诉JSON是可接受的响应类型
  800. //httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accesToken);
  801. IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();
  802. timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
  803. //var sendData = JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented, timeFormat);
  804. using (HttpContent httpContent = new StringContent(""))
  805. {
  806. httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
  807. HttpResponseMessage response = await httpClient.GetAsync("");
  808. string result;
  809. if (!response.IsSuccessStatusCode)
  810. {
  811. result = response.Content.ReadAsStringAsync().Result;
  812. throw new Exception("http通信错误:" + response.StatusCode + ",结果:" + result);
  813. }
  814. result = await response.Content.ReadAsStringAsync();
  815. result = result.Replace(":\"[{", ":[{").Replace("}]\"", "}]").Replace("\\", "");
  816. if (result.IndexOf("更新ok") >= 0 || result.IndexOf("更新OK") >= 0 || result.IndexOf("更新Ok") >= 0)
  817. {
  818. return;
  819. }
  820. dynamic? resultDto = JsonConvert.DeserializeObject(result);
  821. if (resultDto != null)
  822. {
  823. if (resultDto.status != 0)
  824. {
  825. throw new Exception($"调用WebApi失败,返回错误,消息:" + resultDto.status + resultDto.errorMsg);
  826. }
  827. //插入数据库中备份
  828. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  829. {
  830. string sql;
  831. var qztlImportDataEntity = new QztlImportDataEntity()
  832. {
  833. Id = Guid.NewGuid(),
  834. Data = result,
  835. DataType = '0',
  836. IsComplete = 'Y',
  837. CreationTime = DateTime.Now,
  838. };
  839. sql = @"insert into qztl_import_data(id, data, data_type, is_complete,creation_time)
  840. values(@Id, @Data, @DataType, @IsComplete,@CreationTime)";
  841. conn.Execute(sql, qztlImportDataEntity);
  842. }
  843. return;
  844. }
  845. return;
  846. }
  847. }
  848. }
  849. }
  850. }
  851. }