123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- import { Component, OnInit, ViewChild } from "@angular/core";
- import {
- FormBuilder,
- FormGroup,
- Validators,
- FormControl,
- } from "@angular/forms";
- import { ActivatedRoute } from "@angular/router";
- import { NzMessageService } from "ng-zorro-antd";
- import { Subject } from "rxjs";
- import { debounceTime } from "rxjs/operators";
- import { MainService } from "src/app/services/main.service";
- import { ToolService } from "src/app/services/tool.service";
- import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
- @Component({
- selector: "app-hospital-config",
- templateUrl: "./hospital-config.component.html",
- styleUrls: ["./hospital-config.component.less"],
- })
- export class HospitalConfigComponent implements OnInit {
- saveLoading = false;
- hosId;
- validateForm: FormGroup;
- isLoading: boolean = false;
- searchLoading: boolean = false;
- hospitalConfigList = []; //院区系统配置列表
- roleList = []; //角色列表
- taskTypeList = []; //任务类型列表
- allTaskTypeList = []; //任务类型列表
- deptList = []; //科室列表
- deptList2 = []; //科室列表
- groupList = []; //组列表
- onSearchSubject = new Subject(); //搜索防抖
- onSearchInspectionDepartmentScopeSubject = new Subject(); //搜索防抖
- onSearchNucleicAcidPrintingTaskTypeSubject = new Subject(); //搜索防抖
- coopBtns: any = {};
- repairSpecimenStatus = "0"; //是否执行标本验证机制
- repairSpecimenStatusMinute = 0; //验证时间
- repairSpecimenStatusCheckDeptIds = []; //验证检验科范围
- allowNucleicAcidPrinting = "0"; //是否允许核酸打印
- nucleicAcidPrintingTaskType = []; //核酸打印任务类型
- formatterDollar = (value) => Number(value);
- constructor(
- private mainService: MainService,
- private fb: FormBuilder,
- private route: ActivatedRoute,
- private tool: ToolService,
- private message: NzMessageService
- ) {}
- @ViewChild("osComponentRef1", {
- read: OverlayScrollbarsComponent,
- static: false,
- })
- osComponentRef1: OverlayScrollbarsComponent;
- ngOnInit() {
- this.hosId = this.tool.getCurrentHospital().id;
- this.onSearchSubject.pipe(debounceTime(500)).subscribe((v) => {
- this.getDeptList(this.hosId, v).then((result) => {
- this.searchLoading = false;
- if (result.status == 200) {
- this.deptList = result.list;
- }
- });
- });
- this.onSearchInspectionDepartmentScopeSubject.pipe(debounceTime(500)).subscribe((v) => {
- this.getDeptList2(this.hosId, v).then((result) => {
- this.searchLoading = false;
- if (result.status == 200) {
- this.deptList2 = result.list;
- }
- });
- });
- // liao
- this.onSearchNucleicAcidPrintingTaskTypeSubject.pipe(debounceTime(500)).subscribe((v) => {
- this.getTaskTypeList(undefined, v).then((result) => {
- this.searchLoading = false;
- if (result.status == 200) {
- this.allTaskTypeList = result.list;
- }
- });
- });
- this.coopBtns = this.tool.initCoopBtns(this.route);
- this.getInit();
- }
- // 根据科室id查科室
- getDeptById(id) {
- return this.mainService.getFetchData("data", "department", id);
- }
- // 选择是否执行标本验证机制
- changeRepairSpecimenStatus(e) {
- if (e == 1) {
- this.validateForm.addControl(
- "repairSpecimenStatusMinute",
- new FormControl(null, Validators.required)
- );
- this.validateForm.addControl(
- "repairSpecimenStatusCheckDeptIds",
- new FormControl(null, Validators.required)
- );
- //赋值
- this.hospitalConfigList.forEach((config) => {
- if (
- config.key === "repairSpecimenStatusMinute" ||
- config.key === "repairSpecimenStatusCheckDeptIds"
- ) {
- config.show = true;
- }
- if (config.key === "repairSpecimenStatusMinute") {
- this.validateForm.controls[config.key].setValue(Number(config.value));
- } else if (config.key === "repairSpecimenStatusCheckDeptIds") {
- this.validateForm.controls[config.key].setValue(
- config.value ? config.value.split(",").map(Number) : []
- );
- }
- });
- } else {
- this.validateForm.removeControl("repairSpecimenStatusMinute");
- this.validateForm.removeControl("repairSpecimenStatusCheckDeptIds");
- this.hospitalConfigList.forEach((v) => {
- if (
- v.key === "repairSpecimenStatusMinute" ||
- v.key === "repairSpecimenStatusCheckDeptIds"
- ) {
- v.show = false;
- }
- });
- }
- }
- // 选择是否允许核酸打印
- changeAllowNucleicAcidPrinting(e) {
- if (e == 1) {
- this.validateForm.addControl(
- "nucleicAcidPrintingTaskType",
- new FormControl(null, Validators.required)
- );
- //赋值
- this.hospitalConfigList.forEach((config) => {
- if (
- config.key === "nucleicAcidPrintingTaskType"
- ) {
- config.show = true;
- }
- if (config.key === "nucleicAcidPrintingTaskType") {
- this.validateForm.controls[config.key].setValue(
- config.value ? config.value.split(",").map(Number) : []
- );
- }
- });
- } else {
- this.validateForm.removeControl("nucleicAcidPrintingTaskType");
- this.hospitalConfigList.forEach((v) => {
- if (
- v.key === "nucleicAcidPrintingTaskType"
- ) {
- v.show = false;
- }
- });
- }
- }
- //初始化请求数据
- getInit() {
- this.isLoading = true;
- Promise.all([
- this.getRoleList(),
- this.getDeptList(this.hosId),
- this.getGroupList(this.hosId),
- this.getTaskTypeList([255]),
- this.getClassesList(),
- this.getDeptList2(this.hosId),
- this.getTaskTypeList(),
- ])
- .then((result) => {
- if (result[0].status == 200) {
- this.roleList = result[0].list;
- }
- if (result[1].status == 200) {
- this.deptList = result[1].list;
- }
- if (result[2].status == 200) {
- this.groupList = result[2].list;
- }
- if (result[3].status == 200) {
- this.taskTypeList = result[3].list;
- }
- if (result[4].status == 200) {
- this.classesList = result[4].list;
- this.classesList = this.classesList.map((item) => ({
- label: item.name,
- value: item.id,
- checked: false,
- }));
- }
- if (result[5].status == 200) {
- this.deptList2 = result[5].list;
- }
- if (result[6].status == 200) {
- this.allTaskTypeList = result[6].list;
- }
- this.getHospitalConfigList(this.hosId).subscribe((res) => {
- if (res.status == 200) {
- this.hospitalConfigList = res.list;
- //创建表单
- let fbGroup = {};
- this.hospitalConfigList.forEach((item) => {
- if (
- item.key === "repairSpecimenStatusMinute" ||
- item.key === "repairSpecimenStatusCheckDeptIds"
- ) {
- if (
- this.hospitalConfigList.filter(
- (v) => v.key === "repairSpecimenStatus"
- )[0].value == 1
- ) {
- item.show = true;
- } else {
- item.show = false;
- }
- } else {
- item.show = true;
- }
- if (
- item.key === "nucleicAcidPrintingTaskType"
- ) {
- if (
- this.hospitalConfigList.filter(
- (v) => v.key === "allowNucleicAcidPrinting"
- )[0].value == 1
- ) {
- item.show = true;
- } else {
- item.show = false;
- }
- } else {
- item.show = true;
- }
- if (item.key.includes("phone_num_port")) {
- //坐席号码
- fbGroup[item.key] = [null];
- item.required = false;
- } else if (item.key === "rushNoticeShift") {
- //抢单通知班次
- fbGroup[item.key] = [];
- item.required = false;
- } else {
- if (item.show) {
- fbGroup[item.key] = [null, [Validators.required]];
- item.required = true;
- }
- }
- });
- this.validateForm = this.fb.group(fbGroup);
- //赋值
- this.hospitalConfigList.forEach((config) => {
- if (config.show) {
- //默认角色,默认组
- if (
- config.key === "autoCreateUserRoleId" ||
- config.key === "rebackPatientTypeId" ||
- config.key === "transDeptTypeId" ||
- config.key === "autoCreateUserGroupId"
- ) {
- this.validateForm.controls[config.key].setValue(
- config.value - 0
- );
- } else if (config.key === "autoCreateUserDeptId") {
- //默认科室
- let flag = this.deptList.some(
- (item) => item.id == config.value
- );
- console.log(this.deptList);
- if (!flag) {
- this.getDeptById(config.value).subscribe((item) => {
- this.isLoading = false;
- if (item.status == 200) {
- if (item.data.hospital.id == this.hosId) {
- console.log(this.deptList);
- this.deptList.unshift(item.data);
- }
- }
- });
- } else {
- this.isLoading = false;
- }
- this.validateForm.controls[config.key].setValue(
- config.value - 0
- );
- } else if (config.key === "rushNoticeShift") {
- let arr = config.value ? config.value.split(",") : [];
- this.classesList.forEach((item) => {
- item.checked = arr.includes(item.value + "");
- });
- this.validateForm.controls[config.key].setValue(
- this.classesList
- );
- } else if (config.key === "repairSpecimenStatusCheckDeptIds") {
- let arr = config.value ? config.value.split(",").map(Number) : [];
- arr.forEach(v => {
- let flag = this.deptList2.some(
- (item) => item.id == v
- );
- console.log(this.deptList2);
- if (!flag) {
- this.getDeptById(v).subscribe((item) => {
- this.isLoading = false;
- if (item.status == 200) {
- if (item.data.hospital.id == this.hosId) {
- this.deptList2.unshift(item.data);
- }
- }
- });
- } else {
- this.isLoading = false;
- }
- })
- this.validateForm.controls[config.key].setValue(arr);
- } else if (config.key === "nucleicAcidPrintingTaskType") {
- this.validateForm.controls[config.key].setValue(parseInt(config.value));
- } else {
- this.validateForm.controls[config.key].setValue(config.value);
- }
- }
- });
- } else {
- this.isLoading = false;
- }
- });
- })
- .catch((err) => {
- this.isLoading = false;
- });
- }
- // 获取当前院区的班次列表
- classesList = [];
- getClassesList() {
- let postData = {
- idx: 0,
- sum: 9999,
- scheduleClass: {
- hospital: { id: this.hosId },
- },
- };
- return this.mainService
- .getFetchDataList("configuration", "scheduleClass", postData)
- .toPromise();
- }
- // 获取系统配置列表
- getHospitalConfigList(hosId) {
- let postData = { idx: 0, sum: 100, hospitalConfig: { hosId } };
- return this.mainService.getFetchDataList(
- "simple/data",
- "hospitalConfig",
- postData
- );
- }
- // 获取角色列表
- getRoleList() {
- let postData = { idx: 0, sum: 100 };
- return this.mainService
- .getFetchDataList("user/data", "role", postData)
- .toPromise();
- }
- // 获取任务类型列表(患者其他服务)
- getTaskTypeList(associationTypeIds?,keyword?) {
- let postData: any = {
- idx: 0,
- sum: 999,
- taskType: {
- hosIds: this.hosId,
- taskName: keyword,
- simpleQuery: true,
- },
- };
- if (associationTypeIds) {
- postData.taskType.associationTypeIds = associationTypeIds.toString();
- }
- return this.mainService
- .getFetchDataList("configuration", "taskType", postData)
- .toPromise();
- }
- /**
- * 获取科室列表
- * @param hosId 院区id
- * @param dept 模糊搜索
- * @returns
- */
- getDeptList(hosId, dept: any = "") {
- let postData = {
- idx: 0,
- sum: 10,
- department: {
- hospital: { id: hosId },
- dept,
- },
- };
- return this.mainService
- .getFetchDataList("data", "department", postData)
- .toPromise();
- }
- /**
- * 获取检验科室列表
- * @param hosId 院区id
- * @param dept 模糊搜索
- * @returns
- */
- getDeptList2(hosId, dept: any = "") {
- let postData = {
- idx: 0,
- sum: 10,
- department: {
- hospital: { id: hosId },
- dept,
- type: { id: "282" },
- },
- };
- return this.mainService
- .getFetchDataList("data", "department", postData)
- .toPromise();
- }
- /**
- * 获取组列表
- * @param hosId 院区id
- * @returns
- */
- getGroupList(hosId) {
- let postData = { idx: 0, sum: 100, group2: { hospitals: hosId, type: 1 } };
- return this.mainService
- .getFetchDataList("data", "group2", postData)
- .toPromise();
- }
- //搜索
- onSearch(e) {
- this.searchLoading = true;
- this.onSearchSubject.next(e);
- }
- //验证检验科室范围
- onSearchInspectionDepartmentScope(e){
- this.searchLoading = true;
- this.onSearchInspectionDepartmentScopeSubject.next(e);
- }
- //核酸打印任务类型
- onSearchNucleicAcidPrintingTaskType(e){
- this.searchLoading = true;
- this.onSearchNucleicAcidPrintingTaskTypeSubject.next(e);
- }
- // 保存
- submitForm(): void {
- for (const i in this.validateForm.controls) {
- this.validateForm.controls[i].markAsDirty();
- this.validateForm.controls[i].updateValueAndValidity();
- }
- if (this.validateForm.invalid) return;
- let hospitalConfigList = JSON.parse(
- JSON.stringify(this.hospitalConfigList)
- );
- hospitalConfigList.forEach((config) => {
- if (config.show) {
- if (config.key === "rushNoticeShift") {
- config.value = this.validateForm.controls[config.key].value
- .filter((item) => item.checked)
- .map((item) => item.value)
- .toString();
- } else if (config.key === "repairSpecimenStatusCheckDeptIds") {
- config.value =
- this.validateForm.controls[config.key].value.toString();
- } else if (config.key === "nucleicAcidPrintingTaskType") {
- config.value =
- this.validateForm.controls[config.key].value.toString();
- } else {
- config.value = this.validateForm.controls[config.key].value;
- }
- } else {
- config.value = "";
- }
- delete config.required;
- });
- this.saveLoading = true;
- this.mainService.changeHospitalSysConfig(hospitalConfigList).subscribe(
- (result) => {
- this.saveLoading = false;
- if (result["status"] == 200) {
- this.message.create("success", "保存成功");
- this.getInit();
- } else {
- this.message.create("error", "保存失败");
- }
- },
- (error) => {
- this.saveLoading = false;
- this.message.create("error", "保存失败");
- }
- );
- }
- }
|