import request from '@/utils/request'
import requestDownload from '@/utils/request-download'

function getParams(obj) {
  let result = '';
  let item;
  for (item in obj) {
    if (obj[item] && String(obj[item])) {
      result += `&${item}=${obj[item]}`;
    }
  }
  if (result) {
    result = '?' + result.slice(1);
  }
  return result;
}

export function getDicTree() {
  return request({
    url: '/dictionary/getDicTree',
    method: 'get'
  })
}

export function getDictionarySelectList(param) {
  return request({
    url: '/dictionary/getDictionarySelectList',
    method: 'post',
    data: param
  })
}

export function addOrUpdateDictionary(param) {
  return request({
    url: '/dictionary/addOrUpdateDictionary',
    method: 'post',
    data: param
  })
}

export function deleteDictionary(id) {
  return request({
    url: `/dictionary/deleteDictionary/${id}`,
    method: 'delete'
  })
}

export function getHospitalPageList(param) {
  return request({
    url: '/hospital/getHospitalPageList',
    method: 'post',
    data: param
  })
}

export function addOrUpdateHospital(param) {
  return request({
    url: '/hospital/addOrUpdateHospital',
    method: 'post',
    data: param
  })
}

export function deleteHospital(hospitalId) {
  return request({
    url: `/hospital/deleteHospital/${hospitalId}`,
    method: 'delete'
  })
}

export function getSiteList(param) {
  return request({
    url: '/site/getSiteList',
    method: 'post',
    data: param
  })
}

export function addOrUpdateSite(param) {
  return request({
    url: '/site/addOrUpdateSite',
    method: 'post',
    data: param
  })
}

export function deleteSite(siteId) {
  return request({
    url: `/site/deleteSite/${siteId}`,
    method: 'delete'
  })
}

export function getCROPageList(param) {
  return request({
    url: '/cro/getCROList',
    method: 'post',
    data: param
  })
}

export function addOrUpdateCro(param) {
  return request({
    url: '/cro/addOrUpdateCro',
    method: 'post',
    data: param
  })
}

export function deleteCROCompany(croCompanyId) {
  return request({
    url: `/cro/deleteCro/${croCompanyId}`,
    method: 'delete'
  })
}

export function getSponsorPageList(param) {
  return request({
    url: '/sponsor/getSponsorList',
    method: 'post',
    data: param
  })
}

export function addOrUpdateSponsor(param) {
  return request({
    url: '/sponsor/addOrUpdateSponsor',
    method: 'post',
    data: param
  })
}

export function deleteSponsor(sponsorId) {
  return request({
    url: `/sponsor/deleteSponsor/${sponsorId}`,
    method: 'delete'
  })
}

export function getQaTemplateList(param) {
  return request({
    url: '/QATemplate/GetQaTemplateList',
    method: 'post',
    data: param
  })
}

export function addOrUpdateQATemplate(param) {
  return request({
    url: '/QATemplate/AddOrUpdateQATemplate',
    method: 'post',
    data: param
  })
}

export function deleteQATemplate(qaTemplateId) {
  return request({
    url: `/QATemplate/DeleteQATemplate/${qaTemplateId}`,
    method: 'delete'
  })
}

export function getQaTemplateConfigList(qaTemplateId, modalityId) {
  return request({
    url: `/QATemplate/GetQATemplateConfigedList/${qaTemplateId}/${modalityId}`,
    method: 'get'
  })
}

export function configQATemplateItem(param) {
  return request({
    url: '/QATemplate/ConfigQATemplateItem',
    method: 'post',
    data: param
  })
}

export function getQATemplateItemList(param) {
  return request({
    url: '/QATemplate/GetQATemplateItemList',
    method: 'post',
    data: param
  })
}
export function addOrUpdateQATemplateItem(param) {
  return request({
    url: '/QATemplate/AddOrUpdateQATemplateItem',
    method: 'post',
    data: param
  })
}

export function deleteQATemplateItem(qaTemplateItemId) {
  return request({
    url: `/QATemplate/DeleteQATemplateItem/${qaTemplateItemId}`,
    method: 'delete'
  })
}

export function getQCQuestionConfigureList(param) {
  return request({
    url: `/QCQuestionConfigure/getQCQuestionConfigureList`,
    method: 'post',
    data: param
  })
}

export function addOrUpdateQCQuestionConfigure(param) {
  return request({
    url: `/QCQuestionConfigure/addOrUpdateQCQuestionConfigure`,
    method: 'post',
    data: param
  })
}

export function deleteQCQuestionConfigure(qcQuestionConfigureId) {
  return request({
    url: `/QCQuestionConfigure/deleteQCQuestionConfigure/${qcQuestionConfigureId}`,
    method: 'delete'
  })
}
export function getSystemDocumentList(param) {
  return request({
    url: `/SystemDocument/getSystemDocumentList`,
    method: 'post',
    data: param
  })
}

export function addOrUpdateSystemDocument(param) {
  return request({
    url: `/SystemDocument/addOrUpdateSystemDocument`,
    method: 'post',
    data: param
  })
}

export function deleteSystemDocument(id) {
  return request({
    url: `/SystemDocument/deleteSystemDocument/${id}`,
    method: 'delete'
  })
}
export function abandonSystemDocument(id) {
  return request({
    url: `/SystemDocument/AbandonSystemDocument/${id}`,
    method: 'delete'
  })
}

export function uploadSystemDoc(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: `/TrialDocument/UploadSystemDoc`,
    method: 'post',
    data: formData
  })
}

export function getCommonDocumentList(param) {
  return request({
    url: `/CommonDocument/getCommonDocumentList`,
    method: 'post',
    data: param
  })
}
export function getCommonDocument(param) {
  return request({
    url: `/CommonDocument/getCommonDocument`,
    method: 'get',
    params: param
  })
}
export function addOrUpdateCommonDocument(param) {
  return request({
    url: `/CommonDocument/addOrUpdateCommonDocument`,
    method: 'post',
    data: param
  })
}

export function uploadCommonDoc(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: `/CommonDocument/UploadCommonDoc`,
    method: 'post',
    data: formData
  })
}

export function DownloadCommonDoc(code) {
  return requestDownload({
    url: `/CommonDocument/DownloadCommonDoc?code=${code}`,
    method: 'get',
    responseType: 'blob'
  })
}

export function DownloadSystemClinicalFile(clinicalDataSystemSetId) {
  return requestDownload({
    url: `/CommonDocument/DownloadSystemClinicalFile?clinicalDataSystemSetId=${clinicalDataSystemSetId}`,
    method: 'get',
    responseType: 'blob'
  })
}

export function getEmailNoticeConfigList(param) {
  return request({
    url: `/EmailNoticeConfig/getEmailNoticeConfigList`,
    method: 'post',
    data: param
  })
}
export function deleteEmailNoticeConfig(id) {
  return request({
    url: `/EmailNoticeConfig/deleteEmailNoticeConfig/${id}`,
    method: 'delete'
  })
}
export function addOrUpdateEmailNoticeConfigList(param) {
  return request({
    url: `/EmailNoticeConfig/addOrUpdateEmailNoticeConfig`,
    method: 'post',
    data: param
  })
}

export function getBasicDataSelect(param) {
  return request({
    url: `/SystemBasicData/getBasicDataSelect`,
    method: 'post',
    data: param
  })
}

export function getSystemBasicDataList(param) {
  return request({
    url: `/SystemBasicData/getSystemBasicDataList`,
    method: 'post',
    data: param
  })
}
export function deleteSystemBasicData(id) {
  return request({
    url: `/SystemBasicData/deleteSystemBasicData/${id}`,
    method: 'delete'
  })
}
export function addOrUpdateSystemBasicData(param) {
  return request({
    url: `/SystemBasicData/addOrUpdateSystemBasicData`,
    method: 'post',
    data: param
  })
}
export function getChildList(parentId) {
  return request({
    url: `/SystemBasicData/getChildList/${parentId}`,
    method: 'get'
  })
}

export function getSystemBasicData(code) {
  return request({
    url: `/SystemBasicData/getSystemBasicData/${code}`,
    method: 'get'
  })
}

export function getSystemAnonymizationList(param) {
  return request({
    url: `/SystemAnonymization/getSystemAnonymizationList`,
    method: 'post',
    data: param
  })
}

export function addOrUpdateSystemAnonymization(param) {
  return request({
    url: `/SystemAnonymization/addOrUpdateSystemAnonymization`,
    method: 'post',
    data: param
  })
}

export function deleteSystemAnonymization(id) {
  return request({
    url: `/SystemAnonymization/deleteSystemAnonymization/${id}`,
    method: 'delete'
  })
}

export function getBasicDicList(param) {
  return request({
    url: `/Dictionary/getBasicDicList`,
    method: 'post',
    data: param
  })
}

export function addOrUpdateBasicDic(param) {
  return request({
    url: `/Dictionary/addOrUpdateBasicDic`,
    method: 'post',
    data: param
  })
}

export function getDictionaryChildList(id) {
  return request({
    url: `/Dictionary/getChildList/${id}`,
    method: 'get'
  })
}

export function getClinicalDataSetList(param) {
  return request({
    url: `/ClinicalDataSet/getSystemClinicalDataSystemSetList`,
    method: 'post',
    data: param
  })
}

export function addOrUpdateClinicalDataSet(param) {
  return request({
    url: `/ClinicalDataSet/addOrUpdateClinicalDataSystemSet`,
    method: 'post',
    data: param
  })
}

export function deleteClinicalSetData(id) {
  return request({
    url: `/ClinicalDataSet/deleteClinicalSystemSetData/${id}`,
    method: 'delete'
  })
}

export function getReadingQuestionCriterionSystemList(param) {
  return request({
    url: '/ReadingQuestion/getReadingQuestionCriterionSystemList',
    method: 'post',
    data: param
  })
}

export function setSystemReadingQuestionCriterionIsIsEnable(param) {
  return request({
    url: '/ReadingQuestion/setSystemReadingQuestionCriterionIsIsEnable',
    method: 'post',
    data: param
  })
}

export function getReadingQuestionSystemList(param) {
  return request({
    url: '/ReadingQuestion/getReadingQuestionSystemList',
    method: 'post',
    data: param
  })
}

export function addOrUpdateReadingQuestionSystem(param) {
  return request({
    url: '/ReadingQuestion/addOrUpdateReadingQuestionSystem',
    method: 'post',
    data: param
  })
}
export function deleteReadingQuestionSystem(readingQuestionSystemId) {
  return request({
    url: `/ReadingQuestion/deleteReadingQuestionSystem/${readingQuestionSystemId}`,
    method: 'delete'
  })
}

export function getSystemCriterionOtherQuestion(param) {
  return request({
    url: `/ReadingQuestion/getSystemCriterionOtherQuestion`,
    method: 'post',
    data: param
  })
}

export function getSystemGroupNameList(param) {
  return request({
    url: `/ReadingQuestion/getSystemGroupNameList`,
    method: 'post',
    data: param
  })
}

export function setSystemReadingQuestionCriterionIsCompleteConfig(param) {
  return request({
    url: `/ReadingQuestion/setSystemReadingQuestionCriterionIsCompleteConfig`,
    method: 'post',
    data: param
  })
}

export function getReadingMedicineSystemQuestionList(param) {
  return request({
    url: `/ReadingMedicineQuestion/getReadingMedicineSystemQuestionList`,
    method: 'post',
    data: param
  })
}
export function deleteReadingMedicineSystemQuestion(id) {
  return request({
    url: `/ReadingMedicineQuestion/deleteReadingMedicineSystemQuestion/${id}`,
    method: 'delete'
  })
}
export function addOrUpdateReadingMedicineSystemQuestion(param) {
  return request({
    url: `/ReadingMedicineQuestion/addOrUpdateReadingMedicineSystemQuestion`,
    method: 'post',
    data: param
  })
}

export function getSystemReadingQuestion(param) {
  return request({
    url: `/ReadingImageTask/getSystemReadingQuestion`,
    method: 'post',
    data: param
  })
}

export function getQCQuestionSelectList(param) {
  return request({
    url: `/QCQuestionConfigure/GetQCQuestionSelectList`,
    method: 'post',
    data: param
  })
}

export function getQuestionView(param) {
  return request({
    url: `/QCQuestionConfigure/getQuestionView`,
    method: 'post',
    data: param
  })
}

export function getReadingMedicineSystemOtherQuestion(param) {
  return request({
    url: `/ReadingMedicineQuestion/getReadingMedicineSystemOtherQuestion`,
    method: 'post',
    data: param
  })
}

export function getOrganInfoList(param) {
  return request({
    url: `/OrganInfo/getOrganInfoList`,
    method: 'post',
    data: param
  })
}

export function getOrganPageList(param) {
  return request({
    url: `/OrganInfo/getOrganPageList`,
    method: 'post',
    data: param
  })
}

export function addOrUpdateOrganInfo(param) {
  return request({
    url: `/OrganInfo/addOrUpdateOrganInfo`,
    method: 'post',
    data: param
  })
}

export function deleteOrganInfo(id) {
  return request({
    url: `/OrganInfo/deleteOrganInfo/${id}`,
    method: 'delete'
  })
}

export function getCriterionNidusList(param) {
  return request({
    url: `/OrganInfo/getCriterionNidusList`,
    method: 'post',
    data: param
  })
}

export function addOrUpdateCriterionNidus(param) {
  return request({
    url: `/OrganInfo/addOrUpdateCriterionNidus`,
    method: 'post',
    data: param
  })
}

export function deleteCriterionNidus(id) {
  return request({
    url: `/OrganInfo/deleteCriterionNidus/${id}`,
    method: 'delete'
  })
}

export function copySystemCriterionData(param) {
  return request({
    url: `/ReadingQuestion/copySystemCriterionData`,
    method: 'post',
    data: param
  })
}

export function getTumorAssessmentList(param) {
  return request({
    url: `/ReadingQuestion/getTumorAssessmentList`,
    method: 'post',
    data: param
  })
}

export function getTumorAssessmentPageList(param) {
  return request({
    url: `/ReadingQuestion/getTumorAssessmentPageList`,
    method: 'post',
    data: param
  })
}
export function addOrUpdateTumorAssessment(param) {
  return request({
    url: `/ReadingQuestion/addOrUpdateTumorAssessment`,
    method: 'post',
    data: param
  })
}

export function deleteTumorAssessment(id) {
  return request({
    url: `/ReadingQuestion/deleteTumorAssessment/${id}`,
    method: 'delete'
  })
}
export function addOrUpdateReadingQuestionCriterionSystem(param) {
  return request({
    url: `/ReadingQuestion/addOrUpdateReadingQuestionCriterionSystem`,
    method: 'post',
    data: param
  })
}

export function deleteReadingQuestionCriterionSystem(id) {
  return request({
    url: `/ReadingQuestion/deleteReadingQuestionCriterionSystem/${id}`,
    method: 'delete'
  })
}

export function getBasicConfigSelect(searchKey) {
  return request({
    url: `/Dictionary/getBasicConfigSelect?searchKey=${searchKey}`,
    method: 'get'
  })
}

export function getSystemCriterionSelectList(param) {
  return request({
    url: `/ClinicalDataSet/getSystemCriterionSelectList`,
    method: 'post',
    data: param
  })
}

export function getAssessType(param) {
  return request({
    url: `/ReadingQuestion/getAssessType`,
    method: 'post',
    data: param
  })
}

export function setAssessType(param) {
  return request({
    url: `/ReadingQuestion/setAssessType`,
    method: 'post',
    data: param
  })
}

export function setDictionaryFollowVisitUse(param) {
  return request({
    url: `/ReadingQuestion/setDictionaryFollowVisitUse`,
    method: 'post',
    data: param
  })
}

export function setDictionaryBaseLineUse(param) {
  return request({
    url: `/ReadingQuestion/setDictionaryBaseLineUse`,
    method: 'post',
    data: param
  })
}

export function getSystemOncologyInfo(param) {
  return request({
    url: `/ReadingQuestion/getSystemOncologyInfo`,
    method: 'post',
    data: param
  })
}

export function setSystemOncologyInfo(param) {
  return request({
    url: `/ReadingQuestion/setSystemOncologyInfo`,
    method: 'post',
    data: param
  })
}

export function getCriterionDictionaryList(param) {
  return request({
    url: `/Dictionary/getCriterionDictionaryList?SystemCriterionId=${param.SystemCriterionId}`,
    method: 'get'
  })
}

export function getTrialCriterionDictionaryList(param) {
  return request({
    url: `/Dictionary/getTrialCriterionDictionaryList?TrialCriterionId=${param.TrialCriterionId}`,
    method: 'get'
  })
}

export function setCriterionDictionary(params) {
  return request({
    url: `/ReadingQuestion/setCriterionDictionary`,
    method: 'post',
    data: params
  })
}

export function setSystemGlobalInfo(params) {
  return request({
    url: `/ReadingQuestion/setSystemGlobalInfo`,
    method: 'post',
    data: params
  })
}

export function getSystemGlobalInfo(params) {
  return request({
    url: `/ReadingQuestion/getSystemGlobalInfo`,
    method: 'post',
    data: params
  })
}

export function getCriterionDictionary(params) {
  return request({
    url: `/Dictionary/getCriterionDictionary`,
    method: 'post',
    data: params
  })
}

export function addSystemCriterionDictionaryCode(params) {
  return request({
    url: `/ReadingQuestion/addSystemCriterionDictionaryCode`,
    method: 'post',
    data: params
  })
}

export function deleteSystemCriterionDictionary(params) {
  return request({
    url: `/ReadingQuestion/deleteSystemCriterionDictionary`,
    method: 'post',
    data: params
  })
}

export function synchronizeSystemOrgan(params) {
  return request({
    url: `/OrganInfo/synchronizeSystemOrgan`,
    method: 'post',
    data: params
  })
}

export function editCriterionDictionary(params) {
  return request({
    url: `/ReadingQuestion/editCriterionDictionary`,
    method: 'post',
    data: params
  })
}

export function getSystemClinicalQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getSystemClinicalQuestionList`,
    method: 'post',
    data: params
  })
}

export function deleteSystemClinicalQuestion(Id) {
  return request({
    url: `/ClinicalQuestion/deleteSystemClinicalQuestion/${Id}`,
    method: 'post'
  })
}

export function addOrUpdateSystemClinicalQuestion(params) {
  return request({
    url: `/ClinicalQuestion/addOrUpdateSystemClinicalQuestion`,
    method: 'post',
    data: params
  })
}

export function getSystemClinicalOtherQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getSystemClinicalOtherQuestionList`,
    method: 'post',
    data: params
  })
}

export function getSystemClinicalGroupQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getSystemClinicalGroupQuestionList`,
    method: 'post',
    data: params
  })
}

export function getSystemClinicalTableQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getSystemClinicalTableQuestionList`,
    method: 'post',
    data: params
  })
}

export function getTrialClinicalTableQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getTrialClinicalTableQuestionList`,
    method: 'post',
    data: params
  })
}

export function deleteSystemClinicalTableQuestion(id) {
  return request({
    url: `/ClinicalQuestion/deleteSystemClinicalTableQuestion/${id}`,
    method: 'post'
  })
}

export function deleteTrialClinicalTableQuestion(id) {
  return request({
    url: `/ClinicalQuestion/deleteTrialClinicalTableQuestion/${id}`,
    method: 'post'
  })
}

export function addOrUpdateSystemClinicalTableQuestion(params) {
  return request({
    url: `/ClinicalQuestion/addOrUpdateSystemClinicalTableQuestion`,
    method: 'post',
    data: params
  })
}

export function addOrUpdateTrialClinicalTableQuestion(params) {
  return request({
    url: `/ClinicalQuestion/addOrUpdateTrialClinicalTableQuestion`,
    method: 'post',
    data: params
  })
}

export function applySystemClinical(params) {
  return request({
    url: `/ClinicalDataSet/applySystemClinical`,
    method: 'post',
    data: params
  })
}

export function getTrialClinicalQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getTrialClinicalQuestionList`,
    method: 'post',
    data: params
  })
}

export function deleteTrialClinicalQuestion(id) {
  return request({
    url: `/ClinicalQuestion/deleteTrialClinicalQuestion/${id}`,
    method: 'post'
  })
}

export function applyTrialClinical(params) {
  return request({
    url: `/ClinicalDataSet/applyTrialClinical`,
    method: 'post',
    data: params
  })
}

export function addOrUpdateTrialClinicalQuestion(params) {
  return request({
    url: `/ClinicalQuestion/addOrUpdateTrialClinicalQuestion`,
    method: 'post',
    data: params
  })
}

export function getTrialClinicalOtherQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getTrialClinicalOtherQuestionList`,
    method: 'post',
    data: params
  })
}

export function getTrialClinicalGroupQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getTrialClinicalGroupQuestionList`,
    method: 'post',
    data: params
  })
}

export function addBasicDicAndChild(params) {
  return request({
    url: `/Dictionary/addBasicDicAndChild`,
    method: 'post',
    data: params
  })
}

export function getClinicalCalculateQuestions(params) {
  return request({
    url: `/ClinicalQuestion/getClinicalCalculateQuestions`,
    method: 'post',
    data: params
  })
}

export function getTrialClinicalQuestionCalculateRelation(params) {
  return request({
    url: `/ClinicalQuestion/getTrialClinicalQuestionCalculateRelation`,
    method: 'post',
    data: params
  })
}

export function getClinicalQuestionFormList(params) {
  return request({
    url: `/ClinicalAnswer/getClinicalQuestionFormList`,
    method: 'post',
    data: params
  })
}

export function getClinicalFormInfo(params) {
  return request({
    url: `/ClinicalAnswer/getClinicalFormInfo`,
    method: 'post',
    data: params
  })
}

export function Upload(params, type) {
  return request({
    url: `/SystemFile/Upload?fileType=${type}`,
    method: 'post',
    data: params
  })
}

export function getTrialUserIdSelectList(trialId) {
  return request({
    url: `/TrialEmailNoticeConfig/getTrialUserIdSelectList?TrialEmailNoticeConfigId=${trialId}`,
    method: 'get'
  })
}

export function getSysEmailNoticeConfigList(params) {
  return request({
    url: `/TrialEmailNoticeConfig/getSysEmailNoticeConfigList${getParams(params)}`,
    method: 'get'
  })
}


export function batchAddSysEmailConfig(params) {
  return request({
    url: `/TrialEmailNoticeConfig/batchAddSysEmailConfig`,
    method: 'post',
    data: params
  })
}

export function deleteTrialEmailNoticeConfig(trialEmailNoticeConfigId) {
  return request({
    url: `/TrialEmailNoticeConfig/deleteTrialEmailNoticeConfig/${trialEmailNoticeConfigId}`,
    method: 'delete'
  })
}

export function addOrUpdateTrialEmailNoticeConfig(params) {
  return request({
    url: `/TrialEmailNoticeConfig/addOrUpdateTrialEmailNoticeConfig`,
    method: 'post',
    data: params
  })
}

export function getSystemClinicalOtherTableQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getSystemClinicalOtherTableQuestionList`,
    method: 'post',
    data: params
  })
}

export function getTrialClinicalOtherTableQuestionList(params) {
  return request({
    url: `/ClinicalQuestion/getTrialClinicalOtherTableQuestionList`,
    method: 'post',
    data: params
  })
}

export function deleteCommonDocument(commonDocumentId) {
  return request({
    url: `/CommonDocument/deleteCommonDocument/${commonDocumentId}`,
    method: 'delete'
  })
}

export function getSystemCalculateQuestions(params) {
  return request({
    url: `/ReadingQuestion/getSystemCalculateQuestions`,
    method: 'post',
    data: params
  })
}

export function getSystemCalculateTableQuestions(params) {
  return request({
    url: `/ReadingQuestion/getSystemCalculateTableQuestions`,
    method: 'post',
    data: params
  })
}

