<?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="none">
    <class entity-name="dmpSurveyResponseWithScore" table="DMP_RESPONSE" lazy="false">
        <id type="java.lang.Long" name="id">
            <column name="DMP_RESPONSE_ID"/>
            <generator class="sequence" >
				<param name="sequence">dmp_response_seq_id</param>
			</generator>
        </id>
        
<!-- 
x			<xs:element name="xmlVersion" type="xs:string"/>
x			<xs:element name="patient" type="common:PatientLite"/>
x			<xs:element name="icn" type="xs:string" minOccurs="0"/>
x			<xs:element name="vendorMRN" type="xs:string"/>
x			<xs:element name="facility" type="surveys:Facility"/>
x			<xs:element name="vendor" type="surveys:Vendor"/>
x			<xs:element name="survey" type="surveys:Survey"/>
x			<xs:element name="scheduledDate" type="xs:date" nillable="true" minOccurs="0"/>
x			<xs:element name="completedDate" type="xs:dateTime"/>
x			<xs:element name="programName" type="xs:string" minOccurs="0"/>
x			<xs:element name="deviceName" type="xs:string" minOccurs="0"/>
x			<xs:element name="responseStatus" type="surveys:DMPResponseStatus"/>
x			<xs:element name="recordSource" type="basedatatypes:HL72FacilityIdentifier"/>
x			<xs:element name="recordUpdateTime" type="basedatatypes:PointInTime"/>
 -->
 
<!-- import from .../common/PatientLite.hbm -->
&patientLite;


		<property name="xmlVersion" column="XML_VERSION" type="java.lang.String" node="xmlVersion"/>

		<property name="icn" column="ICN" type="java.lang.String" node="icn"/>

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

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

		<property name="responseStatus" column="RESPONSE_STATUS" type="java.lang.String" node="responseStatus"/>

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

		<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>
		
        <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" node="vendor"/>

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

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


        <!--  one-to-many sets -->
		<list name="dmpSurveyQuestionsAndAnswersList" cascade="all" node="surveyQuestionsAndAnswers" collection-type="gov.va.med.cds.persistence.hibernate.common.Dom4JAbleListType">
			<key column="DMP_RESPONSE_ID" not-null="true" update="false" />
			<list-index column="LINE_NBR"  />
			<one-to-many entity-name="dmpSurveyAnswers" node="surveyQuestionAndAnswerWithScore" embed-xml="true" />
		</list>
    </class>


    <class entity-name="dmpSurveyAnswers" table="DMP_QUESTION_ANSWER" lazy="false">
        <id type="java.lang.Long" name="id">
            <column name="DMP_QUESTION_ANSWER_ID"/>
            <generator class="sequence" >
				<param name="sequence">dmp_question_answer_seq_id</param>
			</generator>
        </id>

		<property name="question" column="QUESTION" type="integer" node="questionNumber" />

		<property name="answer" column="ANSWER" type="integer" node="answer" />

		<property name="score" column="SCORE" type="integer" node="score" />
    </class>
    
    
    <class entity-name="survey" table="SURVEY" lazy="false">
        <id type="java.lang.Long" name="id">
            <column name="SURVEY_ID"/>
            <generator class="sequence" >
				<param name="sequence">survey_seq_id</param>
			</generator>
        </id>

		<property name="surveyTitle" column="TITLE" type="java.lang.String" node="title"/>

		<property name="surveyVersion" column="VERSION" type="java.lang.String" node="version"/>

		<property name="surveyType" column="TYPE" type="java.lang.String" node="type"/>
    </class>
	
</hibernate-mapping>
