<?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.web.inpatientmanage.mapper.VitalSignsAppMapper">

    <!-- 三测单患者信息查询-->
    <select id="getVitalSignsInfo" parameterType="java.util.Map"
            resultType="com.openhis.web.inpatientmanage.dto.VitalSignsDto">
        SELECT  T1.id,
                T1.patient_id,
                T1.encounter_id,
                T1.recording_date,
                T1.time_point,
                T1.vital_signs_code,
                T1.vital_signs_values,
                T1.units,
                T1.baby_no,
                T1.location_id,
                T1.recorder,
                T1.remake,
                T2."name",                                -- 患者姓名
                T3.bus_no AS hospitalNo,                  -- 住院号
                T3.class_enum,                            -- 就诊类别
                T3.organization_id,                       -- 科室ID
                T3.start_time AS admissionDate,           -- 入院日期
                T3.end_time AS dischargeDate,             -- 出院日期
                T4.location_id AS bedLocationId,          -- 床位号
                T5.status_enum AS surgeryStatusEnum,      -- 手术状态
                T6.start_time AS surgeryStartTime,        -- 手术开始时间
                T6.end_time AS surgeryEndTime             -- 手术结束时间
        FROM doc_vital_signs T1
        LEFT JOIN adm_patient T2
            ON T1.patient_id = T2.id
            AND T2.delete_flag = '0'
        LEFT JOIN adm_encounter T3
            ON T1.encounter_id = T3.id
            AND T3.delete_flag = '0'
        LEFT JOIN adm_encounter_location T4
            ON T1.encounter_id = T4.encounter_id           -- 就诊ID
            AND T4.form_enum = 8
            AND T4.delete_flag = '0'
        LEFT JOIN cli_procedure T5
            ON T1.patient_id = T5.patient_id               -- 患者ID
            AND T5.delete_flag = '0'
        LEFT JOIN cli_procedure_performer T6
            ON T5.id = T6.procedure_id                     -- 手术ID
            AND T6.delete_flag = '0'
        LEFT JOIN wor_service_request T7
            ON T1.encounter_id = T7.encounter_id
            AND T5.base_service_req_id = T7.id
            AND T7.delete_flag = '0'
        LEFT JOIN wor_service_request_detail T8
            ON T7.id = T8.service_req_id
            AND T8.type_code = '3'
            AND T8.delete_flag = '0'
        <where>
            -- 患者ID
            T1.patient_id = #{patientId}
            AND T1.delete_flag = '0'

        </where>
        ORDER BY recording_date, time_point ASC
    </select>

    <!-- 三测单患者信息查询-->
    <select id="searchVitalSigns" parameterType="java.util.Map"
            resultType="com.openhis.document.domain.VitalSigns">
        SELECT  T1.id,
                T1.patient_id,
                T1.encounter_id,
                T1.recording_date,
                T1.time_point,
                T1.vital_signs_code,
                T1.vital_signs_values,
                T1.units,
                T1.baby_no,
                T1.location_id,
                T1.recorder,
                T1.remake
        FROM doc_vital_signs T1
        <where>
            -- 记录日期
            T1.recording_date &gt;= #{startTime}::date
            AND T1.recording_date &lt;= #{endTime}::date
            AND T1.delete_flag = '0'

        </where>
        ORDER BY T1.recording_date, T1.time_point, T1.vital_signs_code ASC
    </select>

    <!-- 三测单患者信息删除-->
    <delete id="deleteVitalSigns">
        DELETE FROM doc_vital_signs
        <where>
            -- 患者ID
            patient_id = #{patientId}
            -- 就诊ID
            AND encounter_id = #{encounterId}
            -- 记录日期
            AND recording_date = #{recordingDate}
            -- 记录时间
            AND time_point = #{timePoint}
            -- 删除状态
            AND delete_flag = '0'
        </where>
    </delete>
</mapper>