<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false" default-cascade="all">
	<class entity-name="VWOutpatientPharmacyDetailRefillDispense" lazy="false" table="VISTA_HDSI.PRESCRIPTION_52X_REFILL_52_1" node="refillDispenses">
	
		<composite-id name="id">
			<key-property name="PRESCRIPTION" type="big_decimal"/>
			<key-property name="CHILDSUB1" type="big_decimal"/>
		</composite-id>
		
		<property name="prescription" column="PRESCRIPTION" type="big_decimal" insert="false" update="false" node="prescription"/>
		
		<component name="refillDispense" node="refillDispense">
			<property name="daysSupply" column="DAYS_SUPPLY" type="big_decimal" node="daysSupply"/>
			
				<component name="dispensedDrug" node="dispensedDrug">
				<component name="drugUnitPrice" node="drugUnitPrice">
					<property name="value" column="CURRENT_UNIT_PRICE_OF_DRUG" type="java.lang.String" node="value"/>
				</component>
	
				<property name="expirationDate" formula="STRING(DRUG_EXPIRATION_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="expirationDate//literal"/>
				
				<component name="ndc" node="ndc">
					<property name="code" column="NDC" type="java.lang.String" node="code"/>
				</component>
			</component>
		
			<component name="quantityDispensed" node="quantityDispensed">
				<property name="value" column="QTY" type="big_decimal" node="value"/>
			</component>
		</component>
	</class>
	<!-- Association refilldispenses Queries -->
	<query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.refillDispenses"><![CDATA[
		select rfldispense
		 from VWOutpatientPharmacyDetailRefillDispense rfldispense, VWOutpatientPharmacyDetailRead1 as pr1
         where pr1.id = rfldispense.prescription
            and pr1.patient.identifier.identity in ( :pids )
      ]]></query>
  
	<query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.refillDispenses.identifiers"><![CDATA[
		select rfldispense
	    from VWOutpatientPharmacyDetailRefillDispense rfldispense, VWOutpatientPharmacyDetailRead1 as pr1
        where pr1.id = rfldispense.prescription
           and pr1.patient.identifier.identity in ( :pids )
           and pr1.id in (:recordIdentifiers)
     ]]></query>
     
    <query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.refillDispenses.patient.date">
        <![CDATA[
		select rfldispense
		 from VWOutpatientPharmacyDetailRefillDispense rfldispense, VWOutpatientPharmacyDetailRead1 as pr1
         where pr1.id = rfldispense.prescription
            and pr1.patient.identifier.identity in ( :pids )
            and ( (pr1.cancel.cancelDate.timestamp between :startDate and :endDate) or (pr1.cancel.cancelDate.timestamp is null)  )
		]]>
    </query>	
</hibernate-mapping>
