<?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="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>
		<if test="id !=null and id !='' ">
			and id = #{id}
		</if>

	</select>
	<!-- 检查患者是否存在name LIKE CONCAT('%', #{name}, '%') -->
	<select id="checkPatientIsExist" parameterType="pd" resultType="pd">
		select name,phoneNumber from s_dtp_ysfw_archive_management where 1=1
		<if test="name!= null and name!=''">
			and name =#{name}
		</if>
		<if test="documentNumber!= null and documentNumber!=''">
			and documentNumber=#{documentNumber}
		</if>
		<if test="phoneNumber!= null and phoneNumber!=''">
			and phoneNumber=#{phoneNumber}
		</if>
	</select>
	<select id="slectPatientByNameOrPhone" parameterType="pd" resultType="pd">
	select * from s_dtp_ysfw_archive_management where  1=1  AND  name LIKE CONCAT('%', #{query}, '%') or phoneNumber=#{query}
	</select>

	<select id="slectPatientByNameOrPhoneOrIdCard" parameterType="pd" resultType="pd">
		select * from s_dtp_ysfw_archive_management where  1=1  AND name LIKE CONCAT('%', #{query}, '%') or phoneNumber=#{query} or documentNumber=#{query}
	</select>

	<select id="slectPatientById" parameterType="pd" resultType="pd">
		select * from s_dtp_ysfw_archive_management where  1=1  AND id=#{id}
	</select>

	<select id="selectPatientById" parameterType="pd" resultType="pd">
		select * from s_dtp_ysfw_archive_management where  1=1 and id=#{patientId}
	</select>

	<!-- 插入新的档案记录 -->
	<insert id="insertArchiveRecord" parameterType="pd">
		INSERT INTO s_dtp_ysfw_archive_management
		<trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="realNameStatus != null">realNameStatus,</if>
			<if test="name != null and name != ''">name,</if>
			<if test="gender != null">gender,</if>
			<if test="age != null">age,</if>
			<if test="dateBirth != null">dateBirth,</if>
			<if test="phoneNumber != null and phoneNumber != ''">phoneNumber,</if>
			<if test="documentNumber != null and documentNumber != ''">documentNumber,</if>
			<if test="idCardImg != null and idCardImg != ''">idCardImg,</if>
			<if test="landlineNumber != null and landlineNumber != ''">landlineNumber,</if>
			<if test="documentType != null and documentType != ''">documentType,</if>
			<if test="createTime != null">createTime,</if>
			<if test="archiveCreator != null and archiveCreator != ''">archiveCreator,</if>
			<if test="creator != null and creator != ''">creator,</if>
			<if test="archiveCompleteStatus != null">archiveCompleteStatus,</if>
			<if test="contactRelation != null and contactRelation != ''">contactRelation,</if>
			<if test="contactPhone != null and contactPhone != ''">contactPhone,</if>
			<if test="contactName != null and contactName != ''">contactName,</if>
			<if test="flipStatus != null">flipStatus,</if>
			<if test="chronicTumorType != null and chronicTumorType != ''">chronicTumorType,</if>
			<if test="nation != null and nation != ''">nation,</if>
			<if test="nativePlace != null and nativePlace != ''">nativePlace,</if>
			<if test="height != null">height,</if>
			<if test="weight != null">weight,</if>
			<if test="BMI != null and BMI != ''">BMI,</if>
			<if test="storeId != null and storeId != ''">storeId,</if>
			<if test="insurance != null and insurance != ''">insurance,</if>
			<if test="socialSecurityCard != null and socialSecurityCard != ''">socialSecurityCard,</if>
			<if test="timeFirstDiagnosis != null">timeFirstDiagnosis,</if>
			<if test="diseaseType != null and diseaseType != ''">diseaseType,</if>
			<if test="healingLineCollection != null and healingLineCollection != ''">healingLineCollection,</if>
			<if test="disease != null and disease != ''">disease,</if>
			<if test="ownedStore != null and ownedStore != ''">ownedStore,</if>
			<if test="archiveCompleter != null and archiveCompleter != ''">archiveCompleter,</if>
			<if test="acceptFollowUp != null">acceptFollowUp,</if>
			<if test="followUpPerson != null and followUpPerson != ''">followUpPerson,</if>
			<if test="charityAssistance != null">charityAssistance,</if>
			<if test="manufacturer != null and manufacturer != ''">manufacturer,</if>
			<if test="joinProject != null">joinProject,</if>
			<if test="mdmCode != null and mdmCode != ''">mdmCode,</if>
			<if test="productName != null and productName != ''">productName,</if>
			<if test="storeName != null and storeName != ''">storeName,</if>
			<if test="followUpStatus != null">followUpStatus,</if>
		    <if test="noFlipCause != null and noFlipCause != ''">noFlipCause,</if>
			<if test="genericName != null and genericName != ''">genericName,</if>
			<if test="updateTime != null and updateTime != ''">updateTime,</if>
			<if test="dl != null and dl != ''">dl,</if>
			<if test="xl != null and xl != ''">xl,</if>
			<if test="addr != null and addr != ''">addr</if>
		</trim>

		<trim prefix=" VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="realNameStatus != null">#{realNameStatus},</if>
			<if test="name != null and name != ''">#{name},</if>
			<if test="gender != null">#{gender},</if>
			<if test="age != null">#{age},</if>
			<if test="dateBirth != null">#{dateBirth},</if>
			<if test="phoneNumber != null and phoneNumber != ''">#{phoneNumber},</if>
			<if test="documentNumber != null and documentNumber != ''">#{documentNumber},</if>
			<if test="idCardImg != null and idCardImg != ''">#{idCardImg},</if>
			<if test="landlineNumber != null and landlineNumber != ''">#{landlineNumber},</if>
			<if test="documentType != null and documentType != ''">#{documentType},</if>
			<if test="createTime != null">#{createTime},</if>
			<if test="archiveCreator != null and archiveCreator != ''">#{archiveCreator},</if>
			<if test="creator != null and creator != ''">#{creator},</if>
			<if test="archiveCompleteStatus != null">#{archiveCompleteStatus},</if>
			<if test="contactRelation != null and contactRelation != ''">#{contactRelation},</if>
			<if test="contactPhone != null and contactPhone != ''">#{contactPhone},</if>
			<if test="contactName != null and contactName != ''">#{contactName},</if>
			<if test="flipStatus != null">#{flipStatus},</if>
			<if test="chronicTumorType != null and chronicTumorType != ''">#{chronicTumorType},</if>
			<if test="nation != null and nation != ''">#{nation},</if>
			<if test="nativePlace != null and nativePlace != ''">#{nativePlace},</if>
			<if test="height != null">#{height},</if>
			<if test="weight != null">#{weight},</if>
			<if test="BMI != null and BMI != ''">#{BMI},</if>
			<if test="storeId != null and storeId != ''">#{storeId},</if>
			<if test="insurance != null and insurance != ''">#{insurance},</if>
			<if test="socialSecurityCard != null and socialSecurityCard != ''">#{socialSecurityCard},</if>
			<if test="timeFirstDiagnosis != null">#{timeFirstDiagnosis},</if>
			<if test="diseaseType != null and diseaseType != ''">#{diseaseType},</if>
			<if test="healingLineCollection != null and healingLineCollection != ''">#{healingLineCollection},</if>
			<if test="disease != null and disease != ''">#{disease},</if>
			<if test="ownedStore != null and ownedStore != ''">#{ownedStore},</if>
			<if test="archiveCompleter != null and archiveCompleter != ''">#{archiveCompleter},</if>
			<if test="acceptFollowUp != null">#{acceptFollowUp},</if>
			<if test="followUpPerson != null and followUpPerson != ''">#{followUpPerson},</if>
			<if test="charityAssistance != null">#{charityAssistance},</if>
			<if test="manufacturer != null and manufacturer != ''">#{manufacturer},</if>
			<if test="joinProject != null">#{joinProject},</if>
			<if test="mdmCode != null and mdmCode != ''">#{mdmCode},</if>
			<if test="productName != null and productName != ''">#{productName},</if>
			<if test="storeName != null and storeName != ''">#{storeName},</if>
			<if test="followUpStatus != null">#{followUpStatus},</if>
		    <if test="noFlipCause != null and noFlipCause != ''">#{noFlipCause},</if>
			<if test="genericName != null and genericName != ''">#{genericName},</if>
			<if test="updateTime != null and updateTime != ''">#{updateTime},</if>
			<if test="dl != null and dl != ''">#{dl},</if>
			<if test="xl != null and xl != ''">#{xl},</if>
			<if test="addr != null and addr != ''">#{addr}</if>
		</trim>

	</insert>

	<!-- 更新档案记录 -->
	<update id="updateArchiveRecord" parameterType="pd">
		UPDATE s_dtp_ysfw_archive_management
		SET
		<if test="realNameStatus != null ">realNameStatus = #{realNameStatus},</if>
		<if test="gender != null  and gender != ''">gender = #{gender},</if>
		<if test="age != null and age != ''" >age = #{age},</if>
		<if test="dateBirth != null and dateBirth != ''">dateBirth = #{dateBirth},</if>
		<if test="phoneNumber != null and phoneNumber != ''">phoneNumber = #{phoneNumber},</if>
		<if test="documentNumber != null and documentNumber != ''">documentNumber=#{documentNumber},</if>
		<if test="idCardImg != null and idCardImg != ''">idCardImg=#{idCardImg},</if>
		<if test="landlineNumber != null and landlineNumber != ''">landlineNumber = #{landlineNumber},</if>
		<if test="archiveCompleteStatus != null">archiveCompleteStatus = #{archiveCompleteStatus},</if>
		<if test="contactRelation != null and contactRelation != ''">contactRelation = #{contactRelation},</if>
		<if test="contactPhone != null and contactPhone != ''">contactPhone = #{contactPhone},</if>
		<if test="contactName != null and contactName != ''">contactName = #{contactName},</if>
		<if test="flipStatus != null">flipStatus = #{flipStatus},</if>
		<if test="chronicTumorType != null and chronicTumorType != ''">chronicTumorType = #{chronicTumorType},</if>
		<if test="nation != null and nation != ''">nation = #{nation},</if>
		<if test="nativePlace != null and nativePlace != ''">nativePlace = #{nativePlace},</if>
		<if test="height != null and height != ''">height = #{height},</if>
		<if test="weight != null and weight != ''">weight = #{weight},</if>
		<if test="BMI != null and BMI != ''">BMI = #{BMI},</if>
		<if test="insurance != null and insurance != ''">insurance = #{insurance},</if>
		<if test="socialSecurityCard != null and socialSecurityCard != ''">socialSecurityCard = #{socialSecurityCard},</if>
		<if test="timeFirstDiagnosis != null">timeFirstDiagnosis = #{timeFirstDiagnosis},</if>
		<if test="diseaseType != null and diseaseType != ''">diseaseType = #{diseaseType},</if>
		<if test="healingLineCollection != null and healingLineCollection != ''">healingLineCollection = #{healingLineCollection},</if>
		<if test="disease != null and disease != ''">disease = #{disease},</if>
		<if test="ownedStore != null and ownedStore != ''">ownedStore = #{ownedStore},</if>
		<if test="archiveCompleter != null and archiveCompleter != ''">archiveCompleter = #{archiveCompleter},</if>
		<if test="acceptFollowUp != null">acceptFollowUp = #{acceptFollowUp},</if>
		<if test="followUpPerson != null and followUpPerson != ''">followUpPerson = #{followUpPerson},</if>
		<if test="charityAssistance != null">charityAssistance = #{charityAssistance},</if>
		<if test="manufacturer != null and manufacturer != ''">manufacturer = #{manufacturer},</if>
		<if test="joinProject != null and gender != ''">joinProject = #{joinProject},</if>
		<if test="mdmCode != null and mdmCode != ''">mdmCode = #{mdmCode},</if>
		<if test="productName != null and productName != ''">productName = #{productName},</if>
		<if test="storeName != null and storeName != ''">storeName = #{storeName},</if>
		<if test="storeId != null and storeId != ''">storeId = #{storeId},</if>
		<if test="noFlipCause != null and noFlipCause != ''">noFlipCause = #{noFlipCause},</if>
		<if test="followUpStatus != null and followUpStatus != ''">followUpStatus = #{followUpStatus},</if>
		<if test="genericName != null and genericName != ''">genericName = #{genericName},</if>
		updateTime = #{updateTime}
		WHERE id = #{id}
	</update>

	<!--患者绑定微信上翻-->
	<update id="ShaoMaShangFan" parameterType="pd">
		update s_dtp_ysfw_archive_management
		<trim prefix="SET" suffixOverrides="," prefixOverrides=",">

			<if test="openId != null and openId != ''">
				openId = #{openId},
			</if>
			<if test="flipStatus != null and flipStatus != ''">
				flipStatus = #{flipStatus},
			</if>
			<if test="updateTime != null and updateTime != ''">
				updateTime = #{updateTime},
			</if>
			<if test="archiveCreator != null and archiveCreator != ''">
				archiveCreator = #{archiveCreator},
			</if>
		</trim>
		     where id = #{id}
	</update>
	<!--患者解除绑定-->
	<update id="unbound" parameterType="pd">
		update s_dtp_ysfw_archive_management
		<trim prefix="SET" suffixOverrides="," prefixOverrides=",">

			<if test="openId != null and openId != ''">
				openId = #{openId},
			</if>
			<if test="flipStatus != null and flipStatus != ''">
				flipStatus = #{flipStatus},
			</if>
			<if test="noFlipCause != null and noFlipCause != ''">
				noFlipCause = #{noFlipCause},
			</if>
			<if test="updateTime != null and updateTime != ''">
				updateTime = #{updateTime},
			</if>
			<if test="archiveCreator != null and archiveCreator != ''">
				archiveCreator = #{archiveCreator},
			</if>

		</trim>
		where id = #{id}
	</update>

	<!--档案管理修改-->
	<update id="updateArchives" parameterType="pd">
		update s_dtp_ysfw_archive_management
		<trim prefix="SET" suffixOverrides="," prefixOverrides=",">
			<if test="realNameStatus != null and realNameStatus!=''">
				realNameStatus = #{realNameStatus},
			</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="dateBirth != null and dateBirth != ''">
				dateBirth = #{dateBirth},
			</if>
			<if test="phoneNumber != null and phoneNumber != ''">
				phoneNumber = #{phoneNumber},
			</if>
			<if test="documentNumber != null and documentNumber != ''">
				documentNumber = #{documentNumber},
			</if>
		    <if test="idCardImg != null and idCardImg != ''">
				idCardImg = #{idCardImg},
			</if>
			<if test="landlineNumber != null and landlineNumber != ''">
				landlineNumber = #{landlineNumber},
			</if>
			<if test="documentType != null and documentType != ''">
				documentType = #{documentType},
			</if>
			<if test="archiveCreator != null and archiveCreator != ''">
				archiveCreator = #{archiveCreator},
			</if>
			<if test="creator != null and creator != ''">
				creator = #{creator},
			</if>
			<if test="archiveCompleteStatus != null">
				archiveCompleteStatus = #{archiveCompleteStatus},
			</if>
			<if test="contactRelation != null and contactRelation != ''">
				contactRelation = #{contactRelation},
			</if>
			<if test="contactPhone != null and contactPhone != ''">
				contactPhone = #{contactPhone},
			</if>
			<if test="contactName != null and contactName != ''">
				contactName = #{contactName},
			</if>
			<if test="flipStatus != null and flipStatus != ''">
				flipStatus = #{flipStatus},
			</if>
		    <if test="noFlipCause != null and noFlipCause != ''">
				noFlipCause = #{noFlipCause},
			</if>
			<if test="chronicTumorType != null and chronicTumorType != ''">
				chronicTumorType = #{chronicTumorType},
			</if>
			<if test="nation != null and nation != ''">
				nation = #{nation},
			</if>
			<if test="nativePlace != null and nativePlace != ''">
				nativePlace = #{nativePlace},
			</if>
			<if test="height != null and height != ''">
				height = #{height},
			</if>
			<if test="weight != null and weight != ''">
				weight = #{weight},
			</if>
			<if test="BMI != null and BMI != ''">
				BMI = #{BMI},
			</if>
			<if test="insurance != null and insurance != ''">
				insurance = #{insurance},
			</if>
			<if test="socialSecurityCard != null and socialSecurityCard != ''">
				socialSecurityCard = #{socialSecurityCard},
			</if>
			<if test="timeFirstDiagnosis != null and timeFirstDiagnosis != ''">
				timeFirstDiagnosis = #{timeFirstDiagnosis},
			</if>
			<if test="diseaseType != null and diseaseType != ''">
				diseaseType = #{diseaseType},
			</if>
			<if test="healingLineCollection != null and healingLineCollection != ''">
				healingLineCollection = #{healingLineCollection},
			</if>
			<if test="disease != null and disease != ''">
				disease = #{disease},
			</if>
			<if test="ownedStore != null and ownedStore != ''">
				ownedStore = #{ownedStore},
			</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="charityAssistance != null and charityAssistance != ''">
				charityAssistance = #{charityAssistance},
			</if>
			<if test="manufacturer != null and manufacturer != ''">
				manufacturer = #{manufacturer},
			</if>
			<if test="joinProject != null and joinProject != ''">
				joinProject = #{joinProject},
			</if>
			<if test="mdmCode != null and mdmCode != ''">
				mdmCode = #{mdmCode},
			</if>
			<if test="productName != null and productName != ''">
				productName = #{productName},
			</if>
			<if test="storeName != null and storeName != ''">
				storeName = #{storeName},
			</if>
			<if test="storeId != null and storeId != ''">
				storeId = #{storeId},
			</if>
			<if test="followUpStatus != null and followUpStatus != ''">
				followUpStatus = #{followUpStatus},
			</if>
			<if test="genericName != null and genericName != ''">
				genericName = #{genericName},
			</if>
			<if test="waist != null and waist != ''">
				waist = #{waist},
			</if>
			<if test="hip != null and hip != ''">
				hip = #{hip},
			</if>
			<if test="bloodPressure != null and bloodPressure != ''">
				bloodPressure = #{bloodPressure},
			</if>
			<if test="bloodSugar != null and bloodSugar != ''">
				bloodSugar = #{bloodSugar},
			</if>
			<if test="medicalHistory != null and medicalHistory != ''">
				medicalHistory = #{medicalHistory},
			</if>
			<if test="hasSurgicalTraumaHistory != null">
				hasSurgicalTraumaHistory = #{hasSurgicalTraumaHistory},
			</if>
			<if test="infectiousDiseaseHistory != null and infectiousDiseaseHistory != ''">
				infectiousDiseaseHistory = #{infectiousDiseaseHistory},
			</if>
			<if test="allergyHistory != null and allergyHistory != ''">
				allergyHistory = #{allergyHistory},
			</if>
			<if test="businessBelonging != null and businessBelonging != ''">
				businessBelonging = #{businessBelonging},
			</if>
			<if test="zlfq != null and zlfq != ''">
				zlfq = #{zlfq},
			</if>
			<if test="jytb != null and jytb != ''">
				jytb = #{jytb},
			</if>
			<if test="treatmentStage != null and treatmentStage != ''">
				treatmentStage = #{treatmentStage},
			</if>
			<if test="fzjc != null and fzjc != ''">
				fzjc = #{fzjc},
			</if>
			<if test="pdl1 != null and pdl1 != ''">
				pdl1 = #{pdl1},
			</if>
			<if test="zlsd != null and zlsd != ''">
				zlsd = #{zlsd},
			</if>
			<if test="dl != null and dl != ''">dl=#{dl},</if>
			<if test="xl != null and xl != ''">xl=#{xl},</if>
			<if test="addr != null and addr != ''">addr=#{addr},</if>
			<if test="contactName != null and contactName != ''">contactName=#{contactName},</if>
			<if test="contactPhone != null and contactPhone != ''">contactPhone=#{contactPhone},</if>
			<if test="tnb != null and tnb != ''">
				tnb = #{tnb},
			</if>
			<if test="tnbhbz != null and tnbhbz != ''">
				tnbhbz = #{tnbhbz},
			</if>
			<if test="gxy != null and gxy != ''">
				gxy = #{gxy},
			</if>
			<if test="gxyhbz != null and gxyhbz != ''">
				gxyhbz = #{gxyhbz},
			</if>
			<if test="gxz != null and gxz != ''">
				gxz = #{gxz},
			</if>
			<if test="gxzhbz != null and gxzhbz != ''">
				gxzhbz = #{gxzhbz},
			</if>
		</trim>
		where id = #{id}
	</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="filingDate != null">
			and filingDate=#{filingDate}
		</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="filingDate != null">
				filingDate=#{filingDate},
			</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>
	<!--根据所属们id查询患者信息-->
	<select id="getAllPatients" parameterType="pd" resultType="pd">
		select id ,name ,storeName ,storeId from s_dtp_ysfw_archive_management where 1=1 and storeId=#{DeptId}
	</select>

	<select id="selectConsultationAndDrug" parameterType="pd" resultType="pd">
		SELECT
			pc.id AS id,
			pc.storeName,
			pc.storeId,
			pc.patientId,
			pc.createdBy,
			pc.createdDate,
			pc.patientName,
			pc.patientPhone,
			pc.gender,
			pc.age,
			pc.KnowledgeLink,
			pc.questionType,
			pc.consultationQuestion,
			pc.pharmacistAnswer,
			pc.consultationTime,
			pc.disease,
			pc.genericName,
			pc.productName,
			pd.id AS prescriptionDrugId,
			pd.productName AS prescriptionProductName,
			pd.genericName AS prescriptionGenericName,
			pd.mdmCode AS prescriptionmdmCode,
		    pd.prescriptionNumber
		FROM
			s_dtp_ysfw_patient_consultation pc
				LEFT JOIN
			s_dtp_cfdj_prescription_drug pd ON pc.patientId = pd.patientId
		WHERE
			pc.storeId = #{storeId}
		<if test="createdDate != null">
			AND pc.createdDate=#{createdDate}
		</if>
		<if test="query != null and query != ''">
			AND (pc.patientName LIKE CONCAT('%', #{query}, '%')
			OR pc.patientPhone = #{query})
		</if>
		<if test="questionType != null and questionType != ''">
			AND pc.questionType=#{questionType}
		</if>
		<if test="consultationQuestion != null and consultationQuestion != ''">
			AND pc.consultationQuestion=#{consultationQuestion}
		</if>
		<if test="pharmacistAnswer != null and pharmacistAnswer != ''">
			AND pc.pharmacistAnswer=#{pharmacistAnswer}
		</if>

		<if test="beginTime != null and beginTime!='' and endTime != null and endTime!=''">
			and pc.consultationTime between #{beginTime} and #{endTime}
		</if>
		<if test="disease != null and disease != ''">
			AND pc.disease=#{disease}
		</if>
		<if test="product != null and product != ''">
			AND pd.genericName =#{product} OR pd.productName = #{product} OR pd.mdmCode = #{product}
		</if>
		ORDER BY
		pc.id ASC

	</select>
	<!--患者咨询根据id-->
	<select id="findPatientCounselingById" parameterType="pd" resultType="pd">
		select * from s_dtp_ysfw_patient_consultation where 1=1 and id=#{id}
	</select>
	<!--患者咨询 查询所有-->
	<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="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>
	<insert id="insertPatientConsultation" parameterType="pd">
		INSERT INTO s_dtp_ysfw_patient_consultation
		<trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="createdBy != null and createdBy !=''">createdBy,</if>
			<if test="createdDate != null and createdDate !=''">createdDate,</if>
			<if test="patientName != null and patientName != ''">patientName,</if>
			<if test="patientPhone != null and patientPhone != ''">patientPhone,</if>
			<if test="gender != null">gender,</if>
			<if test="age != null">age,</if>
			<if test="KnowledgeLink != null and KnowledgeLink != ''">KnowledgeLink,</if>
			<if test="questionType != null and questionType != ''">questionType,</if>
			<if test="consultationQuestion != null and consultationQuestion != ''">consultationQuestion,</if>
			<if test="pharmacistAnswer != null and pharmacistAnswer != ''">pharmacistAnswer,</if>
			<if test="consultationTime != null">consultationTime,</if>
			<if test="contactRelation != null and contactRelation != ''">contactRelation,</if>
			<if test="disease != null and disease != ''">disease,</if>
			<if test="genericName != null and genericName != ''">genericName,</if>
			<if test="productName != null and productName != ''">productName,</if>
			<if test="storeId != null">storeId,</if>
			<if test="storeName != null and storeName != ''">storeName,</if>
			<if test="patientId != null">patientId,</if>
		</trim>
		<trim prefix=" VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="createdBy != null and createdBy !=''">#{createdBy},</if>
			<if test="createdDate != null and createdDate !=''">#{createdDate},</if>
			<if test="patientName != null and patientName != ''">#{patientName},</if>
			<if test="patientPhone != null and patientPhone != ''">#{patientPhone},</if>
			<if test="gender != null">#{gender},</if>
			<if test="age != null">#{age},</if>
			<if test="KnowledgeLink != null and KnowledgeLink != ''">#{KnowledgeLink},</if>
			<if test="questionType != null and questionType != ''">#{questionType},</if>
			<if test="consultationQuestion != null and consultationQuestion != ''">#{consultationQuestion},</if>
			<if test="pharmacistAnswer != null and pharmacistAnswer != ''">#{pharmacistAnswer},</if>
			<if test="consultationTime != null and consultationTime != ''">#{consultationTime},</if>
			<if test="contactRelation != null and contactRelation != ''">#{contactRelation},</if>
			<if test="disease != null and disease != ''">#{disease},</if>
			<if test="genericName != null and genericName != ''">#{genericName},</if>
			<if test="productName != null and productName != ''">#{productName},</if>
			<if test="storeId != null">#{storeId},</if>
			<if test="storeName != null and storeName != ''">#{storeName},</if>
			<if test="patientId != null and patientId != ''">#{patientId},</if>
		</trim>
	</insert>
	<!--患者咨询 修改-->
	<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="regenerator != null and regenerator != ''">
				regenerator=#{regenerator},
			</if>
			<if test="updateDate != null and updateDate !=''">
				updateDate=#{updateDate},
			</if>
			<if test="questionType != null and questionType != ''">
				questionType=#{questionType},
			</if>
			<if test="KnowledgeLink != null and KnowledgeLink != ''">
				KnowledgeLink=#{KnowledgeLink},
			</if>
			<if test="contactRelation != null and contactRelation != ''">
				contactRelation=#{contactRelation},
			</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>

		</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 * 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 != ''" >
			AND evaluationDate = #{evaluationDate}
		</if>
		<if test="beginTime != null and beginTime!='' and endTime != null and endTime!=''">
			and evaluationDate between #{beginTime} and #{endTime}
		</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">
				id in(#{ids})
			</if>
		</if>
	</delete>

	<!--查询患者基础信息-->
	<select id="selectPatientBasicInfo" parameterType="pd" resultType="pd">
		SELECT * FROM s_dtp_ysfw_patientbasicinfor WHERE 1=1
		<if test="id != null and id != ''">
			AND id = #{id}
		</if>
		<if test="currentEconomicSituation != null and currentEconomicSituation != ''">
			AND currentEconomicSituation = #{currentEconomicSituation}
		</if>
		<if test="patientAwareness != null and patientAwareness != ''">
			AND patientAwareness = #{patientAwareness}
		</if>
		<if test="followUpFeedbackDoctor != null and followUpFeedbackDoctor != ''">
			AND followUpFeedbackDoctor = #{followUpFeedbackDoctor}
		</if>
		<if test="bloodPressureStatus != null and bloodPressureStatus != ''">
			AND bloodPressureStatus = #{bloodPressureStatus}
		</if>
		<if test="heartRate != null and heartRate != ''">
			AND heartRate = #{heartRate}
		</if>
		<if test="smokingHistory != null and smokingHistory != ''">
			AND smokingHistory = #{smokingHistory}
		</if>
		<if test="drinkingHistory != null and drinkingHistory != ''">
			AND drinkingHistory = #{drinkingHistory}
		</if>
		<if test="exerciseHabit != null and exerciseHabit != ''">
			AND exerciseHabit = #{exerciseHabit}
		</if>
		<if test="dietaryPreference != null and dietaryPreference != ''">
			AND dietaryPreference = #{dietaryPreference}
		</if>
		<if test="sleepCondition != null and sleepCondition != ''">
			AND sleepCondition = #{sleepCondition}
		</if>
		<if test="pathologicalStage != null and pathologicalStage != ''">
			AND pathologicalStage = #{pathologicalStage}
		</if>
		<if test="treatmentStage != null and treatmentStage != ''">
			AND treatmentStage = #{treatmentStage}
		</if>
		<if test="accompanyingSymptoms != null and accompanyingSymptoms != ''">
			AND accompanyingSymptoms = #{accompanyingSymptoms}
		</if>
		<if test="hasGeneticTesting != null and hasGeneticTesting != ''">
			AND hasGeneticTesting = #{hasGeneticTesting}
		</if>
		<if test="hasImmuneTesting != null and hasImmuneTesting != ''">
			AND hasImmuneTesting = #{hasImmuneTesting}
		</if>
		<if test="medicalHistory != null and medicalHistory != ''">
			AND medicalHistory = #{medicalHistory}
		</if>
		<if test="medicalHistoryDescription != null and medicalHistoryDescription != ''">
			AND medicalHistoryDescription = #{medicalHistoryDescription}
		</if>
		<if test="infectiousDiseaseHistory != null and infectiousDiseaseHistory != ''">
			AND infectiousDiseaseHistory = #{infectiousDiseaseHistory}
		</if>
		<if test="infectiousDiseaseHistoryDescription != null and infectiousDiseaseHistoryDescription != ''">
			AND infectiousDiseaseHistoryDescription = #{infectiousDiseaseHistoryDescription}
		</if>
		<if test="allergyHistory != null and allergyHistory != ''">
			AND allergyHistory = #{allergyHistory}
		</if>
		<if test="pastAdverseDrugReactionHistory != null and pastAdverseDrugReactionHistory != ''">
			AND pastAdverseDrugReactionHistory = #{pastAdverseDrugReactionHistory}
		</if>
		<if test="hasSurgicalTraumaHistory != null and hasSurgicalTraumaHistory != ''">
			AND hasSurgicalTraumaHistory = #{hasSurgicalTraumaHistory}
		</if>
		<if test="multipleTreatmentReasonsDescription != null and multipleTreatmentReasonsDescription != ''">
			AND multipleTreatmentReasonsDescription = #{multipleTreatmentReasonsDescription}
		</if>
		<if test="familyHistoryId != null and familyHistoryId != ''">
			AND familyHistoryId = #{familyHistoryId}
		</if>
		<if test="previousMedicationId != null and previousMedicationId != ''">
			AND previousMedicationId = #{previousMedicationId}
		</if>
		<if test="contactPersonId != null and contactPersonId != ''">
			AND contactPersonId = #{contactPersonId}
		</if>
		<if test="archiveId != null and archiveId != ''">
			AND archiveId = #{archiveId}
		</if>
		<if test="caregiver != null and caregiver != ''">
			AND caregiver = #{caregiver}
		</if>
		<if test="createdBy != null and createdBy != ''">
			AND createdBy = #{createdBy}
		</if>
		<if test="createdAt != null and createdAt != ''">
			AND createdAt = #{createdAt}
		</if>
		<if test="basicInfoCompleter != null and basicInfoCompleter != ''">
			AND basicInfoCompleter = #{basicInfoCompleter}
		</if>
		<if test="recordUpdateTimestamp != null and recordUpdateTimestamp != ''">
			AND recordUpdateTimestamp = #{recordUpdateTimestamp}
		</if>
		<if test="status != null and status != ''">
			AND status = #{status}
		</if>
		<if test="deleteMarker != null and deleteMarker != ''">
			AND deleteMarker = #{deleteMarker}
		</if>
	</select>

	<!--查询患者基础信息根据Id-->
	<select id="selectPatientBasicInfoById" parameterType="pd" resultType="pd">
		SELECT * FROM s_dtp_ysfw_patientbasicinfor WHERE 1=1
		<if test="id != null and id != ''">
			AND archiveId = #{id}
		</if>

	</select>

	<!--添加患者基础信息-->
	<insert id="insertPatientBasicInfo" parameterType="pd">
		INSERT INTO s_dtp_ysfw_patientbasicinfor
		<trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="id != null and id != ''">id,</if>
			<if test="currentEconomicSituation != null and currentEconomicSituation != ''">currentEconomicSituation,</if>
			<if test="patientAwareness != null and patientAwareness != ''">patientAwareness,</if>
			<if test="followUpFeedbackDoctor != null and followUpFeedbackDoctor != ''">followUpFeedbackDoctor,</if>
			<if test="bloodPressureStatus != null and bloodPressureStatus != ''">bloodPressureStatus,</if>
			<if test="heartRate != null and heartRate != ''">heartRate,</if>
			<if test="smokingHistory != null and smokingHistory != ''">smokingHistory,</if>
			<if test="drinkingHistory != null and drinkingHistory != ''">drinkingHistory,</if>
			<if test="exerciseHabit != null and exerciseHabit != ''">exerciseHabit,</if>
			<if test="dietaryPreference != null and dietaryPreference != ''">dietaryPreference,</if>
			<if test="sleepCondition != null and sleepCondition != ''">sleepCondition,</if>
			<if test="pathologicalStage != null and pathologicalStage != ''">pathologicalStage,</if>
			<if test="treatmentStage != null and treatmentStage != ''">treatmentStage,</if>
			<if test="accompanyingSymptoms != null and accompanyingSymptoms != ''">accompanyingSymptoms,</if>
			<if test="hasGeneticTesting != null and hasGeneticTesting != ''">hasGeneticTesting,</if>
			<if test="hasImmuneTesting != null and hasImmuneTesting != ''">hasImmuneTesting,</if>
			<if test="medicalHistory != null and medicalHistory != ''">medicalHistory,</if>
			<if test="medicalHistoryDescription != null and medicalHistoryDescription != ''">medicalHistoryDescription,</if>
			<if test="infectiousDiseaseHistory != null and infectiousDiseaseHistory != ''">infectiousDiseaseHistory,</if>
			<if test="infectiousDiseaseHistoryDescription != null and infectiousDiseaseHistoryDescription != ''">infectiousDiseaseHistoryDescription,</if>
			<if test="allergyHistory != null and allergyHistory != ''">allergyHistory,</if>
			<if test="pastAdverseDrugReactionHistory != null and pastAdverseDrugReactionHistory != ''">pastAdverseDrugReactionHistory,</if>
			<if test="hasSurgicalTraumaHistory != null and hasSurgicalTraumaHistory != ''">hasSurgicalTraumaHistory,</if>
			<if test="multipleTreatmentReasonsDescription != null and multipleTreatmentReasonsDescription != ''">multipleTreatmentReasonsDescription,</if>
			<if test="familyHistoryId != null and familyHistoryId != ''">familyHistoryId,</if>
			<if test="previousMedicationId != null and previousMedicationId != ''">previousMedicationId,</if>
			<if test="contactPersonId != null and contactPersonId != ''">contactPersonId,</if>
			<if test="archiveId != null and archiveId != ''">archiveId,</if>
			<if test="caregiver != null and caregiver != ''">caregiver,</if>
			<if test="createdBy != null and createdBy != ''">createdBy,</if>
			<if test="createdAt != null and createdAt != ''">createdAt,</if>
			<if test="basicInfoCompleter != null and basicInfoCompleter != ''">basicInfoCompleter,</if>
			<if test="recordUpdateTimestamp != null and recordUpdateTimestamp != ''">recordUpdateTimestamp,</if>
			<if test="status != null and status != ''">status,</if>
			<if test="deleteMarker != null and deleteMarker != ''">deleteMarker</if>
		</trim>

		<trim prefix="VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="id != null and id != ''">#{id},</if>
			<if test="currentEconomicSituation != null and currentEconomicSituation != ''">#{currentEconomicSituation},</if>
			<if test="patientAwareness != null and patientAwareness != ''">#{patientAwareness},</if>
			<if test="followUpFeedbackDoctor != null and followUpFeedbackDoctor != ''">#{followUpFeedbackDoctor},</if>
			<if test="bloodPressureStatus != null and bloodPressureStatus != ''">#{bloodPressureStatus},</if>
			<if test="heartRate != null and heartRate != ''">#{heartRate},</if>
			<if test="smokingHistory != null and smokingHistory != ''">#{smokingHistory},</if>
			<if test="drinkingHistory != null and drinkingHistory != ''">#{drinkingHistory},</if>
			<if test="exerciseHabit != null and exerciseHabit != ''">#{exerciseHabit},</if>
			<if test="dietaryPreference != null and dietaryPreference != ''">#{dietaryPreference},</if>
			<if test="sleepCondition != null and sleepCondition != ''">#{sleepCondition},</if>
			<if test="pathologicalStage != null and pathologicalStage != ''">#{pathologicalStage},</if>
			<if test="treatmentStage != null and treatmentStage != ''">#{treatmentStage},</if>
			<if test="accompanyingSymptoms != null and accompanyingSymptoms != ''">#{accompanyingSymptoms},</if>
			<if test="hasGeneticTesting != null and hasGeneticTesting != ''">#{hasGeneticTesting},</if>
			<if test="hasImmuneTesting != null and hasImmuneTesting != ''">#{hasImmuneTesting},</if>
			<if test="medicalHistory != null and medicalHistory != ''">#{medicalHistory},</if>
			<if test="medicalHistoryDescription != null and medicalHistoryDescription != ''">#{medicalHistoryDescription},</if>
			<if test="infectiousDiseaseHistory != null and infectiousDiseaseHistory != ''">#{infectiousDiseaseHistory},</if>
			<if test="infectiousDiseaseHistoryDescription != null and infectiousDiseaseHistoryDescription != ''">#{infectiousDiseaseHistoryDescription},</if>
			<if test="allergyHistory != null and allergyHistory != ''">#{allergyHistory},</if>
			<if test="pastAdverseDrugReactionHistory != null and pastAdverseDrugReactionHistory != ''">#{pastAdverseDrugReactionHistory},</if>
			<if test="hasSurgicalTraumaHistory != null and hasSurgicalTraumaHistory != ''">#{hasSurgicalTraumaHistory},</if>
			<if test="multipleTreatmentReasonsDescription != null and multipleTreatmentReasonsDescription != ''">#{multipleTreatmentReasonsDescription},</if>
			<if test="familyHistoryId != null and familyHistoryId != ''">#{familyHistoryId},</if>
			<if test="previousMedicationId != null and previousMedicationId != ''">#{previousMedicationId},</if>
			<if test="contactPersonId != null and contactPersonId != ''">#{contactPersonId},</if>
			<if test="archiveId != null and archiveId != ''">#{archiveId},</if>
			<if test="caregiver != null and caregiver != ''">#{caregiver},</if>
			<if test="createdBy != null and createdBy != ''">#{createdBy},</if>
			<if test="createdAt != null and createdAt != ''">#{createdAt},</if>
			<if test="basicInfoCompleter != null and basicInfoCompleter != ''">#{basicInfoCompleter},</if>
			<if test="recordUpdateTimestamp != null and recordUpdateTimestamp != ''">#{recordUpdateTimestamp},</if>
			<if test="status != null and status != ''">#{status},</if>
			<if test="deleteMarker != null and deleteMarker != ''">#{deleteMarker}</if>
		</trim>
	</insert>
	<!--修改患者基础信息-->
	<update id="updatePatientBasicInfo" parameterType="pd">
		UPDATE s_dtp_ysfw_patientbasicinfor SET
		<trim prefix="" suffixOverrides="," prefixOverrides=",">
			<if test="currentEconomicSituation != null and currentEconomicSituation != ''">
				currentEconomicSituation = #{currentEconomicSituation},
			</if>
			<if test="patientAwareness != null and patientAwareness != ''">
				patientAwareness = #{patientAwareness},
			</if>
			<if test="followUpFeedbackDoctor != null and followUpFeedbackDoctor != ''">
				followUpFeedbackDoctor = #{followUpFeedbackDoctor},
			</if>
			<if test="bloodPressureStatus != null and bloodPressureStatus != ''">
				bloodPressureStatus = #{bloodPressureStatus},
			</if>
			<if test="heartRate != null and heartRate != ''">
				heartRate = #{heartRate},
			</if>
			<if test="smokingHistory != null and smokingHistory != ''">
				smokingHistory = #{smokingHistory},
			</if>
			<if test="drinkingHistory != null and drinkingHistory != ''">
				drinkingHistory = #{drinkingHistory},
			</if>
			<if test="exerciseHabit != null and exerciseHabit != ''">
				exerciseHabit = #{exerciseHabit},
			</if>
			<if test="dietaryPreference != null and dietaryPreference != ''">
				dietaryPreference = #{dietaryPreference},
			</if>
			<if test="sleepCondition != null and sleepCondition != ''">
				sleepCondition = #{sleepCondition},
			</if>
			<if test="pathologicalStage != null and pathologicalStage != ''">
				pathologicalStage = #{pathologicalStage},
			</if>
			<if test="treatmentStage != null and treatmentStage != ''">
				treatmentStage = #{treatmentStage},
			</if>
			<if test="accompanyingSymptoms != null and accompanyingSymptoms != ''">
				accompanyingSymptoms = #{accompanyingSymptoms},
			</if>
			<if test="hasGeneticTesting != null and hasGeneticTesting != ''">
				hasGeneticTesting = #{hasGeneticTesting},
			</if>
			<if test="hasImmuneTesting != null and hasImmuneTesting != ''">
				hasImmuneTesting = #{hasImmuneTesting},
			</if>
			<if test="medicalHistory != null and medicalHistory != ''">
				medicalHistory = #{medicalHistory},
			</if>
			<if test="medicalHistoryDescription != null and medicalHistoryDescription != ''">
				medicalHistoryDescription = #{medicalHistoryDescription},
			</if>
			<if test="infectiousDiseaseHistory != null and infectiousDiseaseHistory != ''">
				infectiousDiseaseHistory = #{infectiousDiseaseHistory},
			</if>
			<if test="infectiousDiseaseHistoryDescription != null and infectiousDiseaseHistoryDescription != ''">
				infectiousDiseaseHistoryDescription = #{infectiousDiseaseHistoryDescription},
			</if>
			<if test="allergyHistory != null and allergyHistory != ''">
				allergyHistory = #{allergyHistory},
			</if>
			<if test="pastAdverseDrugReactionHistory != null and pastAdverseDrugReactionHistory != ''">
				pastAdverseDrugReactionHistory = #{pastAdverseDrugReactionHistory},
			</if>
			<if test="hasSurgicalTraumaHistory != null and hasSurgicalTraumaHistory != ''">
				hasSurgicalTraumaHistory = #{hasSurgicalTraumaHistory},
			</if>
			<if test="multipleTreatmentReasonsDescription != null and multipleTreatmentReasonsDescription != ''">
				multipleTreatmentReasonsDescription = #{multipleTreatmentReasonsDescription},
			</if>
			<if test="familyHistoryId != null and familyHistoryId != ''">
				familyHistoryId = #{familyHistoryId},
			</if>
			<if test="previousMedicationId != null and previousMedicationId != ''">
				previousMedicationId = #{previousMedicationId},
			</if>
			<if test="contactPersonId != null and contactPersonId != ''">
				contactPersonId = #{contactPersonId},
			</if>
			<if test="archiveId != null and archiveId != ''">
				archiveId = #{archiveId},
			</if>
			<if test="caregiver != null and caregiver != ''">
				caregiver = #{caregiver},
			</if>
			<if test="createdBy != null and createdBy != ''">
				createdBy = #{createdBy},
			</if>
			<if test="createdAt != null and createdAt != ''">
				createdAt = #{createdAt},
			</if>
			<if test="basicInfoCompleter != null and basicInfoCompleter != ''">
				basicInfoCompleter = #{basicInfoCompleter},
			</if>
			<if test="recordUpdateTimestamp != null and recordUpdateTimestamp != ''">
				recordUpdateTimestamp = #{recordUpdateTimestamp},
			</if>
			<if test="status != null and status != ''">
				status = #{status},
			</if>
			<if test="deleteMarker != null and deleteMarker != ''">
				deleteMarker = #{deleteMarker}
			</if>
		</trim>
		WHERE id = #{id}
	</update>

	<!--假删除患者基础信息表-->
	<update id="deletePatientBasicInfo" parameterType="pd">
		UPDATE s_dtp_ysfw_patientbasicinfor SET status = 0 ,deleteMarker =1 WHERE id = #{id}
	</update>

	<!--物理患者基础信息表-->
	<update id="delPatientBasicInfo" parameterType="pd">
		DELETE FROM s_dtp_ysfw_patientbasicinfor WHERE id = #{id}
	</update>


	<!--联系人信息查询-->
	<select id="selectContacts" parameterType="pd" resultType="pd">
		SELECT * FROM s_dtp_ysfw_contacts WHERE 1=1
		<if test="id != null and id != ''">
			AND id = #{id}
		</if>
		<if test="archiveId != null and archiveId != ''">
			AND archiveId = #{archiveId}
		</if>
		<if test="contactPhone != null and contactPhone != ''">
			AND contactPhone = #{contactPhone}
		</if>
		<if test="contactName != null and contactName != ''">
			AND contactName = #{contactName}
		</if>
		<if test="contactRelationship != null and contactRelationship != ''">
			AND contactRelationship = #{contactRelationship}
		</if>
		<if test="createdBy != null and createdBy != ''">
			AND createdBy = #{createdBy}
		</if>
		<if test="status != null and status != ''">
			AND status = #{status}
		</if>
	</select>

	<!--联系人信息添加-->
	<insert id="insertContact" parameterType="pd">
		INSERT INTO s_dtp_ysfw_contacts
		<trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="archiveId != null and archiveId != ''">archiveId,</if>
			<if test="contactPhone != null and contactPhone != ''">contactPhone,</if>
			<if test="contactName != null and contactNamecontactName != ''">contactName,</if>
			<if test="contactRelationship != null and contactRelationship != ''">contactRelationship,</if>
			<if test="createdBy != null and createdBy != ''">createdBy,</if>
			<if test="createdAt != null and createdAt != ''">createdAt,</if>
			<if test="updatedAt != null and updatedAt != ''">updatedAt,</if>
			<if test="status != null and status != ''">status</if>
		</trim>

		<trim prefix="VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="archiveId != null and archiveId != ''">#{archiveId},</if>
			<if test="contactPhone != null and contactPhone != ''">#{contactPhone},</if>
			<if test="contactName != null and contactName != ''">#{contactName},</if>
			<if test="contactRelationship != null and contactRelationship != ''">#{contactRelationship},</if>
			<if test="createdBy != null and createdBy != ''">#{createdBy},</if>
			<if test="createdAt != null and createdAt != ''">#{createdAt},</if>
			<if test="updatedAt != null and updatedAt != ''">#{updatedAt},</if>
			<if test="status != null and status != ''">#{status}</if>
		</trim>
	</insert>
	<!--联系人信息修改-->
	<update id="updateContact" parameterType="pd">
		UPDATE s_dtp_ysfw_contacts SET
		<trim prefix="" suffixOverrides="," prefixOverrides=",">
			<if test="archiveId != null and archiveId != ''">
				archiveId = #{archiveId},
			</if>
			<if test="contactPhone != null and contactPhone != ''">
				contactPhone = #{contactPhone},
			</if>
			<if test="contactName != null and contactName != ''">
				contactName = #{contactName},
			</if>
			<if test="contactRelationship != null and contactRelationship != ''">
				contactRelationship = #{contactRelationship},
			</if>
			<if test="createdBy != null and createdBy != ''">
				createdBy = #{createdBy},
			</if>
			<if test="status != null and status != ''">
				status = #{status}
			</if>
		</trim>
		WHERE id = #{id}
	</update>

	<select id="findhistoryByarchiveId" parameterType="pd" resultType="pd">
		SELECT * FROM s_dtp_ysfw_family_history WHERE 1=1 and archiveId = #{archiveId}
	</select>
	<select id="findrecordsByarchiveId" parameterType="pd" resultType="pd">
		SELECT * FROM s_dtp_ysfw_medication_records WHERE 1=1 and archiveId = #{archiveId}
	</select>
	<select id="findcontactsByarchiveId" parameterType="pd" resultType="pd">
		SELECT * FROM s_dtp_ysfw_contacts WHERE 1=1 and archiveId = #{archiveId}
	</select>

	<!--家族病史表信息查询-->
	<select id="selectFamilyHistories" parameterType="pd" resultType="pd">
		SELECT * FROM s_dtp_ysfw_family_history WHERE 1=1
		<if test="id != null and id != ''">
			AND id = #{id}
		</if>
		<if test="archiveId != null and archiveId != ''">
			AND archiveId = #{archiveId}
		</if>
		<if test="disease != null and disease != ''">
			AND disease = #{disease}
		</if>
		<if test="member != null and member != ''">
			AND member = #{member}
		</if>
		<if test="createdBy != null and createdBy != ''">
			AND createdBy = #{createdBy}
		</if>
		<if test="status != null and status != ''">
			AND status = #{status}
		</if>
	</select>

	<!--家族病史表信息添加-->
	<insert id="insertFamilyHistory" parameterType="pd">
		INSERT INTO s_dtp_ysfw_family_history
		<trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="archiveId != null and archiveId != ''">archiveId,</if>
			<if test="disease != null and disease != ''">disease,</if>
			<if test="member != null and member != ''">member,</if>
			<if test="createdBy != null and createdBy != ''">createdBy,</if>
			<if test="createdAt != null and createdAt != ''">createdAt,</if>
			<if test="updatedAt != null and updatedAt != ''">updatedAt,</if>
			<if test="status != null and status != ''">status</if>
		</trim>

		<trim prefix="VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="archiveId != null and archiveId != ''">#{archiveId},</if>
			<if test="disease != null and disease != ''">#{disease},</if>
			<if test="member != null and member != ''">#{member},</if>
			<if test="createdBy != null and createdBy != ''">#{createdBy},</if>
			<if test="createdAt != null and createdAt != ''">#{createdAt},</if>
			<if test="updatedAt != null and updatedAt != ''">#{updatedAt},</if>
			<if test="status != null and status != ''">#{status}</if>
		</trim>
	</insert>
	<!--家族病史表信息修改-->
	<update id="updateFamilyHistory" parameterType="pd">
		UPDATE s_dtp_ysfw_family_history SET
		<trim prefix="" suffixOverrides="," prefixOverrides=",">
			<if test="archiveId != null and archiveId != ''">
				archiveId = #{archiveId},
			</if>
			<if test="disease != null and disease != ''">
				disease = #{disease},
			</if>
			<if test="member != null and member != ''">
				member = #{member},
			</if>
			<if test="createdBy != null and createdBy != ''">
				createdBy = #{createdBy},
			</if>
			<if test="status != null and status != ''">
				status = #{status}
			</if>
		</trim>
		WHERE id = #{id}
	</update>
	 <!--用药情况表表信息查询-->
	<select id="selectMedicationRecords" parameterType="pd" resultType="pd">
		SELECT * FROM s_dtp_ysfw_medication_records WHERE 1=1
		<if test="id != null and id != ''">
			AND id = #{id}
		</if>
		<if test="archiveId != null and archiveId != ''">
			AND archiveId = #{archiveId}
		</if>
		<if test="medicationDescription != null and medicationDescription != ''">
			AND medicationDescription = #{medicationDescription}
		</if>
		<if test="medicationType != null and medicationType != ''">
			AND medicationType = #{medicationType}
		</if>
		<if test="createdBy != null and createdBy != ''">
			AND createdBy = #{createdBy}
		</if>
		<if test="status != null and status != ''">
			AND status = #{status}
		</if>
	</select>
	<!--用药情况表表信息添加-->
	<insert id="insertMedicationRecord" parameterType="pd">
		INSERT INTO s_dtp_ysfw_medication_records
		<trim prefix="(" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="archiveId != null and archiveId != ''">archiveId,</if>
			<if test="medicationDescription != null and medicationDescription != ''">medicationDescription,</if>
			<if test="medicationType != null and medicationType != ''">medicationType,</if>
			<if test="createdBy != null and createdBy != ''">createdBy,</if>
			<if test="createdAt != null and createdAt != ''">createdAt,</if>
			<if test="updatedAt != null and updatedAt != ''">updatedAt,</if>
			<if test="status != null and status != ''">status</if>
		</trim>

		<trim prefix="VALUES (" suffix=")" prefixOverrides="," suffixOverrides=",">
			<if test="archiveId != null and archiveId != ''">#{archiveId},</if>
			<if test="medicationDescription != null and medicationDescription != ''">#{medicationDescription},</if>
			<if test="medicationType != null and medicationType != ''">#{medicationType},</if>
			<if test="createdBy != null and createdBy != ''">#{createdBy},</if>
			<if test="createdAt != null and createdAt != ''">#{createdAt},</if>
			<if test="updatedAt != null and updatedAt != ''">#{updatedAt},</if>
			<if test="status != null and status != ''">#{status}</if>
		</trim>
	</insert>

	<!--用药情况表表信息修改-->
	<update id="updateMedicationRecord" parameterType="pd">
		UPDATE s_dtp_ysfw_medication_records SET
		<trim prefix="" suffixOverrides="," prefixOverrides=",">
			<if test="archiveId != null and archiveId != ''">
				archiveId = #{archiveId},
			</if>
			<if test="medicationDescription != null and medicationDescription != ''">
				medicationDescription = #{medicationDescription},
			</if>
			<if test="medicationType != null and medicationType != ''">
				medicationType = #{medicationType},
			</if>
			<if test="created_by != null and created_by != ''">
				createdBy = #{createdBy},
			</if>
			<if test="status != null and status != ''">
				status = #{status}
			</if>
		</trim>
		WHERE id = #{id}
	</update>


	<!--物理删除家 联系人表，族病史表，用药情况表-->
	<update id="physicalDeleteContact" parameterType="pd">
		DELETE FROM s_dtp_ysfw_contacts WHERE id = #{id}
	</update>

	<update id="physicalDeleteFamilyHistory" parameterType="pd">
		DELETE FROM s_dtp_ysfw_family_history WHERE id = #{id}
	</update>

	<update id="physicalDeleteMedicationRecord" parameterType="pd">
		DELETE FROM s_dtp_ysfw_medication_records WHERE id = #{id}
	</update>


	<!--物理删除家 联系人表，族病史表，用药情况表根据档案 archiveId 删除-->
	<update id="DeleteContact" parameterType="pd">
		DELETE FROM s_dtp_ysfw_contacts WHERE archiveId = #{archiveId}
	</update>

	<update id="DeleteFamilyHistory" parameterType="pd">
		DELETE FROM s_dtp_ysfw_family_history WHERE archiveId = #{archiveId}
	</update>

	<update id="DeleteMedicationRecord" parameterType="pd">
		DELETE FROM s_dtp_ysfw_medication_records WHERE archiveId = #{archiveId}
	</update>

	<!--查询对应患者的用药购药信息-->
	<select id="getDrugPurchaseList" parameterType="pd" resultType="pd">
		select
			sddpr.prescriptionNumber , -- 销售
			sdpr.salesOrderNumber, -- 处方编号
			sddpr.prescriptionDate, -- 处方日期
			sdpr.hospital, -- 医院
			sdpr.prescribingDoctor, -- 处方医生
			sdpr.department, -- 科室
			sdpr.attendingDoctor, -- 主管医生
			sdpr.clinicalDiagnosis, --  临床诊断
			sddpr.genericName,-- 	药品通用名
			sddpr.productName,-- 	商品名
			sddpr.medicationRoute,-- 	用药途径
			sddpr.dosageFrequency,-- 	用药频次
			sddpr.singleDoseUnit,-- 	单次剂量
			sdpr.registrant,-- 	登记人
			sdpr.registrationDate,-- 登记日期
			sdpr.saleDate,-- 销售日期
			sddpr.pharmacyName  -- 购药门店名称
		from s_dtp_drug_purchase_record  sddpr
		left join s_dtp_prescription_registration sdpr on sddpr.prescriptionNumber=sdpr.prescriptionNumber
		where sdpr.patientId=#{id}

	</select>

</mapper>
