<?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" [
	<!ENTITY patientLite SYSTEM	 	"classpath://gov/va/med/cds/persistence/hibernate/common/PatientLitePojo.hbm">
	<!ENTITY pharmacyRequest SYSTEM 		"classpath://gov/va/med/cds/persistence/hibernate/pharmacy/VWDetailPharmacyRequest40010.hbm">
	<!ENTITY pharmacyRequestMedicine SYSTEM "classpath://gov/va/med/cds/persistence/hibernate/pharmacy/VWDetailPharmacyRequestMedicine40010.hbm">
	<!ENTITY cosigner SYSTEM 				"classpath://gov/va/med/cds/persistence/hibernate/common/CosignerPractitionerParticipationPojo.hbm">
]>
<hibernate-mapping default-lazy="false" default-cascade="all">
	<class entity-name="vwPharmacyDetailRead40010" name="gov.va.med.cds.template.generated.pharmacy.OutpatientMedicationPromise" table="OUTPATIENT_MED_PRM30_V" lazy="false">
		<id name="id" type="java.lang.Long">
			<column name="OUTPATIENT_MED_PRM_ID"/>
			<generator class="sequence">
				<param name="sequence">outpatient_med_prm_seq_id</param>
			</generator>
		</id>
		<!-- From superclass.  Additional maps in the set section below -->
		<component name="recordIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
			<property name="identity" column="RECORDIDENTIFIER_IDENTITY" type="java.lang.String" />
			<property name="namespaceId" column="RECORDIDENTIFIER_NAMESPACEID" type="java.lang.String" />
			<property name="universalId" column="RECORDIDENTIFIER_UNIVERSALID" type="java.lang.String" />
			<property name="universalIdType" column="RECORDIDENTIFIER_UNIVERSTYP" type="java.lang.String" />
		</component>
		<property name="prescriptionId" column="PRESCRIPTION_ID" type="java.lang.String"/>
		
		<component name="pharmacyRequest" class="gov.va.med.cds.template.generated.pharmacy.PharmacyRequest">
				<!-- import from .../common/CosignerPractitionerParticipation.hbm -->
            	&cosigner;
     
       		 <component name="orderedMedication" class="gov.va.med.cds.template.generated.common.Medicine">
			<!-- import from .../pharmacy/PharmacyRequestMedicine.hbm -->
            	&pharmacyRequestMedicine;
        	</component>
			<!-- import from .../pharmacy/PharmacyRequest.hbm -->
            &pharmacyRequest;
        </component>
        
		<!--  From subclass -->
		<!-- import from .../common/PatientLite.hbm -->
		&patientLite;
    
		<property name="numberOfRefillsAuthorized" column="NUM_REFILLS_AUTHORIZED" type="integer"/>
		
		<list name="sig" table="OUTPPHARM_SIG_V" fetch="subselect" batch-size="100">
			<key column="OUTPATIENT_MED_PRM_ID" not-null="true" update="false"/>
			<list-index column="LINE_NBR"/>
			<element type="string" column="PRESCRIPTION_SIG_TXT" />
		</list>
				
		<list name="originalDispenseSet" where="discriminator='O'" fetch="subselect" batch-size="100">
			<key column="OUTPATIENT_MED_PRM_ID" not-null="true" update="false"/>
			<list-index column="LINE_NBR"/>
			<one-to-many entity-name="vwDetailOriginalMedicationDispense40010" />
		</list>
		<list name="refillDispense" where="discriminator='R'" fetch="subselect" batch-size="100">
			<key column="OUTPATIENT_MED_PRM_ID" not-null="true" update="false"/>
			<list-index column="LINE_NBR"/>
			<one-to-many entity-name="vwDetailRefillMedicationDispense40010" />
		</list>
		
		<component name="cancel" class="gov.va.med.cds.template.generated.pharmacy.CancelAct">
			<property name="cancelDate" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType" >
				<column name="CANCEL_DT"/>
				<column name="CANCEL_DT_NBR"/>
			</property>
			
			<list name="comments" table="CANCEL_COMMENT_V" fetch="subselect" batch-size="100">
				<key column="OUTPATIENT_MED_PRM_ID" not-null="true" update="false"/>
				<list-index column="LINE_NBR"/>
				<element type="string" column="CANCEL_COMMENTS" />
			</list>
		</component>
		<component name="recordSource" class="gov.va.med.cds.template.generated.basedatatypes.HL72FacilityIdentifier">
			<property name="namespaceId" column="RECORDSOURCE_NAMESPACEID" type="java.lang.String" node="namespaceId"/>
			<property name="universalId" column="RECORDSOURCE_UNIVERSALID" type="java.lang.String" node="universalId"/>
			<property name="universalIdType" column="RECORDSOURCE_UNIVERSTYP" type="java.lang.String" node="universalIdType"/>
		</component>
		
		<property name="recordVersion" column="RECORD_VERSION" type="integer"/>
		
		<property name="recordUpdateTime" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType" >
			<column name="RECORD_UPDATE_TM"/>
			<column name="RECORD_UPDATE_TM_NBR"/>
		</property>
		
		<property name="requestId" column="REQUEST_ID" type="java.lang.String"/>
	</class>
	<query name="VWPharmacyDetailRead40010.OutpatientMedicationPromise.patient"><![CDATA[
		from vwPharmacyDetailRead40010 opmp
		where opmp.patient.identifier.assigningFacility || '/' || opmp.patient.identifier.identity in ( :pids )
      ]]></query>
	<query name="VWPharmacyDetailRead40010.OutpatientMedicationPromise.patient.identifiers"><![CDATA[
		from vwPharmacyDetailRead40010 opmp
		where opmp.patient.identifier.assigningFacility || '/' || opmp.patient.identifier.identity in ( :pids ) and
		  opmp.recordIdentifier.identity || '/' || opmp.recordIdentifier.namespaceId || '/' ||
		  opmp.recordIdentifier.universalId || '/' || opmp.recordIdentifier.universalIdType in ( :recordIdentifiers )
      ]]></query>
    <query name="VWPharmacyDetailRead40010.OutpatientMedicationPromise.patient.date">
        <![CDATA[
			from vwPharmacyDetailRead40010 omp
            where omp.patient.identifier.identity in ( :pids )
            and ( (omp.cancel.cancelDate.numeric between :startDate and :endDate) or (omp.cancel.cancelDate.numeric is null)  )
		]]>
    </query>
</hibernate-mapping>
