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

<hibernate-mapping  default-lazy="false" default-cascade="all">
    <class entity-name="healthConcernNotesEvent" lazy="false" table="VISTA_HDSI.PROBX_NOTE_FACILITY_9000011_11" name="gov.va.med.cds.template.generated.problemlist.HealthConcern$HealthConcernNotesEvent">
		<id name="idV" type="java.lang.String">
			<column name="ROWID" />
			<generator class="assigned" />
		</id>
		
		<property name="problem" column="PROBLEM0" type="big_decimal" insert="false" update="false" />
		
		<list name="healthConcernNoteEvent" fetch="subselect" batch-size="100">
			<key column="SUB_NOTE_FACILITY" />            
            <list-index column="CHILDSUB2" />
            <one-to-many entity-name="healthConcernNoteEvent" />
        </list>

<!--		<many-to-one name="facility" entity-name="facilities" column="NOTE_FACILITY" not-found="ignore" node="."/>-->        
    </class>
    
    <class entity-name="healthConcernNoteEvent" lazy="false" table="VISTA_HDSI.PROX_NOTE_9000011_1111" name="gov.va.med.cds.template.generated.problemlist.HealthConcernNoteEvent">
		<composite-id name="idV" class="gov.va.med.cds.persistence.hibernate.common.VistaProblemListCompositeRowIdUserType">
			<key-property name="SUB_NOTE_FACILITY" type="java.lang.String" />
			<key-property name="CHILDSUB2" type="big_decimal" />
		</composite-id>
		
		<component name="narrative" class="gov.va.med.cds.template.generated.basedatatypes.NullableText">
			<property name="value" column="NOTE_NARRATIVE" type="java.lang.String" />
		</component>
		
		<component name="status" class="gov.va.med.cds.template.generated.basedatatypes.VACode">
	        <property name="alternateCode" column="STATUS" type="java.lang.String" />
	        <property name="alternateCodingSystem" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_9000011_1111'" type="java.lang.String"  />
	        <property name="alternateDisplayText" type="java.lang.String" >
	        	<formula>
	        		(CASE
						WHEN ( STATUS = 'A' ) THEN 'ACTIVE'
						WHEN ( STATUS = 'I' ) THEN 'INACTIVE'
						ELSE NULL
					END )
	        	</formula>
	        </property>
		</component>

		<component name="author" class="gov.va.med.cds.template.generated.common.PractitionerParticipationLite" >
			<component name="practitioner" 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="AUTHOR" type="gov.va.med.cds.persistence.hibernate.common.VistaIdentityUserType"/>
					<property name="assigningFacility" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()" type="java.lang.String" insert="false" update="false" />
					<property name="assigningAuthority" formula="'USVHA'" type="java.lang.String"  />
				</component>
				<property name="idSourceTable" formula="'VistA200'" type="java.lang.String" />
				<property name="name" formula="VISTA_HDSI.HDSREPSQLUtil1_MiscNameNE(AUTHOR)" type="gov.va.med.cds.persistence.hibernate.common.VistaPersonNameUserType"/>
			</component>	
		</component>
		
		<component name="facilities" class="gov.va.med.cds.template.generated.common.VisitLocation" >
			<component name="locationCode" class="gov.va.med.cds.template.generated.basedatatypes.HL72CodedElement" >
				<property name="code" type="java.lang.String" >
					<formula>
					(SELECT PROBLEM_LIST.LocationCode
					FROM VISTA_HDSI.PROBLM0_9000011_EXT PROBLEM_LIST, 
						VISTA_HDSI.PROBX_NOTE_FACILITY_9000011_11 NOTE_FACILITY,
						VISTA_HDSI.PROX_NOTE_9000011_1111 NOTE_DETAILS
					WHERE PROBLEM_LIST.ROWID = NOTE_FACILITY.PROBLEM0
					AND NOTE_FACILITY.ROWID = NOTE_DETAILS.SUB_NOTE_FACILITY)
					</formula>
				</property>
				<property name="displayText" type="java.lang.String"  >
					<formula>
					(SELECT PROBLEM_LIST.LocationDisplayText 
					FROM VISTA_HDSI.PROBLM0_9000011_EXT PROBLEM_LIST, 
						VISTA_HDSI.PROBX_NOTE_FACILITY_9000011_11 NOTE_FACILITY,
						VISTA_HDSI.PROX_NOTE_9000011_1111 NOTE_DETAILS
					WHERE PROBLEM_LIST.ROWID = NOTE_FACILITY.PROBLEM0
					AND NOTE_FACILITY.ROWID = NOTE_DETAILS.SUB_NOTE_FACILITY)
					</formula>
				</property>
				<property name="codingSystem" formula="VISTA_HDSI.HDSREPSQLUtil1_StationNumber()||'_9999999.6'" type="java.lang.String" />
			</component>
		</component>
				
    </class>

	<!-- Patient Query -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	AND plr.patient.identifier.identity in ( :pids )
        	AND plr.recordDisposition not in ( 'H', 'h' )
		]]>
	</query>

	<!-- Patient Query with Dates -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.date">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and plr.dateLastModified.timestamp between :startDate and :endDate
        	and plr.recordDisposition not in ( 'H', 'h' )
		]]>
	</query>

	<!-- Patient Query with Status -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.status">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and plr.statusRef in (:status)
        	and plr.recordDisposition not in ( 'H', 'h' )
		]]>
	</query>

	<!-- Patient Query with Dates and Status -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.date.status">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and plr.dateLastModified.timestamp between :startDate and :endDate
        	and plr.statusRef in (:status)
        	and plr.recordDisposition not in ( 'H', 'h' )
		]]>
	</query>

	<!-- Patient Query with Condition -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.condition">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and ( plr.recordDisposition not in ( :condition ) or plr.recordDisposition in ( :condition ) or plr.recordDisposition is null )
		]]>
	</query>

	<!-- Patient Query with Dates and Condition -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.date.condition">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and plr.dateLastModified.timestamp between :startDate and :endDate
        	and ( plr.recordDisposition not in ( :condition ) or plr.recordDisposition in ( :condition ) or plr.recordDisposition is null )
		]]>
	</query>

	<!-- Patient Query with Status and Condition -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.status.condition">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and plr.statusRef in (:status)
        	and ( plr.recordDisposition not in ( :condition ) or plr.recordDisposition in ( :condition ) or plr.recordDisposition is null )
		]]>
	</query>

	<!-- Patient Query with Condition and Status -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.condition.status">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and ( plr.recordDisposition not in ( :condition ) or plr.recordDisposition in ( :condition ) or plr.recordDisposition is null )
        	and plr.statusRef in (:status)
		]]>
	</query>

	<!-- Patient Query with Dates, Status, and Condition -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.date.status.condition">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and plr.dateLastModified.timestamp between :startDate and :endDate
        	and plr.statusRef in (:status)
        	and ( plr.recordDisposition not in ( :condition ) or plr.recordDisposition in ( :condition ) or plr.recordDisposition is null )
		]]>
	</query>

	<!-- Patient Query with Dates, Condition, and Status -->
	<query name="ProblemListRead2.HealthConcern.healthConcernNotesEvent.date.condition.status">
		<![CDATA[ 
        	select hcne
        	from ProblemListRead2 plr, healthConcernNotesEvent hcne
        	where plr.idV = hcne.problem
        	and plr.patient.identifier.identity in ( :pids )
        	and plr.dateLastModified.timestamp between :startDate and :endDate
        	and ( plr.recordDisposition not in ( :condition ) or plr.recordDisposition in ( :condition ) or plr.recordDisposition is null )
        	and plr.statusRef in (:status)
		]]>
	</query>
</hibernate-mapping>