import request from '@/utils/request.js'
import {analysisAgency, analysisDelivery} from '@/model/transition';

// 获取处方列表
export function getRecipeList(data) {
    return request({
        url: '/test/outpatient/outPatientList?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 获取处方列表
export function getRecipeList1(data) {
    return request({
        url: '/test/outpatient/previewList?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 获取处方列表详情数据
export function getRecipeDMsg(data) {
    return request({
        url: '/test/outpatient/per/' + data,
        method: 'get'
    })
};

// 获取处方审核列表详情
export function getRecipeAuditD(data) {
    return request({
        url: '/test/outpatient/' + data,
        method: 'get'
    })
};

// 处方审核
export function auditRecipe(data) {
    return request({
        url: '/test/outpatient/outPatientReview',
        method: 'post',
        data
    })
};

// 获取协定方列表
export function getAccordList(data) {
    return request({
        url: '/basis/prescriptionMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 获取协定方详情 共享至信息
export function getAccordShareList(data) {
    return request({
        url: '/basis/prescriptionMgr/rangCustomer',
        method: 'post',
        data
    })
};

// 获取中药类型选择器
export function getChinesMedType(data) {
    return request({
        url: '/basis/prescriptionMgr/pharmacyCustomer',
        method: 'post',
        data
    })
};

// 添加协定方数据
export function addAccordData(data) {
    return request({
        url: '/basis/prescriptionMgr/AddOrUpdate',
        data,
        method: 'post'
    })
};


// 获取协定方详细数据
export function getAccordDetail(data) {
    return request({
        url: `/basis/prescriptionMgr/${data}`,
        method: 'get'
    })
};


// 删除协定方 
export function deleteAccord(data) {
    return request({
        url: '/basis/prescriptionMgr/BatchDelete?ids=' + data.ids,
        method: 'post',
        data
    })
};


// 获取药房管理 列表
export function getPharmacyList(data) {
    return request({
        url: '/basis/pharmacyMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};


// 新增药房
export function addPharmacyData(data) {
    return request({
        url: '/basis/pharmacyMgr/Add',
        method: 'post',
        data
    })
};

// 获取药房详细信息
export function getPharmacyMsg(data) {
    return request({
        url: `/basis/pharmacyMgr/${data}`,
        method: 'get'
    }).then((res) => {
      if (!res.Data) return res;
      res.Data = {
        ...res.Data,
        ...analysisAgency(res.Data),
        ...analysisDelivery(res.Data),
      }
      return res;
    });
};

// 修改药房信息
export function editPharmacMsg(data) {
    return request({
        url: '/basis/pharmacyMgr/update',
        method: 'post',
        data
    })
};

// 删除药房
export function deletePharmac(data) {
    return request({
        url: '/basis/pharmacyMgr/BatchDelete?ids=' + data.ids,
        method: 'post'
    })
};


// 获取我的患者列表
export function getMyPatiensList(data) {
    return request({
        url: '/my/patientMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 获取患者病案
export function getPatiensCase(data) {
    return request({
        url: '/my/patientMgr/getPatientRecords1?patientId=' + data.patientId + '&limit=' + data.limit + '&page=' + data.page,
        method: 'post',
        data
    })
};

// 获取患者 病案详情
export function getPatiensMedDetail(data) {
    return request({
        url: '/my/patientMgr/PatientDetail?patientId=' + data.patientId + '&namemedicine=' + data.namemedicine,
        method: 'post',
        data
    })
};

// 患者转病例
export function patiensTrunCase(data) {
    return request({
        url: '/my/patientMgr/transferCase',
        method: 'post',
        data
    })
}


//获取药房权限按钮 
export function getPharmacyBR(data) {
    return request({
        url: '/basis/pharmacyMgr/GetButtonRight',
        method: 'post',
        data
    })
};

// 获取协定方权限按钮
export function getRecipeBR(data) {
    return request({
        url: '/basis/prescriptionMgr/GetButtonRight',
        method: 'post',
        data
    })
};

// 获取药品目录列表 
// export function getDrugList(data) {
//     return request({
//         url: '/basis/stitutionsdrugMgr/listPain?page=' + data.page + '&limit=' + data.limit,
//         method: 'post',
//         data
//     })
// };

export function getDrugList(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/drugCataloguelistPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 搜索平台药品
export function searchMyDrug(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/materialQuery',
        method: 'post',
        data
    })
};

// 搜索his 药品
export function searchHisDrug(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/customerQuery',
        method: 'post',
        data
    })
};

// 新增或修改 药品映射
export function addOrUpdateDrug(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/AoU',
        method: 'post',
        data
    })
};
export function getDrugMap(pid) {
    const group = (array, level = 0) => {
        if (!Array.isArray(array) || !array.length) return level > 1 ? void 0 : [];
        return array.map(item => {
            const children = group(item.children, level + 1);
            return children ? {
                value: item.pid,
                label: item.name,
                children, leaf: false,
            } : {
                value: item.pid,
                label: item.name,
                leaf: true,
            };
        });
    };
    return request({url: `/basis/stitutionsdrugMgr/getDrugCatalogueInfo/${pid}`, method: 'get'}).then((res) => {
        if (res.ResultCode !== 0) throw {message: res.ResultInfo};
        const data = res.Data;
        return {
            pid: data.pid,
            groupInfo: group(JSON.parse(data.groupInfo)),
        };
    });
}
// 获取药品映射详情
export function getDrugMapList(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/orgInfo?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};
// 获取药品映射详情
export function getDrugMapList1(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/orgInfoByMat?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
};

// 获取药品管理权限
export function getDrugBM(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/GetButtonRight',
        method: 'post',
        data

    })
};

// 修改药品目录描述 
// export function updateDrugDesc(data) {
//     return request({
//         url: '/basis/stitutionsdrugMgr/update',
//         method: 'post',
//         data
//     })
// };

// 修改药品目录描述 /basis/stitutionsdrugMgr/updateDrugCatalog
export function updateDrugDesc(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/updateDrugCatalog',
        method: 'post',
        data
    })
};

// 添加药品目录
export function addDrugList(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/addDrugCatalog',
        method: 'post',
        data
    })
}

// 药品目录自动映射
export function autoMap(data) {
    return request({
        url: '/basis/stitutionsdrugMgr/AutomaticMapping?orgId=' + data.orgId,
        method: 'post',
        data
    })
};

// 修改处方状态
export function changeRecipeS(data) {
    return request({
        url: '/outpatient/patientprescriptionMgr/update',
        method: 'post',
        data
    })
};

// 处方审核详情 获取合理用药
export function getMedForRecipeA(params) {
    return request({
        url: '/test/outpatient/rewMat',
        method: 'get',
        params
    })
};

// 获取微信支付二维码
export function getWxPayCode(data) {
    return request({
        url: '/outpatient/pay/WxNativepay?PID=' + data.PID,
        method: 'post',
        data

    })
}

// 查询订单状态
export function getOrderState(data) {
    return request({
        url: '/outpatient/pay/queryOrder?PID=' + data.PID,
        method: 'post',
        data
    })
}

/// 添加专家经验 
export function addExperince(data) {
    return request({
        url: '/basis/expertexperienceMgr/Add',
        method: 'post',
        data

    })
}

// 获取专家经验列表
export function getExperinceList(data) {
    return request({
        url: '/basis/expertexperienceMgr/listPain?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
}

// 获取专家经验详情
export function getExperinceDetail(data) {
    return request({
        url: `/basis/expertexperienceMgr/${data.pid}`,
        method: 'get',
        data
    })
};

// 专家经验修改\
export function editExperince(data) {
    return request({
        url: '/basis/expertexperienceMgr/update',
        method: 'post',
        data
    })
}

// 删除专家经验
export function deleteExperince(data) {
    return request({
        url: '/basis/expertexperienceMgr/BatchDelete?id=' + data.id,
        method: 'post',
        data
    })
}

// 验证接口 信息提交
export function validataionSubmit(data) {
    return request({
        url: '/pre_interface/V5.0/insertBasicInfo',
        method: 'post',
        data
    })
}

// 获取验证接口 开方信息
export function getValidationMsg(data) {
    return request({
        url: '/pre_interface/V5.0/getPreItem',
        method: 'post',
        data
    })
}

// 验证页面 收费成功提示
export function paySuccess(data) {
    return request({
        url: '/pre_interface/V5.0/setStatus',
        method: 'post',
        data
    })
}

// 病历管理列表
export function medicalRecords(data) {
    return request({
        url: '/outpatient/CaseManagement/caseManagementList?page=' + data.page + '&limit=' + data.limit,
        method: 'post',
        data
    })
}

// 获取科室树形结构
export function getDepartTreeData(data) {
    return request({
        url: '/basis/hospitaldepartmentsMgr/getMultipleDepartments?institutionId=' + data.institutionId,
        method: 'post',
        data
    })
}
