<?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 name="gov.va.med.cds.template.generated.vitalsigns.VitalSignObservationEvent" table="VISTA_HDSI.GMRV_VITAL_MEASUREMT_120_5_EXT" lazy="false" >
		<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" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false">
				<column name="RowId"/>
			</property>
			<property name="namespaceId" column="NamespaceId||'_120.5'" type="java.lang.String" insert="false" update="false"  />
		</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" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType" insert="false" update="false">
					<column name="PATIENT"/>
				</property>
				<property name="assigningFacility" column="NamespaceId"  type="java.lang.String" insert="false" update="false" not-null="true" />
				<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>

		<property name="observationTime" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserTypeQuery" insert="false" update="false" >
			<column name="DATETIME_VITALS_TAKEN" />
			<column name="NAMESPACEID" />
		</property>

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

		<property name="collectionSessionTime" formula="STRING(DATETIME_VITALS_ENTERED,'^',NAMESPACEID)" type="gov.va.med.cds.persistence.hibernate.common.VistaPointInTimeUserType" insert="false" update="false" />

		<property name="status" column="Status" type="java.lang.String" />

		<property name="supplementalOxygen" column="SUPPLEMENTAL_O2||'^'||UOM" type="gov.va.med.cds.persistence.hibernate.common.SupplementalOxygenUserType" insert="false" update="false" />

		<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="errorEnterer" 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="ErrorEntererNE||'^'||NAMESPACEID" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonIdentifierUserType" insert="false" update="false" />
				<property name="name" column="ErrorEntererNE" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType" insert="false" update="false" />
			</component>
		</component>
 
		<component name="hospitalLocationIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72LocationIdentifier">
			<property name="pointOfCare" column="HospitalLocationAbbreviation" type="java.lang.String"  />
			<property name="room" column="HOSPITAL_LOCATION" type="java.lang.String" />
			<property name="locationDescription" column="HOSPITALLOCATIONX" type="java.lang.String"  />
		</component>

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

		<component name="orderingFacilityIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72OrganizationIdentifier">
			<property name="name" column="HospitalLocationInstitutionX" type="java.lang.String" node="name" />
		</component>

		<component name="stopCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
			<property name="code" column="StopCode" type="java.lang.String" node="code" />
			<property name="displayText" column="StopCodeNumberX" type="java.lang.String" node="displayText" />
		</component>

		<component name="vitalSignObservation" class="gov.va.med.cds.template.generated.vitalsigns.VitalSignObservation">
			<property name="value" column="RATE" type="java.lang.String" />
			<component name="unit" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementLite">
				<property name="code" column="UOM" type="java.lang.String" node="code" insert="false" update="false" />
				<property name="displayText" column="UOM" type="java.lang.String" node="displayText" insert="false" update="false" />
			</component>
		</component>

		<component name="recordSource" class="gov.va.med.cds.template.generated.basedatatypes.HL72FacilityIdentifier">
			<property name="namespaceId" column="NamespaceId" 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>

	</class>

	<!-- Vitals Named Queries HQL -->

	<!-- <query name="VitalsignsRead40010.VitalSignObservationEvent.patient"> -->
	<query name="VitalsignsRead40010.VitalSignObservationEvent.vitalSignObservationEvents">
		<![CDATA[
		from VitalSignObservationEvent vital
		where vital.patient.identifier.identity in ( :pids )
		]]>
	</query>

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

</hibernate-mapping>