package cn.hnthyy.thmz.mapper.thmz;

import cn.hnthyy.thmz.entity.thmz.WorkspaceConfig;
import org.apache.ibatis.annotations.*;

public interface WorkspaceConfigMapper {
    /**
     * 增加医生工作台配置
     * @param workspaceConfig
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into t_workspace_config(user_id_code,symptom_flag,emr_hpi_flag,emr_ps_flag,personal_history_flag,family_history_flag,obsterical_history_flag,pressure_left_flag,tentative_diagnosis_flag,create_id,create_date,update_id,update_date) " +
            "values(#{userIdCode},#{symptomFlag},#{emrHpiFlag},#{emrPsFlag},#{personalHistoryFlag},#{familyHistoryFlag},#{obstericalHistoryFlag},#{pressureLeftFlag},#{tentativeDiagnosisFlag},#{createId},#{createDate},#{updateId},#{updateDate})")
    int inset(WorkspaceConfig workspaceConfig);

    /**
     * 根据主键查询
     * @param id
     * @return
     */
    @Select("select id,user_id_code,symptom_flag,emr_hpi_flag,emr_ps_flag,personal_history_flag,family_history_flag,obsterical_history_flag,pressure_left_flag,tentative_diagnosis_flag,create_id,create_date,update_id,update_date from t_workspace_config where id = #{id}")
    WorkspaceConfig selectWorkspaceConfigById(@Param("id") Long id);


    /**
     * 根据医生编码查询
     * @param userIdCode
     * @return
     */
    @Select("select id,user_id_code,symptom_flag,emr_hpi_flag,emr_ps_flag,personal_history_flag,family_history_flag,obsterical_history_flag,pressure_left_flag,tentative_diagnosis_flag,create_id,create_date,update_id,update_date from t_workspace_config where user_id_code = #{userIdCode}")
    WorkspaceConfig selectWorkspaceConfigByUserIdCode(@Param("userIdCode") String userIdCode);


    /**
     * 更新医生工作台
     * @param workspaceConfig
     * @return
     */
    @Update({"<script>",
            "update t_workspace_config ",
            "<trim prefix='set' prefixOverrides=',' suffix=' where id =#{id} ' >",
            "<when test='symptomFlag!=null'>",
            ",symptom_flag =#{symptomFlag}",
            "</when>",
            "<when test='emrHpiFlag!=null'>",
            ",emr_hpi_flag =#{emrHpiFlag}",
            "</when>",
            "<when test='emrPsFlag!=null'>",
            ",emr_ps_flag =#{emrPsFlag}",
            "</when>",
            "<when test='personalHistoryFlag!=null'>",
            ",personal_history_flag =#{personalHistoryFlag}",
            "</when>",
            "<when test='familyHistoryFlag!=null'>",
            ",family_history_flag =#{familyHistoryFlag}",
            "</when>",
            "<when test='obstericalHistoryFlag!=null'>",
            ",obsterical_history_flag =#{obstericalHistoryFlag}",
            "</when>",
            "<when test='pressureLeftFlag!=null'>",
            ",pressure_left_flag =#{pressureLeftFlag}",
            "</when>",
            "<when test='tentativeDiagnosisFlag!=null'>",
            ",tentative_diagnosis_flag =#{tentativeDiagnosisFlag}",
            "</when>",
            "</trim>",
            "</script>"})
    int updateConfigByKey(WorkspaceConfig workspaceConfig);
}
