<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
	version="1.0">
	<description>Inventory</description>
	<mapped-superclass class="gov.va.med.ccht.model.Attachment" access="FIELD">
		<attributes>
			<basic name="date">
				<column name="ATTACHED_DATE" />
			</basic>
			<basic name="documentName">
				<column name="DOCUMENT_NAME" />
			</basic>			
			<many-to-one name="documentType"
				target-entity="gov.va.med.ccht.model.terminology.DocumentType">
				<join-column name="DOCUMENT_TYPE_ID" />
			</many-to-one>
		</attributes>
	</mapped-superclass>
	<!--
		VISN, Facility, Patient, Device, Vendor and Census related data
		objects
	-->

	<entity class="gov.va.med.ccht.model.inventory.SimpleVisn" access="FIELD"
		name="SimpleVisn">
		<table schema="dbo" name="VISN" />

		<attribute-override name="id">
			<column name="VISN_ID" />
		</attribute-override>
		<attributes>
			<basic name="name">
				<column name="VISN_NAME" />
			</basic>
		</attributes>
	</entity>
	
	<entity class="gov.va.med.ccht.model.inventory.Visn" access="FIELD"
		name="Visn">
		<table schema="dbo" name="VISN" />

		<attribute-override name="id">
			<column name="VISN_ID" />
		</attribute-override>
		<attributes>
			<basic name="name">
				<column name="VISN_NAME" />
			</basic>
			<one-to-many name="facilities"
				target-entity="gov.va.med.ccht.model.inventory.Facility" mapped-by="visn"
				fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.inventory.Facility" access="FIELD"
		name="Facility">
		<table schema="dbo" name="FACILITIES" />
		<attributes>
			<basic name="name">
				<column name="FACILITY_NAME" />
			</basic>
			<basic name="stationNumber">
				<column name="FACILITY_ID" />
			</basic>			 
			<many-to-one name="visn" target-entity="gov.va.med.ccht.model.inventory.Visn">
				<join-column name="VISN_ID" />
			</many-to-one>			
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.inventory.SimpleFacility" access="FIELD"
		name="SimpleFacility">
		<table schema="dbo" name="FACILITIES" />
		<attributes>
			<basic name="name">
				<column name="FACILITY_NAME" />
			</basic>
			<basic name="stationNumber">
				<column name="FACILITY_ID" />
			</basic>			 
			<many-to-one name="visn" target-entity="gov.va.med.ccht.model.inventory.SimpleVisn">
				<join-column name="VISN_ID" />
			</many-to-one>			
		</attributes>
	</entity>
	
	<entity class="gov.va.med.ccht.model.inventory.Vendor" access="FIELD"
		name="Vendor">
		<table schema="dbo" name="VENDOR" />
		<attribute-override name="id">
			<column name="VENDOR_ID" />
		</attribute-override>
		<attributes>
			<basic name="name">
				<column name="vendor_name" />
			</basic>
			<basic name="number">
				<column name="vendor_number" />
			</basic>
			<basic name="email_to">
				<column name="vendor_email_to" />
			</basic>
			<basic name="email_cc">
				<column name="vendor_email_cc" />
			</basic>
			<basic name="dateActive">
				<column name="date_active" />
			</basic>
			<basic name="dateInactive">
				<column name="date_inactive" />
			</basic>
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.inventory.Device" access="FIELD"
		name="Device">
		<table schema="dbo" name="DEVICE" />
		<attribute-override name="id">
			<column name="DEVICE_ID" />
		</attribute-override>
		<attributes>
			<basic name="deviceName">
				<column name="DEVICE_NAME" />
			</basic>
			<basic name="deviceVersion">
				<column name="DEVICE_VERSION" />
			</basic>
			<many-to-one name="vendor"
				target-entity="gov.va.med.ccht.model.inventory.Vendor">
				<join-column name="VENDOR_ID" />
			</many-to-one>
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.inventory.Patient" access="FIELD"
		name="Patient">
		<table schema="dbo" name="PATIENT" />
		<attribute-override name="id">
			<column name="PATIENT_ID" />
		</attribute-override>
		<attributes>
			<basic name="first_name">
				<column name="encryptname_first" />
			</basic>
			<basic name="last_name">
				<column name="encryptname_last" />
			</basic>
			<basic name="middle_name">
				<column name="encryptname_mi" />
			</basic>
			<basic name="ssn">
				<column name="encryptpatient_ssn" />
			</basic>
			<basic name="icn">
				<column name="encryptpatient_icn" />
			</basic>
			<basic name="dateOfBirth">
				<column name="encryptpatient_dob" />
			</basic>
			<basic name="rurality">
				<column name="rurality" />
			</basic>
		</attributes>
	</entity>
	
	<entity class="gov.va.med.ccht.model.inventory.DeviceType"
		access="FIELD" name="DeviceType">
		<table schema="dbo" name="MEDICAL_DEVICE_MODEL_TYPE" />
		<attributes>
			<many-to-one name="vendor"
				target-entity="gov.va.med.ccht.model.inventory.Vendor">
				<join-column name="VENDOR_ID" />
			</many-to-one>		
		</attributes>
	</entity>
		
	<entity class="gov.va.med.ccht.model.inventory.DeviceStatusType"
		access="FIELD" name="DeviceStatusType">
		<table schema="dbo" name="MEDICAL_DEVICE_STATUS_TYPE" />
	</entity>
	<entity class="gov.va.med.ccht.model.inventory.DeviceDecommissionReason"
		access="FIELD" name="DeviceDecommissionReason">
		<table schema="dbo" name="MEDICAL_DEVICE_DECOM_REASON" />
	</entity>
	<entity class="gov.va.med.ccht.model.inventory.DeviceRepairType"
		access="FIELD" name="DeviceRepairType">
		<table schema="dbo" name="MEDICAL_DEVICE_REPAIR_TYPE" />
	</entity>
	
	
	<entity class="gov.va.med.ccht.model.inventory.DeviceDetail" access="FIELD"
		name="DeviceDetail">
		<table schema="dbo" name="MEDICAL_DEVICE_DETAIL" />
		<attribute-override name="id">
			<column name="MED_DVC_DETAIL_ID" />
		</attribute-override>
		<attributes>
			<basic name="serialNumber">
				<column name="SERIAL_NUMBER" />
			</basic>
			<basic name="eeNumber">
				<column name="EE_NUMBER" />
			</basic>
			<basic name="purchaseOrderNumber">
				<column name="PURCHASE_ORDER_NBR" />
			</basic>
			<basic name="dateOfPurchase">
				<column name="DATE_OF_PURCHASE" />
			</basic>
			<basic name="warrantyFromDate">
				<column name="WARRANTY_FROM_DATE" />
			</basic>
			<basic name="warrantyToDate">
				<column name="WARRANTY_TO_DATE" />
			</basic>	
			<basic name="multiPatientUsage">
				<column name="MULT_PATIENT_USAGE_FLAG" />
			</basic>	
			<basic name="lastActiveDate">
				<column name="DATE_LAST_ACTIVE" />
			</basic>																
			<many-to-one name="facility"
				target-entity="gov.va.med.ccht.model.inventory.SimpleFacility">
				<join-column name="FACILITIES_ID" />
			</many-to-one>
			<many-to-one name="deviceType"
				target-entity="gov.va.med.ccht.model.inventory.DeviceType">
				<join-column name="MED_DVC_MODEL_TYPE_ID" />
			</many-to-one>			
			<many-to-one name="deviceDecommissionReason"
				target-entity="gov.va.med.ccht.model.inventory.DeviceDecommissionReason">
				<join-column name="MED_DVC_DECOM_RSN_ID" />
			</many-to-one>
			<one-to-many name="internalDeviceStatuses" target-entity="gov.va.med.ccht.model.inventory.DeviceStatus"
				mapped-by="deviceDetail" fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>	
			<one-to-many name="deviceStatusHistory" target-entity="gov.va.med.ccht.model.inventory.DeviceStatusHistory"
				mapped-by="deviceDetail" fetch="EAGER" >				
			</one-to-many>	
			<one-to-many name="internalPatientDevices" target-entity="gov.va.med.ccht.model.inventory.PatientDevice"
				mapped-by="deviceDetail" fetch="EAGER" >				
			</one-to-many>							
		</attributes>
	</entity>
	
	<entity class="gov.va.med.ccht.model.inventory.PatientDevice" access="FIELD"
		name="PatientDevice">
		<table schema="dbo" name="PATIENT_DEVICE" />
		<attribute-override name="id">
			<column name="PATIENT_DEVICE_ID" />
		</attribute-override>
		<attributes>		
			<basic name="dateFirstUsed">
				<column name="DATE_FIRST_USED" />
			</basic>
			<basic name="dateLastUsed">
				<column name="DATE_LAST_USED" />
			</basic>
			<basic name="signedConsent">
				<column name="SIGNED_CONSENT_FLAG" />
			</basic>
			<basic name="completedTraining">
				<column name="COMPLETED_TRAiNING_FLAG" />
			</basic>
			<basic name="validatedSkills">
				<column name="VALIDATED_SKILLS_FLAG" />
			</basic>
			<basic name="reviewedEquipmentPolicy">
				<column name="REVD_EQUIP_POLICY_FLAG" />
			</basic>
			<basic name="reviewedSafetySheet">
				<column name="REVD_SAFETY_SHEET_FLAG" />
			</basic>
			<basic name="disenrolled">
				<column name="DISENROLL_FR_PGM_FLAG" />
			</basic>
			<basic name="disenrollmentDate">
				<column name="DISENROLLED_DATE" />
			</basic>
			<basic name="enrollmentDate">
				<column name="ENROLLMENT_DATE" />
			</basic><!--																																				
			<many-to-one name="patient"
				target-entity="gov.va.med.ccht.model.inventory.Patient">
				<join-column name="PATIENT_ID" />
			</many-to-one>
			--><many-to-one name="deviceDetail"
				target-entity="gov.va.med.ccht.model.inventory.DeviceDetail">
				<join-column name="MED_DVC_DETAIL_ID" />
			</many-to-one>
			<many-to-one name="careCoordinator"
				target-entity="gov.va.med.ccht.model.SimpleUser">
				<join-column name="CARE_COORDINATOR_ID" />
			</many-to-one>						
		</attributes>
	</entity>
				
	<entity class="gov.va.med.ccht.model.inventory.DeviceStatus" access="FIELD"
		name="DeviceStatus">
		<table schema="dbo" name="MEDICAL_DEVICE_STATUS" />
		<attribute-override name="id">
			<column name="MED_DVC_STATUS_ID" />
		</attribute-override>				
		<attributes>
			<basic name="statusChangeDate">
					<column name="STATUS_CHANGE_DATE" />
			</basic>		
			<many-to-one name="deviceDetail" target-entity="gov.va.med.ccht.model.inventory.DeviceDetail">
				<join-column name="MED_DVC_DETAIL_ID" />
			</many-to-one>
			<many-to-one name="deviceStatusType" target-entity="gov.va.med.ccht.model.inventory.DeviceStatusType">
				<join-column name="MED_DVC_STATUS_TYPE_ID" />
			</many-to-one>			
		</attributes>
	</entity>
	
	<entity class="gov.va.med.ccht.model.inventory.DeviceStatusHistory" access="FIELD"
		name="DeviceStatusHistory">
		<table schema="dbo" name="MEDICAL_DEVICE_STATUS_H" />
		<attribute-override name="id">
			<column name="MED_DVC_STATUS_H_ID" />
		</attribute-override>				
		<attributes>
			<basic name="statusChangeDate">
					<column name="STATUS_CHANGE_DATE" />
			</basic>		
			<many-to-one name="deviceDetail" target-entity="gov.va.med.ccht.model.inventory.DeviceDetail">
				<join-column name="MED_DVC_DETAIL_ID" />
			</many-to-one>
			<many-to-one name="deviceStatusType" target-entity="gov.va.med.ccht.model.inventory.DeviceStatusType">
				<join-column name="MED_DVC_STATUS_TYPE_ID" />
			</many-to-one>			
		</attributes>
	</entity>
		
	<entity class="gov.va.med.ccht.model.inventory.DeviceRequirement" access="FIELD"
		name="DeviceRequirement">
		<table schema="dbo" name="MEDICAL_DEVICE_SHORTAGE" />
		<attribute-override name="id">
			<column name="MED_DVC_SHORTAGE_ID" />
		</attribute-override>				
		<attributes>
			<basic name="assessmentDate">
					<column name="DATE_SHORTAGE_POSTED" />
			</basic>
			<basic name="devicesNeeded">
					<column name="QUANTITY_NEEDED" />
			</basic>		
			<many-to-one name="facility"
				target-entity="gov.va.med.ccht.model.inventory.SimpleFacility">
				<join-column name="FACILITIES_ID" />
			</many-to-one>
			<many-to-one name="deviceType"
				target-entity="gov.va.med.ccht.model.inventory.DeviceType">
				<join-column name="MED_DVC_MODEL_TYPE_ID" />
			</many-to-one>
			<transient name="devicesOnHand"/>				
		</attributes>
	</entity>		
	<!--  QIR -->				
	<entity class="gov.va.med.ccht.model.qir.QIR" access="FIELD"
		name="QIR">
		<table schema="qir" name="QIR" />
		<attribute-override name="id">
			<column name="QIR_ID" />
		</attribute-override>				
		<attributes>
			<basic name="serialNumber"> <column name="MED_DVC_SERIAL_NBR" /> </basic>
			<basic name="submittedBy"> <column name="SUBMITTED_BY" /> </basic>	
			<basic name="submittedDate"> <column name="DATE_SUBMITTED" /> </basic>	
			<basic name="vendorResponseDueDate"> <column name="VENDOR_RESP_DUE_DATE" /> </basic>	
			<basic name="emailReminderSentDate"> <column name="DATE_EMAIL_REMINDER_SENT" /> </basic>
			<basic name="statusChangeDate"> <column name="DATE_LAST_STATUS" /> </basic>							
			<basic name="purchaseOrderNumber"> <column name="PURCHASE_ORDER_NBR" /> </basic>	
			<basic name="headline"> <column name="QIR_SUMMARY" /> </basic>
			<basic name="complaint"> <column name="QIR_COMPLAINT" /> </basic>
			<basic name="isDmpIssue"> <column name="DMP_RELATED" /> </basic>

			<many-to-one name="dmpQirType"
				target-entity="gov.va.med.ccht.model.qir.DmpQirType">
				<join-column name="DMP_QIR_TYPE_ID" />
			</many-to-one>
			
			<many-to-one name="visn"
				target-entity="gov.va.med.ccht.model.inventory.SimpleVisn">
				<join-column name="VISN_ID" />
			</many-to-one>
			<many-to-one name="facility"
				target-entity="gov.va.med.ccht.model.inventory.SimpleFacility">
				<join-column name="FACILITIES_ID" />
			</many-to-one>			
			<many-to-one name="deviceType"
				target-entity="gov.va.med.ccht.model.inventory.DeviceType">
				<join-column name="MED_DVC_MODEL_TYPE_ID" />
			</many-to-one>
			<many-to-one name="qirType"
				target-entity="gov.va.med.ccht.model.qir.QIRType">
				<join-column name="QIR_TYPE_ID" />
			</many-to-one>
			<many-to-one name="qirStatusType"
				target-entity="gov.va.med.ccht.model.qir.QIRStatusType">
				<join-column name="QIR_STATUS_TYPE_ID" />
			</many-to-one>
			<many-to-one name="vendor"
				target-entity="gov.va.med.ccht.model.inventory.Vendor">
				<join-column name="VENDOR_ID" />
			</many-to-one>
			<one-to-many name="internalQIRRemarks" target-entity="gov.va.med.ccht.model.qir.QIRRemarks"
				mapped-by="qir" fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>
			<one-to-many name="internalQIRVendorActions" target-entity="gov.va.med.ccht.model.qir.QIRVendorAction"
				mapped-by="qir" fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>
			<one-to-many name="internalQIRAttachments" target-entity="gov.va.med.ccht.model.qir.QIRSimpleAttachment"
				mapped-by="qir" fetch="EAGER">
				<cascade>
					<cascade-all />
				</cascade>
			</one-to-many>																		
			<transient name="modifiedByName"/>				
		</attributes>
	</entity>
	
	<entity class="gov.va.med.ccht.model.qir.QIRRemarks" access="FIELD"
		name="QIRRemarks">
		<table schema="qir" name="QIR_REMARKS" />
		<attribute-override name="id">
			<column name="QIR_REMARK_ID" />
		</attribute-override>
		<attributes>
			<basic name="date">
				<column name="REMARK_DATE" />
			</basic>
			<basic name="remarks">
				<column name="REMARK_TEXT" />
			</basic>
			<many-to-one name="qir" target-entity="gov.va.med.ccht.model.qir.QIR">
				<join-column name="QIR_ID" />
			</many-to-one>
		</attributes>
	</entity>

	<entity class="gov.va.med.ccht.model.qir.QIRVendorAction" access="FIELD"
		name="QIRVendorAction">
		<table schema="qir" name="QIR_VENDOR_ACTIONS" />
		<attribute-override name="id">
			<column name="QIR_VENDOR_ACTION_ID" />
		</attribute-override>
		<attributes>
			<basic name="date">
				<column name="ACTION_DATE" />
			</basic>
			<basic name="action">
				<column name="ACTION_TEXT" />
			</basic>
			<many-to-one name="qir" target-entity="gov.va.med.ccht.model.qir.QIR">
				<join-column name="QIR_ID" />
			</many-to-one>
		</attributes>
	</entity>
		
	<entity class="gov.va.med.ccht.model.qir.QIRSimpleAttachment" access="FIELD"
		name="QIRSimpleAttachment">
		<table schema="qir" name="QIR_DOC_ATTACHMENTS" />
		<attribute-override name="id">
			<column name="QIR_DOC_ATTCHMNT_ID" />
		</attribute-override>
		<attributes>
			<basic name="length">
				<column name="DOCUMENT_SIZE" />
			</basic>			
			<many-to-one name="qir" target-entity="gov.va.med.ccht.model.qir.QIR">
				<join-column name="QIR_ID" />
			</many-to-one>
		</attributes>
	</entity>	
	<entity class="gov.va.med.ccht.model.qir.QIRAttachment" access="FIELD"
		name="QIRAttachment">
		<table schema="qir" name="QIR_DOC_ATTACHMENTS" />
		<attribute-override name="id">
			<column name="QIR_DOC_ATTCHMNT_ID" />
		</attribute-override>
		<attributes>
			<basic name="qirId">
				<column name="QIR_ID" />
			</basic>
			<basic name="length">
				<column name="DOCUMENT_SIZE" />
			</basic>			
			<basic name="data">
				<column name="DOCUMENT_DATA" />
			</basic>			
		</attributes>
	</entity>	
	<entity class="gov.va.med.ccht.model.inventory.DeviceTrackerLog" access="FIELD"
		name="DeviceTrackerLog">
		<table schema="dbo" name="MED_DVC_TRACKER_LOG" />
		<attribute-override name="id">
			<column name="MED_DVC_TRACKER_LOG_ID" />
		</attribute-override>
		<attributes>
			<basic name="processed">
				<column name="vendor_compliance_process" />
			</basic>
			<basic name="vendorId">
				<column name="vendor_id" />
			</basic>
		</attributes>
	</entity>
	<entity class="gov.va.med.ccht.model.inventory.Survey" access="FIELD"
		name="Survey">
		<table schema="dbo" name="SURVEY" />
		<attribute-override name="id">
			<column name="SURVEY_ID" />
		</attribute-override>
		<attributes>
			<basic name="title">
				<column name="TITLE" />
			</basic>
			<basic name="viewResponses">
				<column name="VIEW_RESPONSES" />
			</basic>
			<basic name="surveyVersion">
				<column name="VERSION" />
			</basic>
		</attributes>
	</entity>
	<entity class="gov.va.med.ccht.model.inventory.FacilityActivity" access="FIELD"
		name="FacilityActivity">
		<table schema="dbo" name="FACILITY_ACTIVITY" />
		<attribute-override name="id">
			<column name="ACTIVITY_ID" />
		</attribute-override>
		<attributes>
			<basic name="dialogue">
				<column name="DIALOGUE" />
			</basic>
			<basic name="patientTotals">
				<column name="PATIENT_TOTALS" />
			</basic>
			<basic name="reportWeek">
				<column name="RPT_WK" />
			</basic>
			<many-to-one name="facility"
				target-entity="gov.va.med.ccht.model.inventory.Facility">
				<join-column name="FACILITY_ID" />
			</many-to-one>			
			<many-to-one name="vendor"
				target-entity="gov.va.med.ccht.model.inventory.Vendor">
				<join-column name="VENDOR_ID" />
			</many-to-one>			
		</attributes>
	</entity>
	<entity class="gov.va.med.ccht.model.inventory.SurveyedActivity" access="FIELD"
		name="SurveyedActivity">
		<table schema="dbo" name="SURVEYED_ACTIVITY" />
		<attribute-override name="id">
			<column name="SURVEYED_ACTIVITY_ID" />
		</attribute-override>
		<attributes>
			<many-to-one name="visn"
				target-entity="gov.va.med.ccht.model.inventory.Visn">
				<join-column name="VISN_ID" />
			</many-to-one>			
		</attributes>
	</entity>
	<entity class="gov.va.med.ccht.model.inventory.SurveyedActivityResponse" access="FIELD"
		name="SurveyedActivityResponse">
		<table schema="dbo" name="SURVEYED_ACTIVITY_REPSONSE" />
		<attribute-override name="id">
			<column name="SURVEYED_ACTIVITY_RESPONSE_ID" />
		</attribute-override>
		<attributes>
			<basic name="recievedDate">
				<column name="RECEIVED_DATE" />
			</basic>
			<basic name="completedDate">
				<column name="COMPLETED_DATE" />
			</basic>
			<basic name="scheduledDate">
				<column name="SCHEDULED_DATE" />
			</basic>
			<many-to-one name="survey"
				target-entity="gov.va.med.ccht.model.inventory.Survey">
				<join-column name="SURVEY_ID" />
			</many-to-one>			
		</attributes>
	</entity>

</entity-mappings>