<?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" name="gov.va.med.cds.template.generated.pharmacy.OutpatientMedicationPromise" >
		<!-- <id name="id" type="gov.va.med.cds.persistence.hibernate.common.VistaRowIdUserType">
			<column name="ROWID"/>
			<generator class="assigned"/>
		</id> -->
		
		<id name="idV" type="big_decimal">
			<column name="ROWID"/>
			<generator class="assigned"/>
		</id>

		<component name="recordIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier" >
			<property name="identity" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false">
				<column name="RowId"/>
			</property>
			<property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52_.001'" type="java.lang.String" />
			<property name="universalId" formula="VISTA_HDSI.HDSREPSQLUtil1_KSPDomainName()" type="java.lang.String" insert="false" update="false" />
			<property name="universalIdType" formula="'DNS'" type="java.lang.String" insert="false" update="false" />
		</component>

		<property name="prescriptionId" column="RX_" type="java.lang.String" insert="false" update="false" />
		
		<property name="pharmacyPatientType" column="PharmacyPatientType" type="java.lang.String"  />

       <component name="specialDrugTracking" class="gov.va.med.cds.template.generated.pharmacy.SpecialDrugTracking">
			<component name="totalDailyDosage" class="gov.va.med.cds.template.generated.basedatatypes.PhysicalQuantity">
				<property name="value" column="CLOZAPINE_DOSAGE_MGDAY" type="java.lang.String"/>
				<component name="unit" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="displayText" type="java.lang.String" >
						<formula>
							(CASE
                         		WHEN (CLOZAPINE_DOSAGE_MGDAY IS NOT NULL) THEN 'MG/DAY'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				</component>
			</component>
			
			<component name="wbcObservation" class="gov.va.med.cds.template.generated.pharmacy.WbcObservation">
				<component name="count" class="gov.va.med.cds.template.generated.basedatatypes.PhysicalQuantity">
					<property name="value" column="WBC_RESULTS" type="java.lang.String"/>
				</component>
				<property name="testDate" formula="STRING(DATE_OF_WBC_TEST,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone" insert="false" update="false" />
			</component>
		</component>
		
        <component name="dataEnterer"  class="gov.va.med.cds.template.generated.common.PractitionerParticipationLite" >
			<property name="time" formula="STRING(LOGIN_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone" />
			<component name="practitioner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
				<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier" >
					<property name="identity" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false">
						<column name="ENTERED_BY"/>
					</property>
					<property name="assigningFacility" type="java.lang.String" insert="false" update="false">
						<formula>
								(CASE
                         			WHEN (ENTERED_BY IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()
                         			ELSE NULL
                      			END)
							</formula>
						</property>
						<property name="assigningAuthority" type="java.lang.String">
							<formula>
								(CASE
                         			WHEN (ENTERED_BY IS NOT NULL) THEN 'USVHA'
                         			ELSE NULL
                      			END)
							</formula>
						</property>
					</component>
					<property name="idSourceTable" type="java.lang.String">
						<formula>
							(CASE
                         		WHEN (ENTERED_BY IS NOT NULL) THEN 'VISTA200'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				<property name="name" formula="VISTA_HDSI.HDSREPSQLUtil1_MiscNameNE(ENTERED_BY)" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType"  />
			</component>	
		</component>

		<component name="pharmacyRequest" class="gov.va.med.cds.template.generated.pharmacy.PharmacyRequest">
			<component name="cosigner" class="gov.va.med.cds.template.generated.common.PractitionerParticipationLite" >
				<component name="practitioner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
					<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier" >
						<property name="identity" column="COSIGNING_PHYSICIAN" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" />
						<property name="assigningFacility" type="java.lang.String" insert="false" update="false">
							<formula>
								(CASE
                         			WHEN (COSIGNING_PHYSICIAN IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()
                         			ELSE NULL
                      			END)
							</formula>
						</property>
						<property name="assigningAuthority" type="java.lang.String">
							<formula>
								(CASE
                         			WHEN (COSIGNING_PHYSICIAN IS NOT NULL) THEN 'USVHA'
                         			ELSE NULL
                      			END)
							</formula>
						</property>
					</component>
					<property name="idSourceTable" type="java.lang.String">
						<formula>
							(CASE
                         		WHEN (COSIGNING_PHYSICIAN IS NOT NULL) THEN 'VISTA200'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
					<property name="name" formula="VISTA_HDSI.HDSREPSQLUtil1_MiscNameNE(COSIGNING_PHYSICIAN)" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType"/>
				</component>
			</component>
            
           <component name="orderedMedication" class="gov.va.med.cds.template.generated.common.Medicine">
				<component name="cmopDrugCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="code" column="CMOP_ID" type="java.lang.String" />
					<property name="codingSystem" type="java.lang.String">
						<formula>
							(CASE
                         		WHEN (CMOP_ID IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_50' 
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				</component>
				
				<component name="medicationCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElement">
					<property name="code" column="MEDICATIONCODE_CODE" type="java.lang.String" />
					<property name="displayText" column="MEDICATIONCODE_TEXT" type="java.lang.String" />
					<property name="codingSystem" column="MEDICATIONCODE_SYSTEM" type="java.lang.String"/>
				</component>
				
				<component name="tradeName" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="displayText" column="TRADE_NAME" type="java.lang.String" />
					<property name="codingSystem" type="java.lang.String" >
						<formula>
							(CASE
                         		WHEN (TRADE_NAME IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52' 
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				</component>
			</component>
            
            <component name="genericRequestIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
				<property name="identity" column="GENERIC_REQUEST_IDENTIFIER" type="java.lang.String" />
				<property name="namespaceId" type="java.lang.String" >
	                <formula>
	                 (CASE
	                     WHEN (GENERIC_REQUEST_IDENTIFIER IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_100'
	                     ELSE NULL
	                  END)
	                </formula>
                </property>
			</component>
            
            <component name="orderLocationIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72LocationIdentifier">
				<property name="pointOfCare" column="CLINICX" type="java.lang.String" />
                <property name="room" column="CLINIC" type="gov.va.med.cds.persistence.hibernate.common.VistaIntegerToStringUserType" />
			</component>
            
            <component name="orderedItem" class="gov.va.med.cds.template.generated.common.PharmacyOrderableItem">
				<component name="itemCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="code" column="PHARMACY_ORDERABLE_ITEM" type="gov.va.med.cds.persistence.hibernate.common.VistaIntegerToStringUserType" />
					<property name="displayText" column="PHARMACYORDERABLEITEMX" type="java.lang.String" />
					<property name="codingSystem" type="java.lang.String" >
					 	<formula>
	                 		(CASE
	                    		 WHEN (PHARMACY_ORDERABLE_ITEM IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52_39.2'
	                     		ELSE NULL
	                  		END)
	                	</formula>
                	</property>	
				</component>
				
				<component name="dosageFormCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="code" column="DOSAGE_FORM" type="java.lang.String" />
					<property name="displayText" column="DOSAGE_NAME" type="java.lang.String" />
					<property name="codingSystem" type="java.lang.String">
						<formula>
	                 		(CASE
	                    		 WHEN (DOSAGE_FORM IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_50.7_.02'
	                     		ELSE NULL
	                  		END)
	                	</formula>
                	</property>	
				</component>
			</component>
            
             <component name="orderingInstitutionIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72OrganizationIdentifier">
                <property name="identity" column="OrderingInstitutionIdentity" type="java.lang.String" />
                <property name="name" column="DIVISIONX" type="java.lang.String" />
                <property name="assigningAuthority" type="java.lang.String" >
                    <formula>
                     (CASE
                         WHEN (OrderingInstitutionIdentity IS NOT NULL) THEN 'USVHA'
                         ELSE NULL
                      END)
                    </formula>
                </property>
            </component>
		
			<property name="orderDate" formula="STRING(ISSUE_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone" insert="false" update="false"/>
			
            <property name="status" formula="'CM'" type="java.lang.String" />
            
           <component name="statusModifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
                <property name="code" type="java.lang.String" >
                    <formula>
                        (CASE
                        WHEN ( STATUS = 'ACTIVE' ) THEN '4500659'
                        WHEN ( STATUS = 'NON-VERIFIED' ) THEN '4500817'
                        WHEN ( STATUS = 'REFILL' ) THEN '4500869'
                        WHEN ( STATUS = 'HOLD' ) THEN '4500752'
                        WHEN ( STATUS = 'DRUG INTERACTIONS' ) THEN '4500716'
                        WHEN ( STATUS = 'SUSPENDED' ) THEN '4500913'
                        WHEN ( STATUS = 'DONE' ) THEN '4500710'
                        WHEN ( STATUS = 'EXPIRED' ) THEN '4500725'
                        WHEN ( STATUS = 'DISCONTINUED' ) THEN '4500704'
                        WHEN ( STATUS = 'DELETED' ) THEN '4500698'
                        WHEN ( STATUS = 'DISCONTINUED BY PROVIDER' ) THEN '4500706'
                        WHEN ( STATUS = 'DISCONTINUED (EDIT)' ) THEN '4500705'
                        WHEN ( STATUS = 'PROVIDER HOLD' ) THEN '4500861'
                        ELSE NULL
                        END)
                    </formula>
                </property>
                <property name="displayText" column="STATUS" type="java.lang.String"/>
                <property name="codingSystem" type="java.lang.String" >
                    <formula>
                     (CASE
                         WHEN (STATUS IS NOT NULL) THEN '99VA_52_100'
                         ELSE NULL
                      END)
                    </formula>                
                </property>
            </component>
        </component>
			
		<component name="patient" class="gov.va.med.cds.template.generated.common.PatientLite">
			<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier">
				<property name="identity" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false">
					<column name="PATIENT"/>
				</property>
				<property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" />
				<property name="assigningAuthority" formula="'USVHA'" type="java.lang.String" />
			</component>
			<property name="name" formula="VISTA_HDSI.HDSREPSQLUtil1_PatientNE(PATIENT)" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" />
		</component>

       	 <property name="expirationDate" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQueryNoTimezone" insert="false" update="false" >
            <column name="EXPIRATION_DATE" />
            <formula>VISTA_HDSI.HDSREPSQLUtil1_StationNumber()</formula>
        </property>
       	
        <property name="lastDispenseDate" formula="STRING(LAST_DISPENSED_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone"  insert="false" update="false" />

        <property name="numberOfRefillsAuthorized" column="OF_REFILLS" type="integer" />

        <property name="singlePatientInstruction" column="PATIENT_INSTRUCTIONS" type="java.lang.String" />

        <property name="singleOtherPatientInstruction" column="OTHER_PATIENT_INSTRUCTIONS" type="java.lang.String" />
        
        <property name="singleExpandedPatientInstruction" column="EXPANDEDPATIENTINSTRUCWP" type="java.lang.String" />
        
        <property name="singlePharmacyInstruction" column="PHARMACYINSTRUCTIONSWP" type="java.lang.String" />

        <property name="singleSig" type="java.lang.String" >
            <formula>
                    (CASE
                    WHEN ( SIG IS NOT NULL ) THEN SIG
                    ELSE SIGX 
                    END)
            </formula>
        </property>
        
        <component name="digitalSignatureIndicator" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
            <property name="code" type="java.lang.String" >
                <formula>
                    (CASE
                    WHEN ( SIGNATURE_STATUS = 'NO' ) THEN '0'
                    WHEN ( SIGNATURE_STATUS = 'YES' ) THEN '1'
                    ELSE NULL
                    END)
                </formula>
            </property>
            <property name="displayText" column="SIGNATURE_STATUS" type="java.lang.String" />
            <property name="codingSystem" type="java.lang.String">
                    <formula>
                     (CASE
                         WHEN (SIGNATURE_STATUS IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52'
                         ELSE NULL
                      END)
                    </formula>                
            </property>
        </component>        
        
        <component name="copayTransactionType" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="COPAY_TRANSACTION_TYPE" type="gov.va.med.cds.persistence.hibernate.common.VistaIntegerToStringUserType" />
			<property name="displayText" column="COPAYTRANSACTIONTYPEX" type="java.lang.String" />
			<property name="codingSystem" type="java.lang.String" >
				<formula>
					(CASE
                         WHEN (COPAY_TRANSACTION_TYPE IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52_105'
                         ELSE NULL
                     END)
				</formula>
			</property>
		</component>
		

        <component name="transitionalRxBenefit" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
            <property name="code" type="java.lang.String" >
                <formula>
                        (CASE
                        WHEN ( TPB_RX = 'NO' ) THEN '0'
                        WHEN ( TPB_RX = 'YES' ) THEN '1'
                        ELSE NULL
                        END)
                    </formula>
            </property>
            <property name="displayText" column="TPB_RX" type="java.lang.String" />
            <property name="codingSystem" type="java.lang.String">
                    <formula>
                     (CASE
                         WHEN (TPB_RX IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52'
                         ELSE NULL
                      END)
                    </formula>                
            </property>
        </component>

        <property name="treatmentFactor" type="gov.va.med.cds.persistence.hibernate.common.VistaOutpatientPharmacyTreatmentFactorType" insert="false" update="false" >
		  <column name="SERVICE_CONNECTED"/>
		  <column name="MILITARY_SEXUAL_TRAUMA"/>
		  <column name="AGENT_ORANGE_EXPOSURE"/>
		  <column name="IONIZING_RADIATION_EXPOSURE"/>
		  <column name="SouthwestAsiaConditions"/>
		  <column name="HEAD_ANDOR_NECK_CANCER"/>
		  <column name="COMBAT_VETERAN"/>
		  <column name="Proj112Shad"/>
		</property>

        <component name="originalDispense" class="gov.va.med.cds.template.generated.pharmacy.OutpatientMedicationDispense" >
            <property name="singleComment" column="REMARKS" type="java.lang.String" />
            <property name="dispenseDate" formula="STRING(DISPENSED_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone" />
            <property name="fillDate" formula="STRING(FILL_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone" />
           <component name="quantityDispensed" class="gov.va.med.cds.template.generated.basedatatypes.PhysicalQuantity">
				<property name="value" column="QTY" type="gov.va.med.cds.persistence.hibernate.common.VistaBigDecimalToStringUserType" />
				<component name="unit" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="displayText" column="DISPENSED_UNIT" type="java.lang.String" />
					<property name="codingSystem" type="java.lang.String">
						<formula>
							(CASE
                         		WHEN (DISPENSED_UNIT IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_50'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				</component>
			</component>
			
			<component name="currentProvider"  class="gov.va.med.cds.template.generated.common.PractitionerLite">
				<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier" >
					<property name="identity" column="PROVIDER" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType"/>
					<property name="assigningFacility" type="java.lang.String" insert="false" update="false" >
						<formula>
								(CASE
                         			WHEN (PROVIDER IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()
                         			ELSE NULL
                      			END)
							</formula>
						</property>
						<property name="assigningAuthority" type="java.lang.String">
							<formula>
								(CASE
                         			WHEN (PROVIDER IS NOT NULL) THEN 'USVHA'
                         			ELSE NULL
                      			END)
							</formula>
						</property>
					</component>
					<property name="idSourceTable" type="java.lang.String">
						<formula>
							(CASE
                         		WHEN (PROVIDER IS NOT NULL) THEN 'VISTA200'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				<property name="name" formula="VISTA_HDSI.HDSREPSQLUtil1_MiscNameNE(PROVIDER)" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" />
			</component>
			
            <property name="singleProviderComment" column="PROVIDERCOMMENTSWP" type="java.lang.String" />
           
            <property name="loginDate" formula="STRING(LOGIN_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone"  />
            <property name="daysSupply" column="DAYS_SUPPLY" type="gov.va.med.cds.persistence.hibernate.common.VistaIntegerToStringUserType" />
			<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
				<property name="identity" column="RowId" type="java.lang.String" insert="false" update="false" />
				<property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52'" type="java.lang.String" />
			</component>
            
           <component name="levelOfUnderstanding" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" type="java.lang.String" >
					<formula>
						(CASE
						WHEN ( WAS_COUNSELING_UNDERSTOOD = 'NO' ) THEN '4500630'
						WHEN ( WAS_COUNSELING_UNDERSTOOD = 'YES' ) THEN '4500633'
						ELSE NULL
						END)
					</formula>
				</property>
				<property name="displayText" column="WAS_COUNSELING_UNDERSTOOD" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String" >
                    <formula>
                     (CASE
                         WHEN (WAS_COUNSELING_UNDERSTOOD IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52'
                         ELSE NULL
                      END)
                    </formula>                
                </property>
			</component>
			
			<property name="mailWindow" column="MAILWINDOW" type="java.lang.String" />
			<property name="releaseDate" formula="STRING(RELEASED_DATETIME,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone" insert="false" update="false" />
			
			<component name="wasPatientCounseled" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" type="java.lang.String" >
					<formula>
						(CASE
                        WHEN ( WAS_THE_PATIENT_COUNSELED = 'NO' ) THEN '4500630'
                        WHEN ( WAS_THE_PATIENT_COUNSELED = 'YES' ) THEN '4500633'
						ELSE NULL
						END)
					</formula>
				</property>
				<property name="displayText" column="WAS_THE_PATIENT_COUNSELED" type="java.lang.String" />
			    <property name="codingSystem" type="java.lang.String" >
                    <formula>
                     (CASE
                         WHEN (WAS_THE_PATIENT_COUNSELED IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52'
                         ELSE NULL
                      END)
                    </formula>                
                </property>
			</component>
            <component name="division" class="gov.va.med.cds.template.generated.common.PharmacyDivision">
				<component name="divisionId" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="code" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" />
					<property name="displayText" column="DIVISIONX" type="java.lang.String" insert="false" update="false"/>
					<property name="codingSystem" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52_20'" type="java.lang.String" />
				</component>
				
				<component name="ncpdpId" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="code" column="NCPDP_NUMBER" type="java.lang.String" insert="false" update="false" />
					<property name="displayText" column="DIVISIONX" type="java.lang.String" insert="false" update="false" />
					<property name="codingSystem" type="java.lang.String" >
						<formula>
							(CASE
                         		WHEN (DIVISIONX IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52.2_.09'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				</component>
			</component>
			
			<component name="dispensedDrug" class="gov.va.med.cds.template.generated.pharmacy.DispensedDrugInstance">
				<component name="drugUnitPrice" class="gov.va.med.cds.template.generated.basedatatypes.Money">
					<property name="value" column="UNIT_PRICE_OF_DRUG" type="java.lang.String" insert="false" update="false" />
				</component>
				
				<property name="expirationDate" formula="STRING(DRUG_EXPIRATION_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone" insert="false" update="false" />
				<property name="lotId" column="LOT_" type="java.lang.String" insert="false" update="false" />
				
				<component name="ndc" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
					<property name="code" column="NDC" type="java.lang.String" insert="false" update="false" />
					<property name="codingSystem" type="java.lang.String" insert="false" update="false" >
						<formula>
							(CASE
                         		WHEN (NDC IS NOT NULL) THEN 'NDC'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				</component>
			</component>
            
           <component name="pharmacist" class="gov.va.med.cds.template.generated.common.PractitionerParticipationLite" >
				<component name="practitioner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
					<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier" >
						<property name="identity" column="PHARMACIST" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false"/>
						<property name="assigningFacility" type="java.lang.String" insert="false" update="false" >
							<formula>
								(CASE
                         			WHEN (PHARMACIST IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()
                         			ELSE NULL
                      			END)
							</formula>
						</property>
						<property name="assigningAuthority" type="java.lang.String">
							<formula>
								(CASE
                         			WHEN (PHARMACIST IS NOT NULL) THEN 'USVHA'
                         			ELSE NULL
                      			END)
							</formula>
						</property>
					</component>
					<property name="idSourceTable" type="java.lang.String">
						<formula>
							(CASE
                         		WHEN (PHARMACIST IS NOT NULL) THEN 'VISTA200'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
					<property name="name" formula="VISTA_HDSI.HDSREPSQLUtil1_MiscNameNE(PHARMACIST)" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" />
				</component>
 			</component>
			
			<component name="cmopEventStatus" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" type="java.lang.String" >
				    <formula>
                        (CASE
                        WHEN ( CMOP_EVENT_STATUS = 'TRANSMITTED' ) THEN '0'
                        WHEN ( CMOP_EVENT_STATUS = 'DISPENSED' ) THEN '1'
                        WHEN ( CMOP_EVENT_STATUS = 'RETRANSMITTED' ) THEN '2'
                        WHEN ( CMOP_EVENT_STATUS = 'NOT DISPENSED' ) THEN '3'
                        ELSE NULL
                        END)
                    </formula>
				</property>
				<property name="displayText" column="CMOP_EVENT_STATUS" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String" >
					<formula>
							(CASE
                         		WHEN (CMOP_EVENT_STATUS IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52.01'
                         		ELSE NULL
                      		END)
						</formula>
				</property>
			</component>  
         </component>
            
        <list name="refillDispense" fetch="subselect" batch-size="100">
            <key column="PRESCRIPTION" />
            <list-index column="CHILDSUB1" />
            <one-to-many entity-name="refillDispense40010" />
        </list>

        <list name="partialDispense" fetch="subselect" batch-size="100">
            <key column="PRESCRIPTION" />
            <list-index column="CHILDSUB1" />
            <one-to-many entity-name="partialDispense40010" />
        </list>

        <component name="cancel" class="gov.va.med.cds.template.generated.pharmacy.CancelAct">
           <property name="cancelDate" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQueryNoTimezone" insert="false" update="false" >
            	<column name="CANCEL_DATE" />
            	<formula>VISTA_HDSI.HDSREPSQLUtil1_StationNumber()</formula>
       	  	</property>
          	<property name="SingleComment" column="DELETION_COMMENTS" type="java.lang.String" />
        </component>
        
        <list name="medicationInstructions" fetch="subselect" batch-size="100">
            <key column="PRESCRIPTION" />
            <list-index column="CHILDSUB1" />
            <one-to-many entity-name="medicationInstruction40010" />
        </list>

       <component name="finisher" class="gov.va.med.cds.template.generated.common.PractitionerParticipationLite">
			<property name="time" formula="STRING(FinishDateTime,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeNoTimezone" insert="false" update="false" />
			<component name="practitioner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
				<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier" >
					<property name="identity" column="FINISHING_PERSON"  type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" />
					<property name="assigningFacility" type="java.lang.String" insert="false" update="false">
						<formula>
							(CASE
                         		WHEN (FINISHING_PERSON IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()
                         		ELSE NULL
                      		END)
						</formula>
					</property>
					<property name="assigningAuthority" type="java.lang.String">
						<formula>
							(CASE
                         		WHEN (FINISHING_PERSON IS NOT NULL) THEN 'USVHA'
                         		ELSE NULL
                      		END)
						</formula>
					</property>
				</component>
				<property name="idSourceTable" type="java.lang.String">
					<formula>
						(CASE
                         	WHEN (FINISHING_PERSON IS NOT NULL) THEN 'VISTA200'
                         	ELSE NULL
                      	END)
					</formula>
				</property>
		    	<property name="name" formula="VISTA_HDSI.HDSREPSQLUtil1_MiscNameNE(FINISHING_PERSON)" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" />
			</component>
		</component>
		
		<list name="activityLog" fetch="subselect" batch-size="100">
            <key column="PRESCRIPTION" />
            <list-index column="CHILDSUB1" />
            <one-to-many entity-name="activityLog40010" />
        </list>
         
     	<component name="recordSource" class="gov.va.med.cds.template.generated.basedatatypes.HL72FacilityIdentifier">
			<property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52'" type="java.lang.String" />
			<property name="universalId" formula="VISTA_HDSI.HDSREPSQLUtil1_KSPDomainName()" type="java.lang.String" />
			<property name="universalIdType" formula="'DNS'" type="java.lang.String" />
		</component>

	</class>
	
	<!-- 
		NOTE: PharmacyRead40010 date queries use the OutpatientMedicationPromise.storedprocedure.rowids.date pre-query which returns 
		rowids that satisfy cancel date/expiray date and date ranges and null cancel/expiray dates.
	 -->
    <sql-query name="OutpatientMedicationPromise.storedprocedure.rowids" callable="true">
        <![CDATA[
        { call VISTA_HDSI.HDSREPOPRxUtil1_getRxProfiles(?) }
         ]]>
    </sql-query> 

    <sql-query name="OutpatientMedicationPromise.storedprocedure.rowids.date" callable="true">
        <![CDATA[
        { call VISTA_HDSI.HDSREPOPRxUtil1_getRxByDate(?,?,?) }
         ]]>
    </sql-query>
    
     <query name="PharmacyRead40010.OutpatientMedicationPromise.patient">
        <![CDATA[
        from outpatientMedicationPromise omp
        where omp.recordIdentifier.identity in (:pids)
        ]]>
    </query>   
    
    <query name="PharmacyRead40010.OutpatientMedicationPromise.identifiers">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and omp.id in ( :recordIdentifiers )
        ]]>
    </query>
      
    <query name="PharmacyRead40010.OutpatientMedicationPromise.patient.date">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)     
            and 
            case 
				when omp.cancel.cancelDate.timestamp < omp.expirationDate.timestamp
				then omp.cancel.cancelDate.timestamp 
				else omp.expirationDate.timestamp 
			end	between :startDate and :endDate
        ]]>
    </query>
     
    <query name="RDIIntoleranceConditionPharmacyRead40010.OutpatientMedicationPromise.patient">
        <![CDATA[
        from outpatientMedicationPromise omp
        where omp.recordIdentifier.identity in (:pids)
        ]]>
    </query>
    
    <query name="RDIIntoleranceConditionPharmacyRead40010.OutpatientMedicationPromise.patient.identifiers">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and omp.id in ( :recordIdentifiers )
        ]]>
    </query>
      
    <query name="RDIIntoleranceConditionPharmacyRead40010.OutpatientMedicationPromise.patient.date">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and 
            case 
				when omp.cancel.cancelDate.timestamp < omp.expirationDate.timestamp
				then omp.cancel.cancelDate.timestamp 
				else omp.expirationDate.timestamp 
			end	between :startDate and :endDate
        ]]>
    </query>
    
    <query name="RDIIntoleranceConditionPharmacyRead40011.OutpatientMedicationPromise.patient">
        <![CDATA[
        from outpatientMedicationPromise omp
        where omp.recordIdentifier.identity in (:pids)
        ]]>
    </query>
    
    <query name="RDIIntoleranceConditionPharmacyRead40011.OutpatientMedicationPromise.patient.identifiers">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and omp.id in ( :recordIdentifiers )
        ]]>
    </query>
      
    <query name="RDIIntoleranceConditionPharmacyRead40011.OutpatientMedicationPromise.patient.date">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and 
            case 
				when omp.cancel.cancelDate.timestamp < omp.expirationDate.timestamp
				then omp.cancel.cancelDate.timestamp 
				else omp.expirationDate.timestamp 
			end	between :startDate and :endDate
        ]]>
    </query>

    <query name="RDIIntoleranceConditionPharmacyRead40012.OutpatientMedicationPromise.patient">
        <![CDATA[
        from outpatientMedicationPromise omp
        where omp.recordIdentifier.identity in (:pids)
        ]]>
    </query>
    
    <query name="RDIIntoleranceConditionPharmacyRead40012.OutpatientMedicationPromise.patient.identifiers">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and omp.id in ( :recordIdentifiers )
        ]]>
    </query>
      
    <query name="RDIIntoleranceConditionPharmacyRead40012.OutpatientMedicationPromise.patient.date">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and 
            case 
				when omp.cancel.cancelDate.timestamp < omp.expirationDate.timestamp
				then omp.cancel.cancelDate.timestamp 
				else omp.expirationDate.timestamp 
			end	between :startDate and :endDate
        ]]>
    </query> 

    <query name="RDIAllergiesPharmacyRead40013.OutpatientMedicationPromise.patient">
        <![CDATA[
        from outpatientMedicationPromise omp
        where omp.recordIdentifier.identity in (:pids)
        ]]>
    </query>
    
    <query name="RDIAllergiesPharmacyRead40013.OutpatientMedicationPromise.patient.identifiers">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and omp.id in ( :recordIdentifiers )
        ]]>
    </query>
      
    <query name="RDIAllergiesPharmacyRead40013.OutpatientMedicationPromise.patient.date">
        <![CDATA[
            from outpatientMedicationPromise omp
            where omp.recordIdentifier.identity in (:pids)
            and 
            case 
				when omp.cancel.cancelDate.timestamp < omp.expirationDate.timestamp
				then omp.cancel.cancelDate.timestamp 
				else omp.expirationDate.timestamp 
			end	between :startDate and :endDate
        ]]>
    </query>       
</hibernate-mapping>
