<?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="outpatientMedicationPromise" table="VISTA_HDSI.PRESCRIPTION_52_EXT" lazy="false" node="outpatientMedicationPromises">

		<id name="id" type="big_decimal">
			<column name="ROWID" />
			<generator class="assigned" />
		</id>

		<component name="recordIdentifier" node="recordIdentifier">
			<property name="identity" column="ROWID" type="java.lang.String" insert="false" update="false" node="identity" />
			<property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52_.001'" 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>

		<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="code" column="MEDICATIONCODE_CODE" type="java.lang.String" node="code"/>
                    <property name="displayText" column="MEDICATIONCODE_TEXT" type="java.lang.String" node="displayText"/>
                </component>
            </component>
        </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"/>

        <property name="sig" type="java.lang.String" node="sig">
            <formula>
                    (CASE
                    WHEN ( SIG IS NOT NULL ) THEN SIG
                    ELSE SIGX 
                    END)
            </formula>
        </property>
        
        <component name="originalDispense" node="originalDispense">
            <component name="quantityDispensed" node="quantityDispensed">
                <property name="value" column="QTY" type="java.lang.String" node="value" />
            </component>
            <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" node="value" />
                </component>
                <property name="expirationDate" formula="STRING(DRUG_EXPIRATION_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" node="expirationDate//literal" />
                <component name="ndc" node="ndc">
                    <property name="code" column="NDC" type="java.lang.String" node="code" />
                </component>
            </component>
         </component>
            
        <list name="refillDispense" node="." fetch="subselect" batch-size="100">
            <key column="PRESCRIPTION" />
            <list-index column="CHILDSUB1" />
            <one-to-many entity-name="refillDispense40010" />
        </list>

        <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>

	</class>

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