hospital-config.component.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import {
  3. FormBuilder,
  4. FormGroup,
  5. Validators,
  6. FormControl,
  7. } from "@angular/forms";
  8. import { ActivatedRoute } from "@angular/router";
  9. import { NzMessageService } from "ng-zorro-antd";
  10. import { Subject } from "rxjs";
  11. import { debounceTime } from "rxjs/operators";
  12. import { MainService } from "src/app/services/main.service";
  13. import { ToolService } from "src/app/services/tool.service";
  14. import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
  15. @Component({
  16. selector: "app-hospital-config",
  17. templateUrl: "./hospital-config.component.html",
  18. styleUrls: ["./hospital-config.component.less"],
  19. })
  20. export class HospitalConfigComponent implements OnInit {
  21. saveLoading = false;
  22. hosId;
  23. validateForm: FormGroup;
  24. isLoading: boolean = false;
  25. searchLoading: boolean = false;
  26. hospitalConfigList = []; //院区系统配置列表
  27. roleList = []; //角色列表
  28. taskTypeList = []; //任务类型列表
  29. allTaskTypeList = []; //任务类型列表
  30. deptList = []; //科室列表
  31. deptList2 = []; //科室列表
  32. groupList = []; //组列表
  33. onSearchSubject = new Subject(); //搜索防抖
  34. onSearchInspectionDepartmentScopeSubject = new Subject(); //搜索防抖
  35. onSearchNucleicAcidPrintingTaskTypeSubject = new Subject(); //搜索防抖
  36. coopBtns: any = {};
  37. repairSpecimenStatus = "0"; //是否执行标本验证机制
  38. repairSpecimenStatusMinute = 0; //验证时间
  39. repairSpecimenStatusCheckDeptIds = []; //验证检验科范围
  40. allowNucleicAcidPrinting = "0"; //是否允许核酸打印
  41. nucleicAcidPrintingTaskType = []; //核酸打印任务类型
  42. formatterDollar = (value) => Number(value);
  43. constructor(
  44. private mainService: MainService,
  45. private fb: FormBuilder,
  46. private route: ActivatedRoute,
  47. private tool: ToolService,
  48. private message: NzMessageService
  49. ) {}
  50. @ViewChild("osComponentRef1", {
  51. read: OverlayScrollbarsComponent,
  52. static: false,
  53. })
  54. osComponentRef1: OverlayScrollbarsComponent;
  55. ngOnInit() {
  56. this.hosId = this.tool.getCurrentHospital().id;
  57. this.onSearchSubject.pipe(debounceTime(500)).subscribe((v) => {
  58. this.getDeptList(this.hosId, v).then((result) => {
  59. this.searchLoading = false;
  60. if (result.status == 200) {
  61. this.deptList = result.list;
  62. }
  63. });
  64. });
  65. this.onSearchInspectionDepartmentScopeSubject.pipe(debounceTime(500)).subscribe((v) => {
  66. this.getDeptList2(this.hosId, v).then((result) => {
  67. this.searchLoading = false;
  68. if (result.status == 200) {
  69. this.deptList2 = result.list;
  70. }
  71. });
  72. });
  73. // liao
  74. this.onSearchNucleicAcidPrintingTaskTypeSubject.pipe(debounceTime(500)).subscribe((v) => {
  75. this.getTaskTypeList(undefined, v).then((result) => {
  76. this.searchLoading = false;
  77. if (result.status == 200) {
  78. this.allTaskTypeList = result.list;
  79. }
  80. });
  81. });
  82. this.coopBtns = this.tool.initCoopBtns(this.route);
  83. this.getInit();
  84. }
  85. // 根据科室id查科室
  86. getDeptById(id) {
  87. return this.mainService.getFetchData("data", "department", id);
  88. }
  89. // 选择是否执行标本验证机制
  90. changeRepairSpecimenStatus(e) {
  91. if (e == 1) {
  92. this.validateForm.addControl(
  93. "repairSpecimenStatusMinute",
  94. new FormControl(null, Validators.required)
  95. );
  96. this.validateForm.addControl(
  97. "repairSpecimenStatusCheckDeptIds",
  98. new FormControl(null, Validators.required)
  99. );
  100. //赋值
  101. this.hospitalConfigList.forEach((config) => {
  102. if (
  103. config.key === "repairSpecimenStatusMinute" ||
  104. config.key === "repairSpecimenStatusCheckDeptIds"
  105. ) {
  106. config.show = true;
  107. }
  108. if (config.key === "repairSpecimenStatusMinute") {
  109. this.validateForm.controls[config.key].setValue(Number(config.value));
  110. } else if (config.key === "repairSpecimenStatusCheckDeptIds") {
  111. this.validateForm.controls[config.key].setValue(
  112. config.value ? config.value.split(",").map(Number) : []
  113. );
  114. }
  115. });
  116. } else {
  117. this.validateForm.removeControl("repairSpecimenStatusMinute");
  118. this.validateForm.removeControl("repairSpecimenStatusCheckDeptIds");
  119. this.hospitalConfigList.forEach((v) => {
  120. if (
  121. v.key === "repairSpecimenStatusMinute" ||
  122. v.key === "repairSpecimenStatusCheckDeptIds"
  123. ) {
  124. v.show = false;
  125. }
  126. });
  127. }
  128. }
  129. // 选择是否允许核酸打印
  130. changeAllowNucleicAcidPrinting(e) {
  131. if (e == 1) {
  132. this.validateForm.addControl(
  133. "nucleicAcidPrintingTaskType",
  134. new FormControl(null, Validators.required)
  135. );
  136. //赋值
  137. this.hospitalConfigList.forEach((config) => {
  138. if (
  139. config.key === "nucleicAcidPrintingTaskType"
  140. ) {
  141. config.show = true;
  142. }
  143. if (config.key === "nucleicAcidPrintingTaskType") {
  144. this.validateForm.controls[config.key].setValue(
  145. config.value ? config.value.split(",").map(Number) : []
  146. );
  147. }
  148. });
  149. } else {
  150. this.validateForm.removeControl("nucleicAcidPrintingTaskType");
  151. this.hospitalConfigList.forEach((v) => {
  152. if (
  153. v.key === "nucleicAcidPrintingTaskType"
  154. ) {
  155. v.show = false;
  156. }
  157. });
  158. }
  159. }
  160. //初始化请求数据
  161. getInit() {
  162. this.isLoading = true;
  163. Promise.all([
  164. this.getRoleList(),
  165. this.getDeptList(this.hosId),
  166. this.getGroupList(this.hosId),
  167. this.getTaskTypeList([255]),
  168. this.getClassesList(),
  169. this.getDeptList2(this.hosId),
  170. this.getTaskTypeList(),
  171. ])
  172. .then((result) => {
  173. if (result[0].status == 200) {
  174. this.roleList = result[0].list;
  175. }
  176. if (result[1].status == 200) {
  177. this.deptList = result[1].list;
  178. }
  179. if (result[2].status == 200) {
  180. this.groupList = result[2].list;
  181. }
  182. if (result[3].status == 200) {
  183. this.taskTypeList = result[3].list;
  184. }
  185. if (result[4].status == 200) {
  186. this.classesList = result[4].list;
  187. this.classesList = this.classesList.map((item) => ({
  188. label: item.name,
  189. value: item.id,
  190. checked: false,
  191. }));
  192. }
  193. if (result[5].status == 200) {
  194. this.deptList2 = result[5].list;
  195. }
  196. if (result[6].status == 200) {
  197. this.allTaskTypeList = result[6].list;
  198. }
  199. this.getHospitalConfigList(this.hosId).subscribe((res) => {
  200. if (res.status == 200) {
  201. this.hospitalConfigList = res.list;
  202. //创建表单
  203. let fbGroup = {};
  204. this.hospitalConfigList.forEach((item) => {
  205. if (
  206. item.key === "repairSpecimenStatusMinute" ||
  207. item.key === "repairSpecimenStatusCheckDeptIds"
  208. ) {
  209. if (
  210. this.hospitalConfigList.filter(
  211. (v) => v.key === "repairSpecimenStatus"
  212. )[0].value == 1
  213. ) {
  214. item.show = true;
  215. } else {
  216. item.show = false;
  217. }
  218. } else {
  219. item.show = true;
  220. }
  221. if (
  222. item.key === "nucleicAcidPrintingTaskType"
  223. ) {
  224. if (
  225. this.hospitalConfigList.filter(
  226. (v) => v.key === "allowNucleicAcidPrinting"
  227. )[0].value == 1
  228. ) {
  229. item.show = true;
  230. } else {
  231. item.show = false;
  232. }
  233. } else {
  234. item.show = true;
  235. }
  236. if (item.key.includes("phone_num_port")) {
  237. //坐席号码
  238. fbGroup[item.key] = [null];
  239. item.required = false;
  240. } else if (item.key === "rushNoticeShift") {
  241. //抢单通知班次
  242. fbGroup[item.key] = [];
  243. item.required = false;
  244. } else {
  245. if (item.show) {
  246. fbGroup[item.key] = [null, [Validators.required]];
  247. item.required = true;
  248. }
  249. }
  250. });
  251. this.validateForm = this.fb.group(fbGroup);
  252. //赋值
  253. this.hospitalConfigList.forEach((config) => {
  254. if (config.show) {
  255. //默认角色,默认组
  256. if (
  257. config.key === "autoCreateUserRoleId" ||
  258. config.key === "rebackPatientTypeId" ||
  259. config.key === "transDeptTypeId" ||
  260. config.key === "autoCreateUserGroupId"
  261. ) {
  262. this.validateForm.controls[config.key].setValue(
  263. config.value - 0
  264. );
  265. } else if (config.key === "autoCreateUserDeptId") {
  266. //默认科室
  267. let flag = this.deptList.some(
  268. (item) => item.id == config.value
  269. );
  270. console.log(this.deptList);
  271. if (!flag) {
  272. this.getDeptById(config.value).subscribe((item) => {
  273. this.isLoading = false;
  274. if (item.status == 200) {
  275. if (item.data.hospital.id == this.hosId) {
  276. console.log(this.deptList);
  277. this.deptList.unshift(item.data);
  278. }
  279. }
  280. });
  281. } else {
  282. this.isLoading = false;
  283. }
  284. this.validateForm.controls[config.key].setValue(
  285. config.value - 0
  286. );
  287. } else if (config.key === "rushNoticeShift") {
  288. let arr = config.value ? config.value.split(",") : [];
  289. this.classesList.forEach((item) => {
  290. item.checked = arr.includes(item.value + "");
  291. });
  292. this.validateForm.controls[config.key].setValue(
  293. this.classesList
  294. );
  295. } else if (config.key === "repairSpecimenStatusCheckDeptIds") {
  296. let arr = config.value ? config.value.split(",").map(Number) : [];
  297. arr.forEach(v => {
  298. let flag = this.deptList2.some(
  299. (item) => item.id == v
  300. );
  301. console.log(this.deptList2);
  302. if (!flag) {
  303. this.getDeptById(v).subscribe((item) => {
  304. this.isLoading = false;
  305. if (item.status == 200) {
  306. if (item.data.hospital.id == this.hosId) {
  307. this.deptList2.unshift(item.data);
  308. }
  309. }
  310. });
  311. } else {
  312. this.isLoading = false;
  313. }
  314. })
  315. this.validateForm.controls[config.key].setValue(arr);
  316. } else if (config.key === "nucleicAcidPrintingTaskType") {
  317. this.validateForm.controls[config.key].setValue(parseInt(config.value));
  318. } else {
  319. this.validateForm.controls[config.key].setValue(config.value);
  320. }
  321. }
  322. });
  323. } else {
  324. this.isLoading = false;
  325. }
  326. });
  327. })
  328. .catch((err) => {
  329. this.isLoading = false;
  330. });
  331. }
  332. // 获取当前院区的班次列表
  333. classesList = [];
  334. getClassesList() {
  335. let postData = {
  336. idx: 0,
  337. sum: 9999,
  338. scheduleClass: {
  339. hospital: { id: this.hosId },
  340. },
  341. };
  342. return this.mainService
  343. .getFetchDataList("configuration", "scheduleClass", postData)
  344. .toPromise();
  345. }
  346. // 获取系统配置列表
  347. getHospitalConfigList(hosId) {
  348. let postData = { idx: 0, sum: 100, hospitalConfig: { hosId } };
  349. return this.mainService.getFetchDataList(
  350. "simple/data",
  351. "hospitalConfig",
  352. postData
  353. );
  354. }
  355. // 获取角色列表
  356. getRoleList() {
  357. let postData = { idx: 0, sum: 100 };
  358. return this.mainService
  359. .getFetchDataList("user/data", "role", postData)
  360. .toPromise();
  361. }
  362. // 获取任务类型列表(患者其他服务)
  363. getTaskTypeList(associationTypeIds?,keyword?) {
  364. let postData: any = {
  365. idx: 0,
  366. sum: 999,
  367. taskType: {
  368. hosIds: this.hosId,
  369. taskName: keyword,
  370. simpleQuery: true,
  371. },
  372. };
  373. if (associationTypeIds) {
  374. postData.taskType.associationTypeIds = associationTypeIds.toString();
  375. }
  376. return this.mainService
  377. .getFetchDataList("configuration", "taskType", postData)
  378. .toPromise();
  379. }
  380. /**
  381. * 获取科室列表
  382. * @param hosId 院区id
  383. * @param dept 模糊搜索
  384. * @returns
  385. */
  386. getDeptList(hosId, dept: any = "") {
  387. let postData = {
  388. idx: 0,
  389. sum: 10,
  390. department: {
  391. hospital: { id: hosId },
  392. dept,
  393. },
  394. };
  395. return this.mainService
  396. .getFetchDataList("data", "department", postData)
  397. .toPromise();
  398. }
  399. /**
  400. * 获取检验科室列表
  401. * @param hosId 院区id
  402. * @param dept 模糊搜索
  403. * @returns
  404. */
  405. getDeptList2(hosId, dept: any = "") {
  406. let postData = {
  407. idx: 0,
  408. sum: 10,
  409. department: {
  410. hospital: { id: hosId },
  411. dept,
  412. type: { id: "282" },
  413. },
  414. };
  415. return this.mainService
  416. .getFetchDataList("data", "department", postData)
  417. .toPromise();
  418. }
  419. /**
  420. * 获取组列表
  421. * @param hosId 院区id
  422. * @returns
  423. */
  424. getGroupList(hosId) {
  425. let postData = { idx: 0, sum: 100, group2: { hospitals: hosId, type: 1 } };
  426. return this.mainService
  427. .getFetchDataList("data", "group2", postData)
  428. .toPromise();
  429. }
  430. //搜索
  431. onSearch(e) {
  432. this.searchLoading = true;
  433. this.onSearchSubject.next(e);
  434. }
  435. //验证检验科室范围
  436. onSearchInspectionDepartmentScope(e){
  437. this.searchLoading = true;
  438. this.onSearchInspectionDepartmentScopeSubject.next(e);
  439. }
  440. //核酸打印任务类型
  441. onSearchNucleicAcidPrintingTaskType(e){
  442. this.searchLoading = true;
  443. this.onSearchNucleicAcidPrintingTaskTypeSubject.next(e);
  444. }
  445. // 保存
  446. submitForm(): void {
  447. for (const i in this.validateForm.controls) {
  448. this.validateForm.controls[i].markAsDirty();
  449. this.validateForm.controls[i].updateValueAndValidity();
  450. }
  451. if (this.validateForm.invalid) return;
  452. let hospitalConfigList = JSON.parse(
  453. JSON.stringify(this.hospitalConfigList)
  454. );
  455. hospitalConfigList.forEach((config) => {
  456. if (config.show) {
  457. if (config.key === "rushNoticeShift") {
  458. config.value = this.validateForm.controls[config.key].value
  459. .filter((item) => item.checked)
  460. .map((item) => item.value)
  461. .toString();
  462. } else if (config.key === "repairSpecimenStatusCheckDeptIds") {
  463. config.value =
  464. this.validateForm.controls[config.key].value.toString();
  465. } else if (config.key === "nucleicAcidPrintingTaskType") {
  466. config.value =
  467. this.validateForm.controls[config.key].value.toString();
  468. } else {
  469. config.value = this.validateForm.controls[config.key].value;
  470. }
  471. } else {
  472. config.value = "";
  473. }
  474. delete config.required;
  475. });
  476. this.saveLoading = true;
  477. this.mainService.changeHospitalSysConfig(hospitalConfigList).subscribe(
  478. (result) => {
  479. this.saveLoading = false;
  480. if (result["status"] == 200) {
  481. this.message.create("success", "保存成功");
  482. this.getInit();
  483. } else {
  484. this.message.create("error", "保存失败");
  485. }
  486. },
  487. (error) => {
  488. this.saveLoading = false;
  489. this.message.create("error", "保存失败");
  490. }
  491. );
  492. }
  493. }