<?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/PatientLite.hbm">
]
>
<!-- cascade="all|none|save-update|delete|all-delete-orphan"  -->

<hibernate-mapping default-lazy="false" default-cascade="save-update">
    <class entity-name="adlSurveyResponse" table="SURVEY_RESPONSE" lazy="false">
        <id type="java.lang.Long" name="id">
            <column name="SURVEY_RESPONSE_ID"/>
            <generator class="sequence" >
				<param name="sequence">survey_response_seq_id</param>
			</generator>
        </id>

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


		<property name="programName" column="PROGRAM_NAME" type="java.lang.String" node="programName"/>

		<property name="surveyAcceptedStatus" column="SURVEY_ACCEPTED_STATUS" type="java.lang.String" node="surveyAcceptedStatus"/>

		<property name="vendorMrn" column="VENDOR_MRN" type="java.lang.String" node="vendorMRN"/>

		<property name="deviceName" column="DEVICE_NAME" type="java.lang.String" node="deviceName"/>

		<property name="currentDialogName" column="CURRENT_DIALOG_NAME" type="java.lang.String" node="currentDialogueName"/>

        <component name="surveyScores" node="surveyScores">
			<property name="mentalScore" column="MENTAL_SCORE" type="double" node="mentalScore"/>
			<property name="physicalScore" column="PHYSICAL_SCORE" type="double" node="physicalScore"/>
         </component>	
 
		<property name="scheduledDate" node="scheduledDate">
			<column name="SCHEDULED_DT"/>
			<type name="gov.va.med.cds.persistence.hibernate.common.Dom4jDateUserType">
				<param name="dateFormat">yyyy-MM-dd</param>
				<param name="nodeName">scheduledDate</param>
			</type>
		</property>

		<!-- 2013-01-09T07:46:00-05:00 from prod - user type strips ':' from timezone -->
		<property name="completedDate" node="completedDate">
			<column name="COMPLETED_DT"/>
			<type name="gov.va.med.cds.persistence.hibernate.common.Dom4jDateUserType">
				<param name="dateFormat">yyyy-MM-dd'T'HH:mm:ssZZ</param>
				<param name="nodeName">completedDate</param>
			</type>
		</property>
		
		<property name="disenrollmentDate" node="disenrollmentDate">
			<column name="DISENRMENT_DT"/>
			<type name="gov.va.med.cds.persistence.hibernate.common.Dom4jDateUserType">
				<param name="dateFormat">yyyy-MM-dd</param>
				<param name="nodeName">disenrollmentDate</param>
			</type>
		</property>

		<property name="inactivationDate" node="inactivationDate">
			<column name="INACTIVATION_DT"/>
			<type name="gov.va.med.cds.persistence.hibernate.common.Dom4jDateUserType">
				<param name="dateFormat">yyyy-MM-dd</param>
				<param name="nodeName">inactivationDate</param>
			</type>
		</property>

		<property name="enrollmentDate" node="enrollmentDate">
			<column name="ENROLLMENT_DT"/>
			<type name="gov.va.med.cds.persistence.hibernate.common.Dom4jDateUserType">
				<param name="dateFormat">yyyy-MM-dd</param>
				<param name="nodeName">enrollmentDate</param>
			</type>
		</property>

		<property name="activationDate" node="activationDate">
			<column name="ACTIVATION_DT"/>
			<type name="gov.va.med.cds.persistence.hibernate.common.Dom4jDateUserType">
				<param name="dateFormat">yyyy-MM-dd</param>
				<param name="nodeName">activationDate</param>
			</type>
		</property>
		
        <component name="recordUpdateTime" node="recordUpdateTime">
          <property name="literal" type="gov.va.med.cds.persistence.hibernate.common.Dom4jPointInTimeUserType" node="literal" >
            <column name="RECORD_CREATION_TM"/>
            <column name="RECORD_CREATION_TM_NBR"/>
          </property>
        </component>	

		<property name="requestId" column="REQUEST_ID" type="java.lang.String" node="requestId" />

        <component name="recordSource" node="recordSource">
			<property name="namespaceId" column="RECORDSOURCE_NAMESPACEID" type="java.lang.String" node="namespaceId" />
			<property name="universalId" column="RECORDSOURCE_UNIVERSALID" type="java.lang.String" node="universalId" />
			<property name="universalIdType" column="RECORDSOURCE_UNIVERSTYP" type="java.lang.String" node="universalIdType" />
		</component>
		

		<!--  one-to-one relationships (use many to one when parent and child primary key are different-->

		<many-to-one name="vendor" entity-name="vendor" column="VENDOR_ID" unique="true"/>

		<many-to-one name="facility" entity-name="facility" column="FACILITY_ID" unique="true"/>

		<many-to-one name="surveyPatient" entity-name="surveyPatient" column="SURVEY_PATIENT_ID" unique="true"/>

		<many-to-one name="careCoordinator" entity-name="careCoordinator" column="CARE_COORDINATOR_ID" unique="true"/>

		<many-to-one name="survey" entity-name="survey" column="SURVEY_ID" unique="true"/>

		<list name="adlSurveyQuestionsAndAnswersList" cascade="all" node="adlSurveyQuestionsAndAnswers" collection-type="gov.va.med.cds.persistence.hibernate.common.Dom4JAbleListType">
			<key column="SURVEY_RESPONSE_ID" not-null="true" update="false" />
			<list-index column="LINE_NBR"  />
			<one-to-many entity-name="SurveyQuestionsAndAnswers" node="adlSurveyQuestionAndAnswer" embed-xml="true" />
		</list> 
		  
    </class>
    
</hibernate-mapping>
