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.

905 lines
39 KiB

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