<?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="NonVAMedicationsRead3" table="NONVAMED_V" lazy="false" node="nonVaMedicationEvent" >
        <id name="id" type="java.lang.Long">
            <column name="NONVAMED_ID" />
            <generator class="sequence" >
				<param name="sequence">NONVAMED_ID_SEQ_ID</param>
			</generator>
        </id>
        
         <component name="recordIdentifier" node="recordIdentifier" >
            <property name="identity" column="NONVAMED_ID" type="java.lang.String" insert="false" update="false" node="identity" />
            <!-- property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_55.05'" type="java.lang.String" node="namespaceId"/-->
        </component>
        

        <component name="pharmacyPatient" node="pharmacyPatient">
            <component name="identifier" node="identifier">
                <property name="identity" column="PATIENT_IDENTITY" type="java.lang.String" node="identity"/>
                <property name="assigningFacility" column="PATIENT_ASSIGNING_FACILITY" type="java.lang.String" not-null="true" node="assigningFacility"/>
				<property name="assigningAuthority" column="PATIENT_ASSIGNING_AUTHORITY" type="java.lang.String" node="assigningAuthority"/>
            </component>
		    <component name="name" node="name">
				    <property name="prefix" column="PATIENT_NAME_PREFIX" type="java.lang.String" node="prefix"/>
				    <property name="given" column="PATIENT_NAME_GIVEN" type="java.lang.String" node="given"/>
				    <property name="middle" column="PATIENT_NAME_MIDDLE" type="java.lang.String" node="middle"/>
				    <property name="family" column="PATIENT_NAME_FAMILY" type="java.lang.String" node="family"/>
				    <property name="suffix" column="PATIENT_NAME_SUFFIX" type="java.lang.String" node="suffix"/>
				    <property name="title" column="PATIENT_NAME_TITLE" type="java.lang.String" node="title"/>
		    </component>
        </component>
        
        <!-- ADD Patient Name into table will use patientLite declared above-->
        <!-- property name="name" column="PatientNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" node="pharmacyPatient//name"  /-->
     
        <component name="dosage" node="dosage">
  		    <property name="value" column="DOSAGE_QTY" type="java.lang.String" node="value"/>
        
 	        <!-- component name="unit" node="unit">
            <property name="code" column="Units" type="java.lang.String" node="code"/>
            <property name="codingSystem" type="java.lang.String" node="codingSystem">
               <formula>
                 (CASE
                     WHEN (Units IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_50'
                     ELSE NULL
                  END)
                </formula>  
            </property>
 		      </component-->
        </component>

		<!-- component name="route" node="route">
			<property name="code" column="RouteCode" type="java.lang.String" node="code"/>
			<property name="displayText" column="RouteDisplayText" type="java.lang.String" node="displayText"/>
			<property name="codingSystem" type="java.lang.String" node="codingSystem">
			   <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" node="schedule">
		    <property name="displayText" column="SCHEDULE_FREQUENCY" type="java.lang.String" node="displayText" />
		    <!-- property name="codingSystem" type="java.lang.String" node="codingSystem">
               <formula>
                 (CASE
                     WHEN (SCHEDULE IS NOT NULL) THEN VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_55.05_4'
                     ELSE NULL
                  END)
                </formula>  
            </property-->
		 </component>
	 
		 <component name="status" node="status">
			<!-- property name="code" type="java.lang.String" node="code">
		      <formula>
		          (CASE
		              WHEN (Status = 'DISCONTINUED') THEN '1'
		              WHEN (Status = 'DATE OF DEATH ENTERED') THEN '2'
		              ELSE ''
		           END)
		      </formula>
		    </property-->
			<property name="displayText" column="STATUS" type="java.lang.String" node="displayText"/>
			<!-- property name="codingSystem" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_51.2'" type="java.lang.String" node="codingSystem"/-->
		 </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" node="discontinueDate//literal"/>
		 
		 <component name="orderIdentifier" node="orderIdentifier">
			 <property name="identity" column="ORDER_NUMBER" type="big_decimal" node="identity"/>
			 <property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_55.05_7'" type="java.lang.String" node="namespaceId"/>
		 </component>
		 
		 <component name="documentedBy" node="documentedBy">
		    <property name="time" formula="STRING(DOCUMENTED_DATE,'^',(VISTA_HDSI.HDSREPSQLUtil1_StationNumber()))" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" node="time//literal"/>
			<component name="practitioner" node="practitioner">
				<component name="identifier" node="identifier">
					<property name="identity" column="DOCUMENTED_BY" type="big_decimal" node="identity"/>
					<property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="assigningFacility"/>
					<property name="assigningAuthority" formula="'USVHA'" type="java.lang.String" node="assigningAuthority"/>
				</component>
				<property name="idSourceTable" formula="'VistA200'" type="java.lang.String" node="idSourceTable"/>
			</component>		 
			<property name="name" column="DocumentedByNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" node="practitioner//name"/>
		 </component>
		 -->
		<component name="medication" node="medication">
			<component name="medicationCode" node="medicationCode">
				<!-- property name="code" column="MedicationCode" type="java.lang.String" node="code"/-->
				<property name="displayText" column="MEDICATION_NAME" type="java.lang.String" node="displayText"/>
				<property name="alternateDisplayText" column="GENERIC_MEDICATION_NAME" type="java.lang.String" node="alternateDisplayText"/>
				<!-- property name="codingSystem" type="java.lang.String" node="codingSystem">
				    <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" node="startDate//literal"/>
		
		<component name="orderLocationIdentifier" node="orderLocationIdentifier">
			<property name="pointOfCare" column="CLINICX" type="java.lang.String" node="pointOfCare"/>
			<property name="room" column="CLINIC" type="big_decimal" node="room"/>		
		</component>
		
		<component name="comments" node="comments">
			<property name="comment" column="COMMENTS7WP" type="java.lang.String" node="comment"/>
		</component>
		
		<property name="source" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" node="source"/>
		-->
		<component name="pharmacyOrderableItem" node="pharmacyOrderableItem">
			<!-- component name="itemCode" node="itemCode">
				<property name="code" column="ORDERABLE_ITEM" type="big_decimal" node="code"/>
				<property name="displayText" column="ORDERABLEITEMX" type="java.lang.String" node="displayText"/>
				<property name="codingSystem" type="java.lang.String" node="codingSystem">
				    <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" node="dosageFormCode">
				<!-- property name="code" column="DosageFormCode" type="java.lang.String" node="code"/-->
				<property name="displayText" column="MEDICATION_FORM" type="java.lang.String" node="displayText"/>
				<!-- property name="codingSystem" type="java.lang.String" node="codingSystem">
				     <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" node="disclaimers">
			<property name="disclaimer" column="DISCLAIMER1WP" type="java.lang.String" node="disclaimer"/>
		</component>
		
        <component name="recordSource" node="recordSource">
			<property name="namespaceId" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_55.05'" type="java.lang.String" node="namespaceId"/>
			<property name="universalId" column="DomainNameX" type="java.lang.String" node="universalId"/>
			<property name="universalIdType" formula="'DNS'" type="java.lang.String" node="universalIdType"/>
        </component>
                
    	<property name="StatusQuery" column="StatusQuery" type="java.lang.String" node="StatusQuery"/>
    	-->
    	<property name="StatusQuery" column="STATUS" type="java.lang.String" insert="false" update="false" node="StatusQuery"/>
		<property name="recordStatus" column="RECORD_STATUS" type="integer" insert="false" update="false" node="recordStatus" />
	

    </class>
    
    <query name="NonVAMedicationsRead3.NonVaMedicationEvent.patient">
        <![CDATA[
        from NonVAMedicationsRead3 nvm
        where nvm.pharmacyPatient.identifier.assigningFacility || '/' || nvm.pharmacyPatient.identifier.identity in ( :pids )
		and nvm.recordStatus = 0
      ]]>
    </query>
     
    <query name="NonVAMedicationsRead3.NonVaMedicationEvent.patient.status">
        <![CDATA[
        from NonVAMedicationsRead3 nvm
        where nvm.pharmacyPatient.identifier.assigningFacility || '/' || nvm.pharmacyPatient.identifier.identity in ( :pids )
        and nvm.StatusQuery in ( :status )
		and nvm.recordStatus = 0
      ]]>
    </query>

    <query name="NonVAMedicationsRead3.NonVaMedicationEvent.nonVaMedicationEvents.identifiers">
        <![CDATA[
        from NonVAMedicationsRead3 nvm
        where nvm.id in ( :recordIdentifiers )
		and nvm.recordStatus = 0
        ]]>
     </query>
  
</hibernate-mapping>
