import request from '@/utils/request1.js'
import request1 from '@/utils/request.js'

/**
 * 获取中医 病名
 * @deprecated
 */
export function getCDiseaseName(data) {
    return request({
        url: '/basis/knowlib/diseaseQuery',
        method: 'post',
        data
    })
};

// 获取 西医病名
export function getXDiseaseName(data) {
    return request({
        url: '/basis/knowlib/westQuery',
        method: 'post',
        data
    })
};


/**
 * 获取中医证型
 * @deprecated
 */
export function getCCardType(data) {
    return request({
        url: '/basis/knowlib/symptomQuery',
        method: 'post',
        data
    })
};

/**
 * 获取中医治法
 * @deprecated
 */
export function getCTherapy(data) {
    return request({
        url: '/basis/knowlib/getTherapyAll',
        method: 'post',
        data
    })
};

// 获取穴位信息
export function getXueweiList(data) {
    return request({
        url: '/basis/knowlib/acupointQuery',
        method: 'post',
        data
    })
};

// 获取脉象接口 
export function getPulseSelect(data) {
    return request({
        url: '/basis/knowlib/pulseQuery',
        method: 'post',
        data
    })
};

// 获取舌象接口
export function getTongueSelect(data) {
    return request({
        url: '/basis/knowlib/tongueQuery',
        method: 'post',
        data
    })
};

// 获取只能辨证 分类接口
export function getDialecticalC(data) {
    return request({
        url: '/basis/knowlib/getSyndromeClassify',
        method: 'post',
        data
    })
};

// 获取只能辨证 症状
export function getSymptoms(data) {
    return request1({
        url: '/basis/knowlib/getSyndromeGroup',
        method: 'post',
        data
    })
};

// 获取只能辨证 症状
export function getSymptomsPain(data) {
    // ?page=' + data.page + '&limit=' + data.limit
    return request1({
        url: '/basis/knowlib/getSyndromeGroupPain',
        method: 'post',
        data
    })
};

// 获取疾病 查询列表
export function getDiseaseList(data, signal) {
    return request({
        url: '/basis/knowlib/diseaseQuery',
        method: 'post',
        data, signal,
    })
};

// 获取疾病详情
export function getDiseasetDetail(data) {
    return request({
        url: '/basis/knowlib/diseaseInfoQuery?disid=' + data.disid,
        method: 'post',
        data
    })
};

// 获取只能辨证问卷接口 
export function getDialecticalq(data) {
    return request1({
        url: '/basis/knowlib/getSyndromeAsk',
        method: 'post',
        data
    })
}

// 提交智能辨证问卷
export function submitDialetQ(data) {
    return request1({
        url: '/basis/knowlib/getSyndromeSymptom',
        method: 'post',
        data
    })
};

// 查询穴位
export function getAcupoint(data) {
    return request({
        url: '/basis/knowlib/acupointQuery',
        method: 'post',
        data
    })
};

// 获取经络
export function collateralChannels(data) {
    return request({
        url: '/basis/knowlib/meridianQuery',
        method: 'post',
        data
    })
};


// 获取穴位详情
export function getAcupointD(data) {
    return request({
        url: '/basis/knowlib/acupointInfoQuery?acuid=' + data.acuid,
        method: 'post',
        data
    })
};

//获取名医验案列表
export function getDoctorCaseL(data) {
    return request({
        url: '/basis/knowlib/verifyQuery',
        method: 'post',
        data
    })
}

// 获取名医验案前置页面数据
export function getDoctorCaseIndexL(data, signal) {
    return request({
        url: '/basis/knowlib/verifyIndexQuery',
        method: 'post',
        data, signal,
    })
}

// 获取名医验案详情接口 
export function getDCaseDetail(data) {
    return request({
        url: '/basis/knowlib/verifyInfoQuery?verId=' + data.verId,
        method: 'post',
        data
    })
};

//获取标准功效查询接口
export function getEffectQuery(data) {
    return request({
        url: '/basis/knowlib/effectQuery?effictId=' + data.effictId + '&effecttype=' + data.effecttype,
        method: 'post',
        data
    }).then(res => {
      if (data.effictId && res.data.effects.length > 1) {
        res.data.effects = res.data.effects.filter(item => item.effectid === data.effictId)
      }
      return res;
    })
}

// 获取中药
export function getMedList(data) {
    return request({
        url: '/basis/knowlib/medicineQuery',
        method: 'post',
        data
    })
}

// 获取方剂列表 
export function getPrescriptionsList(data, signal) {
    return request({
        url: '/basis/knowlib/prescriptionQuery?effected=' + data.effected,
        method: 'post',
        data, signal,
    })
};

// 获取方剂详情接口 
export function getPreDetal(data) {
    return request({
        url: '/basis/knowlib/prescriptionInfoQuery?preid=' + data.preid,
        method: 'post',
        data
    })
};

// 获取中成药列表
export function getChinesePatentMedicineList(data, signal) {
    data.categoryId = data.effected;
    return request({
        url: '/basis/knowlib/patentDrugList?effected=' + data.effected,
        method: 'post',
        data, signal,
    })
}

// 获取中成药详情接口
export function getChinesePatentMedicineDetail(data) {
    return request({
        url: '/basis/knowlib/patentDrugDetail?id=' + data.id,
        method: 'post',
        data
    });
}

// 获取中药详情
export function getMedDetail(data) {
    return request({
        url: '/basis/knowlib/medicineInfoQuery?matid=' + data.matid,
        method: 'post',
        data
    })
};

// 获取疾病分类 
export function getDiseaseClass(data) {
    return request({
        url: '/basis/knowlib/departmentQuery',
        method: 'post',
        data
    })
};

// 获取体质辨识问卷
export function getPhysicalTest(data) {
    return request({
        url: `/basis/knowlib/questionnaireSelection/${data.basisPatientId}`,
        method: 'get',
        params: data
    })
}

// 获取基公卫 问卷内容
export function getBasicQuestion(data) {
    return request({
        url: '/basis/knowlib/getPhysical2',
        method: 'post',
        data
    })
}
// 获取 体质辨识问卷 内容
export function getPhysicalQ(data) {
    return request({
        url: '/basis/knowlib/getPhysical?groups=' + data.groups,
        method: 'post',
        data
    })
};

// 获取体质辨识结果 
export function getPhysicaRes(data) {
    return request({
        url: '/basis/knowlib/analysisgroup',
        method: 'post',
        data
    })
};

// 获取公卫问卷辨识结果
export function getBasicRes(data) {
    return request({
        url: '/basis/knowlib/analysisgroup2',
        method: 'post',
        data
    })
}

// 获取合理用药信息 (机构药品)
export function getRationalMed(data) {
    return request({
        // url: '/basis/knowlib/getMatInfo?matID=' + data.matID,
        url: '/basis/knowlib/getMatInfo1',
        method: 'post',
        data
    }).then(res => {
        try {
            if (res.data.matsjj) res.data.matsjj = (res.data.mattaboo || res.data.matsjj || '').replace(/\s/g, ' ');
            const patient = JSON.parse(sessionStorage.getItem('patiensInfo'));
            if (patient.sex === '男') res.data.matyfsjj = ''
        } catch (e) {}
        return res;
    });
};

// 获取合理用药信息 (平台药品)
export function getRationalMedForPlat(data) {
    return request({
        // url: '/basis/knowlib/getMatInfoByPlat?matID=' + data.matID,
        url: '/basis/knowlib/getMatInfoByPlat1',
        method: 'post',
        data
    }).then(res => {
        try {
            if (res.data.matsjj) res.data.matsjj = (res.data.mattaboo || res.data.matsjj || '').replace(/\s/g, ' ');
            const patient = JSON.parse(sessionStorage.getItem('patiensInfo'));
            if (patient.sex === '男') res.data.matyfsjj = ''
        } catch (e) {}
        return res;
    });
};

// 推导处方接口
export function inferRecipe(data) {
    return request({
        url: '/basis/knowlib/treatmentScheme',
        method: 'post',
        data
    })
};

// 名家验案 和方剂 转方/合方
export function changeAndJoin(data) {
    return request1({
        url: "/test/outpatient/changePre",
        method: 'post',
        data
    })
};

// 获取经络详情
export function getMerD(data) {
    return request({
        url: '/basis/knowlib/meridianInfoQuery?merid=' + data.merid,
        method: 'post',
        data
    })
};

export function getBookCategories() {
    return request1({
        url: '/book/bookClassify/list',
        method: 'post',
    }).then(res => res.Data.map(item => ({label: item['classifyName'], value: item['classifyId']})));
}

export function getBookList(query) {
    const data = {page: 1, limit: 40};
    for (const [key, value] of Object.entries(query)) {
        if (value) { data[key] = value; }
    }
    return request1({
        url: '/book/book/list',
        method: 'post',
        data,
    }).then(res => {
        if (res.Data == null) res.Data = {current: 1, total: 0, records: []};
        return {
            page: res.Data.current,
            total: res.Data.total,
            data: res.Data.records,
        };
    });
}

export function getBookListOfMy() {
    return request1({
        url: '/book/book/myBookshelf',
        method: 'post',
    }).then(res => {
        return {
            page: 1,
            total: res.Data.length,
            data: res.Data.map(item => Object.assign(item, {id: item.bookId})),
        };
    });
}

export function getBookListOfRecommend(id) {
    return request1({
        url: '/book/book/recommend',
        method: 'post',
        data: {id},
    }).then(res => res.Data.filter(item => item.id !== id));
}

export function getBook(id) {
    return request1({
        url: `/book/book/detail`,
        method: 'post',
        data: {id},
    }).then(res => res.Data);
}

export function getBookContent(data) {
    return request1({
        url: `/book/bookContent/detail`,
        method: 'post',
        data,
    }).then(res => res.Data.content || '(空)');
}

export function setBookStatus(id, status) {
    return request1({
        url: `/book/book/addBookshelf`,
        method: 'post',
        data: {
            ...status,
            bookId: id,
        },
    });
}

// 获取耳穴列表
export function getAcuMeridianList(data) {
    return request({
        url: '/basis/knowlib/acuMeridianList',
        method: 'post',
        data
    })
}

// 获取耳穴详情
export function getAcuMeridianDetail(id) {
    return request({
        url: '/basis/knowlib/acuMeridianDetail?id=' + id,
        method: 'post',
    })
}
