<?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="intoleranceConditions" table="VISTA_HDSI.PATIENT_ALLERGIES_120_8_EXT" lazy="false"  name="gov.va.med.cds.template.generated.allergies.IntoleranceCondition">

        <id name="id" type="gov.va.med.cds.persistence.hibernate.common.VistaRowIdUserType">
            <column name="ROWID" />
            <generator class="assigned" />
        </id>
        
        <property name="id" column="ROWID" type="gov.va.med.cds.persistence.hibernate.common.VistaRowIdUserType" insert="false" update="false" />
        
        <component name="recordIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
            <property name="identity" column="ROWID" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType"  insert="false" update="false" />
            <property name="namespaceId" formula="NAMESPACEID||'_120.8'" type="java.lang.String" />
        </component>
        
        <property name="observationTime" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQuery" insert="false" update="false" >
		  <column name="ORIGINATION_DATETIME"/>
		  <column name="NAMESPACEID"/>
		</property>
       
        <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" column="PATIENT" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" not-null="true" insert="false" update="false" />
                <property name="assigningFacility" type="java.lang.String" column="DefaultInstitution" insert="false" update="false" />
                <property name="assigningAuthority" type="java.lang.String" formula="'USVHA'" />
            </component>
            <property name="name" column="PatientNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        </component>

        <component name="allergyType" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="ALLERGY_TYPE" type="java.lang.String" />
			<property name="displayText" column="ALLERGYTYPETEXT" type="java.lang.String"  />
			<property name="codingSystem" type="java.lang.String" >
        		<formula>
        		(CASE
				    WHEN (ALLERGY_TYPE IS NOT NULL OR ALLERGYTYPETEXT IS NOT NULL) THEN 'L'
				    ELSE NULL
				 END)
        		</formula>
        	</property>
		</component>

        <component name="gmrAllergyAgent" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElement">
			<property name="code" column="GmrAllergyAgentVuid" type="java.lang.String"  />
			<property name="displayText" column="GmrAllergyAgentDisplayText" type="java.lang.String"  />
			<property name="codingSystem" column="GmrAllergyAgentCodingSystem" type="java.lang.String"  />
			<property name="alternateCode" column="GmrAllergyAgentAlternateCode" type="java.lang.String" />
			<property name="alternateCodingSystem" column="GmrAllergyAgentAlternCodSys" type="java.lang.String"  />
		</component>

          <component name="agent" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="REACTANT" type="java.lang.String"  />
		</component>
		
       <component name="informationSourceCategory" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="ObservedHistoricalVuid" type="java.lang.String"  />
			<property name="displayText" column="OBSERVEDHISTORICALTEXT" type="java.lang.String"  />
			<property name="codingSystem" type="java.lang.String">
        		<formula>
        		(CASE
				    WHEN (ObservedHistoricalVuid IS NOT NULL OR OBSERVEDHISTORICALTEXT IS NOT NULL) THEN '99VA8985.1'
				    ELSE NULL
				 END)
        		</formula>
        	</property>
		</component>

        <component name="mechanism" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="MechanismVuid" type="java.lang.String"  />
			<property name="displayText" column="MECHANISMTEXT" type="java.lang.String"  />
			<property name="codingSystem" type="java.lang.String" >
        		<formula>
        		(CASE
				    WHEN (MechanismVuid IS NOT NULL OR MECHANISMTEXT IS NOT NULL) THEN '99VA8985.1'
				    ELSE NULL
				 END)
        		</formula>
        	</property>
		</component>

		<property name="verified" type="java.lang.String" >
        	<formula>
        		(CASE
				   	WHEN (VERIFIED = 1) THEN 'YES'
				    ELSE 'NO'
				 END)
        	</formula>
        </property>
        			
        <list name="reaction" fetch="subselect" batch-size="100">
            <key column="PATIENT_ALLERGIES" />
            <list-index column="CHILDSUB1" />
            <one-to-many entity-name="rdiReaction" />
        </list>
                         
        <component name="author" class="gov.va.med.cds.template.generated.common.PractitionerParticipationLite">
            <property name="time" formula="STRING(ORIGINATION_DATETIME,'^',NAMESPACEID)" 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">
            	<property name="name"  column="AuthorNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        	</component>
        </component>              			
 
         <list name="drugClass" fetch="subselect" batch-size="100">
            <key column="PATIENT_ALLERGIES" not-null="true" update="false"/>
            <list-index column="CHILDSUB1" />
            <one-to-many entity-name="rdiDrugClass" />
        </list> 
 
        <list name="drugIngredients" fetch="subselect" batch-size="100">
            <key column="PATIENT_ALLERGIES" not-null="true" update="false"/>
            <list-index column="CHILDSUB1" />
            <one-to-many entity-name="drugIngredient" />
        </list>
                       								       
        <component name="facilityIdentifier"  class="gov.va.med.cds.template.generated.basedatatypes.HL72OrganizationIdentifier">
		    <property name="name" column="OfficialVaName" type="java.lang.String"/>
		</component>
		
       <component name="severity"  class="gov.va.med.cds.template.generated.allergies.SeverityObservationEvent">
            <component name="value" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="SEVERITYX" type="java.lang.String" />
				<property name="displayText" type="java.lang.String" >
					<formula>
 					(CASE
					    WHEN ( SEVERITYX = '1' ) THEN 'MILD'
					    WHEN ( SEVERITYX = '2' ) THEN 'MODERATE'
					    WHEN ( SEVERITYX = '3' ) THEN 'SEVERE'					
					    ELSE NULL
					END )
        			</formula>
        		</property>
         		<property name="codingSystem" type="java.lang.String" >
				    <formula>
        			(CASE
				    	WHEN (SEVERITYX IS NOT NULL) THEN NULL
				    	ELSE NULL
				 	END)
        			</formula>
        		</property>
        	</component>
		</component>
		
        <property name="status" column="STATUS" type="java.lang.String"/>      
                        
    </class>

    <query name="RDIIntoleranceConditionPharmacyRead40010.IntoleranceCondition.intoleranceConditions">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
      ]]>
	</query>

    <query name="RDIIntoleranceConditionPharmacyRead40010.IntoleranceCondition.patient">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
      ]]>
 	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40010.IntoleranceCondition.intoleranceConditions.date">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ( (ic.observationTime.timestamp between :startDate and :endDate) or (ic.observationTime.timestamp is null)  )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40010.IntoleranceCondition.intoleranceConditions.identifiers">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ic.id in ( :recordIdentifiers )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40010.IntoleranceCondition.intoleranceConditions.patient.date">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ( (ic.observationTime.timestamp between :startDate and :endDate) or (ic.observationTime.timestamp is null)  )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40010.IntoleranceCondition.intoleranceConditions.patient.identifiers">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ic.id in ( :recordIdentifiers )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40011.IntoleranceCondition.intoleranceConditions">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
      ]]>
	</query>

    <query name="RDIIntoleranceConditionPharmacyRead40011.IntoleranceCondition.patient">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
      ]]>
 	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40011.IntoleranceCondition.intoleranceConditions.date">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ( (ic.observationTime.timestamp between :startDate and :endDate) or (ic.observationTime.timestamp is null)  )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40011.IntoleranceCondition.intoleranceConditions.identifiers">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ic.id in ( :recordIdentifiers )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40011.IntoleranceCondition.intoleranceConditions.patient.date">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ( (ic.observationTime.timestamp between :startDate and :endDate) or (ic.observationTime.timestamp is null)  )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40011.IntoleranceCondition.intoleranceConditions.patient.identifiers">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ic.id in ( :recordIdentifiers )
      ]]>
	</query>
    <query name="RDIIntoleranceConditionPharmacyRead40012.IntoleranceCondition.intoleranceConditions">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
      ]]>
	</query>

    <query name="RDIIntoleranceConditionPharmacyRead40012.IntoleranceCondition.patient">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
      ]]>
 	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40012.IntoleranceCondition.intoleranceConditions.date">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ( (ic.observationTime.timestamp between :startDate and :endDate) or (ic.observationTime.timestamp is null)  )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40012.IntoleranceCondition.intoleranceConditions.identifiers">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ic.id in ( :recordIdentifiers )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40012.IntoleranceCondition.intoleranceConditions.patient.date">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ( (ic.observationTime.timestamp between :startDate and :endDate) or (ic.observationTime.timestamp is null)  )
      ]]>
	</query>
	
    <query name="RDIIntoleranceConditionPharmacyRead40012.IntoleranceCondition.intoleranceConditions.patient.identifiers">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ic.id in ( :recordIdentifiers )
      ]]>
	</query>
    <query name="RDIAllergiesPharmacyRead40013.IntoleranceCondition.intoleranceConditions">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
      ]]>
	</query>

    <query name="RDIAllergiesPharmacyRead40013.IntoleranceCondition.patient">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
      ]]>
 	</query>
	
    <query name="RDIAllergiesPharmacyRead40013.IntoleranceCondition.intoleranceConditions.date">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ( (ic.observationTime.timestamp between :startDate and :endDate) or (ic.observationTime.timestamp is null)  )
      ]]>
	</query>
	
    <query name="RDIAllergiesPharmacyRead40013.IntoleranceCondition.intoleranceConditions.identifiers">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ic.id in ( :recordIdentifiers )
      ]]>
	</query>
	
    <query name="RDIAllergiesPharmacyRead40013.IntoleranceCondition.intoleranceConditions.patient.date">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ( (ic.observationTime.timestamp between :startDate and :endDate) or (ic.observationTime.timestamp is null)  )
      ]]>
	</query>
	
    <query name="RDIAllergiesPharmacyRead40013.IntoleranceCondition.intoleranceConditions.patient.identifiers">
		<![CDATA[
		from intoleranceConditions ic
		where ic.patient.identifier.identity in ( :pids )
		and ic.id in ( :recordIdentifiers )
      ]]>
	</query>						
</hibernate-mapping>
