<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.openhis.administration.mapper.EncounterDiagnosisMapper">

    <delete id="deleteByEncounterId">
        DELETE
        FROM adm_encounter_diagnosis
        WHERE encounter_id = #{encounterId}
          AND tcm_flag = 0
    </delete>

    <delete id="deleteTcmByEncounterId">
        DELETE
        FROM adm_encounter_diagnosis
        WHERE encounter_id = #{encounterId}
          AND tcm_flag = 0
    </delete>
    <select id="getEncounterDiagnosisByEncounterConDefId"
            resultType="com.openhis.administration.domain.EncounterDiagnosis">
        SELECT *
        FROM adm_encounter_diagnosis T1
                 INNER JOIN cli_condition T2 ON T1.condition_id = T2.id
        WHERE T1.encounter_id = #{encounterId}
          AND T2.definition_id = #{conditionDefId}
          AND T1.delete_flag = '0'
          AND T2.delete_flag = '0'
          AND T1.tenant_id = #{tenantId}
    </select>

</mapper>