<?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="VWOutpatientPharmacyDetailRead1" table="VISTA_HDSI.PRESCRIPTION_52_EXT" lazy="false" node="outpatientMedicationPromise">
		<id name="id" type="big_decimal">
			<column name="ROWID"/>
			<generator class="assigned"/>
		</id>
		
		<component name="recordIdentifier" node="recordIdentifier">
			<property name="identity" column="ROWID" type="big_decimal" insert="false" update="false" node="identity"/>
			<property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52'" type="java.lang.String" node="namespaceId"/>
			<property name="universalId" formula="VISTA_HDSI.HDSREPSQLUtil1_KSPDomainName()" type="java.lang.String" insert="false" update="false" node="universalId"/>
			<property name="universalIdType" formula="'DNS'" type="java.lang.String" insert="false" update="false" node="universalIdType"/>
		</component>
		
		<component name="patient" node="patient">
			<component name="identifier" node="identifier">
				<property name="identity" column="PATIENT" type="big_decimal" node="identity"/>
				<property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" node="assigningFacility"/>
				<property name="assigningAuthority" formula="'USVHA'" type="java.lang.String" node="assigningAuthority"/>
			</component>
		</component>
		
	
		<property name="numberOfRefillsAuthorized" column="OF_REFILLS" type="big_integer" node="numberOfRefillsAuthorized"/>
		
		<component name="sigs" node="sigs">
			<property name="sig" column="SIG" type="java.lang.String" node="sig"/>
		</component>
		
		<component name="originalDispense" node="originalDispense">
		<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="UNIT_PRICE_OF_DRUG" type="java.lang.String" insert="false" update="false" 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" insert="false" update="false" node="code"/>
				</component>
			</component>
				
			<component name="quantityDispensed" node="quantityDispensed">
				<property name="value" column="QTY" type="big_decimal" node="value"/>
			</component>
	
		</component>
		
		<component name="cancel" node="cancel">
			<property name="cancelDate" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQuery" insert="false" update="false" node="cancelDate//literal">
				<column name="CANCEL_DATE"/>
				<formula>VISTA_HDSI.HDSREPSQLUtil1_StationNumber()</formula>
			</property>
		</component>
	
		<component name="recordSource" node="recordSource">
			<property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52'" type="java.lang.String" node="namespaceId"/>
			<property name="universalId" formula="VISTA_HDSI.HDSREPSQLUtil1_KSPDomainName()" type="java.lang.String" node="universalId"/>
			<property name="universalIdType" formula="'DNS'" type="java.lang.String" node="universalIdType"/>
		</component>

		<property name="prescriptionId" column="RX_" type="java.lang.String" insert="false" update="false" node="prescriptionId"/>
		
		<component name="pharmacyRequest" node="pharmacyRequest">
				<component name="orderedMedication" node="orderedMedication">
					<component name="medicationCode" node="medicationCode">
						<property name="displayText" column="MEDICATIONCODE_TEXT" type="java.lang.String" node="displayText"/>
					</component>
				</component>
		</component>
	</class>

	<query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.outpatientMedicationPromises"><![CDATA[
        from VWOutpatientPharmacyDetailRead1 pr
        where pr.patient.identifier.identity in ( :pids )
      ]]></query>
	
	<query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.outpatientMedicationPromises.identifiers"><![CDATA[
        from VWOutpatientPharmacyDetailRead1 pr
        where pr.patient.identifier.identity in ( :pids )
        and pr.id in (:recordIdentifiers)
      ]]></query>

    <query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.outpatientMedicationPromises.date">
        <![CDATA[
			from VWOutpatientPharmacyDetailRead1 pr
            where pr.patient.identifier.identity in ( :pids )
            and ( (pr.cancel.cancelDate.timestamp between :startDate and :endDate) or (pr.cancel.cancelDate.timestamp is null)  )
		]]>
    </query>	
    
	<query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.patient"><![CDATA[
        from VWOutpatientPharmacyDetailRead1 pr
        where pr.patient.identifier.identity in ( :pids )
      ]]></query>
	
	<query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.patient.identifiers"><![CDATA[
        from VWOutpatientPharmacyDetailRead1 pr
        where pr.patient.identifier.identity in ( :pids )
        and pr.id in (:recordIdentifiers)
      ]]></query>

    <query name="VWOutpatientPharmacyDetailRead1.OutpatientMedicationPromise.patient.date">
        <![CDATA[
			from VWOutpatientPharmacyDetailRead1 pr
            where pr.patient.identifier.identity in ( :pids )
            and ( (pr.cancel.cancelDate.timestamp between :startDate and :endDate) or (pr.cancel.cancelDate.timestamp is null)  )
		]]>
    </query>	
</hibernate-mapping>
