<?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="PharmaceuticalServiceMapper">

	<!--档案管理查询-->
	<select id="selectArchivesList" parameterType="pd" resultType="pd">
		select *,DATE_FORMAT(updateTime, '%Y-%m-%d %H:%i:%s') AS updateTime2 from s_dtp_ysfw_archive_management where 1=1
		<if test="archivesId != null and archivesId!=''">
			and id=#{archivesId}
		</if>
		<if test="serviceTypeNumber!= null and serviceTypeNumber!=''">
			and serviceTypeNumber=#{serviceTypeNumber}
		</if>
		<if test="serviceTypeName!= null and serviceTypeName!=''">
			and serviceTypeName=#{serviceTypeName}
		</if>
		<if test="followUpPerson!= null and followUpPerson!=''">
			and followUpPerson=#{followUpPerson}
		</if>
		<if test="gender!= null and gender!=''">
			and gender=#{gender}
		</if>
		<if test="name!= null and name!=''">
			and name=#{name}
		</if>
		<if test="genericName!= null and genericName!=''">
			and genericName=#{genericName}
		</if>
		<if test="acceptFollowUp!= null and acceptFollowUp!=''">
			and acceptFollowUp=#{acceptFollowUp}
		</if>
		<if test="archiveCompleteStatus!= null and archiveCompleteStatus!=''">
			and archiveCompleteStatus=#{archiveCompleteStatus}
		</if>
		<if test="followUpPerson!= null and followUpPerson!=''">
			and followUpPerson=#{followUpPerson}
		</if>
		<if test="storeName!= null and storeName!=''">
			and storeName=#{storeName}
		</if>
		<if test="disease!= null and disease!=''">
			and disease=#{disease}
		</if>
		<if test="flipStatus!= null and flipStatus!=''">
			and flipStatus=#{flipStatus}
		</if>
		<if test="updateTime!= null and updateTime!=''">
			and updateTime like concat(#{updateTime}, '%')
		</if>
		<if test="joinProject!= null and joinProject!=''">
			and joinProject=#{joinProject}
		</if>
		<if test="charityAssistance!= null and charityAssistance!=''">
			and charityAssistance=#{charityAssistance}
		</if>

	</select>

	<!--档案管理修改-->
	<update id="updateArchives" parameterType="pd" >
		<if test="up != null and up!=''">
			update s_dtp_ysfw_archive_management set
		</if>
		<if test="name!= null and name!=''">
			name=#{name},
		</if>
		<if test="gender!= null and  gender!=''">
			gender=#{gender},
		</if>
		<if test="age!= null and age!=''">
			age=#{age},
		</if>
		<if test="phoneNumber!= null and  phoneNumber!=''">
			phoneNumber=#{phoneNumber},
		</if>
		<if test="documentType!= null and documentType!=''">
			documentType=#{documentType},
		</if>
		<if test="documentNumber!= null and documentNumber!=''">
			documentNumber=#{documentNumber},
		</if>
		<if test="realNameStatus!= null and realNameStatus!=''">
			realNameStatus=#{realNameStatus},
		</if>
		<if test="flipStatus!= null and flipStatus!=''">
			flipStatus=#{flipStatus},
		</if>
		<if test="disease!= null and disease!=''">
			disease=#{disease},
		</if>
		<if test="genericName!= null and genericName!=''">
			genericName=#{genericName},
		</if>
		<if test="productName!= null and productName!=''">
			productName=#{productName},
		</if>
		<if test="mdmCode!= null and mdmCode!=''">
			mdmCode=#{mdmCode},
		</if>
		<if test="manufacturer!= null and manufacturer!=''">
			manufacturer=#{manufacturer},
		</if>
		<if test="storeName!= null and storeName!=''">
			storeName=#{storeName},
		</if>
		<!--<if test="归属门店!= null and 归属门店!=''">
                 归属门店=#{归属门店},
        </if>-->
		<if test="archiveCreator!= null and archiveCreator!=''">
			archiveCreator=#{archiveCreator},
		</if>
		<if test="archiveCompleter!= null and archiveCompleter!=''">
			archiveCompleter=#{archiveCompleter},
		</if>
		<if test="acceptFollowUp!= null and acceptFollowUp!=''">
			acceptFollowUp=#{acceptFollowUp},
		</if>
		<if test="followUpPerson!= null and followUpPerson!=''">
			followUpPerson=#{followUpPerson},
		</if>
		<if test="archiveCompleteStatus!= null and archiveCompleteStatus!=''">
			archiveCompleteStatus=#{archiveCompleteStatus},
		</if>
		<if test="charityAssistance!= null and charityAssistance!=''">
			charityAssistance=#{charityAssistance},
		</if>
		<if test="joinProject!= null and joinProject!=''">
			joinProject=#{joinProject},
		</if>
		<if test="followUpStatus!= null and followUpStatus!=''">
			followUpStatus=#{followUpStatus},
		</if>
		<if test="updateTime!= null and updateTime!=''">
			updateTime=#{updateTime}
		</if>
		<!--<if test="createTime!= null and createTime!=''">
			create_time=#{createTime}
		</if>-->

		<if test="up != null and up!=''">
			<if test="id!= null and id!=''">
				where id=#{id}
			</if>
		</if>
	</update>

	<!--档案管理删除-->
	<delete id="archivesRemove" parameterType="pd">
		<if test="ids != null">
			delete from s_dtp_ysfw_archive_management where
			<if test="ids != null">
				id in(#{ids})
			</if>
		</if>
	</delete>

	<!--随访任务 查询-->
	<select id="selectFollowUpList" parameterType="pd" resultType="pd">
		select *,DATE_FORMAT(updatedAt, '%Y-%m-%d %H:%i:%s') AS updateTime2 from s_dtp_ysfw_follow_up_task where 1=1
		<if test="id != null and id != ''">
			and id=#{id}
		</if>
		<if test="appointmentDate != null and appointmentDate != ''">
			and appointmentDate=#{appointmentDate}
		</if>
		<if test="businessBelonging != null and businessBelonging != ''">
			and businessBelonging=#{businessBelonging}
		</if>
		<if test="taskName != null and taskName != ''">
			and taskName=#{taskName}
		</if>
		<if test="taskTheme != null and taskTheme != ''">
			and taskTheme=#{taskTheme}
		</if>
		<if test="patientName != null and patientName != ''">
			and patientName=#{patientName}
		</if>
		<if test="gender != null and gender != ''">
			and gender=#{gender}
		</if>
		<if test="age != null and age != ''">
			and age=#{age}
		</if>
		<if test="followUpSummary != null and followUpSummary != ''">
			and followUpSummary=#{followUpSummary}
		</if>
		<if test="disease != null and disease != ''">
			and disease=#{disease}
		</if>
		<if test="storeName != null and storeName != ''">
			and storeName=#{storeName}
		</if>
		<if test="genericName != null and genericName != ''">
			and genericName=#{genericName}
		</if>
		<if test="productName != null and productName != ''">
			and productName=#{productName}
		</if>
		<if test="taskFollower != null and taskFollower != ''">
			and taskFollower=#{taskFollower}
		</if>
		<if test="actualFollowUpTime != null and actualFollowUpTime != ''">
			and actualFollowUpTime=#{actualFollowUpTime}
		</if>
		<if test="callConnectedCount != null and callConnectedCount != ''">
			and callConnectedCount=#{callConnectedCount}
		</if>
		<if test="outboundCallCount != null and outboundCallCount != ''">
			and outboundCallCount=#{outboundCallCount}
		</if>
		<if test="nextOutboundCallCount != null and nextOutboundCallCount != ''">
			and nextOutboundCallCount=#{nextOutboundCallCount}
		</if>
		<if test="taskStatus != null and taskStatus != ''">
			and taskStatus=#{taskStatus}
		</if>
		<if test="lastOutboundStatus != null and lastOutboundStatus != ''">
			and lastOutboundStatus=#{lastOutboundStatus}
		</if>
		<if test="createdAt != null and createdAt != ''">
			and createdAt=#{createdAt}
		</if>
		<if test="updatedAt != null and updatedAt != ''">
			and updatedAt=#{updatedAt}
		</if>

	</select>

	<!--随访任务 修改-->
	<update id="updateFollowUp" parameterType="pd" >
		<if test="up != null and up!=''">
			update s_dtp_ysfw_follow_up_task
		</if>
		<trim prefix=" SET " suffix="" prefixOverrides="," suffixOverrides=",">
			<if test="appointmentDate != null and appointmentDate != ''">
				appointmentDate=#{appointmentDate},
			</if>
			<if test="businessBelonging != null and businessBelonging != ''">
				businessBelonging=#{businessBelonging},
			</if>
			<if test="taskName != null and taskName != ''">
				taskName=#{taskName},
			</if>
			<if test="taskTheme != null and taskTheme != ''">
				taskTheme=#{taskTheme},
			</if>
			<if test="patientName != null and patientName != ''">
				patientName=#{patientName},
			</if>
			<if test="gender != null and gender != ''">
				gender=#{gender},
			</if>
			<if test="age != null and age != ''">
				age=#{age},
			</if>
			<if test="followUpSummary != null and followUpSummary != ''">
				followUpSummary=#{followUpSummary},
			</if>
			<if test="disease != null and disease != ''">
				disease=#{disease},
			</if>
			<if test="storeName != null and storeName != ''">
				storeName=#{storeName},
			</if>
			<if test="genericName != null and genericName != ''">
				genericName=#{genericName},
			</if>
			<if test="productName != null and productName != ''">
				productName=#{productName},
			</if>
			<if test="taskFollower != null and taskFollower != ''">
				taskFollower=#{taskFollower},
			</if>
			<if test="actualFollowUpTime != null and actualFollowUpTime != ''">
				actualFollowUpTime=#{actualFollowUpTime},
			</if>
			<if test="callConnectedCount != null and callConnectedCount != ''">
				callConnectedCount=#{callConnectedCount},
			</if>
			<if test="outboundCallCount != null and outboundCallCount != ''">
				outboundCallCount=#{outboundCallCount},
			</if>
			<if test="nextOutboundCallCount != null and nextOutboundCallCount != ''">
				nextOutboundCallCount=#{nextOutboundCallCount},
			</if>
			<if test="taskStatus != null and taskStatus != ''">
				taskStatus=#{taskStatus},
			</if>
			<if test="lastOutboundStatus != null and lastOutboundStatus != ''">
				lastOutboundStatus=#{lastOutboundStatus},
			</if>
			<if test="createdAt != null and createdAt != ''">
				createdAt=#{createdAt},
			</if>
			<if test="updatedAt != null and updatedAt != ''">
				updatedAt=#{updatedAt},
			</if>
		</trim>
		<if test="up != null and up!=''">
			<if test="id!= null and id!=''">
				where id=#{id}
			</if>
		</if>
	</update>

	<!--随访任务 删除-->
	<delete id="followUpRemove" parameterType="pd">
		<if test="ids != null">
			delete from s_dtp_ysfw_follow_up_task where
			<if test="ids != null">
				id in(#{ids})
			</if>
		</if>
	</delete>


	<!--随访跟进人分配 查询-->
	<select id="selectFollowUpAssignList" parameterType="pd" resultType="pd">
		select *,DATE_FORMAT(updatedAt, '%Y-%m-%d %H:%i:%s') AS updateTime2 from s_dtp_ysfw_follow_up_assign where 1=1
		<if test="id != null and id != ''">
			and id=#{id}
		</if>
		<if test="patientName != null and patientName != ''">
			and patientName=#{patientName}
		</if>
		<if test="patientPhone != null and patientPhone != ''">
			and patientPhone=#{patientPhone}
		</if>
		<if test="gender != null and gender != ''">
			and gender=#{gender}
		</if>
		<if test="age != null and age != ''">
			and age=#{age}
		</if>
		<if test="disease != null and disease != ''">
			and disease=#{disease}
		</if>
		<if test="clinicalDiagnosis != null">
			and clinicalDiagnosis=#{clinicalDiagnosis}
		</if>
		<if test="medicineName != null and medicineName != ''">
			and medicineName=#{medicineName}
		</if>
		<if test="lastPurchaseDate != null">
			and lastPurchaseDate=#{lastPurchaseDate}
		</if>
		<!--<if test="建档日期 != null">
			and `建档日期`=#{建档日期}
		</if>-->
		<if test="followUpPersonName != null and followUpPersonName != ''">
			and followUpPersonName=#{followUpPersonName}
		</if>
		<if test="followUpPersonPhone != null and followUpPersonPhone != ''">
			and followUpPersonPhone=#{followUpPersonPhone}
		</if>
		<if test="followUpPersonRole != null and followUpPersonRole != ''">
			and followUpPersonRole=#{followUpPersonRole}
		</if>
		<if test="storeName != null and storeName != ''">
			and storeName=#{storeName}
		</if>
		<if test="patientAssignmentStatus != null and patientAssignmentStatus != ''">
			and patientAssignmentStatus=#{patientAssignmentStatus}
		</if>
		<if test="terminatedEmployeeName != null">
			and terminatedEmployeeName=#{terminatedEmployeeName}
		</if>
		<if test="terminatedEmployeePhone != null">
			and terminatedEmployeePhone=#{terminatedEmployeePhone}
		</if>
		<if test="terminatedEmployeeStore != null">
			and terminatedEmployeeStore=#{terminatedEmployeeStore}
		</if>
		<if test="createdAt != null">
			and createdAt=#{createdAt}
		</if>
		<if test="updatedAt != null">
			and updatedAt=#{updatedAt}
		</if>

	</select>

	<!--随访跟进人分配 修改-->
	<update id="updateFollowUpAssign" parameterType="pd" >
		<if test="up != null and up!=''">
			update s_dtp_ysfw_follow_up_assign
		</if>
		<trim prefix=" SET " suffix="" prefixOverrides="," suffixOverrides=",">
			<if test="patientName != null and patientName != ''">
				patientName=#{patientName},
			</if>
			<if test="patientPhone != null and patientPhone != ''">
				patientPhone=#{patientPhone},
			</if>
			<if test="gender != null and gender != ''">
				gender=#{gender},
			</if>
			<if test="age != null and age != ''">
				age=#{age},
			</if>
			<if test="disease != null and disease != ''">
				disease=#{disease},
			</if>
			<if test="clinicalDiagnosis != null">
				clinicalDiagnosis=#{clinicalDiagnosis},
			</if>
			<if test="medicineName != null and medicineName != ''">
				medicineName=#{medicineName},
			</if>
			<if test="lastPurchaseDate != null">
				lastPurchaseDate=#{lastPurchaseDate},
			</if>
			<if test="followUpPersonName != null and followUpPersonName != ''">
				followUpPersonName=#{followUpPersonName},
			</if>
			<if test="followUpPersonPhone != null and followUpPersonPhone != ''">
				followUpPersonPhone=#{followUpPersonPhone},
			</if>
			<if test="followUpPersonRole != null and followUpPersonRole != ''">
				followUpPersonRole=#{followUpPersonRole},
			</if>
			<if test="storeName != null and storeName != ''">
				storeName=#{storeName},
			</if>
			<if test="patientAssignmentStatus != null and patientAssignmentStatus != ''">
				patientAssignmentStatus=#{patientAssignmentStatus},
			</if>
			<if test="terminatedEmployeeName != null">
				terminatedEmployeeName=#{terminatedEmployeeName},
			</if>
			<if test="terminatedEmployeePhone != null">
				terminatedEmployeePhone=#{terminatedEmployeePhone},
			</if>
			<if test="terminatedEmployeeStore != null">
				terminatedEmployeeStore=#{terminatedEmployeeStore},
			</if>
			<if test="createdAt != null">
				createdAt=#{createdAt},
			</if>
			<if test="updatedAt != null">
				updatedAt=#{updatedAt},
			</if>
		</trim>
		<if test="up != null and up!=''">
			<if test="id!= null and id!=''">
				where id=#{id}
			</if>
		</if>
	</update>

	<!--随访跟进人分配 删除-->
	<delete id="followUpAssignRemove" parameterType="pd">
		<if test="ids != null">
			delete from s_dtp_ysfw_follow_up_assign where
			<if test="ids != null">
				id in(#{ids})
			</if>
		</if>
	</delete>

	<!--患者咨询 查询-->
	<select id="selectPatientCounselingList" parameterType="pd" resultType="pd">
		select *,DATE_FORMAT(consultationTime, '%Y-%m-%d %H:%i:%s') AS updateTime2 from s_dtp_ysfw_patient_consultation where 1=1
		<if test="id != null and id != ''">
			and id=#{id}
		</if>
		<if test="createdBy != null and createdBy != ''">
			AND createdBy=#{createdBy}
		</if>
		<if test="createdDate != null">
			AND createdDate=#{createdDate}
		</if>
		<if test="patientName != null and patientName != ''">
			AND patientName=#{patientName}
		</if>
		<if test="patientPhone != null and patientPhone != ''">
			AND patientPhone=#{patientPhone}
		</if>
		<if test="gender != null and gender != ''">
			AND gender=#{gender}
		</if>
		<if test="age != null">
			AND age=#{age}
		</if>
		<if test="questionType != null and questionType != ''">
			AND questionType=#{questionType}
		</if>
		<if test="consultationQuestion != null and consultationQuestion != ''">
			AND consultationQuestion=#{consultationQuestion}
		</if>
		<if test="pharmacistAnswer != null and pharmacistAnswer != ''">
			AND pharmacistAnswer=#{pharmacistAnswer}
		</if>
		<if test="consultationTime != null">
			AND consultationTime=#{consultationTime}
		</if>
		<if test="disease != null and disease != ''">
			AND disease=#{disease}
		</if>
		<if test="genericName != null and genericName != ''">
			AND genericName=#{genericName}
		</if>
		<if test="productName != null and productName != ''">
			AND productName=#{productName}
		</if>

	</select>

	<!--患者咨询 修改-->
	<update id="updatePatientCounseling" parameterType="pd" >
		<if test="up != null and up!=''">
			update s_dtp_ysfw_patient_consultation
		</if>
		<trim prefix=" SET " suffix="" prefixOverrides="," suffixOverrides=",">
			<if test="createdBy != null and createdBy != ''">
				createdBy=#{createdBy},
			</if>
			<if test="createdDate != null">
				createdDate=#{createdDate},
			</if>
			<if test="patientName != null and patientName != ''">
				patientName=#{patientName},
			</if>
			<if test="patientPhone != null and patientPhone != ''">
				patientPhone=#{patientPhone},
			</if>
			<if test="gender != null and gender != ''">
				gender=#{gender},
			</if>
			<if test="age != null">
				age=#{age},
			</if>
			<if test="questionType != null and questionType != ''">
				questionType=#{questionType},
			</if>
			<if test="consultationQuestion != null and consultationQuestion != ''">
				consultationQuestion=#{consultationQuestion},
			</if>
			<if test="pharmacistAnswer != null and pharmacistAnswer != ''">
				pharmacistAnswer=#{pharmacistAnswer},
			</if>
			<if test="consultationTime != null">
				consultationTime=#{consultationTime},
			</if>
			<if test="disease != null and disease != ''">
				disease=#{disease},
			</if>
			<if test="genericName != null and genericName != ''">
				genericName=#{genericName},
			</if>
			<if test="productName != null and productName != ''">
				productName=#{productName},
			</if>
		</trim>
		<if test="up != null and up!=''">
			<if test="id!= null and id!=''">
				where id=#{id}
			</if>
		</if>
	</update>

	<!--患者咨询 删除-->
	<delete id="patientCounselingRemove" parameterType="pd">
		<if test="ids != null">
			delete from s_dtp_ysfw_patient_consultation where
			<if test="ids != null">
				id in(#{ids})
			</if>
		</if>
	</delete>

	<!--随访满意度评价 查询-->
	<select id="selectFindFollowUpEvaluationList" parameterType="pd" resultType="pd">
		select *,DATE_FORMAT(evaluationDate, '%Y-%m-%d %H:%i:%s') AS updateTime2 from s_ysfw_follow_up_evaluation where 1=1
		<if test="id != null and id != ''">
			AND id = #{id}
		</if>
		<if test="businessId != null and businessId != ''">
			AND businessId = #{businessId}
		</if>
		<if test="businessName != null and businessName != ''">
			AND businessName = #{businessName}
		</if>
		<if test="createdBy != null and createdBy != ''">
			AND createdBy = #{createdBy}
		</if>
		<if test="createdDate != null">
			AND createdDate = #{createdDate}
		</if>
		<if test="patientName != null and patientName != ''">
			AND patientName = #{patientName}
		</if>
		<if test="followUpTask != null and followUpTask != ''">
			AND followUpTask = #{followUpTask}
		</if>
		<if test="taskFollower != null and taskFollower != ''">
			AND taskFollower = #{taskFollower}
		</if>
		<if test="evaluationDate != null">
			AND evaluationDate = #{evaluationDate}
		</if>
		<if test="chainStoreName != null and chainStoreName != ''">
			AND chainStoreName = #{chainStoreName}
		</if>
		<if test="storeName != null and storeName != ''">
			AND storeName = #{storeName}
		</if>
		<if test="taskId != null and taskId != ''">
			AND taskId = #{taskId}
		</if>


	</select>

	<!--随访满意度评价 修改-->
	<update id="updateFindFollowUpEvaluation" parameterType="pd" >
		<if test="up != null and up!=''">
			update s_ysfw_follow_up_evaluation
		</if>
		<trim prefix=" SET " suffix="" prefixOverrides="," suffixOverrides=",">
			<if test="businessName != null and businessName != ''">
				businessName = #{businessName},
			</if>
			<if test="createdBy != null and createdBy != ''">
				createdBy = #{createdBy},
			</if>
			<if test="createdDate != null">
				createdDate = #{createdDate},
			</if>
			<if test="patientName != null and patientName != ''">
				patientName = #{patientName},
			</if>
			<if test="followUpTask != null and followUpTask != ''">
				followUpTask = #{followUpTask},
			</if>
			<if test="taskFollower != null and taskFollower != ''">
				taskFollower = #{taskFollower},
			</if>
			<if test="evaluationDate != null">
				evaluationDate = #{evaluationDate},
			</if>
			<if test="chainStoreName != null and chainStoreName != ''">
				chainStoreName = #{chainStoreName},
			</if>
			<if test="storeName != null and storeName != ''">
				storeName = #{storeName},
			</if>
			<if test="taskId != null and taskId != ''">
				taskId = #{taskId},
			</if>
		</trim>
		<if test="up != null and up!=''">
			<if test="id!= null and id!=''">
				where id=#{id}
			</if>
		</if>
	</update>

	<!--随访满意度评价 删除-->
	<delete id="findFollowUpEvaluationRemove" parameterType="pd">
		<if test="ids != null">
			delete from s_ysfw_follow_up_evaluation where
			<if test="ids != null">
				businessId in(#{ids})
			</if>
		</if>
	</delete>
</mapper>
