import request from '@/utils/request'

export function fetchList(params) {
  return request({
    url: '/api/patients',
    method: 'get',
    params: params
  })
}

export function fetchAllList() {
  return request({
    url: '/api/patients/all',
    method: 'get'
  })
}
export function GetPatientTotal() {
  return request({
    url: '/api/patients/total',
    method: 'get'
  })
}

export function generateDialysisNo() {
  return request({
    url: '/api/patients/generatedialysisno',
    method: 'get'
  })
}

export function createPatient(patient) {
  return request({
    url: '/api/patients/create?record_date=' + patient.record_date + '&is_infectious=' + patient.is_infectious + '&remind_cycle=' + patient.remind_cycle,
    method: 'post',
    data: patient
  })
}
export function editPatient(id, patient) {
  return request({
    url: '/api/patients/edit?id=' + id + '&record_date=' + patient.record_date + '&is_infectious=' + patient.is_infectious + '&remind_cycle=' + patient.remind_cycle,
    method: 'put',
    data: patient
  })
}
export function fetchPatient(id) {
  return request({
    url: '/api/patients/get?id=' + id,
    method: 'get'
  })
}

export function fetchPatientDialysisSolutions(params) {
  return request({
    url: '/api/patients/dialysissolutions',
    method: 'Get',
    params: params
  })
}

export function createPatientDialysisSolution(id, solution, mode) {
  return request({
    url: '/api/patients/dialysissolution/create?patient=' + id + '&mode=' + mode,
    method: 'post',
    data: solution,
    headers: {
      'Permission': 3
    }

  })
}

export function editPatientDialysisSolution(patient, id, solution, mode) {
  return request({
    url: '/api/patients/dialysissolution/edit?patient=' + patient + '&id=' + id + '&mode=' + mode,
    method: 'put',
    data: solution,
    headers: {
      'Permission': 3
    }

  })
}

export function createChildPatientDialysisSolution(id, solution) {
  return request({
    url: '/api/patients/dialysissolution/child/create?patient=' + id,
    method: 'post',
    data: solution
  })
}

export function editChildPatientDialysisSolution(patient, id, solution) {
  return request({
    url: '/api/patients/dialysissolution/child/edit?patient=' + patient + '&id=' + id,
    method: 'put',
    data: solution
  })
}

export function editDialysisSolutionDetail(patient, id, solution) {
  return request({
    url: '/api/patients/dialysissolution/detail/edit?patient=' + patient + '&id=' + id,
    method: 'put',
    data: solution
  })
}

export function deleteDialysisSolution(id) {
  return request({
    url: '/api/patients/dialysissolution/delete?id=' + id,
    method: 'delete'
  })
}

export function createDryWeight(patient, weight) {
  return request({
    url: '/api/patients/dryweight/create?id=' + patient,
    method: 'post',
    data: weight
  })
}

export function getDryWeights(params) {
  return request({
    url: '/api/patients/dryweight/get',
    method: 'get',
    params: params
  })
}

export function getPatientDialysisRecords(params) {
  return request({
    url: '/api/patients/dialysisrecords',
    method: 'get',
    params: params
  })
}
export function getPatientProEducation(params) {
  return request({
    url: '/api/patients/proeducation',
    method: 'get',
    params: params
  })
}

export function getCourseOfDiseaseRecords(patient_id, start_time_ymd, end_time_ymd) {
  var params = {
    patient_id: patient_id,
    start_time: start_time_ymd,
    end_time: end_time_ymd
  }
  return request({
    url: '/api/patient/courses',
    method: 'get',
    params: params
  })
}

export function createCourseOfDiseaseRecord(patient_id, content, record_time, title) {
  var params = {
    patient_id: patient_id,
    content: content,
    record_time: record_time,
    title: title
  }
  return request({
    url: '/api/patient/course/create',
    method: 'post',
    params: params
  })
}

export function modifyCourseOfDiseaseRecord(patient_id, content, record_time, id, title) {
  console.log(title)
  var params = {
    patient_id: patient_id,
    content: content,
    record_time: record_time,
    id: id,
    title: title

  }
  return request({
    url: '/api/patient/course/modify',
    method: 'post',
    params: params
  })
}

export function getRescueRecords(patient_id, start_time_ymd, end_time_ymd) {
  var params = {
    patient_id: patient_id,
    start_time: start_time_ymd,
    end_time: end_time_ymd
  }
  return request({
    url: '/api/patient/rescues',
    method: 'get',
    params: params
  })
}

export function createRescueRecord(patient_id, content) {
  var params = {
    patient_id: patient_id,
    content: content
  }
  return request({
    url: '/api/patient/rescue/create',
    method: 'post',
    params: params
  })
}

export function deleteCourseOfDiseaseRecords(patient_id, ids_str) {
  var params = {
    patient_id: patient_id,
    ids: ids_str
  }
  return request({
    url: '/api/patient/course/delete',
    method: 'post',
    params: params
  })
}

export function deleteRescueRecords(patient_id, ids_str) {
  var params = {
    patient_id: patient_id,
    ids: ids_str
  }
  return request({
    url: '/api/patient/rescue/delete',
    method: 'post',
    params: params
  })
}

export function EditLapseto(patient_id, data) {
  console.log('data', data)
  return request({
    url: '/api/patients/lapseto/edit?id=' + patient_id,
    method: 'post',
    data: data
  })
}

export function PostSearch(keyword) {
  return request({
    url: '/api/patients/search?keyword=' + keyword,
    method: 'post'

  })
}

export function OpenView(id) {
  return request({
    url: '/api/patients/querypatientbyId',
    method: 'Get',
    params: {
      id: id
    }
  })
}

export function code(id) {
  return request({
    url: '/api/patients/codebyId',
    method: 'Get',
    params: {
      id: id
    }
  })
}

export function GetCoursePrintData(id) {
  return request({
    url: '/api/print/course',
    method: 'Get',
    params: {
      id: id
    }
  })
}

export function GetRemind(params) {
  return request({
    url: '/api/infectious/remind',
    method: 'Get',
    params: params
  })
}

export function PostRemind(params) {
  return request({
    url: '/api/remind/is_open',
    method: 'Post',
    params: params
  })
}

export function getDryWeightData(patientid, params) {
  console.log('patientid', patientid)
  return request({
    url: '/api/patient/getdryweightdata?patientid=' + patientid,
    method: 'Get',
    params: params
  })
}

export function getAllDoctor(params) {
  return request({
    url: '/api/patient/getAllDoctor',
    method: 'Get',
    params: params
  })
}

export function UpdateDryWeightData(params) {
  return request({
    url: '/api/patient/updatedryweightdata',
    method: 'Post',
    params: params,
    headers: {
      'Permission': 3
    }

  })
}

export function getAllData(id, page, limit) {
  const params = {
    id: id,
    page: page,
    limit: limit
  }
  return request({
    url: '/api/patient/getalldata',
    method: 'Get',
    params: params
  })
}

export function postExportPatients(params) {
  return request({
    url: '/api/patients/export',
    method: 'Post',
    data: params
  })
}

export function getMaxDialysisNo() {
  return request({
    url: '/api/patients/dialysis_no',
    method: 'Get'
  })
}

export function getDryWeightDetail(id, params) {
  return request({
    url: '/api/paients/getdryweightdetail?id=' + id,
    method: 'get',
    params: params
  })
}

export function modifyDryWeightData(params) {
  return request({
    url: '/api/patients/modifydryweightdata',
    method: 'get',
    params: params
  })
}

export function deleteDryWeight(id, data) {
  console.log('id', id)
  return request({
    url: '/api/patient/deletedryweight?id=' + id,
    method: 'delete',
    data: data
  })
}
