package com.eitc.patient.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.eitc.common.core.controller.BaseController;
import com.eitc.common.core.domain.AjaxResult;
import com.eitc.patient.domain.MedicalHistory;
import com.eitc.patient.service.IMedicalHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * MedicalHistoryController
 *
 * @author mtx
 * @date: 2024/05/22 9:37
 */
@Api(tags = "病史")
@RestController
@RequestMapping("/app/patient/medical-history")
public class AppMedicalHistoryController extends BaseController {

    @Resource
    private IMedicalHistoryService medicalHistoryService;

    /**
     * 查询患者
     */
    @GetMapping("/list")
    @ApiOperation("查询患者")
    public AjaxResult list(MedicalHistory medicalHistory) {
        LambdaQueryWrapper<MedicalHistory> eq = Wrappers.<MedicalHistory>lambdaQuery()
                .eq(Objects.nonNull(medicalHistory.getMedicalRecordId()), MedicalHistory::getMedicalRecordId, medicalHistory.getMedicalRecordId())
                .eq(Objects.nonNull(medicalHistory.getPatientId()), MedicalHistory::getPatientId, medicalHistory.getPatientId())
                .orderByDesc(MedicalHistory::getUpdateDate);

        return success(medicalHistoryService.list(eq));
    }

}
