import request from '@/utils/request'

const defaultYearDate = () => new Date()
const withYearDate = (query) => ({
  yearDate: (query && query.yearDate) || defaultYearDate(),
  ...(query || {})
})

// 查询患者诊断信息列�?
export function listPatientDiagnosis(query) {
  return request({
    url: '/outpatientService/patientDiagnosis/list',
    method: 'get',
    params: withYearDate(query)
  })
}

// 查询患者诊断信息详�?
export function getPatientDiagnosis(id) {
  return request({
    url: '/outpatientService/patientDiagnosis/getInfo/' + id,
    method: 'get',
    params: { yearDate: defaultYearDate() }
  })
}

// 新增患者诊断信�?
export function addPatientDiagnosis(data) {
  return request({
    url: '/outpatientService/patientDiagnosis/add',
    method: 'post',
    data: data
  })
}

// 修改患者诊断信�?
export function updatePatientDiagnosis(data) {
  return request({
    url: '/outpatientService/patientDiagnosis/update',
    method: 'post',
    data: data
  })
}

// 删除患者诊断信�?
export function delPatientDiagnosis(id) {
  return request({
    url: '/outpatientService/patientDiagnosis/remove/' + id,
    method: 'get',
    params: { yearDate: defaultYearDate() }
  })
}


// 获取药品列表
export function gainDrugList(data) {
  return request({
    url: '/outpatientService/patientDiagnosis/gainDrugList',
    method: 'post',
    data: data
  })
}

// 获取药品价格列表
export function gainDrugPriceList(query) {
  return request({
    url: '/outpatientService/patientDiagnosis/gainDrugPriceList',
    method: 'get',
    params: withYearDate(query)
  })
}

// 获取 药品 名称 列表 
export function gainDrugNameList() {
  return request({
    url: '/outpatientService/patientDiagnosis/gainMedicineNameList',
    method: 'get',
    params: { yearDate: defaultYearDate() },
  })
}

// 获取 药品 名称 列表  参数 药品 名称 
export function gainDrugNameListName(name) {
  return request({
    url: '/outpatientService/patientDiagnosis/gainMedicineNameListName?name=' + name,
    method: 'get',
    params: { yearDate: defaultYearDate() },
  })
}

// 获取 药品 档案 列表
export function gainMedicineArchiveList(query) {
  return request({
    url: '/outpatientService/patientDiagnosis/gainMedicineArchiveList',
    method: 'get',
    params: withYearDate(query)
  })
}

// 获取 药品 档案 库存 详细 列表
export function gainDrugInventoryList(query) {
  return request({
    url: '/outpatientService/patientDiagnosis/gainDrugInventoryList',
    method: 'get',
    params: withYearDate(query)
  })
}

// 修改患者诊断状�?( 修改�?已发�?)
export function deliverMedicine(id) {
  return request({
    url: '/outpatientService/patientDiagnosis/deliverMedicine/' + id,
    method: 'get',
    params: { yearDate: defaultYearDate() }
  })
}

// 修改患者诊断状�?( 修改�?已退�?)
export function returnedMedication(id) {
  return request({
    url: '/outpatientService/patientDiagnosis/returnedMedication/' + id,
    method: 'get',
    params: { yearDate: defaultYearDate() }
  })
}

// 保存 患�?诊断 信息
export function saveDiagnosis(data) {
  return request({
    url: '/outpatientService/patientDiagnosis/save',
    method: 'post',
    data: data
  })
}

// 保存 变成 待发  修改 库存  患�?诊断 信息
export function saveAddDiagnosis(data) {
  return request({
    url: '/outpatientService/patientDiagnosis/saveAddDiagnosis',
    method: 'post',
    data: data
  })
}

// 保存 修改 患�?诊断 信息
export function saveUpdate(data) {
  return request({
    url: '/outpatientService/patientDiagnosis/saveUpdate',
    method: 'post',
    data: data
  })
}


// 获取 
export function gainPatientDiagnosisListXml() {
  return request({
    url: '/outpatientService/patientDiagnosis/gainPatientDiagnosisListXml',
    method: 'get',
    params: { yearDate: defaultYearDate() },
  })
}

// gainPatientDiagnosisListTotalPriceXml
export function gainPatientDiagnosisListTotalPriceXml() {
  return request({
    url: '/outpatientService/patientDiagnosis/gainPatientDiagnosisListTotalPriceXml',
    method: 'get',
    params: { yearDate: defaultYearDate() },
  })
}



// obtainSymptomStatisticsNumber
// 获取 
export function obtainSymptomStatisticsNumber(query) {
  return request({
    url: '/outpatientService/patientDiagnosis/obtainSymptomStatisticsNumber',
    method: 'get',
    params: withYearDate(query)
  })
}

// obtainSymptomStatisticsNumberMonth
// 获取
export function obtainSymptomStatisticsNumberMonth(query) {
  return request({
    url: '/outpatientService/patientDiagnosis/obtainSymptomStatisticsNumberMonth',
    method: 'get',
    params: withYearDate(query)
  })
}
// 调用后端的代码判断是否可用医�?
export function verifyInsuranceStatus(idCard, name) {
  return request({
    url: '/outpatientService/patientDiagnosis/verify',
    method: 'get',
    params: withYearDate({ idCard, name })
  })
}

// 获取历史医保报销累计金额（按患者ID�?
export function getHistoryReimbursement(patientId, yearDate = new Date()) {
  return request({
    url: '/outpatientService/patientDiagnosis/getHistoryReimbursementByYear',
    method: 'get',
    params: { patientId, yearDate }
  })
}

// 发药更正：仅调整医保与报销比率
export function adjustBasic(data) {
  return request({
    url: '/outpatientService/patientDiagnosis/adjustBasic',
    method: 'post',
    data: data
  })
}



