<?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-cascade="all">
    <class entity-name="NonVAMedicationsRead2" table="VISTA_HDSI.PHARM_PAX_NONVAMEDS_55_05_EXT" name="gov.va.med.cds.template.generated.pharmacy.NonVaMedicationEvent" >
        <id name="nvmId" type="java.lang.String">
            <column name="ROWID" />
            <generator class="assigned" />
        </id>
    
        <property name="nvmId" column="ROWID" type="java.lang.String" insert="false" update="false" />
        
        <component name="pharmacyPatient" class="gov.va.med.cds.template.generated.common.PatientLite">
            <component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier">
                <property name="identity" column="PHARMACY_PATIENT" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false" />
                <property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" />
                <property name="assigningAuthority" formula="'USVHA'" type="java.lang.String" />
            </component>
            <property name="name" column="PatientNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        </component>
        
        <component name="dosage" class="gov.va.med.cds.template.generated.basedatatypes.PhysicalQuantity">
  		    <property name="value" column="DOSE" type="java.lang.String" />
 	        <component name="unit" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
            	<property name="code" column="Units" type="java.lang.String"/>
            	<property name="codingSystem" type="java.lang.String">
               	<formula>
                 	(CASE
                    	 WHEN (Units IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_50'
                    	 ELSE NULL
                  	END)
                	</formula>  
            	</property>
			</component>
        </component>

		<component name="route" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="RouteCode" type="java.lang.String"/>
			<property name="displayText" column="RouteDisplayText" type="java.lang.String"/>
			<property name="codingSystem" type="java.lang.String" >
			   <formula>
			     (CASE
			         WHEN (RouteCode IS NOT NULL OR RouteDisplayText 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()||'_55.05_4'
                     ELSE NULL
                  END)
                </formula>  
            </property>
		 </component>
		 
		 <component name="status" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" type="java.lang.String" >
		      <formula>
		          (CASE
		              WHEN (Status = 'DISCONTINUED') THEN '1'
		              WHEN (Status = 'DATE OF DEATH ENTERED') THEN '2'
		              ELSE ''
		           END)
		      </formula>
		    </property>
			<property name="displayText" column="StatusXExt" type="java.lang.String" />
			<property name="codingSystem" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_51.2'" type="java.lang.String" />
		 </component>

		 <property name="discontinueDate" formula="STRING(DISCONTINUED_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
		 
		 <component name="orderIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
			 <property name="identity" column="ORDER_NUMBER" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false" />
			 <property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_55.05_7'" type="java.lang.String" />
		 </component>
		 
		 <component name="documentedBy" class="gov.va.med.cds.template.generated.common.PractitionerParticipationLite" >
		    <property name="time" formula="STRING(DOCUMENTED_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" 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="DOCUMENTED_BY" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false"/>
					<property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" />
					<property name="assigningAuthority" formula="'USVHA'" type="java.lang.String" />
				</component>
				<property name="idSourceTable" formula="'VistA200'" type="java.lang.String" />
				<property name="name" column="DocumentedByNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" />
			</component>		 	
		 </component>
		 
		<component name="medication" class="gov.va.med.cds.template.generated.common.Medicine">
			<component name="medicationCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElement">
				<property name="code" column="MedicationCode" type="java.lang.String" />
				<property name="displayText" column="MedicationDisplayText" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String" >
				    <formula>
				        (CASE
				            WHEN (MedicationCode IS NOT NULL OR MedicationDisplayText IS NOT NULL) THEN MedicationCodingSystem
				            ELSE NULL
				        END)
                    </formula>	
				</property>
			</component>
		</component>
		
		<property name="startDate" formula="STRING(START_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />
		
		<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="comments" class="gov.va.med.cds.template.generated.pharmacy.NonVaMedicationEvent$Comments">
			<property name="singleComment" column="COMMENTS7WP" type="java.lang.String" />
		</component>
		
		<property name="source" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" />
		
		<component name="pharmacyOrderableItem" 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="ORDERABLE_ITEM" type="gov.va.med.cds.persistence.hibernate.common.VistaIntegerToStringUserType" />
				<property name="displayText" column="ORDERABLEITEMX" type="java.lang.String" />
				<property name="codingSystem" type="java.lang.String" >
				    <formula>
                        (CASE
                            WHEN (ORDERABLE_ITEM IS NOT NULL OR ORDERABLEITEMX IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_50.7'
                            ELSE NULL
                        END)
                    </formula>  
				</property>
			</component>
			<component name="dosageFormCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="DosageFormCode" type="java.lang.String" />
				<property name="displayText" column="DosageFormDisplayText" type="java.lang.String"/>
				<property name="codingSystem" type="java.lang.String" >
				     <formula>
                        (CASE
                            WHEN (DosageFormCode IS NOT NULL OR DosageFormDisplayText IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_50.606'
                            ELSE NULL
                        END)
                    </formula>  
				</property>
			</component>
		</component>

		<component name="disclaimers" class="gov.va.med.cds.template.generated.pharmacy.NonVaMedicationEvent$Disclaimers">
			<property name="singleDisclaimer" column="DISCLAIMER1WP" type="java.lang.String"/>
		</component>
		
        <component name="recordSource" class="gov.va.med.cds.template.generated.basedatatypes.HL72FacilityIdentifier">
			<property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_55.05'" type="java.lang.String" />
			<property name="universalId" column="DomainNameX" type="java.lang.String" />
			<property name="universalIdType" formula="'DNS'" type="java.lang.String" />
        </component>
        
        <component name="recordIdentifier"  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()||'_55.05'" type="java.lang.String" />
        </component>
        
    	<property name="StatusQuery" column="StatusQuery" type="java.lang.String" />
    </class>
    
    <query name="NonVAMedicationsRead2.NonVaMedicationEvent.nonVaMedicationEvents">
        <![CDATA[
        from NonVAMedicationsRead2 nvm
        where nvm.pharmacyPatient.identifier.identity in ( :pids )
      ]]>
    </query>
    
    <query name="NonVAMedicationsRead2.NonVaMedicationEvent.nonVaMedicationEvents.status">
        <![CDATA[
        from NonVAMedicationsRead2 nvm
        where nvm.pharmacyPatient.identifier.identity in ( :pids )
        and nvm.StatusQuery in ( :status )
      ]]>
    </query>

    <query name="NonVAMedicationsRead2.NonVaMedicationEvent.nonVaMedicationEvents.identifiers">
        <![CDATA[
        from NonVAMedicationsRead2 nvm
        where nvm.pharmacyPatient.identifier.identity in ( :pids ) and
        nvm.nvmId in ( :recordIdentifiers )
      ]]>
    </query>
</hibernate-mapping>
