<?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"
[
<!ENTITY patientLite SYSTEM 	"classpath://gov/va/med/cds/persistence/hibernate/common/PatientLitePojo.hbm">
<!ENTITY author SYSTEM 			"classpath://gov/va/med/cds/persistence/hibernate/common/AuthorPractitionerParticipationPojo.hbm">
]
>

<hibernate-mapping default-lazy="false" default-cascade="all">
    <class entity-name="allergyAssessments" name="gov.va.med.cds.template.generated.allergies.AllergyAssessment" table="ALLERGY_ASSESSMENT_V" lazy="false"  >
        <id name="id" type="java.lang.Long">
            <column name="ALLERGY_ASSESSMENT_ID" />
            <generator class="sequence" >
				<param name="sequence">allergy_assessment_seq_id</param>
			</generator>
        </id>
        
<!-- import from .../common/PatientLite.hbm -->
&patientLite;

 		<property name="requestId" column="REQUEST_ID" type="java.lang.String"/>
 		        
        <component name="recordIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72EntityIdentifier">
            <property name="identity" column="RECORDIDENTIFIER_IDENTITY" type="java.lang.String"  />
            <property name="namespaceId" column="RECORDIDENTIFIER_NAMESPACEID" type="java.lang.String"  />
            <property name="universalId" column="RECORDIDENTIFIER_UNIVERSALID" type="java.lang.String"  />
            <property name="universalIdType" column="RECORDIDENTIFIER_UNIVERSTYP" type="java.lang.String"  />
        </component>

         <property name="observationTime" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType" >
             <column name="ALGYASMT_OBSERVATION_TM"/>
            <column name="ALGYASMT_OBSERVATION_TM_NBR"/>
        </property>
        
        <component name="assessmentValue"  class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="ASSESSMENT_VAL_CODE" type="java.lang.String"/>
			<property name="displayText" column="ASSESSMENT_VAL_DSPLYTXT" type="java.lang.String" />
			<property name="codingSystem" column="ASSESSMENT_VAL_CODSYS" type="java.lang.String" />
		</component>
		
    </class>

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

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

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

