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.

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