package com.bzd.web.controller.dtp;

import com.baidu.aip.ocr.AipOcr;
import com.bzd.common.annotation.Log;
import com.bzd.common.config.HealthConfig;
import com.bzd.common.config.dao.PageData;
import com.bzd.common.core.controller.BaseController;
import com.bzd.common.core.domain.AjaxResult;
import com.bzd.common.core.page.TableDataInfo;
import com.bzd.common.enums.BusinessType;
import com.bzd.common.utils.ServletUtils;
import com.bzd.common.utils.StringUtils;
import com.bzd.common.utils.file.FileUploadUtils;
import com.bzd.common.utils.file.MimeTypeUtils;
import com.bzd.system.service.PharmaceuticalService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;

import static com.bzd.common.config.datasource.DynamicDataSourceContextHolder.log;

/**
 * 药事服务管理
 * creator wsp
 */
@Controller
@RequestMapping("/dtp/pmService")
public class PharmaceuticalServiceController extends BaseController {

    // 档案馆
    private String prefix_archives = "dtp/archives";

    // 随访任务
    private String prefix_followUp = "dtp/followUp";

    // 随访人员分配
    private String prefix_followUp_assign = "dtp/followUpAssign";

    //患者咨询
    private String prefix_patient_counseling = "dtp/patientCounseling";

    //患者咨询
    private String prefix_followUp_evaluation = "dtp/followUpEvaluation";

    @Autowired
    private PharmaceuticalService pharmaceuticalService;

    private final AipOcr client;
    /**
     * 档案管理页
     *
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/archives")
    public String archives() {
        return prefix_archives + "/archivesList";
    }

    /**
     * 档案管理数据查询
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/archivesList")
    @ResponseBody
    public TableDataInfo archivesList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findArchivesList(pd);
        return getDataTable(pageData);
    }
    /**
     * 档案管理数据查询
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/slectPatientByNameOrPhone")
    @ResponseBody
    public TableDataInfo slectPatientByNameOrPhone() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.slectPatientByNameOrPhone(pd);
        return getDataTable(pageData);
    }
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/slectPatientByNameOrPhoneOrIdCard")
    @ResponseBody
    public AjaxResult slectPatientByNameOrPhoneOrIdCard() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData>  pageData = pharmaceuticalService.slectPatientByNameOrPhoneOrIdCard(pd);

        return AjaxResult.success(pageData);
    }
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/slectPatientByNameAndPhone")
    @ResponseBody
    public AjaxResult slectPatientByNameAndPhone() throws Exception {
        PageData pd = this.getPageData();
        PageData pageData = pharmaceuticalService.slectPatientByNameAndPhone(pd);
        if(StringUtils.isNotNull(pageData)){
            return AjaxResult.success(pageData);
        }else {
            return AjaxResult.warn("未查询到数据");
        }
}

    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/slectPatientById")
    @ResponseBody
    public AjaxResult slectPatientById() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData>  pageData = pharmaceuticalService.slectPatientById(pd);

        return AjaxResult.success(pageData);
    }

    /**
     * 档案管理数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "档案管理删除", businessType = BusinessType.DELETE)
    @PostMapping("/archivesRemove")
    @ResponseBody
    public AjaxResult archivesRemove() throws Exception {
        PageData pd = this.getPageData();
        Integer integer = pharmaceuticalService.archivesRemove(pd);
        return toAjax(integer);
    }

    /**
     * 档案管理数据编辑
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/archivesEdit/{id}")
    public String archivesView(@PathVariable("id") String Id, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        pd.put("id", Id);

        PageData pageData1= new PageData();
        List<PageData> list= pharmaceuticalService.findArchivesList(pd);
        if(list.size()>0){
             pageData1 = pharmaceuticalService.findArchivesList(pd).get(0);
            mmap.put("dl",pageData1.get("dl"));
            mmap.put("xl",pageData1.get("xl"));
            mmap.putAll(pageData1);
        }
        /*Object updatePatientBasicInfo =  pharmaceuticalService.findBasicInfoById(pd);
        if(StringUtils.isNotNull(updatePatientBasicInfo)){
            PageData BasicpageData = (PageData) updatePatientBasicInfo;
            mmap.putAll(BasicpageData);
            pd.put("archiveId", Id);
            List<PageData>  records =pharmaceuticalService.findrecordsByarchiveId(pd);
            mmap.put("recordsData",records);
            List<PageData>  history =  pharmaceuticalService.findhistoryByarchiveId(pd);
            mmap.put("historyData",history);
            List<PageData>  contacts =  pharmaceuticalService.findcontactsByarchiveId(pd);
            mmap.put("contactsData",contacts);
        }*/
        pd.put("archiveId", Id);
        List<PageData>  records =pharmaceuticalService.findrecordsByarchiveId(pd);
        mmap.put("recordsData",records);
        return prefix_archives + "/archivesEdit";
    }


    /**
     * 档案管理数据编辑2
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/archivesyygyList")
    public String archivesyygyList( ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        return prefix_archives + "/archivesyygyList";
    }
    /**
     * 患者建档
     * @return
     * @throws Exception
     */
    @GetMapping("/archivesAdd")
    public String archivesAdd(ModelMap mmap) {
        mmap.put("posts", 1);
        return prefix_archives + "/archivesAdd";
    }
    /**
     * 带回调的患者建档
     * @return
     * @throws Exception
     */
    @GetMapping("/addArchivesCallback")
    public String addArchivesCallback(ModelMap mmap) {
        mmap.put("posts", 1);
        return prefix_archives + "/archivesAddCallback";
    }

    /**
     * 保存处方照片
     */
    @Log(title = "处方信息", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIdcardImg")
    @ResponseBody
    public AjaxResult updatePrescriptionImg(@RequestParam("idcardImgfile") MultipartFile file)
    {
        try
        {
            if (!file.isEmpty())
            {
                String idCardImg = FileUploadUtils.upload(HealthConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
                return success(idCardImg);
            }
            return error();
        }
        catch (Exception e)
        {
            log.error("修改处方信息失败！", e);
            return error(e.getMessage());
        }
    }
    public PharmaceuticalServiceController() {
        this.client = new AipOcr("116175151", "kCf9zQbSFkHmqKlo2bewI7Fe", "IHaSX3X76k0vLBTcOT3Z8SKJ1q6SF07i");
    }
    @RequiresPermissions("dtp:pmService:add")
    @PostMapping("/idCard")
    @ResponseBody
    public AjaxResult recognizeIdCard(@RequestParam("image") MultipartFile file) {
        try {
            byte[] imageBytes = file.getBytes();
            HashMap<String, String> options = new HashMap<>();
            options.put("detect_direction", "true");
            options.put("detect_risk", "false");
            String idCardSide = "front";
            JSONObject res = client.idcard(imageBytes, idCardSide, options);
            return AjaxResult.success(res.toMap());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
    /**
     * 患者建档新增保存
     */
    @Log(title = "患者建档新增保存", businessType = BusinessType.INSERT)
    @PostMapping("/archivesAdd")
    @ResponseBody
    public AjaxResult addSave() throws Exception {
        PageData pd = new PageData();
        pd = this.getPageData();
       Object dateBirth= pd.get("dateBirth");
       if(StringUtils.isNotNull(dateBirth)){
          Integer age = ServletUtils.calculateAge(dateBirth.toString());//根据出生日期字符串计算年龄
           pd.put("age",age);
       }
        if (pharmaceuticalService.checkPatientIsExist(pd))
        {
            return error("患者建档新增保存： '" + pd.getString("name") +"+"+ pd.getString("documentNumber") +"+" +pd.getString("phoneNumber")+"'失败，患者姓,身份证名或电话已存在");
        }
        Integer integer = pharmaceuticalService.addArchives(pd);
        return toAjax(integer);
    }
    /**
     * 带回调的患者建档新增保存
     */
    @Log(title = "患者建档新增保存带回调的", businessType = BusinessType.INSERT)
    @PostMapping("/addArchivesCallback")
    @ResponseBody
    public AjaxResult addArchivesCallback2() {
        PageData pd = this.getPageData();
        try {
            Object dateBirth= pd.get("dateBirth");
            if(StringUtils.isNotNull(dateBirth)){
                Integer age = ServletUtils.calculateAge(dateBirth.toString());//根据出生日期字符串计算年龄
                pd.put("age",age);
            }
            if (pharmaceuticalService.checkPatientIsExist(pd))
            {
                return error("患者建档新增保存： '" + pd.getString("name") +"+"+ pd.getString("documentNumber") +"+" +pd.getString("phoneNumber")+"'失败，患者姓,身份证名或电话已存在");
            }

            PageData pdc = pharmaceuticalService.addArchivesCallback(pd);
            return AjaxResult.success(pdc);
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 扫码上翻
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/ShaoMaShangFan")
    @ResponseBody
    public AjaxResult ShaoMaShangFan() throws Exception {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Object openId = pd.get("openId");
            Object patientId = pd.get("patientId");
            if(patientId != null && !pd.get("patientId").toString().isEmpty()){
                pd.put("id", patientId);
            }
            if(openId != null && !pd.get("openId").toString().isEmpty()){
                Integer updateResult = pharmaceuticalService.ShaoMaShangFan(pd);
                if (updateResult == 1) {
                    // 成功更新
                    return AjaxResult.success("上翻成功");
                } else {
                    // 更新失败
                    logger.error("Failed to update archives with ID: {}", pd.get("id"));
                    return AjaxResult.error("上翻失败");
                }
            }else{
                logger.error("Failed to update archives with openId: {}", pd.get("openId"));
                return AjaxResult.error("上翻失败");
            }

        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }
    /**
     * 解绑
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "解绑", businessType = BusinessType.UPDATE)
    @PostMapping("/unbound")
    @ResponseBody
    public AjaxResult unbound() throws Exception {
        PageData pd = this.getPageData();
        pd.put("up", "up");
            try {
                Object id = pd.get("id");
                if(StringUtils.isNull(id)){
                    return AjaxResult.error("未获取患者id 无法解绑");
                }
                    pd.put("noFlipCause", "患者已解绑");//未扫码原因之一
                    Integer updateResult = pharmaceuticalService.unbound(pd);
                    if (updateResult == 1) {
                        // 成功更新
                        return AjaxResult.success("解绑成功");
                    } else {
                        // 更新失败
                        logger.error("解绑 操作 Failed to update archives with ID: {}", pd.get("id"));
                        return AjaxResult.error("解绑失败");
                    }
            } catch (Exception e) {
                // 异常处理
                logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
                return AjaxResult.error("系统异常：" + e.getMessage());
            }
      }

    /**
     * 保存档案管理数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/archivesEdit")
    @ResponseBody
    public AjaxResult archivesEditSave() throws Exception {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {

            Integer updateResult = pharmaceuticalService.updateArchives(pd);

            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }
    /**
     * 获取对应患者的用药购药信息
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/getDrugPurchaseList")
    @ResponseBody
    public TableDataInfo getDrugPurchaseList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.getDrugPurchaseList(pd);
        return getDataTable(pageData);
    }

    /**
     * 随访任务页
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/followUp")
    public String followUp() {
        return prefix_followUp + "/followUpList";
    }

    /**
     * 随访任务数据查询
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:archivesList")
    @PostMapping("/followUpList")
    @ResponseBody
    public TableDataInfo followUpList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findFollowUpList(pd);
        return getDataTable(pageData);
    }

    /**
     * 随访任务数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "档案管理删除", businessType = BusinessType.DELETE)
    @PostMapping("/followUpRemove")
    @ResponseBody
    public AjaxResult followUpRemove() throws Exception {
        PageData pd = this.getPageData();
        try {
            Integer deleteResult = pharmaceuticalService.followUpRemove(pd);
            if (deleteResult == 1) {
                // 删除成功
                return AjaxResult.success("删除成功");
            } else {
                // 删除失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 随访任务数据修改
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/followUpEdit/{followUpId}")
    public String followUpView(@PathVariable("followUpId") Long followUpId, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        pd.put("id", followUpId);
        PageData pageData = pharmaceuticalService.findFollowUpList(pd).get(0);
        mmap.putAll(pageData);
        return prefix_followUp + "/followUpEdit";
    }

    /**
     * 保存随访任务数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/followUpEdit")
    @ResponseBody
    public AjaxResult followUpEditSave() {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Integer updateResult = pharmaceuticalService.updateFollowUp(pd);
            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    @GetMapping("/selectAdverseReactions")
    @ResponseBody
    public String selectAdverseReactions()
    {
        String data = "[{\"n\":\"血液系统\",\"s\":[{\"n\":\"中性粒细胞减少\",\"s\":[{\"n\":\"1级 计数范围: 正常值下限 ~ 1500 mm³ (正常值下限 ~ 1.5 × 10⁹/L)\"},{\"n\":\"2级 计数范围: 1500 ~ 1000 mm³ (1.5 ~ 1.0 × 10⁹/L)\"},{\"n\":\"3级 计数范围: 1000 ~ 500 mm³ (1.0 ~ 0.5 × 10⁹/L)\"},{\"n\":\"4级 计数范围: < 500 mm³ (< 0.5 × 10⁹/L)\"}]},{\"n\":\"血小板减少\",\"s\":[{\"n\":\"1级 计数范围: 正常值下限 ~ 75,000 mm³ (正常值下限 ~ 75.0 × 10⁹/L)\"},{\"n\":\"2级 计数范围: 75,000 ~ 50,000 mm³ (75.0 ~ 50.0 × 10⁹/L)\"},{\"n\":\"3级 计数范围: 50,000 ~ 25,000 mm³ (50.0 ~ 25.0 × 10⁹/L)\"}]},{\"n\":\"肌酐升高\",\"s\":[{\"n\":\"1级 肌酐水平: > 正常值上限 ~ 1.5 倍正常值上限\"},{\"n\":\"2级 肌酐水平: > 1.5 ~ 3.0 倍基线数值 (> 1.5 ~ 3.0 倍正常值上限)\"},{\"n\":\"3级 肌酐水平: > 3.0 倍基线数值 (> 3.0 ~ 6.0 倍正常值上限)\"},{\"n\":\"4级 肌酐水平: > 6.0 倍正常值上限\"}]},{\"n\":\"贫血\",\"s\":[{\"n\":\"1级 血红蛋白: < 正常值下限 ~ 10.0 g/dL (< 正常值下限 ~ 6.2 mmol/L; < 正常值下限 ~ 100 g/L)\"},{\"n\":\"2级 血红蛋白: < 10.0 ~ 8.0 g/dL (< 6.2 ~ 4.9 mmol/L; < 100 ~ 80 g/L)\"},{\"n\":\"3级 血红蛋白: < 8.0 g/dL (< 4.9 mmol/L; < 80 g/L); 需要输血治疗\"}]},{\"n\":\"白细胞数降低\",\"s\":[{\"n\":\"1级 计数范围: 正常值下限 ~ 3000 mm³ (正常值下限 ~ 3.0 × 10⁹/L)\"},{\"n\":\"2级 计数范围: 3000 ~ 2000 mm³ (3.0 ~ 2.0 × 10⁹/L)\"},{\"n\":\"3级 计数范围: 2000 ~ 1000 mm³ (2.0 ~ 1.0 × 10⁹/L)\"},{\"n\":\"4级 计数范围: < 1000 mm³ (< 1.0 × 10⁹/L)\"}]},{\"n\":\"淋巴细胞计数降低\",\"s\":[{\"n\":\"1级 计数范围: 正常值下限 ~ 800/mm³ (正常值下限 ~ 0.8 × 10⁹/L)\"},{\"n\":\"2级 计数范围: 800 ~ 500/mm³ (0.8 ~ 0.5 × 10⁹/L)\"},{\"n\":\"3级 计数范围: 500 ~ 200/mm³ (0.5 ~ 0.2 × 10⁹/L)\"},{\"n\":\"4级 计数范围: < 200/mm³ (< 0.2 × 10⁹/L)\"}]}]},{\"n\":\"消化系统\",\"s\":[{\"n\":\"厌食纳差\",\"s\":[{\"n\":\"正常\"},{\"n\":\"食欲减退，但不伴有饮食习惯改变\"},{\"n\":\"进食改变，但不伴有体重降低或营养不良;需要口服补充营养\"},{\"n\":\"出现明显体重降低或营养不良症状;需要鼻饲或全肠外营养\"},{\"n\":\"危及生命:需要紧急治疗\"}]},{\"n\":\"牙痛\",\"s\":[{\"n\":\"轻度疼痛\"},{\"n\":\"影响工具性日常生活活动\"},{\"n\":\"影响自理性日常生活活动\"}]},{\"n\":\"呕吐临床表现\",\"s\":[{\"n\":\"24小时内1-2次发作(间隔5分钟)\"},{\"n\":\"24小时内3-5次发作(间隔5分钟)\"},{\"n\":\"24小时内发作≥6次以上(间隔5分钟);需要鼻饲，全肠外营养或住院治疗\"},{\"n\":\"危及生命;需要紧急治疗\"},{\"n\":\"轻度症状;无需治疗\"},{\"n\":\"中度症状;需要医学干预(如鼻填塞，烧灼，局部使用血管收缩剂)\"},{\"n\":\"需要输血，需要侵入性干预(例如出血部位止血)\"}]},{\"n\":\"口腔粘膜炎\",\"s\":[{\"n\":\"黏膜红斑、疼痛，不影响进食\"},{\"n\":\"黏膜红斑明显，疼痛加重，散在溃疡，能进半流质饮食\"},{\"n\":\"黏膜溃疡及疼痛比2级明显，溃疡大于1.5cm或有多个溃疡，只能进流质饮食\"},{\"n\":\"疼痛剧烈，溃疡融合成大片状，不能进食\"},{\"n\":\"毛发质地异常变白\"}]},{\"n\":\"腹泻\",\"s\":[{\"n\":\"1级:大便次数增加 每天<4 次;造口排出物轻度增加\"},{\"n\":\"2级:大便次数增加 每天4~6 次;造口排出物中度增加\"},{\"n\":\"3级:大便次数增加 每天≥7次以上;需要住院治疗;与基线相比，造口排出物重度增加;自理性日常生活活动受限\"},{\"n\":\"4级:危及生命;需要紧急治疗\"}]},{\"n\":\"恶心\",\"s\":[{\"n\":\"无\"},{\"n\":\"食欲降低，不伴进食习惯改变\"},{\"n\":\"经口摄食减少不伴明显的体重下降脱水或营养不良，经口摄入能量水分不足\"},{\"n\":\"需要鼻饲，全肠外营养或者住院\"}]},{\"n\":\"便秘\",\"s\":[{\"n\":\"正常\"},{\"n\":\"偶然或间断性出现:偶尔需使用粪便软化剂，轻泻药，饮食习惯调整，灌肠\"},{\"n\":\"需要手工疏通的顽固性便秘;影响个人日常生活活动\"}]},{\"n\":\"消化不良\",\"s\":[{\"n\":\"轻度症状;无需治疗\"},{\"n\":\"中度症状:需要治疗\"},{\"n\":\"严重症状:手术干预治疗\"}]}]},{\"n\":\"泌尿系统\",\"s\":[{\"n\":\"血尿\",\"s\":[{\"n\":\"无症状，仅临床观察或诊断所见，无需治疗\"},{\"n\":\"有症状，需要导尿或膀胱灌洗;影响工具性日常生活活动\"},{\"n\":\"大量血尿;需要输血，静脉给药或住院治疗;需要择期内窥镜，放射学或手术干预;影响自理性日常生活活动\"},{\"n\":\"危及生命，需要紧急放射学或手术治疗\"},{\"n\":\"死亡\"}]},{\"n\":\"蛋白尿\",\"s\":[{\"n\":\"尿蛋白(+)或24小时尿蛋白定量0.15~1.0g\"},{\"n\":\"尿蛋白(++)~(+++)或24小时尿蛋白定量1.0~3.4g\"},{\"n\":\"肾病综合征\"},{\"n\":\"死亡\"},{\"n\":\"1级 覆盖小于10%的体表面积，但是不伴红斑和瘙痒\"},{\"n\":\"2级 覆盖10~30%的体表面积，伴有红斑和瘙痒:影响借助于工具的日常生活活动\"},{\"n\":\"3级 覆盖超过30%的体表面积，伴有瘙痒:影响自理性日常生活活动\"}]},{\"n\":\"尿酸\",\"s\":[{\"n\":\"尿酸升高\"}]}]},{\"n\":\"神经系统毒性\",\"s\":[{\"n\":\"眩晕\",\"s\":[{\"n\":\"轻度不平稳或有移动感\"},{\"n\":\"中度不平稳;影响工具性日常生活活动\"},{\"n\":\"重度不平稳:影响个人日常生活活动\"},{\"n\":\"1级 无症状，实验室检查(例如:B型钠尿钛)或心脏影像学检查发现异常\"},{\"n\":\"2级 中度活动或劳累时出现症状\"},{\"n\":\"3级 静息状态下或最低程度活动或劳累时便出现症状;住院;新发症状\"},{\"n\":\"4级 危及生命;需要紧急治疗(例如:连续静脉输液治疗或机械辅助血液循环)\"}]},{\"n\":\"味觉障碍\",\"s\":[{\"n\":\"味觉改变但不影响正常饮食\"},{\"n\":\"味觉改变且影响正常饮食(如:口服补充物);毒性或不舒服味觉;丢失味觉\"}]},{\"n\":\"嗜睡症\",\"s\":[{\"n\":\"轻度但多于平常的睡眠\"},{\"n\":\"中度镇静;影响工具性日常生活活动\"},{\"n\":\"视觉障碍，痉挛\"},{\"n\":\"危及生命，需要紧急治疗\"},{\"n\":\"死亡\"}]},{\"n\":\"神经痛\",\"s\":[{\"n\":\"轻度疼痛\"},{\"n\":\"中度疼痛;影响工具性日常生活活动\"},{\"n\":\"重度疼痛;影响个人日常生活活动\"}]},{\"n\":\"认知影响\",\"s\":[{\"n\":\"记忆障碍/轻度记忆障碍\"},{\"n\":\"记忆障碍/重度记忆障碍:自我照顾日常日常生活活动受限\"},{\"n\":\"意识模糊/中度定向障碍:工具性日常生活活动受限\"},{\"n\":\"意识模糊/重度定向障碍，自我照顾日常日常生活活动受限\"}]},{\"n\":\"失眠\",\"s\":[]},{\"n\":\"头疼\",\"s\":[{\"n\":\"轻度疼痛\"},{\"n\":\"中度疼痛;影响工具性日常生活活动\"},{\"n\":\"重度疼痛;影响自理性日常生活活动\"},{\"n\":\"心脏生物标志物检查异常，包括异常ECG\"},{\"n\":\"筛查检查异常伴轻微症状\"},{\"n\":\"检查结果中等异常或存在轻度活动性症状\"},{\"n\":\"中等-严重失代偿，需IV给药治疗或干预措施，危及生命的疾病\"}]},{\"n\":\"周围神经病\",\"s\":[{\"n\":\"1级 轻度感觉异常，腱反射消失或感觉麻木(包括针刺感)，但不影响功能\"},{\"n\":\"2级 中度感觉异常，感觉缺失或感觉麻木(包括针刺感)，不影响日常工作，但影响功能\"},{\"n\":\"3级 重度感觉异常，感觉缺失或感觉麻木(包括针刺感)严重影响日常工作生活\"},{\"n\":\"4级 长期感觉缺失，影响功能\"}]}]},{\"n\":\"循环系统\",\"s\":[{\"n\":\"心肌炎\",\"s\":[{\"n\":\"1级 心脏生物标志物检查异常，包括异常ECG\"},{\"n\":\"2级 筛查检查异常伴轻微症状\"}]},{\"n\":\"高血压\",\"s\":[{\"n\":\"正常范围\"},{\"n\":\"高血压前期\"},{\"n\":\"第一阶段高血压\"},{\"n\":\"第二阶段高血压(收缩压≥160mmHg，舒张压>100mmHg);需要医学干预;需一种以上药物或较以往更强的治疗\"},{\"n\":\"危及生命(如恶性高血压，一过性或持久性神经损伤，高血压危象);需紧急治疗\"},{\"n\":\"收缩压140-159mmHg, 舒张压90-99mmHg;需要医学干预:反复或持久的症状\"},{\"n\":\"24小时收缩压120-139mmHg, 舒张压80-89mmHg\"},{\"n\":\"甲变色\"},{\"n\":\"指甲丢失\"},{\"n\":\"指甲隆起\"},{\"n\":\"指甲软化\"}]},{\"n\":\"心力衰竭(心室功能障碍)\",\"s\":[{\"n\":\"1级 无症状，实验室检查(例如:B型钠尿钛)或心脏影像学检查发现异常\"},{\"n\":\"2级 中度活动或劳累时出现症状\"}]},{\"n\":\"血栓\",\"s\":[]},{\"n\":\"心律不齐\",\"s\":[]}]},{\"n\":\"皮肤系统\",\"s\":[{\"n\":\"脱发\",\"s\":[{\"n\":\"1级 头发减少较此人正常发量不足50%，远看不明显，而近看能看出。需要改变发型来掩饰头发丢失，但不需要假发或假发片来掩饰\"},{\"n\":\"2级 头发减少较正常人发量超过50%；他人很容易发现，如果患者希望完全掩饰头发减少则必需使用假发或假发片，伴有心理影响\"}]},{\"n\":\"手足综合症\",\"s\":[{\"n\":\"正常\"},{\"n\":\"无痛性轻微皮肤改变或皮肤炎(如红斑，水肿，角化过度)\"},{\"n\":\"痛性皮肤改变(如剥落，水疱，出血，肿胀，角化过度);影响工具性日常生活活动\"},{\"n\":\"重度皮肤改变(剥落，水疱，出血，肿胀，角化过度)，伴疼痛;影响个人日常生活活动\"}]},{\"n\":\"瘙痒症\",\"s\":[{\"n\":\"轻度或局限的;需要局部干预\"},{\"n\":\"剧烈或广泛;持续性;影响理性日常生活活动或睡眠;需要口服可的松或免疫抑制剂治疗\"}]},{\"n\":\"皮疹\",\"s\":[{\"n\":\"1级 丘疹和/或脓疱<10%体表面积，伴或不伴有痒或压痛症状\"},{\"n\":\"2级 丘疹和/或脓疱占10~30%体表面积，伴或不伴有瘙痒或压痛症状;造成心理影响;影响日常生活工具性活动\"},{\"n\":\"3级 >30%体表面积伴中度或严重临床症状;影响日常生活自理能力;需要静脉给予抗生素治疗\"},{\"n\":\"4级 危及生命\"}]},{\"n\":\"皮肤色素脱失\",\"s\":[{\"n\":\"以躯干非暴露部位为主的对称性皮肤散在的或针尖样大小的色素脱失点\"},{\"n\":\"以躯干非暴露部位为主的较多皮肤点状色素脱失斑\"},{\"n\":\"以躯干非暴露部位为主的广泛和密集皮肤色素脱失斑\"}]},{\"n\":\"皮肤色素沉着\",\"s\":[{\"n\":\"色素沉着小于10%的体表面积，没有心理影响\"},{\"n\":\"色素沉着大于10%的体表面积，伴有心理影响\"}]},{\"n\":\"毛细血管异常增生\",\"s\":[{\"n\":\"单个或多个结节，最大径<10mm，伴或不伴有破裂出血\"},{\"n\":\"单个或多个结节，最大径>10mm，伴或不伴有破裂出血\"},{\"n\":\"多个结节，伴有感染\"}]},{\"n\":\"甲沟炎\",\"s\":[{\"n\":\"正常\"},{\"n\":\"甲周水肿或红斑，指甲根部外皮断裂\"},{\"n\":\"需要手术治疗或静脉注射抗生素，日常活动自理能力受限\"}]},{\"n\":\"多形性红斑\",\"s\":[{\"n\":\"1级 靶病灶小于10%体表面积，不伴有皮肤压痛\"},{\"n\":\"2级 靶病灶覆盖10~30%的体表面积，伴有皮肤压痛\"},{\"n\":\"3级 靶病灶超过30%的体表面积，伴有口腔和生殖器侵袭\"},{\"n\":\"4级 靶病灶超过30%的体表面积;伴有体液和电解质异常;需要ICU或烧伤科护理\"}]},{\"n\":\"皮肤干燥\",\"s\":[{\"n\":\"1级 覆盖小于10%的体表面积，但是不伴红斑和瘙痒\"},{\"n\":\"2级 覆盖10~30%的体表面积，伴有红斑和瘙痒;影响借助于工具的日常生活活动\"},{\"n\":\"3级 覆盖超过30%的体表面积，伴有瘙痒;影响自理性日常生活活动\"}]},{\"n\":\"指甲改变\",\"s\":[{\"n\":\"指甲变色\"},{\"n\":\"指甲隆起\"},{\"n\":\"指甲软化\"},{\"n\":\"指甲丢失\"}]}]},{\"n\":\"全身系统毒性\",\"s\":[{\"n\":\"体重减轻\",\"s\":[{\"n\":\"参照基线，体重减轻5~<10%，无需治疗\"},{\"n\":\"参照基线，体重减轻10~<20%，需要给予营养支持\"},{\"n\":\"参照基线，体重减轻>20%，需要鼻饲或全肠外营养\"}]},{\"n\":\"疼痛\",\"s\":[{\"n\":\"轻度疼痛\"},{\"n\":\"中度疼痛;影响工具性日常生活活动\"},{\"n\":\"重度疼痛;影响自理性日常生活活动\"}]},{\"n\":\"水肿\",\"s\":[{\"n\":\"体格检查时有四陷性水肿\"},{\"n\":\"影响日常家务活动，需要药物治疗\"},{\"n\":\"影响日常生活活动自理能力，需要静脉用药治疗，皮肤破损\"},{\"n\":\"危及生命\"}]},{\"n\":\"乏力\",\"s\":[{\"n\":\"不舒适感或健康状况不佳\"},{\"n\":\"不舒适感或健康状况不佳，影响日常家务活动\"},{\"n\":\"不适感或健康状况不佳，影响自理性日常生活活动\"}]},{\"n\":\"发热\",\"s\":[{\"n\":\"38.0-39.0°C\"},{\"n\":\">39.0~40.0°C\"},{\"n\":\">40.0°C ≤24小时\"},{\"n\":\">40.0°C 超过24小时\"}]},{\"n\":\"体重增加\",\"s\":[{\"n\":\"轻度 参照基线，与基线值相比增加5%-<10%\"},{\"n\":\"中度 参照基线，与基线值相比增加10%-<20%\"},{\"n\":\"重度 参照基线，与基线值相比增加≥20%\"}]},{\"n\":\"毛发\",\"s\":[{\"n\":\"毛发质地异常变白\"}]},{\"n\":\"难受\",\"s\":[]}]},{\"n\":\"呼吸系统\",\"s\":[{\"n\":\"声音嘶哑\",\"s\":[{\"n\":\"说话困难，声音有变化\"}]},{\"n\":\"咳嗽\",\"s\":[{\"n\":\"轻度症状;需要非处方药干预\"},{\"n\":\"中度症状:需要药物干预;影响工具性日常生活活动\"},{\"n\":\"重度症状;影响自理性日常生活活动\"}]},{\"n\":\"肺炎\",\"s\":[{\"n\":\"无症状，无须处理\"},{\"n\":\"有症状，需医疗干预\"},{\"n\":\"症状严重，影响日常活动，需吸氧\"},{\"n\":\"危及生命，需要气管插管或气管切开\"},{\"n\":\"死亡\"}]},{\"n\":\"上呼吸道感染\",\"s\":[{\"n\":\"中度;需要口服药物治疗(抗生素，抗真菌或抗病毒治疗)\"},{\"n\":\"需要静脉注射抗生素，抗真菌或抗病毒药物治疗;需要进行侵入性的治疗\"}]},{\"n\":\"鼻出血\",\"s\":[{\"n\":\"轻度症状;无需治疗\"},{\"n\":\"中度症状:需要医学干预(如鼻填塞，烧灼，局部使用血管收缩剂)\"},{\"n\":\"需要输血，需要侵入性干预(例如出血部位止血)\"}]},{\"n\":\"呼吸困难\",\"s\":[{\"n\":\"中度活动时呼吸短促\"},{\"n\":\"少量活动时呼吸短促;影响借助于工具的日常生活活动\"},{\"n\":\"休息时呼吸短促;影响自理性日常生活活动\"}]},{\"n\":\"间质性肺炎\",\"s\":[]},{\"n\":\"后鼻滴涕\",\"s\":[]}]},{\"n\":\"内分泌系统\",\"s\":[{\"n\":\"甲状腺减退\",\"s\":[{\"n\":\"无症状，仅临床检查或诊断所见，无需治疗\"},{\"n\":\"有症状，甲状腺激素替代治疗，影响工具性日常活动\"},{\"n\":\"严重，影响个人日常生活活动，需要住院治疗\"},{\"n\":\"危及生命，需要紧急治疗\"}]},{\"n\":\"甲亢\",\"s\":[{\"n\":\"无症状，仅为临床或诊断所见，无需治疗\"},{\"n\":\"甲状腺抑制治疗:借助于工具的日常活动受限\"},{\"n\":\"自理性日常活动受限，需要住院治疗\"},{\"n\":\"危及生命，需要紧急治疗\"},{\"n\":\"死亡\"}]},{\"n\":\"甲状腺过氧化酶抗体升高\",\"s\":[]},{\"n\":\"垂体功能减退\",\"s\":[]}]},{\"n\":\"实验室检查\",\"s\":[{\"n\":\"谷草转氨酶(AST)升高\",\"s\":[{\"n\":\">ULN-3.0xULN\"},{\"n\":\">3.0-5.0xULN\"},{\"n\":\">5.0-20.0xULN\"},{\"n\":\">20.0xULN\"}]},{\"n\":\"谷丙转氨酶(ALT)升高\",\"s\":[{\"n\":\">ULN-3.0xULN\"},{\"n\":\">3.0-5.0xULN\"},{\"n\":\">5.0-20.0xULN\"},{\"n\":\">20.0xULN\"}]},{\"n\":\"低蛋白血症\",\"s\":[{\"n\":\"危及生命，需要治疗\"},{\"n\":\"死亡\"}]},{\"n\":\"胆红素升高\",\"s\":[{\"n\":\">ULN-1.5xULN\"},{\"n\":\">1.5-3.0xULN\"},{\"n\":\">3.0-10.0xULN\"},{\"n\":\">10.0xULN\"}]},{\"n\":\"高甘油三酯\",\"s\":[]},{\"n\":\"高胆固醇\",\"s\":[]},{\"n\":\"高血糖\",\"s\":[{\"n\":\"异常血糖高于基线值，无药物干预指征(空腹血糖>ULN-160mg/dL或>ULN-8.9mmol/L)\"},{\"n\":\"与基线期相比加强对糖尿病的日常管理，有开始口服降糖药的指征;进行糖尿病检测(空腹血糖>160mg/dL-250mg/dL或>8.9mmol/L-13.9mmol/L)\"},{\"n\":\"危及生命的后果;有紧急干预指征(空腹血糖>500mg/dL或>27.8mmol/L)\"}]},{\"n\":\"低钠血症\",\"s\":[]}]},{\"n\":\"视觉系统\",\"s\":[{\"n\":\"视力模糊\",\"s\":[{\"n\":\"无需治疗\"}]}]},{\"n\":\"感染和传染性疾病\",\"s\":[{\"n\":\"带状疱疹\",\"s\":[{\"n\":\"一级 病变局限，需要进行局部治疗\"},{\"n\":\"二级 局部感染合并中度临床症状; 需要口服药物治疗;影响年龄相适应的工具性日常生活活动\"},{\"n\":\"三级 严重或具有临床意义但不会立即危及生命; 需要住院治疗或延长住院时间; 需要静脉给药治疗; 影响日常生活自理能力\"}]}]},{\"n\":\"一般情况和用药部位表现\",\"s\":[{\"n\":\"注射部位反应\",\"s\":[{\"n\":\"压痛伴或不伴有症状(例如:热感，红斑，痒)\"},{\"n\":\"疼痛;脂肪营养不良;水肿;静脉炎\"},{\"n\":\"溃疡形成或坏死;严重的组织损伤;需要手术治疗\"},{\"n\":\"危及生命;需要紧急治疗\"}]}]}]";
        return data;
    }

    /**
     * 随访任务页
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/followUpAssign")
    public String followUpAssign() {
        return prefix_followUp_assign + "/followUpAssignList";
    }

    /**
     * 随访任务数据查询
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:followUpAssignList")
    @PostMapping("/followUpAssignList")
    @ResponseBody
    public TableDataInfo followUpAssignList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findFollowUpAssignList(pd);
        return getDataTable(pageData);
    }

    /**
     * 随访任务数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "档案管理删除", businessType = BusinessType.DELETE)
    @PostMapping("/followUpAssignRemove")
    @ResponseBody
    public AjaxResult followUpAssignRemove() throws Exception {
        PageData pd = this.getPageData();
        try {
            Integer deleteResult = pharmaceuticalService.followUpAssignRemove(pd);
            if (deleteResult == 1) {
                // 删除成功
                return AjaxResult.success("删除成功");
            } else {
                // 删除失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 随访任务数据修改
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/followUpAssignEdit/{followUpAssignId}")
    public String followUpAssignView(@PathVariable("followUpAssignId") Long followUpAssignId, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        pd.put("id", followUpAssignId);
        PageData pageData = pharmaceuticalService.findFollowUpAssignList(pd).get(0);
        mmap.putAll(pageData);
        return prefix_followUp_assign + "/followUpAssignEdit";
    }

    /**
     * 保存随访任务数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/followUpAssignEdit")
    @ResponseBody
    public AjaxResult followUpAssignEditSave() {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Integer updateResult = pharmaceuticalService.updateFollowUpAssign(pd);
            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 患者咨询 页面
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/patientCounseling")
    public String patientCounseling() {
        return prefix_patient_counseling + "/patientCounselingList";
    }

    /**
     * 患者咨询数据查询
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:patientCounselingList")
    @PostMapping("/patientCounselingList")
    @ResponseBody
    public TableDataInfo patientCounselingList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findPatientCounselingList(pd);
        return getDataTable(pageData);
    }

    /**
     * 患者咨询数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "患者咨询删除", businessType = BusinessType.DELETE)
    @PostMapping("/patientCounselingRemove")
    @ResponseBody
    public AjaxResult patientCounselingRemove() throws Exception {
        PageData pd = this.getPageData();
        try {
            Integer deleteResult = pharmaceuticalService.patientCounselingRemove(pd);
            if (deleteResult == 1) {
                // 删除成功
                return AjaxResult.success("删除成功");
            } else {
                // 删除失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 患者咨询数据修改
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/patientCounselingEdit/{id}")
    public String patientCounselingView(@PathVariable("id") Long id, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        if (id != null && id != 0) {
            pd.put("id", id);
            PageData pageData = pharmaceuticalService.findPatientCounselingById(pd).get(0);
            mmap.putAll(pageData);
        }else {
            mmap.put("null","暂无数据");
        }
        return prefix_patient_counseling + "/patientCounselingEdit";
    }

    /**
     * 患者咨询添加跳转页面
     */
    @RequiresPermissions("dtp:pmService:add")
    @GetMapping("/patientCounselingAdd")
    public String patientCounselingAdd(ModelMap mmap) throws Exception {
        mmap.put("userid", getSysUser().getUserId());

        PageData pd = new PageData();
        pd.put("DeptId", getSysUser().getDeptId());
        List<PageData> patients = pharmaceuticalService.getAllPatients(pd);
        mmap.addAttribute("patients", patients);
        mmap.put("patients", patients);
        return prefix_patient_counseling + "/patientCounselingAdd";
    }


    /**
     * 患者咨询信息保存
     */
    @RequiresPermissions("dtp:pmService:add")
    @Log(title = "患者咨询信息新增", businessType = BusinessType.INSERT)
    @PostMapping("/patientCounselingAdd")
    @ResponseBody
    public AjaxResult patientCounselingSave() throws Exception {
        PageData pd = new PageData();
        pd = this.getPageData();
        try {

            Integer result= pharmaceuticalService.insertPatientConsultation(pd);
            if(result>0){
                return AjaxResult.success("添加成功：");
            }else {
                return AjaxResult.error("添加失败");
            }
        }catch (Exception e) {
            return AjaxResult.error("添加失败" + e.getMessage());
        }
    }


    /**
     * 患者咨询数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "档案管理修改", businessType = BusinessType.UPDATE)
    @PostMapping("/patientCounselingEdit")
    @ResponseBody
    public AjaxResult patientCounselingEditSave() {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Integer updateResult = pharmaceuticalService.updatePatientCounseling(pd);
            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }


    /**
     * 随访满意度评价 页面
     * @return
     */
    @RequiresPermissions("dtp:pmService:view")
    @GetMapping("/followUpEvaluation")
    public String followUpEvaluation() {
        return prefix_followUp_evaluation + "/followUpEvaluationList";
    }

    /**
     * 随访满意度评价 数据查询
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:patientCounselingList")
    @PostMapping("/followUpEvaluationList")
    @ResponseBody
    public TableDataInfo followUpEvaluationList() throws Exception {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> pageData = pharmaceuticalService.findFollowUpEvaluationList(pd);
        return getDataTable(pageData);
    }

    /**
     * 随访满意度评价 数据删除 根据id
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:remove")
    @Log(title = "随访满意度评价删除", businessType = BusinessType.DELETE)
    @PostMapping("/followUpEvaluationRemove")
    @ResponseBody
    public AjaxResult followUpEvaluationRemove() throws Exception {
        PageData pd = this.getPageData();
        try {
            Integer deleteResult = pharmaceuticalService.followUpEvaluationRemove(pd);
            if (deleteResult == 1) {
                // 删除成功
                return AjaxResult.success("删除成功");
            } else {
                // 删除失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("删除失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }

    /**
     * 随访满意度评价数据修改
     *
     * @return
     * @throws Exception
     */
    @RequiresPermissions("dtp:pmService:edit")
    @GetMapping("/followUpEvaluationEdit/{followUpEvaluationId}")
    public String followUpEvaluationView(@PathVariable("followUpEvaluationId") Long followUpEvaluationId, ModelMap mmap) throws Exception {
        PageData pd = this.getPageData();
        pd.put("id", followUpEvaluationId);
        PageData pageData = pharmaceuticalService.findFollowUpEvaluationList(pd).get(0);
        mmap.putAll(pageData);
        return prefix_followUp_evaluation + "/followUpEvaluationEdit";
    }

    /**
     * 保存随访满意度评价数据修改
     */
    @RequiresPermissions("dtp:pmService:edit")
    @Log(title = "随访满意度评价修改", businessType = BusinessType.UPDATE)
    @PostMapping("/followUpEvaluationEdit")
    @ResponseBody
    public AjaxResult followUpEvaluationEditSave() {
        PageData pd = this.getPageData();
        pd.put("up", "up");
        try {
            Integer updateResult = pharmaceuticalService.updateFollowUpEvaluation(pd);
            if (updateResult == 1) {
                // 成功更新
                return AjaxResult.success("修改成功");
            } else {
                // 更新失败
                logger.error("Failed to update archives with ID: {}", pd.get("id"));
                return AjaxResult.error("修改失败");
            }
        } catch (Exception e) {
            // 异常处理
            logger.error("Error occurred while updating archives with ID: {}, Exception: {}", pd.get("id"), e.getMessage(), e);
            return AjaxResult.error("系统异常：" + e.getMessage());
        }
    }
}
