<?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">
]
>
<hibernate-mapping default-lazy="false" default-cascade="all">
	<class entity-name="LabTestPromise" table="LAB_TEST_PRM_V" lazy="false" name="gov.va.med.cds.template.generated.lab.LabTestPromise" >
		<id type="java.lang.Long">
			<column name="LAB_TEST_PRM_ID" />
			<generator class="sequence">
				<param name="sequence">lab_test_prm_seq_id</param>
			</generator>
		</id>

		<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>

		<!-- import from .../common/PatientLite.hbm -->
		&patientLite;

		<property name="reportCompleteDate" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType">
			<column name="REPORT_COMPLETE_DT" />
			<column name="REPORT_COMPLETE_DT_NBR" />
		</property>

		<property name="labSubscript" column="LAB_SUBSCRIPT" type="java.lang.String" />

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

		<list name="labCommentEvents" fetch="subselect" batch-size="100">
			<key column="LAB_TEST_PRM_ID" not-null="true" update="false" />
			<list-index column="LINE_NBR" />
			<one-to-many entity-name="LabTestComments" />
		</list>

		<!-- associated class LabTestRequest -->
		<component name="labTestRequest" class="gov.va.med.cds.template.generated.lab.LabTestRequest">
			<component name="author" class="gov.va.med.cds.template.generated.common.PractitionerLite">
				<component name="identifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonIdentifier">
					<property name="identity" column="AUTH_PERSON_IDENTITY" type="java.lang.String" />
					<property name="assigningFacility" column="AUTH_PERSON_ASGNING_FACILITY" type="java.lang.String" />
					<property name="assigningAuthority" column="AUTH_PERSON_ASGNING_AUTHORITY" type="java.lang.String" />
				</component>
				<property name="idSourceTable" column="AUTH_PRACTITIONER_ID_SRC_TBL" type="java.lang.String"/>
				<component name="name" class="gov.va.med.cds.template.generated.basedatatypes.HL72PersonName">
					<property name="prefix" column="AUTH_NAME_PREFIX" type="java.lang.String" />
					<property name="given" column="AUTH_NAME_GIVEN" type="java.lang.String" />
					<property name="middle" column="AUTH_NAME_MIDDLE" type="java.lang.String" />
					<property name="family" column="AUTH_NAME_FAMILY" type="java.lang.String" />
					<property name="suffix" column="AUTH_NAME_SUFFIX" type="java.lang.String" />
					<property name="title" column="AUTH_NAME_TITLE" type="java.lang.String" />
				</component>
			</component>
		
			<component name="orderingFacilityIdentifier" class="gov.va.med.cds.template.generated.basedatatypes.HL72OrganizationIdentifierExtended">
				<property name="identity" column="ORD_FCLTY_IDENTITY" type="java.lang.String" />
				<property name="name" column="ORD_FCLTY_NAME" type="java.lang.String" />
				<property name="assigningAuthority" column="ORD_FCLTY_ASSIGNING_AUTHORITY" type="java.lang.String" />
				<property name="nameTypeCode" column="ORD_FCLTY_NAME_TYP_CODE" type="java.lang.String" />
				<property name="identityTypeCode" column="ORD_FCLTY_IDENTITY_TYP_CODE" type="java.lang.String" />
				<property name="nameRepresentation" column="ORD_FCLTY_NAME_REP" type="java.lang.String" />
				<property name="stationNumber" column="ORD_FCLTY_STATION_NUMBER" type="java.lang.String" />
			</component>
		</component>

		<component name="specimen" class="gov.va.med.cds.template.generated.lab.Specimen">
			<component name="specimenSource" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElementExtended">
				<property name="code" column="SPECIMEN_SRC_CODE" type="java.lang.String" />
				<property name="displayText" column="SPECIMEN_SRC_DSPLYTXT" type="java.lang.String" />
				<property name="codingSystem" column="SPECIMEN_SRC_CODSYS" type="java.lang.String" />
				<property name="codingSystemVersion" column="SPECIMEN_SRC_CODSYS_VER" type="java.lang.String" />
				<property name="alternateCode" column="SPECIMEN_SRC_ALT_CODE" type="java.lang.String" />
				<property name="alternateDisplayText" column="SPECIMEN_SRC_ALT_DSPLYTXT" type="java.lang.String" />
				<property name="alternateCodingSystem" column="SPECIMEN_SRC_ALT_CODSYS" type="java.lang.String" />
				<property name="alternateCodingSystemVersion" column="SPECIMEN_SRC_ALT_CODSYS_VER" type="java.lang.String" />
				<property name="originalText" column="SPECIMEN_SRC_ORIG_TXT" type="java.lang.String" />
			</component>
			<property name="specimenTakenDate" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType">
				<column name="SPECIMEN_TAKEN_DT" />
				<column name="SPECIMEN_TAKEN_DT_NBR" />
			</property>
		</component>

		<list name="labTests" cascade="all" fetch="subselect" batch-size="100">
			<key column="LAB_TEST_PRM_ID" not-null="true" update="false" />
			<list-index column="LINE_NBR" />
			<one-to-many entity-name="LabTest" />
		</list>

		<component name="recordSource" class="gov.va.med.cds.template.generated.basedatatypes.HL72FacilityIdentifier">
			<property name="namespaceId" column="RECORDSOURCE_NAMESPACEID" type="java.lang.String" />
			<property name="universalId" column="RECORDSOURCE_UNIVERSALID" type="java.lang.String" />
			<property name="universalIdType" column="RECORDSOURCE_UNIVERSTYP" type="java.lang.String" />
		</component>

		<property name="recordVersion" column="RECORD_VERSION" type="integer" />

		<property name="recordUpdateTime" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType">
			<column name="RECORD_UPDATE_TM" />
			<column name="RECORD_UPDATE_TM_NBR" />
		</property>
	</class>

	<class entity-name="LabTestComments" table="LAB_COMMENT_EVENT_V" lazy="false" name="gov.va.med.cds.template.generated.lab.LabCommentEvent">
		<id type="java.lang.Long">
			<column name="LAB_COMMENT_EVENT_ID" />
			<generator class="sequence">
				<param name="sequence">LAB_COMMENT_EVENT_SEQ_ID</param>
			</generator>
		</id>

		<list name="comments" cascade="all" table="LAB_COMMENT_V" fetch="subselect" batch-size="100">
			<key column="LAB_COMMENT_EVENT_ID" not-null="true" update="false"/>
			<list-index column="LINE_NBR" />
			<element type="string" column="COMMENT_TXT" />
		</list>

	</class>

	<query name="MHVLabRead40011.LabTestPromise.patient">
		<![CDATA[
		from LabTestPromise ltp
		where ltp.patient.identifier.assigningFacility || '/' || ltp.patient.identifier.identity in ( :pids )
      ]]>
	</query>

	<query name="MHVLabRead40011.LabTestPromise.patient.date">
		<![CDATA[
		from LabTestPromise ltp
		where ltp.patient.identifier.assigningFacility || '/' || ltp.patient.identifier.identity in ( :pids )
		and ( ltp.specimen.specimenTakenDate.numeric between :startDate and :endDate or ltp.specimen.specimenTakenDate.numeric is null )
      ]]>
	</query>

	<query name="MHVLabRead40011.LabTestPromise.patient.identifiers">
		<![CDATA[
		from LabTestPromise ltp
		where ltp.patient.identifier.assigningFacility || '/' || ltp.patient.identifier.identity in ( :pids ) and
		ltp.recordIdentifier.identity || '/' || ltp.recordIdentifier.namespaceId || '/' ||
		ltp.recordIdentifier.universalId || '/' || ltp.recordIdentifier.universalIdType in ( :recordIdentifiers )
      ]]>
	</query>

</hibernate-mapping>
