import request from '@/utils/request'

export function getAdviceConfig(type) {
  return request({
    url: '/api/getadviceconfigs?type=' + type,
    method: 'get'
  })
}

export function getAllAdviceConfig() {
  return request({
    url: '/api/getalladviceconfig',
    method: 'get'
  })
}

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

  })
}

export function EditDoctorAdvice(patient, id, advice,mode) {
  return request({
    url: '/api/patients/advice/edit?id=' + id + '&patient=' + patient+"&mode="+mode,
    method: 'Put',
    data: advice,
    headers:{"Permission":2},

  })
}

export function ExecDoctorAdvice(patient, id, time,mode) {
  var params = {
    id: id,
    patient: patient,
    execution_time: time,
    mode:mode
  }
  return request({
    url: '/api/patients/advice/exec',
    method: 'Post',
    params: params,
    headers:{"Permission":2},

  })
}
export function CheckDoctorAdvice(patient, id,mode) {
  var params = {
    id: id,
    patient: patient,
    mode:mode
    // execution_time: time,
  }
  return request({
    url: '/api/patients/advice/check',
    method: 'Post',
    params: params,
    headers:{"Permission":2},

  })
}


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

// export function StopDoctorAdvice(id, reason,mode) {
//   return request({
//     url: '/api/patients/advice/stop?id=' + id+"&mode="+mode,
//     method: 'Post',
//     data: reason,
//     headers:{"Permission":3},
//
//   })
// }

export function StopGroupAdvice(groupno, reason,mode) {
  return request({
    url: '/api/patients/advice/stopgroup?groupno=' + groupno+"&mode="+mode,
    method: 'Post',
    data: reason,
    headers:{"Permission":3},

  })
}



export function DeleteDoctorAdvice(id,mode) {
  return request({
    url: '/api/patients/advice/delete?id=' + id+"&mode="+mode,
    method: 'Delete',
    headers:{"Permission":2},

  })
}

export function CreateDrugDic(data) {
  return request({
    url: '/api/drugdic/create',
    method: 'post',
    data: data
  })
}
export function UpdateDrugDic(id, data) {
  return request({
    url: '/api/drugdic/update?id=' + id,
    method: 'put',
    data: data
  })
}
export function DeleteDrugDic(id) {
  return request({
    url: '/api/drugdic/delete?id=' + id,
    method: 'delete'
  })
}

export function CreateDrugWay(data) {
  return request({
    url: '/api/drugway/create',
    method: 'post',
    data: data
  })
}

export function UpdateDrugWay(id, data) {
  return request({
    url: '/api/drugway/update?id=' + id,
    method: 'put',
    data: data
  })
}
export function DeleteDrugWay(id) {
  return request({
    url: '/api/drugway/delete?id=' + id,
    method: 'delete'
  })
}

export function CreateExecutionFrequency(data) {
  return request({
    url: '/api/executionfrequency/create',
    method: 'post',
    data: data
  })
}

export function UpdateExecutionFrequency(id, data) {
  return request({
    url: '/api/executionfrequency/update?id=' + id,
    method: 'put',
    data: data
  })
}
export function DeleteExecutionFrequency(id) {
  return request({
    url: '/api/executionfrequency/delete?id=' + id,
    method: 'delete'
  })
}
export function CreateAdviceTemplate(data) {
  return request({
    url: '/api/advicetemplate/create',
    method: 'post',
    data: data
  })
}

export function UpdateAdviceTemplate(id, data) {
  return request({
    url: '/api/advicetemplate/update?id=' + id,
    method: 'put',
    data: data
  })
}
export function DeleteAdviceTemplate(id, template_id, parent_id) {
  return request({
    url: '/api/advicetemplate/delete?id=' + id + '&template_id=' + template_id + '&parent_id=' + parent_id,
    method: 'delete'
  })
}

export function postAdviceTemplate(params, name, advice_type) {
  return request({
    url: '/api/advicetemplate/create?template_name=' + name + '&advice_type=' + advice_type,
    method: 'post',
    data: params
  })
}

export function CreateGroupAdvice(id, groupno, advices,mode) {
  if (advices.remind > 0) {
    return request({
      url: '/api/patients/advice/creategroup?id=' + id + '&groupno=' + groupno+"&mode="+mode,
      method: 'post',
      data: advices,
      headers:{"Permission":2},

    })
  } else {
    return request({
      url: '/api/patients/advice/creategroup?id=' + id + '&groupno=' + groupno+"&mode="+mode,
      method: 'post',
      data: advices,
      headers:{"Permission":2},

    })
  }
}
export function DeleteGroupAdvice(groupno,mode) {
  return request({
    url: '/api/patients/advice/deletegroup?groupno=' + groupno+"&mode="+mode,
    method: 'delete',
    headers:{"Permission":3},

  })
}

export function getAllAdviceTemplate() {
  return request({
    url: '/api/advicetemplate/list',
    method: 'get'
  })
}

export function CreateSingleAdviceTemplate(advices) {
  return request({
    url: '/api/advicetemplate/add',
    method: 'post',
    params: advices

  })
}
export function DeleteParentAdviceTemplate(id) {
  return request({
    url: '/api/adviceparenttemplate/delete?template_id=' + id,
    method: 'delete'

  })
}

export function CreateSubAdvice(params) {
  return request({
    url: '/api/subadvice/create',
    method: 'post',
    params: params
  })
}

export function updateTemplateName(params) {
  return request({
    url: '/api/template/modify',
    method: 'post',
    params: params
  })
}

export function getDoctorAdviceConfig() {
  return request({
    url: '/api/adviceconfig/get',
    method: 'get'
  })
}

export function postDoctorAdviceConfig(params) {
  return request({
    url: '/api/adviceconfig/isopen',
    method: 'post',
    params: params
  })
}

export function getDoctorInitConfig() {
  return request({
    url: '/api/advicetemplate/init/get',
    method: 'get'
  })
}

export function PostInitAdviceTemplate(params) {
  return request({
    url: '/api/advicetemplate/init/commit',
    method: 'post',
    params: params

  })
}

export function getPrintInfo(data) {
  return request({
    url: '/api/advicetemplate/getprintinfo',
    method: 'post',
    data: data
  })
}





export function EditNewDoctorAdvice(patient, id, advice,mode) {
  return request({
    url: '/api/patients/advice/edit?id=' + id + '&patient=' + patient+"&mode="+mode,
    method: 'Put',
    data: advice,
    headers:{"Permission":2},

  })
}





export function CreateNewDoctorAdvice(id, advice,mode) {
  return request({
    url: '/api/patients/advice/create?id=' + id+"&mode="+mode,
    method: 'post',
    data: advice,
    headers:{"Permission":2},

  })
}



export function CreateNewGroupAdvice(id, groupno, advices,mode) {
  if (advices.remind > 0) {
    return request({
      url: '/api/patients/advice/creategroup?id=' + id + '&groupno=' + groupno+"&mode="+mode,
      method: 'post',
      data: advices,
      headers:{"Permission":3},

    })
  } else {
    return request({
      url: '/api/patients/advice/creategroup?id=' + id + '&groupno=' + groupno+"&mode="+mode,
      method: 'post',
      data: advices,
      headers:{"Permission":3},

    })
  }
}



export function DeleteNewDoctorAdvice(id,mode) {
  return request({
    url: '/api/patients/advice/delete?id=' + id+"&mode="+mode,
    method: 'Delete',
    headers:{"Permission":2},

  })
}



export function DeleteNewGroupAdvice(groupno,mode) {
  return request({
    url: '/api/patients/advice/deletegroup?groupno=' + groupno+"&mode="+mode,
    method: 'delete',
    headers:{"Permission":3},

  })
}



export function StopDoctorAdvice(id, reason,mode) {
  return request({
    url: '/api/patients/advice/stop?id=' + id+"&mode="+mode,
    method: 'Post',
    data: reason,
    headers:{"Permission":2},

  })
}




export function ExecGroupAdvice(groupno, time,mode) {
  return request({
    url: '/api/patients/advice/execgroup?groupno=' + groupno + '&execution_time=' + time+"&mode="+mode,
    method: 'Post',
    headers:{"Permission":2},

  })
}


export function CheckGroupAdvice(groupno,mode) {
  var params = {
    groupno: groupno,
    mode: mode,
  }
  return request({
    url: '/api/patients/advice/checkgroup',
    method: 'Post',
    params: params,
    headers:{"Permission":2},

  })
}

