package com.ruoyi.web.modules.architecture.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.modules.architecture.service.IAppMedicationCompatibilityService;
import com.ruoyi.web.modules.architecture.service.IAppMedicationDrugService;

/**
 * 移动端用药工具 — 用药配伍。
 */
@RestController
@RequestMapping("/app/medication/compatibility")
public class BizAppMedicationCompatibilityController extends BaseController
{
    @Autowired
    private IAppMedicationDrugService appMedicationDrugService;

    @Autowired
    private IAppMedicationCompatibilityService appMedicationCompatibilityService;

    /**
     * 药物名称下拉（药物1、药物2共用）。
     */
    @GetMapping("/names")
    public AjaxResult drugNames(@RequestParam(value = "keyword", required = false) String keyword)
    {
        return success(appMedicationDrugService.selectDrugNameOptions(keyword));
    }

    /**
     * 配伍检查：双向禁配关联，有禁忌时返回主药 compat_result。
     */
    @GetMapping("/check")
    public AjaxResult check(
            @RequestParam("drugName1") String drugName1,
            @RequestParam("drugName2") String drugName2)
    {
        return success(appMedicationCompatibilityService.checkCompatibility(drugName1, drugName2));
    }
}
