<?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="MedicationInstruction" lazy="false" table="VISTA_HDSI.PRESX_MEDICATION_INSTR_52_0113" name="gov.va.med.cds.template.generated.pharmacy.OutpatientMedicationPromise1$MedicationInstructions">
	
		<composite-id class="gov.va.med.cds.persistence.hibernate.common.VistaPharmacyCompositeRowIdUserType" >
			<key-property name="PRESCRIPTION" column="PRESCRIPTION" type="big_decimal"/>
			<key-property name="CHILDSUB1" column="CHILDSUB1" type="big_decimal"/>
	 	</composite-id> 
		
		<property name="prescription" column="PRESCRIPTION" type="big_decimal" insert="false" update="false" />
		
		<component name="singleInstruction" class="gov.va.med.cds.template.generated.pharmacy.MedicationInstructionComponent">
			<component name="conjunction" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" type="java.lang.String" >
					<formula>
						(CASE
						WHEN ( CONJUNCTION = 'AND' ) THEN 'A'
						WHEN ( CONJUNCTION = 'THEN' ) THEN 'T'
						WHEN ( CONJUNCTION = 'EXCEPT' ) THEN 'X'
						ELSE NULL
						END)
					</formula>
				</property>
				<property name="displayText" column="CONJUNCTION" type="java.lang.String" />
				<property name="codingSystem" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52.0113'" type="java.lang.String" />
			</component>
			
			<property name="dispenseUnitsPerDose" column="DISPENSE_UNITS_PER_DOSE" type="java.lang.String" />
			<property name="dosageOrdered" column="DOSAGE_ORDERED" type="java.lang.String" />
			
			<component name="noun" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="displayText" column="NOUN" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String">
					<formula>
							(CASE
                         		WHEN (NOUN IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_51.2' 
                         		ELSE NULL
                      		END)
						</formula>
				</property>
			</component>
			
			<component name="route" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="ROUTE" type="java.lang.String" />
				<property name="displayText" column="ROUTEX" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String" >
					<formula>
							(CASE
                         		WHEN (ROUTE IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_51.2' 
                         		ELSE NULL
                      		END)
						</formula>
				</property>
			</component>
			
			<component name="schedule" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="displayText" column="SCHEDULE" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String" >
					<formula>
							(CASE
                         		WHEN (SCHEDULE IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52.0113'
                         		ELSE NULL
                      		END)
						</formula>
				</property>
			</component>
			
			<component name="verb" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="displayText" column="VERB" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String" >
					<formula>
							(CASE
                         		WHEN (VERB IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52.0113'
                         		ELSE NULL
                      		END)
						</formula>
				</property>
			</component>
			
			<component name="giveUnits" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="UNITS" type="java.lang.String" />
				<property name="displayText" column="UNITSX" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String" >
					<formula>
							(CASE
                         		WHEN (UNITS IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_52.0113'
                         		ELSE NULL
                      		END)
						</formula>
				</property>
			</component>
			
			<property name="intendedDuration" column="DURATION" type="java.lang.String" />
		</component>
	</class>
	
	<!-- Association medicationInstruction Queries -->
    
    <query name="OutpatientPharmacyRead1.OutpatientMedicationPromise.medicationInstructions.date"><![CDATA[
        select medInstr
          from MedicationInstruction medInstr, OutpatientPharmacyRead1 as pr1
          where pr1.id = medInstr.prescription
            and pr1.recordIdentifier.identity in (:pids)
            and ( (pr1.expirationDate.timestamp between :startDate and :endDate) or (pr1.expirationDate.timestamp is null)  )
    ]]></query>
    
    <query name="OutpatientPharmacyRead1.OutpatientMedicationPromise.medicationInstructions"><![CDATA[
        select medInstr
         from MedicationInstruction medInstr, OutpatientPharmacyRead1 as pr1
         where pr1.id = medInstr.prescription
            and pr1.recordIdentifier.identity in (:pids)
    ]]></query>
   
    <query name="OutpatientPharmacyRead1.OutpatientMedicationPromise.medicationInstructions.identifiers">
        <![CDATA[
        select medInstr
         from MedicationInstruction medInstr, OutpatientPharmacyRead1 pr1
         where pr1.id = medInstr.prescription
            and pr1.recordIdentifier.identity in (:pids)
            and pr1.id in ( :recordIdentifiers )
        ]]>
    </query>  
</hibernate-mapping>
