<?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="allergyAssessments" table="VISTA_HDSI.ADVERSE_REACTION_AS_120_86_EXT" name="gov.va.med.cds.template.generated.allergies.AllergyAssessment" >
    
        <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.86'" type="java.lang.String" />
        </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" column="NAME" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" not-null="true" insert="false" update="false" />
                <property name="assigningFacility" column="DefaultInstitution" type="java.lang.String" />
                <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>
     
        <property name="observationTime" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQuery" insert="false" update="false" >
		  <column name="ASSESSMENT_DATETIME"/>
		  <column name="NAMESPACEID"/>
		</property>
        
        <component name="assessmentValue" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
            <property name="code" column="ReactionAssessmentVuid" type="java.lang.String"  />
            <property name="displayText" column="ReactionAssessmentText" type="java.lang.String"  />
            <property name="codingSystem" type="java.lang.String" >
        		<formula>
        			(CASE
				   	 	WHEN (ReactionAssessmentVuid IS NOT NULL OR ReactionAssessmentText IS NOT NULL) THEN '99VA8985.1'
				    	ELSE NULL
				 	END)
        		</formula>
          </property>
        </component>
        
        <property name="status" formula="'F'" type="java.lang.String"/>

        <component name="author" class="gov.va.med.cds.template.generated.common.PractitionerParticipationLite">
        	<component name="practitioner" class="gov.va.med.cds.template.generated.common.PractitionerLite">
            	<property name="identifier"  formula="AuthorNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false"/>
            	<property name="name"  column="AuthorNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false"/>
        	</component>
        </component>

        <component name="recordSource" class="gov.va.med.cds.template.generated.basedatatypes.HL72FacilityIdentifier">
            <property name="universalId" column="DomainNameX" type="java.lang.String" />
            <property name="universalIdType" formula="'DNS'" type="java.lang.String"/>
        </component>
        
    </class>


    <query name="AllergyAssessmentRead40010.AllergyAssessment.patient">
		<![CDATA[
		from allergyAssessments aa
		where aa.patient.identifier.identity in ( :pids )
      ]]>
	</query>

	<query name="AllergyAssessmentRead40010.AllergyAssessment.patient.date">
		<![CDATA[
		from allergyAssessments aa
		where aa.patient.identifier.identity in ( :pids )
		and ( (aa.observationTime.timestamp between :startDate and :endDate) or (aa.observationTime.timestamp is null)  )
      ]]>
	</query>

    <query name="AllergyAssessmentRead40010.AllergyAssessment.patient.identifiers">
		<![CDATA[
		from allergyAssessments aa
		where aa.patient.identifier.identity in ( :pids ) and
		aa.id in ( :recordIdentifiers )
      ]]>
	</query> 

    <query name="RDIAllergiesPharmacyRead40013.AllergyAssessment.patient">
		<![CDATA[
		from allergyAssessments aa
		where aa.patient.identifier.identity in ( :pids )
      ]]>
	</query>

	<query name="RDIAllergiesPharmacyRead40013.AllergyAssessment.patient.date">
		<![CDATA[
		from allergyAssessments aa
		where aa.patient.identifier.identity in ( :pids )
		and ( (aa.observationTime.timestamp between :startDate and :endDate) or (aa.observationTime.timestamp is null)  )
      ]]>
	</query>

    <query name="RDIAllergiesPharmacyRead40013.AllergyAssessment.patient.identifiers">
		<![CDATA[
		from allergyAssessments aa
		where aa.patient.identifier.identity in ( :pids ) and
		aa.id in ( :recordIdentifiers )
      ]]>
	</query> 
</hibernate-mapping>
