<?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="VWOutpatientPharmacyPartialDispense" lazy="false" table="VISTA_HDSI.PRESCRIPTIOX_PARTIAL_DATE_52_2" node="partialDispenses">
	
		<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="partialDispense" node="partialDispense">
		
			<component name="division" node="division">
				<component name="divisionId" node="divisionId">
					<property name="code" column="DIVISION" type="java.lang.String" node="code"/>
					<property name="displayText" column="DIVISIONX" type="java.lang.String" node="displayText"/>
				</component>
			</component>
			
			<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>
							
				<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>
			
			<property name="currentProvider" type="gov.va.med.cds.persistence.hibernate.common.VistaReducedReadPersonNameUserType" node="currentProvider//name">
                <formula>
                    (CASE
                         WHEN (PROVIDER IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_MiscNameNE(PROVIDER)
                         ELSE NULL
                    END)
                </formula>
            </property>
		
		</component>
	</class>
	
	<!-- Association partial dispenses Queries -->
	<query name="VWOutpatientPharmacyRead1.OutpatientMedicationPromise.partialDispenses"><![CDATA[
        select prtldispense
         from VWOutpatientPharmacyPartialDispense prtldispense, VWOutpatientPharmacyRead1 as pr1
         where pr1.id = prtldispense.prescription
            and pr1.patient.identifier.identity in ( :pids )
      ]]></query>
      
	<query name="VWOutpatientPharmacyRead1.OutpatientMedicationPromise.partialDispenses.identifiers"><![CDATA[
		 select prtldispense
         from VWOutpatientPharmacyPartialDispense prtldispense, VWOutpatientPharmacyRead1 as pr1
         where pr1.id = prtldispense.prescription
            and pr1.patient.identifier.identity in ( :pids )
        	and pr1.id in (:recordIdentifiers)
       
     ]]></query>
     
	<query name="VWOutpatientPharmacyRead1.OutpatientMedicationPromise.partialDispenses.date"><![CDATA[
    select prtldispense
         from VWOutpatientPharmacyPartialDispense prtldispense, VWOutpatientPharmacyRead1 as pr1
         where pr1.id = prtldispense.prescription
            and pr1.patient.identifier.identity in ( :pids )
            and ( (pr1.expirationDate.timestamp between :startDate and :endDate) or (pr1.expirationDate.timestamp is null)  )
       ]]></query>
</hibernate-mapping>
