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

    <!-- 查询 先登记后销售的处方信息-->
    <select id="selectPrescriptionRegistration" parameterType="pd" resultType="pd">
        SELECT
        sddpr.mdmCode,
        sddpr.administrationMethod,
        sddpr.productName,
        sddpr.genericName,
        sddpr.specification,
        sddpr.pharmacyName,
        sddpr.prescriptionNumber as prescriptionNumbery,
        sddpr.drugsLinkId as drugsLinkIdy,
        sddpr.salesOrderNumber as salesOrderNumbery,
        sddpr.dvalueDays,
        sdphl.standardName,
        sdpr.*
        FROM
        s_dtp_prescription_registration sdpr
        LEFT JOIN s_dtp_drug_purchase_record sddpr ON sddpr.drugsLinkId = sdpr.drugsLinkId
        LEFT JOIN s_dtp_pzxx_hospital_list sdphl on sdphl.id = sdpr.hospital
        WHERE 1=1
        <if test="mdmCode != null and mdmCode != ''">
            and sddpr.mdmCode = #{mdmCode}
        </if>
        <if test="administrationMethod != null and administrationMethod != ''">
            and sddpr.administrationMethod = #{administrationMethod}
        </if>
        <if test="productName != null and productName != ''">
            and sddpr.productName = #{productName}
        </if>
        <if test="genericName != null and genericName != ''">
            and sddpr.genericName = #{genericName}
        </if>
        <if test="specification != null and specification != ''">
            and sddpr.specification = #{specification}
        </if>
        <if test="prescriptionNumber != null and prescriptionNumber != ''">
            and sddpr.prescriptionNumber = #{prescriptionNumber}
        </if>
        <if test="dvalueDays != null">
            and sddpr.dvalueDays = #{dvalueDays}
        </if>
        <if test="hospital != null and hospital != ''">
            and sdpr.hospital = #{hospital}
        </if>
        <if test="prescribingDoctor != null and prescribingDoctor != ''">
            and sdpr.prescribingDoctor = #{prescribingDoctor}
        </if>
        <if test="department != null and department != ''">
            and sdpr.department = #{department}
        </if>
        <if test="prescriptionDiagnosis != null and prescriptionDiagnosis != ''">
            and sdpr.prescriptionDiagnosis = #{prescriptionDiagnosis}
        </if>
        <if test="attendingDoctor != null and attendingDoctor != ''">
            and sdpr.attendingDoctor = #{attendingDoctor}
        </if>
        <if test="clinicalDiagnosis != null and clinicalDiagnosis != ''">
            and sdpr.clinicalDiagnosis = #{clinicalDiagnosis}
        </if>
        <if test="prescriptionImageUrl != null and prescriptionImageUrl != ''">
            and sdpr.prescriptionImageUrl = #{prescriptionImageUrl}
        </if>
        <if test="prescriptionIssueDate != null">
            and sdpr.prescriptionIssueDate = #{prescriptionIssueDate}
        </if>
        <if test="saleDate != null">
            and sdpr.saleDate = #{saleDate}
        </if>
        <if test="registrationDate != null">
            and sdpr.registrationDate = #{registrationDate}
        </if>
        <if test="drugVarietyCount != null">
            and sdpr.drugVarietyCount = #{drugVarietyCount}
        </if>
        <if test="drugQuantity != null">
            and sdpr.drugQuantity = #{drugQuantity}
        </if>
        <if test="invoiceCode != null and invoiceCode != ''">
            and sdpr.invoiceCode = #{invoiceCode}
        </if>
        <if test="invoiceImageUrl != null and invoiceImageUrl != ''">
            and sdpr.invoiceImageUrl = #{invoiceImageUrl}
        </if>
        <if test="registerPharmacistName != null and registerPharmacistName != ''">
            and sdpr.registerPharmacistName = #{registerPharmacistName}
        </if>
        <if test="registrant != null and registrant != ''">
            and sdpr.registrant = #{registrant}
        </if>
        <if test="reviewingName != null and reviewingName != ''">
            and sdpr.reviewingName = #{reviewingName}
        </if>
        <if test="prescriptionNumber != null and prescriptionNumber != ''">
            and sdpr.prescriptionNumber = #{prescriptionNumber}
        </if>
        <if test="salesOrderNumber != null and salesOrderNumber != ''">
            and sdpr.salesOrderNumber = #{salesOrderNumber}
        </if>
        <if test="patientId != null">
            and sdpr.patientId = #{patientId}
        </if>
        <if test="patientName != null and patientName != ''">
            and sdpr.patientName = #{patientName}
        </if>
        <if test="patientPhone != null and patientPhone != ''">
            and sdpr.patientPhone = #{patientPhone}
        </if>
        <if test="gender != null">
            and sdpr.gender = #{gender}
        </if>
        <if test="age != null">
            and sdpr.age = #{age}
        </if>
        <if test="drugsLinkId != null">
            and sdpr.drugsLinkId = #{drugsLinkId}
        </if>
        <if test="status != null and status != ''">
            and sdpr.status = #{status}
        </if>
        <if test="reviewStatus != null">
            and sdpr.reviewStatus = #{reviewStatus}
        </if>
        <if test="prescriptionType != null and prescriptionType != ''">
            and sdpr.prescriptionType = #{prescriptionType}
        </if>
        <if test="source != null and source != ''">
            and sdpr.source = #{source}
        </if>
        <if test="drugRoute != null and drugRoute != ''">
            and sdpr.drugRoute = #{drugRoute}
        </if>
        <if test="storeId != null and storeId != ''">
            and sdpr.storeId = #{storeId}
        </if>
        <if test="storeName != null and storeName != ''">
            and sdpr.storeName = #{storeName}
        </if>
        <if test="createdBy != null and createdBy != ''">
            and sdpr.createdBy = #{createdBy}
        </if>
        <if test="createdTime != null">
            and sdpr.createdTime = #{createdTime}
        </if>
        <if test="updatedBy != null and updatedBy != ''">
            and sdpr.updatedBy = #{updatedBy}
        </if>
        <if test="updatedTime != null">
            and sdpr.updatedTime = #{updatedTime}
        </if>
        <if test="remarks != null and remarks != ''">
            and sdpr.remarks = #{remarks}
        </if>
        <if test="id != null and id != ''">
            and sdpr.id = #{id}
        </if>
        <if test="createTime != null and createTime != ''">
            and sdpr.createTime = #{createTime}
        </if>
        <if test="query != null and query != ''">
            AND (sdpr.patientName LIKE CONCAT('%', #{query}, '%') or sdpr.patientPhone = #{query})
        </if>
        <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
            and sdpr.registrationDate between #{beginTime} and #{endTime}
        </if>
        <if test="sbeginTime != null and sbeginTime != '' and sendTime != null and sendTime != ''">
            and sdpr.saleDate between #{sbeginTime} and #{sendTime}
        </if>
        <if test="sales_is != null and sales_is != ''">
            and sdpr.status   &lt;&gt;  #{sales_is}
        </if>
        <if test="sales_yes != null and sales_yes != ''">
            and sdpr.status =#{sales_yes}
        </if>
    </select>

    <!-- 根据patientId查询单条记录 -->
    <select id="selectOneByPatientId" parameterType="pd" resultType="pd">
        SELECT *
        FROM s_dtp_prescription_registration t1
        WHERE patientId = #{patientId}
          AND registrationDate = (
            SELECT MAX(registrationDate)
            FROM s_dtp_prescription_registration
            WHERE patientId = #{patientId}
        )
    </select>
    <!-- 根据prescriptionNumber查询多条条记录 -->
    <select id="selectListRecordByPrescriptionNumber" parameterType="pd" resultType="pd">
        SELECT
            sddpr.*,
            dtp.dosage_max,
            dtp.dosage_min,
            dtp.unit_max,
            dtp.unit_min,
            dtp.unit_normal,
            dtp.dosage_normal,
            dtp.packing_value,
            dtp.packing_unit
        FROM
            s_dtp_drug_purchase_record sddpr
            left join s_gxhpz_product_dtpinfo dtp on dtp.product_code = sddpr.mdmCode
            where sddpr.drugsLinkId=#{drugsLinkId}
    </select>
    <!-- 根据ID查询单条记录 -->
    <select id="selectOneById" parameterType="pd" resultType="pd">
        select * from s_dtp_prescription_registration where id=#{id}
    </select>
    <!-- 插入新记录 -->
    <insert id="insertPrescriptionRegistration" parameterType="pd">
        insert into s_dtp_prescription_registration
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hospital != null and hospital != ''">
                hospital,
            </if>
            <if test="prescribingDoctor != null and prescribingDoctor != ''">
                prescribingDoctor,
            </if>
            <if test="department != null and department != ''">
                department,
            </if>
            <if test="prescriptionDiagnosis != null and prescriptionDiagnosis != ''">
                prescriptionDiagnosis,
            </if>
            <if test="attendingDoctor != null and attendingDoctor != ''">
                attendingDoctor,
            </if>
            <if test="clinicalDiagnosis != null and clinicalDiagnosis != ''">
                clinicalDiagnosis,
            </if>
            <if test="dl != null and dl != ''">dl,</if>
            <if test="xl != null and xl != ''">xl,</if>
            <if test="prescriptionImageUrl != null and prescriptionImageUrl != ''">
                prescriptionImageUrl,
            </if>
            <if test="prescriptionIssueDate != null">
                prescriptionIssueDate,
            </if>
            <if test="saleDate != null">
                saleDate,
            </if>
            <if test="registrationDate != null">
                registrationDate,
            </if>
            <if test="drugVarietyCount != null">
                drugVarietyCount,
            </if>
            <if test="drugQuantity != null">
                drugQuantity,
            </if>
            <if test="invoiceCode != null and invoiceCode != ''">
                invoiceCode,
            </if>
            <if test="invoiceImageUrl != null and invoiceImageUrl != ''">
                invoiceImageUrl,
            </if>
            <if test="registerPharmacistName != null and registerPharmacistName != ''">
                registerPharmacistName,
            </if>
            <if test="registrant != null and registrant != ''">
                registrant,
            </if>
            <if test="reviewingName != null and reviewingName != ''">
                reviewingName,
            </if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">
                prescriptionNumber,
            </if>
            <if test="salesOrderNumber != null and salesOrderNumber != ''">
                salesOrderNumber,
            </if>
            <if test="patientId != null">
                patientId,
            </if>
            <if test="patientName != null and patientName != ''">
                patientName,
            </if>
            <if test="patientPhone != null and patientPhone != ''">
                patientPhone,
            </if>
            <if test="gender != null  and gender != ''">
                gender,
            </if>
            <if test="age != null  and age != ''">
                age,
            </if>
            <if test="drugsLinkId != null  and drugsLinkId != ''" >
                drugsLinkId,
            </if>
            <if test="status != null  and status != ''">
                status,
            </if>
            <if test="reviewStatus != null  and reviewStatus != ''">
                reviewStatus,
            </if>
            <if test="prescriptionType != null  and prescriptionType != ''">
                prescriptionType,
            </if>
            <if test="source != null and source != ''">
                source,
            </if>
            <if test="drugRoute != null and drugRoute != ''">
                drugRoute,
            </if>
            <if test="storeId != null and storeId != ''">
                storeId,
            </if>
            <if test="storeName != null and storeName != ''">
                storeName,
            </if>
            <if test="createdBy != null and createdBy != ''">
                createdBy,
            </if>
            <if test="createdTime != null">
                createdTime,
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updatedBy,
            </if>
            <if test="updatedTime != null">
                updatedTime,
            </if>
            <if test="remarks != null and remarks != ''">
                remarks
            </if>
        </trim>
        VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hospital != null and hospital != ''">
                #{hospital},
            </if>
            <if test="prescribingDoctor != null and prescribingDoctor != ''">
                #{prescribingDoctor},
            </if>
            <if test="department != null and department != ''">
                #{department},
            </if>
            <if test="prescriptionDiagnosis != null and prescriptionDiagnosis != ''">
                #{prescriptionDiagnosis},
            </if>
            <if test="attendingDoctor != null and attendingDoctor != ''">
                #{attendingDoctor},
            </if>
            <if test="clinicalDiagnosis != null and clinicalDiagnosis != ''">
                #{clinicalDiagnosis},
            </if>
            <if test="dl != null and dl != ''">#{dl},</if>
            <if test="xl != null and xl != ''">#{xl},</if>
            <if test="prescriptionImageUrl != null and prescriptionImageUrl != ''">
                #{prescriptionImageUrl},
            </if>
            <if test="prescriptionIssueDate != null">
                #{prescriptionIssueDate},
            </if>
            <if test="saleDate != null">
                #{saleDate},
            </if>
            <if test="registrationDate != null">
                #{registrationDate},
            </if>
            <if test="drugVarietyCount != null">
                #{drugVarietyCount},
            </if>
            <if test="drugQuantity != null">
                #{drugQuantity},
            </if>
            <if test="invoiceCode != null and invoiceCode != ''">
                #{invoiceCode},
            </if>
            <if test="invoiceImageUrl != null and invoiceImageUrl != ''">
                #{invoiceImageUrl},
            </if>
            <if test="registerPharmacistName != null and registerPharmacistName != ''">
                #{registerPharmacistName},
            </if>
            <if test="registrant != null and registrant != ''">
                #{registrant},
            </if>
            <if test="reviewingName != null and reviewingName != ''">
                #{reviewingName},
            </if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">
                #{prescriptionNumber},
            </if>
            <if test="salesOrderNumber != null and salesOrderNumber != ''">
                #{salesOrderNumber},
            </if>
            <if test="patientId != null">
                #{patientId},
            </if>
            <if test="patientName != null and patientName != ''">
                #{patientName},
            </if>
            <if test="patientPhone != null and patientPhone != ''">
                #{patientPhone},
            </if>
            <if test="gender != null  and gender != ''">
                #{gender},
            </if>
            <if test="age != null  and age != ''">
                #{age},
            </if>
            <if test="drugsLinkId != null  and drugsLinkId != ''" >
                #{drugsLinkId},
            </if>
            <if test="status != null  and status != ''">
                #{status},
            </if>
            <if test="reviewStatus != null  and reviewStatus != ''">
                #{reviewStatus},
            </if>
            <if test="prescriptionType != null  and prescriptionType != ''">
                #{prescriptionType},
            </if>
            <if test="source != null and source != ''">
                #{source},
            </if>
            <if test="drugRoute != null and drugRoute != ''">
                #{drugRoute},
            </if>
            <if test="storeId != null and storeId != ''">
                #{storeId},
            </if>
            <if test="storeName != null and storeName != ''">
                #{storeName},
            </if>
            <if test="createdBy != null and createdBy != ''">
                #{createdBy},
            </if>
            <if test="createdTime != null">
                #{createdTime},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                #{updatedBy},
            </if>
            <if test="updatedTime != null">
                #{updatedTime},
            </if>
            <if test="remarks != null and remarks != ''">
                #{remarks}
            </if>
        </trim>
    </insert>

    <!-- 更新记录 -->
    <update id="updatePrescriptionRegistration" parameterType="pd">
        update s_dtp_prescription_registration
        <trim prefix="SET " suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="hospital != null and hospital != ''">
                hospital = #{hospital},
            </if>
            <if test="prescribingDoctor != null and prescribingDoctor != ''">
                prescribingDoctor = #{prescribingDoctor},
            </if>
            <if test="department != null and department != ''">
                department = #{department},
            </if>
            <if test="prescriptionDiagnosis != null and prescriptionDiagnosis != ''">
                prescriptionDiagnosis = #{prescriptionDiagnosis},
            </if>
            <if test="attendingDoctor != null and attendingDoctor != ''">
                attendingDoctor = #{attendingDoctor},
            </if>
            <if test="clinicalDiagnosis != null and clinicalDiagnosis != ''">
                clinicalDiagnosis = #{clinicalDiagnosis},
            </if>
            <if test="dl != null and dl != ''">dl=#{dl},</if>
            <if test="xl != null and xl != ''">xl=#{xl},</if>
            <if test="prescriptionImageUrl != null and prescriptionImageUrl != ''">
                prescriptionImageUrl = #{prescriptionImageUrl},
            </if>
            <if test="prescriptionIssueDate != null">
                prescriptionIssueDate = #{prescriptionIssueDate},
            </if>
            <if test="saleDate != null">
                saleDate = #{saleDate},
            </if>
            <if test="registrationDate != null">
                registrationDate = #{registrationDate},
            </if>
            <if test="drugVarietyCount != null">
                drugVarietyCount = #{drugVarietyCount},
            </if>
            <if test="drugQuantity != null">
                drugQuantity = #{drugQuantity},
            </if>
            <if test="invoiceCode != null and invoiceCode != ''">
                invoiceCode = #{invoiceCode},
            </if>
            <if test="invoiceImageUrl != null and invoiceImageUrl != ''">
                invoiceImageUrl = #{invoiceImageUrl},
            </if>
            <if test="registerPharmacistName != null and registerPharmacistName != ''">
                registerPharmacistName = #{registerPharmacistName},
            </if>
            <if test="registrant != null and registrant != ''">
                registrant = #{registrant},
            </if>
            <if test="reviewingName != null and reviewingName != ''">
                reviewingName = #{reviewingName},
            </if>
            <if test="prescriptionNumber != null and prescriptionNumber != ''">
                prescriptionNumber = #{prescriptionNumber},
            </if>
            <if test="salesOrderNumber != null and salesOrderNumber != ''">
                salesOrderNumber = #{salesOrderNumber},
            </if>
            <if test="patientId != null">
                patientId = #{patientId},
            </if>
            <if test="patientName != null and patientName != ''">
                patientName = #{patientName},
            </if>
            <if test="patientPhone != null and patientPhone != ''">
                patientPhone = #{patientPhone},
            </if>
            <if test="gender != null">
                gender = #{gender},
            </if>
            <if test="age != null">
                age = #{age},
            </if>
            <if test="drugsLinkId != null">
                drugsLinkId = #{drugsLinkId},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="reviewStatus != null">
                reviewStatus = #{reviewStatus},
            </if>
            <if test="prescriptionType != null">
                prescriptionType = #{prescriptionType},
            </if>
            <if test="source != null and source != ''">
                source = #{source},
            </if>
            <if test="drugRoute != null and drugRoute != ''">
                drugRoute = #{drugRoute},
            </if>
            <if test="storeId != null and storeId != ''">
                storeId = #{storeId},
            </if>
            <if test="storeName != null and storeName != ''">
                storeName = #{storeName},
            </if>
            <if test="createdBy != null and createdBy != ''">
                createdBy = #{createdBy},
            </if>
            <if test="createdTime != null">
                createdTime = #{createdTime},
            </if>
            <if test="updatedBy != null and updatedBy != ''">
                updatedBy = #{updatedBy},
            </if>
            <if test="updatedTime != null">
                updatedTime = #{updatedTime},
            </if>
            <if test="remarks != null and remarks != ''">
                remarks = #{remarks}
            </if>
        </trim>
        <if test="id != null">
            where id = #{id}
        </if>
    </update>


    <insert id="batchAddDrugPurchaseRecord" parameterType="java.util.List">
        <foreach collection="dataList" item="item" index="index">
            INSERT INTO s_dtp_drug_purchase_record (
            <trim prefix="" suffix="" prefixOverrides="," suffixOverrides=",">
                <if test="item.mdmCode != null and item.mdmCode != ''">mdmCode,</if>
                <if test="item.productName != null and item.productName != ''">productName,</if>
                <if test="item.genericName != null and item.genericName != ''">genericName,</if>
                <if test="item.specification != null and item.specification != ''">specification,</if>
                <if test="item.manufacturerShortName != null and item.manufacturerShortName != ''">manufacturerShortName,</if>
                <if test="item.administrationMethod != null and item.administrationMethod != ''">administrationMethod,</if>
                <if test="item.packageQuantity != null">packageQuantity,</if>
                <if test="item.singleDoseValue != null">singleDoseValue,</if>
                <if test="item.singleDoseUnit != null and item.singleDoseUnit != ''">singleDoseUnit,</if>
                <if test="item.dosageFrequency != null and item.dosageFrequency != ''">dosageFrequency,</if>
                <if test="item.dosageFrequencyDays != null">dosageFrequencyDays,</if>
                <if test="item.dvalueDays != null and  item.dvalueDays != ''">dvalueDays,</if>
                <if test="item.medicationRoute != null and item.medicationRoute != ''">medicationRoute,</if>
                <if test="item.sales != null and item.sales != ''">sales,</if>
                <if test="item.prescriptionNumber != null and item.prescriptionNumber != ''">prescriptionNumber,</if>
                <if test="item.prescriptionDate != null">prescriptionDate,</if>
                <if test="item.hospital != null and item.hospital != ''">hospital,</if>
                <if test="item.prescribingDoctor != null and item.prescribingDoctor != ''">prescribingDoctor,</if>
                <if test="item.department != null and item.department != ''">department,</if>
                <if test="item.attendingPhysician != null and item.attendingPhysician != ''">attendingPhysician,</if>
                <if test="item.clinicalDiagnosis != null and item.clinicalDiagnosis != ''">clinicalDiagnosis,</if>
                <if test="item.registrant != null and item.registrant != ''">registrant,</if>
                <if test="item.registrationDate != null">registrationDate,</if>
                <if test="item.saleDate != null">saleDate,</if>
                <if test="item.pharmacyName != null and item.pharmacyName != ''">pharmacyName,</if>
                <if test="item.storeId != null">storeId,</if>
                <if test="item.createdBy != null and item.createdBy != ''">createdBy,</if>
                <if test="item.createdTime != null">createdTime,</if>
                <if test="item.updatedBy != null and item.updatedBy != ''">updatedBy,</if>
                <if test="item.updatedTime != null">updatedTime,</if>
                <if test="item.remarks != null and item.remarks != ''">remarks</if>
            </trim>
            )
            VALUES (
            <trim prefix="" suffix="" prefixOverrides="," suffixOverrides=",">
                <if test="item.mdmCode != null and item.mdmCode != ''">#{item.mdmCode},</if>
                <if test="item.productName != null and item.productName != ''">#{item.productName},</if>
                <if test="item.genericName != null and item.genericName != ''">#{item.genericName},</if>
                <if test="item.specification != null and item.specification != ''">#{item.specification},</if>
                <if test="item.manufacturerShortName != null and item.manufacturerShortName != ''">#{item.manufacturerShortName},</if>
                <if test="item.administrationMethod != null and item.administrationMethod != ''">#{item.administrationMethod},</if>
                <if test="item.packageQuantity != null">#{item.packageQuantity},</if>
                <if test="item.singleDoseValue != null">#{item.singleDoseValue},</if>
                <if test="item.singleDoseUnit != null and item.singleDoseUnit != ''">#{item.singleDoseUnit},</if>
                <if test="item.dosageFrequency != null and item.dosageFrequency != ''">#{item.dosageFrequency},</if>
                <if test="item.dosageFrequencyDays != null">#{item.dosageFrequencyDays},</if>
                <if test="item.dvalueDays != null and  item.dvalueDays != ''">#{item.dvalueDays},</if>
                <if test="item.medicationRoute != null and item.medicationRoute != ''">#{item.medicationRoute},</if>
                <if test="item.sales != null and item.sales != ''">#{item.sales},</if>
                <if test="item.prescriptionNumber != null and item.prescriptionNumber != ''">#{item.prescriptionNumber},</if>
                <if test="item.prescriptionDate != null">#{item.prescriptionDate},</if>
                <if test="item.hospital != null and item.hospital != ''">#{item.hospital},</if>
                <if test="item.prescribingDoctor != null and item.prescribingDoctor != ''">#{item.prescribingDoctor},</if>
                <if test="item.department != null and item.department != ''">#{item.department},</if>
                <if test="item.attendingPhysician != null and item.attendingPhysician != ''">#{item.attendingPhysician},</if>
                <if test="item.clinicalDiagnosis != null and item.clinicalDiagnosis != ''">#{item.clinicalDiagnosis},</if>
                <if test="item.registrant != null and item.registrant != ''">#{item.registrant},</if>
                <if test="item.registrationDate != null">#{item.registrationDate},</if>
                <if test="item.saleDate != null">#{item.saleDate},</if>
                <if test="item.pharmacyName != null and item.pharmacyName != ''">#{item.pharmacyName},</if>
                <if test="item.storeId != null">#{item.storeId},</if>
                <if test="item.createdBy != null and item.createdBy != ''">#{item.createdBy},</if>
                <if test="item.createdTime != null">#{item.createdTime},</if>
                <if test="item.updatedBy != null and item.updatedBy != ''">#{item.updatedBy},</if>
                <if test="item.updatedTime != null">#{item.updatedTime},</if>
                <if test="item.remarks != null and item.remarks != ''">#{item.remarks}</if>
            </trim>
            )
        </foreach>
    </insert>


    <!-- 删除记录 -->
    <delete id="deletePrescriptionRegistrationByIds" parameterType="java.util.List">
        <if test="list != null and list.size() > 0">
            delete from s_dtp_prescription_registration
            where id in
            <foreach item="id" index="index" collection="list" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </delete>

    <insert id="batchDeleteDrugPurchaseRecord" parameterType="pd">
        delete from s_dtp_drug_purchase_record where drugsLinkId = #{drugsLinkId}
    </insert>
    <!-- 更新记录 -->
    <update id="Review" parameterType="pd">
        update s_dtp_prescription_registration
        <trim prefix="SET " suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="reviewingName != null and reviewingName != ''">
                reviewingName = #{reviewingName},
            </if>
            <if test="reviewStatus != null and remarks != ''">
                reviewStatus = #{reviewStatus},
            </if>
            <if test="remarks != null and remarks != ''">
                remarks = #{remarks}
            </if>
        </trim>
        <if test="prescriptionNumber != null and prescriptionNumber != ''">
            where prescriptionNumber = #{prescriptionNumber}
        </if>
    </update>

    <insert id="batchAddDrugPurchaseRecordNew" parameterType="pd">
        INSERT INTO s_dtp_drug_purchase_record (
        <trim prefix="" suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="mdmCode != null or mdmCode != ''">mdmCode,</if>
            <if test="productName != null or productName != ''">productName,</if>
            <if test="genericName != null or genericName != ''">genericName,</if>
            <if test="specification != null or specification != ''">specification,</if>
            <if test="manufacturerShortName != null or manufacturerShortName != ''">manufacturerShortName,</if>
            <if test="administrationMethod != null or administrationMethod != ''">administrationMethod,</if>
            <if test="packageQuantity != null">packageQuantity,</if>
            <if test="singleDoseValue != null">singleDoseValue,</if>
            <if test="singleDoseUnit != null or singleDoseUnit != ''">singleDoseUnit,</if>
            <if test="dosageFrequency != null or dosageFrequency != ''">dosageFrequency,</if>
            <if test="dosageFrequencyDays != null or dosageFrequencyDays != ''">dosageFrequencyDays,</if>
            <if test="dvalueDays != null or  dvalueDays != ''">dvalueDays,</if>
            <if test="medicationRoute != null or medicationRoute != ''">medicationRoute,</if>
            <if test="sales != null or sales != ''">sales,</if>
            <if test="prescriptionNumber != null or prescriptionNumber != ''">prescriptionNumber,</if>
            <if test="prescriptionDate != null">prescriptionDate,</if>
            <if test="hospital != null or hospital != ''">hospital,</if>
            <if test="prescribingDoctor != null or prescribingDoctor != ''">prescribingDoctor,</if>
            <if test="department != null or department != ''">department,</if>
            <if test="attendingPhysician != null or attendingPhysician != ''">attendingPhysician,</if>
            <if test="clinicalDiagnosis != null or clinicalDiagnosis != ''">clinicalDiagnosis,</if>
            <if test="registrant != null or registrant != ''">registrant,</if>
            <if test="registrationDate != null">registrationDate,</if>
            <if test="saleDate != null">saleDate,</if>
            <if test="pharmacyName != null or pharmacyName != ''">pharmacyName,</if>
            <if test="storeId != null">storeId,</if>
            <if test="drugsLinkId != null">drugsLinkId,</if>
            <if test="createdBy != null or createdBy != ''">createdBy,</if>
            <if test="createdTime != null">createdTime,</if>
            <if test="updatedBy != null or updatedBy != ''">updatedBy,</if>
            <if test="updatedTime != null">updatedTime,</if>
            <if test="remarks != null or remarks != ''">remarks</if>
        </trim>
        )
        VALUES (
        <trim prefix="" suffix="" prefixOverrides="," suffixOverrides=",">
            <if test="mdmCode != null or mdmCode != ''">#{mdmCode},</if>
            <if test="productName != null or productName != ''">#{productName},</if>
            <if test="genericName != null or genericName != ''">#{genericName},</if>
            <if test="specification != null or specification != ''">#{specification},</if>
            <if test="manufacturerShortName != null or manufacturerShortName != ''">#{manufacturerShortName},</if>
            <if test="administrationMethod != null or administrationMethod != ''">#{administrationMethod},</if>
            <if test="packageQuantity != null">#{packageQuantity},</if>
            <if test="singleDoseValue != null">#{singleDoseValue},</if>
            <if test="singleDoseUnit != null or singleDoseUnit != ''">#{singleDoseUnit},</if>
            <if test="dosageFrequency != null or dosageFrequency != ''">#{dosageFrequency},</if>
            <if test="dosageFrequencyDays != null or dosageFrequencyDays != ''">#{dosageFrequencyDays},</if>
            <if test="dvalueDays != null or  dvalueDays != ''">#{dvalueDays},</if>
            <if test="medicationRoute != null or medicationRoute != ''">#{medicationRoute},</if>
            <if test="sales != null or sales != ''">#{sales},</if>
            <if test="prescriptionNumber != null or prescriptionNumber != ''">#{prescriptionNumber},</if>
            <if test="prescriptionDate != null">#{prescriptionDate},</if>
            <if test="hospital != null or hospital != ''">#{hospital},</if>
            <if test="prescribingDoctor != null or prescribingDoctor != ''">#{prescribingDoctor},</if>
            <if test="department != null or department != ''">#{department},</if>
            <if test="attendingPhysician != null or attendingPhysician != ''">#{attendingPhysician},</if>
            <if test="clinicalDiagnosis != null or clinicalDiagnosis != ''">#{clinicalDiagnosis},</if>
            <if test="registrant != null or registrant != ''">#{registrant},</if>
            <if test="registrationDate != null">#{registrationDate},</if>
            <if test="saleDate != null">#{saleDate},</if>
            <if test="pharmacyName != null or pharmacyName != ''">#{pharmacyName},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="drugsLinkId != null">#{drugsLinkId},</if>
            <if test="createdBy != null or createdBy != ''">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null or updatedBy != ''">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
            <if test="remarks != null or remarks != ''">#{remarks}</if>
        </trim>
        )
    </insert>
</mapper>
