<?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="all">
    <class table="DMP_RESPONSE" lazy="false" name="gov.va.med.cds.template.generated.surveys.DMPSurveyResponse" >
        <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"/>
 -->
 
<!-- <many-to-one name="surveyPatient" entity-name="surveyPatient" column="SURVEY_PATIENT_ID" unique="true"/> -->
<component name="surveyPatient" class="gov.va.med.cds.template.generated.surveys.DMPSurveyPatient">
	<!-- import from .../common/PatientLite.hbm -->
&patientLite;
	<property name="icn" column="ICN" type="java.lang.String"/>
</component>

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

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

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

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

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

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

		<property name="scheduledDate" column="SCHEDULED_DT" type="java.util.Date"/>

		<!-- 2013-01-09T07:46:00-05:00 from prod - user type strips ':' from timezone -->
		<property name="completedDate" column="COMPLETED_DT" type="java.util.Date"/>
		
        <property name="recordUpdateTime" type="gov.va.med.cds.persistence.hibernate.common.PointInTimeUserType"  >
           <column name="RECORD_CREATION_TM"/>
           <column name="RECORD_CREATION_TM_NBR"/>
        </property>
       	
		<property name="requestId" column="REQUEST_ID" type="java.lang.String"/>

        <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>
		
		<!--  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="survey" entity-name="survey" column="SURVEY_ID" unique="true"/>

        <!--  one-to-many sets -->
        <component name="surveyQuestionsAndAnswersWithScores" class="gov.va.med.cds.template.generated.surveys.DMPQuestionsAndAnswersWithScores">
			<list name="surveyQuestionAndAnswerWithScore" cascade="all">
				<key column="DMP_RESPONSE_ID" not-null="true" update="false" />
				<list-index column="LINE_NBR"  />
				<one-to-many entity-name="dmpSurveyAnswers"/>
			</list>
		</component>
				
    </class>

    <class entity-name="dmpSurveyAnswers" table="DMP_QUESTION_ANSWER" lazy="false" name="gov.va.med.cds.template.generated.surveys.DMPQuestionAndAnswerWithScore">
        <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="questionNumber" column="QUESTION" type="integer"/>
		<property name="answer" column="ANSWER" type="integer"/>
		<property name="score" column="SCORE" type="integer"/>
    </class>   
    
    <class entity-name="survey" table="SURVEY" lazy="false" name="gov.va.med.cds.template.generated.surveyscommon.Survey" >
        <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"/>

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

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