smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -82,6 +82,7 @@
        <result property="visitCount" column="visit_count"/>
        <result property="isVisitAgain" column="is_visit_again"/>
        <result property="upid" column="upid"/>
        <result property="visitType" column="visit_type"/>
        <result property="visitTime" column="visit_time"/>
        <result property="visitDeptName" column="visit_dept_name"/>
        <result property="visitDeptCode" column="visit_dept_code"/>
@@ -302,6 +303,11 @@
        END
    </sql>
    <!-- 当前执行方式:首次随访 current_preachform 为空时,取 preachform 的第一个执行方式兜底 -->
    <sql id="effectiveCurrentPreachformExpr">
        COALESCE(NULLIF(TRIM(current_preachform), ''), TRIM(SUBSTRING_INDEX(preachform, ',', 1)))
    </sql>
    <select id="selectServiceSubtaskBySendstate" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
            resultMap="ServiceSubtaskResult">
        <include refid="selectServiceSubtaskVo"/>
@@ -404,6 +410,7 @@
        <if test="managementDoctorCode != null ">and management_doctor_code = #{managementDoctorCode}</if>
        <if test="submit != null ">and submit = #{submit}</if>
        <if test="upid != null ">and upid = #{upid}</if>
        <if test="visitCount != null ">and visit_count = #{visitCount}</if>
        <if test="patfrom != null ">and patfrom = #{patfrom}</if>
        <if test="serviceType != null ">and service_type = #{serviceType}</if>
        <if test="patid != null ">and patid = #{patid}</if>
@@ -567,6 +574,9 @@
        <if test="pid != null ">and pid = #{pid}</if>
        <if test="preachform != null ">and preachform = #{preachform}</if>
        <if test="currentPreachform != null ">and current_preachform = #{currentPreachform}</if>
        <if test="currentPreachforms != null and currentPreachforms != ''">
            and FIND_IN_SET(<include refid="effectiveCurrentPreachformExpr"/>, #{currentPreachforms})
        </if>
        <if test="guid != null  and guid != ''">and guid = #{guid}</if>
        <if test="textParam != null  and textParam != ''">and text_param = #{textParam}</if>
        <if test="bedNo != null">and bed_no = #{bedNo}</if>
@@ -949,6 +959,12 @@
        </if>
        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
        <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
        <if test="startOutHospTime != null">
            AND date_format(endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
        </if>
        <if test="endOutHospTime != null">
            AND date_format(endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
        </if>
        ) a where a.finished =1)
    </select>
@@ -1639,6 +1655,22 @@
        where patid = #{patid} and taskid = #{taskid}
    </update>
    <!-- 人工随访:软删除患者出院记录对应的未完成随访任务 -->
    <update id="deleteUnfinishedServiceSubtaskByInhospids">
        update service_subtask
        set del_flag = 1
        where del_flag = 0
          and patid = #{patid}
          and sendstate in
          <foreach collection="sendstates" item="sendstate" open="(" separator="," close=")">
              #{sendstate}
          </foreach>
          and inhospid in
          <foreach collection="inhospids" item="inhospid" open="(" separator="," close=")">
              #{inhospid}
          </foreach>
    </update>
    <select id="getSfStatistics" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
            resultMap="ServiceSubtaskResult">
        select id,
@@ -1663,6 +1695,7 @@
        taskid,
        task_name,
        visit_time,
        visit_dept_code,
        finishtime,
        endtime,
        senddate,
@@ -1951,6 +1984,8 @@
        taskid,
        task_name,
        visit_time,
        visit_dept_code,
        visit_dept_name,
        finishtime,
        endtime,
        senddate,
@@ -2281,14 +2316,14 @@
    <select id="getSfStatisticsScriptDetails" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
            resultMap="ServiceSubtaskScriptCountResult">
        SELECT
        a.id as scriptid,
        a.templateid as templateid,
        a.script_type,
        MIN(a.id) as scriptid,
        MIN(a.templateid) as templateid,
        MIN(a.script_type) as script_type,
        a.script_content,
        b.subtask_type,
        b.completed_quantity,
        b.all_quantity,
        ROUND(b.completed_quantity/b.all_quantity,2) as completed_percentage
        SUM(b.completed_quantity) as completed_quantity,
        SUM(b.all_quantity) as all_quantity,
        ROUND(SUM(b.completed_quantity)/SUM(b.all_quantity),2) as completed_percentage
        FROM
        <if test="type == 1">
            ivr_task_template_script a
@@ -2351,25 +2386,37 @@
        group by ssd.scriptid) b
        ON a.id = b.scriptid
        <!-- 适用单条查询 -->
        <if test="scriptids != null">
        <if test="scriptids != null and scriptids != ''">
            AND a.scriptid in
            (SELECT lib_script.scriptid FROM
            svy_lib_template_script lib_script
            WHERE lib_script.scriptid in (${scriptids}))
        </if>
        <!-- 同一道题会被复制到多个任务模板,按题目内容合并,保证一道题只返回一条 -->
        GROUP BY a.script_content, b.subtask_type
        ORDER BY MIN(a.id)
    </select>
    <select id="getSfStatisticsScriptItemDetails" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
            resultMap="ServiceSubtaskScriptCountResult">
        SELECT
        ssd.scriptid,
        a.script_content,
        ss.type as subtask_type,
        IFNULL(ssd.matchedtext,ssd.asrtext) AS option_text,
        COUNT(*) AS chosen_quantity
        FROM
        service_subtask_detail ssd
        INNER JOIN service_subtask ss ON ssd.sub_id = ss.id
        INNER JOIN
        <if test="type == 1">
            ivr_task_template_script a ON a.id = ssd.scriptid
        </if>
        <if test="type == 2">
            svy_task_template_script a ON a.id = ssd.scriptid
        </if>
        where 1=1
        and ss.del_flag=0
        and ssd.del_flag=0
        <if test="orgid != null and orgid != ''">
            and ss.orgid = #{orgid}
        </if>
@@ -2408,7 +2455,7 @@
        <if test="configValue != null and configValue != ''">
            AND ssd.categoryid IN (${configValue})
        </if>
        group by ssd.scriptid, IFNULL(ssd.matchedtext,ssd.asrtext)
        group by a.script_content, ss.type, IFNULL(ssd.matchedtext,ssd.asrtext)
    </select>
    <select id="getDataByTime" resultMap="ServiceSubtaskResult">
@@ -2899,6 +2946,9 @@
                #{state}
            </foreach>
        </if>
        <if test="currentPreachforms != null and currentPreachforms != ''">
            AND FIND_IN_SET(<include refid="effectiveCurrentPreachformExpr"/>, #{currentPreachforms})
        </if>
        <if test="orgid != null and orgid != ''">
            AND orgid = #{orgid}
        </if>