import { number } from '@intlify/core-base';
import request from '/@/utils/request';
import { ITendencyRequestData } from "/@/views/QC/patientTestingTrend/type";
import { AxiosPromise } from 'axios';
import type { AddNewPbsParams, PatientListByTransferInOrOutParams, SaveDefaultFormValueParams, LoadDefaultFormValueParams, ListPatientsParams, ListPatientsItem, getBillsParams, getBillsParamsReponseItem, CopyPBSParams, ListReceipts1Params, DiagnosisFindParams, SaveDefaultPharmacyParams, AddressListParams } from './types';
import type { ICommonListParams } from './../common.type';

//定义用于查接用的接口
export interface QueryConditions {
    page: number;
    size: number;
    wherecondition: string;
    ordercondition: string;
}

export interface PatientInfo2 {
    code: string;//??
    createTime: string;//($date-time) 创建时间
    createUser: number;//($int32) 创建人ID
    deletedTime: string;//($date-time) 创建日期
    id: number;//($int32) 表主键唯一ID
    isDeleted: null;//($int32) 是否删除
    patientAvatarIcon: string;// 患者头像url地址
    patientBaoxiaoState: string;//患者报销方式(字典编号)
    patientBedNo: string;//床号
    patientBloodType: string;//患者血型(字典编号)
    patientCardNo: string;//患者卡号
    patientCareer: string;//患者职业(字典编号)
    patientComp
    any: string;//患者单位
    patientCrb:
     string;//患者传染病(以逗号分割)
    patientDegr
    ee: string;//学历(字典编号)
    patientDiag
    nose: string;//诊断意见
    patientDoct
    or: string;//主治医生(用户表编号)
    patientFirs
    tTimeMedTime: string;//($date-time)首次透析时间
    patientFrom
    : number;//($int32)患者来源(0:门诊 1:住院)
    patientGend
    er: number;//($int32)患者性别 0:男 1:女
    patientHeig
    ht: number;//($int32)患者身高(cm)
    patientHemo
    Code: string;//透析号
    alMedCount: number;//($int32)患者初始透析次数
    alWeight: number;//($int32)患者初始体重(KG)
    patientIsAl
    cohol: number;//($int32)是否饮酒 0:否 1:是
    patientIsEy
    eObstacle: number;//($int32)是否视力障碍 0:否 1:是
    patientIsRe
    ligion: number;//($int32)宗教
    patientIsSm
    oking: number;//($int32)是否吸烟 0:否 1:是
    patientMobi
    le: string;//手机号
    patientName
    : string;//病人姓名
    patientNati
    on: string;//患者民族(字典编号)
    patientNick
    Name: string;//患者别名
    patientNo: 
    string;//门诊住院号
    patientNurs
    e: string;//主管护士(用户表编号)
    patientReceiveTime: string;//($date-time)接收时间
    patientRh: string;//RH(字典编号)
    patientTelNo: string;//电话号码
    patientTelNoRelative: string;//联系人电话
    patientType: string;//患者类型 
    patientWard: string;//病区
    patientWeddingState: string;//婚姻状态(字典编号)
    patientYibaoAlarmDate: string;//医保到期提醒时间
    patientYibaoCode: string;//医保卡号
    patientYibaoEndDate: string;//($date-time)医保到期日期
    patientYoudaoPeriod: string;//诱导期(字典编号)
    remark: string;//备注
    updateTime: string;//($date-time)更新日期
    updateUser: number;//($int32)更新人代码
}


export interface UpdateRecordPatSnapParams {
    recordCode: string; // 透析单编号
    patientFrom: number; // 患者来源
    patientNo: string; // 住院门诊号
    InHospitalWardCode: string; // 病区
    InHospitalBedNo: string; // 床号
    InHospitalTime: string; // 入院时间
    isSyncUpdateToPatInfo: 0 | 1; // 是否将修改内容同步至患者信息
    patientHemoCode?: string | number; // 透析号
}

export interface ListBillsetsByPat {
    bill_item_time: string;
    count: number;
}

export function regeneratePatQRCode(params: object) {
    return request({
        url: '/patient/info/regeneratePatQRCode',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
            },
        params
    });
}
/**
 * 获取患者信息
 * @param params 
 * @returns 
 */
export function detail2(params: string) :AxiosPromise<any> {
	return request({
		url: '/patient/info/detail2',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		data: params,
	});
}

/**
 * 获取患者慢病备案信息
 * @param code 
 * @returns 
 */
export function getMBXXApi(code: string) {
    return request({
        url: '/patient/info/getMBXX',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params: { code }
    })
}

/** 
* 查询检索血透患者
*@param params 要传的参数值
*@return 返回的接口数据
*/
export function QueryList(params: object) {
    return request({
        url: '/patient/info/list',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
            },
        params
    });
}


/** 查询血透患者 - 专门查转入转出  */
export function patientListByTransferInOrOutApi(data: PatientListByTransferInOrOutParams) {
    return request({
        url: '/patient/info/queryInAndOuts',
        method: 'post',
        data
    })
}

export function Add(params: string) {
	return request({
		url: '/patient/info/add',
		method: 'post',
		data: params,
	});
}
export function update(params: Object) {
	return request({
		url: '/patient/info/update',
		method: 'post',
		data: params,
	});
}
export function deleteId(params: string) {
	return request({
		url: '/patient/info/delete',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		data: params,
	});
}
// 获取转归类型
export function getComeOutRecord() {
	return request({
		url: '/patient/operate/status/info/listOperateStatusTypes',
		method: 'post'
	})
}
// 保存转归记录
export function addOutComeRecord(params: string) {
	return request({
		url: '/patient/operate/status/info/add',
		method: 'post',
		data: params,
	});
}
// 修改转归记录
export function editOutComeRecord(params: string) {
	return request({
		url: '/patient/operate/status/info/update',
		method: 'post',
		data: params,
	});
}
// 获取转归记录
export function getOutComeRecordList(params: object) {
	return request({
		url: '/patient/operate/status/info/list',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		params,
	});
}
// 获取转归记录
export function syncPatients(params: object) {
	return request({
		url: '/his/syncPatients',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		params,
	});
}
//HIS帐单金额
export function checkHisBill(params: object) {
    return request({
        url: '/patient/bill/info/checkHisBill',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
            },
        params
    });
}
//HIS帐单金额
export function addBillToHis(params: object) {
    return request({
        url: '/patient/bill/info/addBillToHis',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
            },
        params
    });
}

/**
 * 获取指定条件下拥有门诊处方的患者
 * @param params 
 * @returns 
 */
export function listPatients(params: ListPatientsParams): AxiosPromise<ListPatientsItem[]> {
    params.patientName=params.patientName.toLowerCase()
    return request({
        url: '/patient/bill/set/info/listPatients',
        method: 'post',
        data:params
    });
}

/**
 * 获取门诊处方
 * @param params 
 * @returns 
 */
export function getBills(params: getBillsParams): AxiosPromise<getBillsParamsReponseItem[]> {
    return request({
        url: '/patient/bill/set/info/getBills',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
            },
        params
    });
}
export function ChufangSave(params: object) {
    return request({
        url: '/patient/bill/set/info/save',
        method: 'post',
        data:params
    });
}
export function ChufangAdd(params: object) {
    return request({
        url: '/patient/bill/set/info/add',
        method: 'post',
        data:params
    });
}
export function deleteChufang(params: string) {
	return request({
		url: '/patient/bill/set/info/delete',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		data:params,
	});
}
export function exportToExcel(params: string) {
    return request({
        url: '/patient/info/exportToExcel',
		method: 'post',
		responseType: 'blob',
        params
    });
}
//在操作患者删除与患者转出时, 先调用API:
export function beforeDeletePatient(params: object) {
    return request({
        url: '/patient/info/beforeDeletePatient',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
            },
        params
    });
}



/**
 * 患者检验趋势
 * @param data 
 * @returns 
 */
export function apiInspectionTrend(data: ITendencyRequestData) {
    return request({
        url: "/lis/stat/listHistroByTest",
        method: "post",
        headers: {
            "Content-Type": "application/json"
        },
        data
    });
}


/**
 * 更新透析单中的患者信息（透析单页面里面使用的）
 * @param params 
 * @returns 
 */
export function updateRecordPatSnapApi(params: UpdateRecordPatSnapParams) {
    return request({
        url: '/patient/hemo/med/record/updateRecordPatSnap',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}


/**
 * 该API用于在日期选择框标明哪天是有处方的, 有几个处方
 * @param patientCode 
 * @returns 
 */
export function listBillsetsByPatApi(patientCode: string) :AxiosPromise<ListBillsetsByPat[]> {
    return request({
        url: '/patient/bill/set/info/listBillsetsByPat',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params: { patientCode: patientCode }
    })
}


/**
 * 复制处方
 * @param params 
 * @returns 
 */
export function copyPBSApi(params: CopyPBSParams) {
    return request({
        url: '/patient/bill/set/info/copyPBS',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}


/**
 * 获取处方打印所需指定数据
 * @param params 
 * @returns 
 */
export function listReceipts1Api(params: ListReceipts1Params) {
    return request({
        url: '/patient/bill/set/info/listReceipts1',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}

/**
 * 根据处方编号,查询治疗项目
 * @param pbsCode 
 * @returns 
 */
export function listReceipts2Api(pbsCode: string) {
    return request({
        url: '/patient/bill/set/info/listReceipts2',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params: { pbsCode  }
    })
}

/**
 * 
根据处方编号,查询检验项目
 * @param pbsCode 
 * @returns 
 */
export function listReceipts3Api(pbsCode: string) {
    return request({
        url: '/patient/bill/set/info/listReceipts3',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params: { pbsCode  }
    })
}

/**
 * 查询门诊处方诊断接口（旧）
 * @param params 
 * @returns 
 */
export function diagnosisFindApi(params: DiagnosisFindParams) {
    return request({
        url: '/his/diagnose/sync/find',
        method: 'post',
        params
    })
}


/**
 * 查询诊断列表接口API
 * @param params 
 * @returns 
 */
export function getDiagnosisFindListApi(params: ICommonListParams) {
    return request({
        url: '/his/diagnose/sync/list',
        method: 'post',
        params
    })
}

/**
 * 查询门诊处方诊断接口（新）（常用诊断）
 * @param params 
 * @returns 
 */
export function getClientConfigApi(params: DiagnosisFindParams) {
    return request({
        url: '/his/diagnose/sync/getClientConfig',
        method: 'post',
        params
    })
}

/**
 * 获取药房列表
 * @param params 
 * @returns 
 */
export function pharmacyListApi(params) {
    return request({
        url: '/his/pharmacy/list',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}


/**
 * 保存默认药房
 * @param params 
 * @returns 
 */
export function saveDefaultPharmacyApi(params: SaveDefaultPharmacyParams) {
    return request({
        url: '/his/pharmacy/saveDefaultPharmacy',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}

/**
 * 加载默认药房
 * @param clientCode 
 * @returns 
 */
export function loadDefaultPharmacyApi(clientCode: string) {
    return request({
        url: '/his/pharmacy/loadDefaultPharmacy',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params: { clientCode }
    })
}


/**
 * 获取默认报销方式
 * @param patCode 
 * @returns 
 */
export function loadDefaultBaoxiaoTypeApi(patCode: string) {
    return request({
        url: '/his/pharmacy/loadDefaultBaoxiaoType',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params: { patCode }
    })
}

/**
 * 保存默认报销方式
 * @param patCode 
 * @returns 
 */
export function saveDefaultBaoxiaoTypeApi(patCode: string, baoxiaoType: string) {
    return request({
        url: '/his/pharmacy/saveDefaultBaoxiaoType',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params: { patCode, baoxiaoType }
    })
}


/**
 * 保存默认表单值
 * @param params 
 * @returns 
 */
export function saveDefaultFormValueApi(params: SaveDefaultFormValueParams) {
    return request({
        url: '/his/pharmacy/saveDefaultFormValue',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}

/**
 * 获取默认表单值
 * @param params 
 * @returns 
 */
export function loadDefaultFormValueApi(params: LoadDefaultFormValueParams) {
    return request({
        url: '/his/pharmacy/loadDefaultFormValue',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}


/**
 * 获取参保地数据
 * @param params 
 * @returns 
 */
export function addressListApi(params: AddressListParams) {
    return request({
        url: '/su/dict/medical/inrance/list',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}

/**
 * 新增患者默认处方
 * @param data 
 * @returns 
 */
export function addNewPbsApi(params: AddNewPbsParams) {
    return request({
        url: '/patient/bill/set/info/addNewPbs',
        method: 'post',
        // headers: {
        //     'Content-Type': 'application/x-www-form-urlencoded'
        // },
        params
    })
}
/**
 * 导出全部患者检验信息
 * @param data 
 * @returns 
 */
export function exportAll(params) {
    return request({
        url: '/export',
        method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        params
    })
}