<?xml version="1.0"?>
<project name="OracleDB" default="load">
	<description>
        Oracle database load, clean, export, import build file for vhim 3.6.2.
    </description>
	<property file="${cds.run.properties.path}"/>
	<!-- set global properties for this build -->
	<property name="src" location="environments/database/scripts"/>
	<!-- Variables Required to be set by the calling environment -->
	<!--
		cds.jdbc.host
		cds.jdbc.port
		cds.jdbc.dbname
		cds.jdbc.username
		cds.jdbc.password-->
	<!---->
	<!-- database connection url -->
	<property name="db.url" value="${cds.jdbc.host}:${cds.jdbc.port}/${cds.jdbc.dbname}"/>
	
	<!-- SET ALLERGIES VARIABLES -->
	<!-- Starting Patient VPID.  Set to a value > 0. -->
	<property name="starting_avpid" value="10000"/>
	<!-- How many Allergies per patient to create, modify value to change -->
	<property name="num_allergies" value="6"/>
	<!-- How many Patients to assign the above number of Allergies to, modify value to change -->
	<property name="num_apatients" value="15"/>
	<!-- How many Reactions per Allergy to create, modify value to change -->
	<property name="num_reactions" value="1"/>
	
	<!-- SET PHARMACY VARIABLES -->
	<!-- Starting Patient VPID.  Set to a value > 0. -->
	<property name="starting_pvpid" value="5000"/>
	<!-- How many Pharmacies per patient to create, modify value to change -->
	<property name="num_pharmacy" value="10"/>
	<!-- How many Patients to assign the above number of Pharmacy to, modify value to change -->
	<property name="num_ppatients" value="15"/>
	
		
	<!-- SET VITALS VARIABLES -->
	<!-- Starting Patient VPID.  Set to a value > 0. -->
	<property name="starting_vvpid" value="1"/>
	<!-- How many Vitals per patient to create, modify value to change -->
	<property name="num_vitals" value="10"/>
	<!-- How many Patients to assign the above number of Vitals to, modify value to change -->
	<property name="num_vpatients" value="10"/>
	
	<!-- SET  LAB VARIABLES -->
	<!-- Starting Patient VPID.  Set to a value > 0. -->
	<property name="starting_lvpid" value="500"/>
	<!-- How many Allergies per patient to create, modify value to change -->
	<property name="num_lab" value="6"/>
	<!-- How many Patients to assign the above number of Allergies to, modify value to change -->
	<property name="num_lpatients" value="20"/>


	<target name="db_load" depends="db_load_allergies, db_load_outppharm, db_load_vitals, db_load_lab" description="load database">
		<echo message="all database ${cds.jdbc.host}:${cds.jdbc.port}/${cds.jdbc.dbname} load finished"/>
	</target>
	
	<target name="db_load_allergies" description="load allergies into database">
		<echo message="about to load allergies into database ${cds.jdbc.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
			<arg line="-s"/>
			<arg line="${cds.jdbc.username}/${cds.jdbc.password}@${db.url}"/>
			<arg line="@new_allergies_load4x_arms.sql"/>
			<arg line="${num_allergies}"/>
			<arg line="${num_apatients}"/>
			<arg line="${num_reactions}"/>
			<arg line="${starting_avpid}"/>
			<arg line="1>logs\load_allergy_output.txt"/>
			<arg line="2>>logs\load_allergy_logfile.log"/>
		</exec>
		<echo message="allergies for database ${cds.jdbc.username}@${db.url} load finished"/>
	</target>
	
	<target name="db_load_outppharm" description="load outpatient pharmacy into database" >
		<echo message="about to load out-patient-pharmacy into database ${cds.jdbc.username}@${db.url}"/>
	    	<exec dir="${src}" executable="sqlplus" failonerror="true">
	    	<arg line="-s"/>
		<arg line="${cds.jdbc.username}/${cds.jdbc.password}@${db.url}"/>
		<arg line="@new_outppharm_load4x_arms.sql"/>
	    	<arg line="${num_pharmacy}"/>
		<arg line="${num_ppatients}"/>
		<arg line="${starting_pvpid}"/>
	        <arg line="1>logs\load_outppharm_output.txt"/>
		<arg line="2>>logs\load_outppharm_logfile.log"/>
	    </exec>
	    <echo message="out-patient-pharmacy for database ${cds.jdbc.username}@${db.url} load finished"/>
  	</target>
  	
	<!--target name="db_load_patient" description="load patient table with 50,000 records" >
		<echo message="about to load patient table into database ${cds.jdbc.username}@${db.url}"/>
	    	<exec dir="${src}" executable="sqlplus" failonerror="true">
	    	<arg line="-s"/>
		<arg line="${cds.jdbc.username}/${cds.jdbc.password}@${db.url}"/>
		<arg line="@person_populate.sql"/>
	    </exec>
	    <echo message="load patient for database ${cds.jdbc.username}@${db.url} finished"/>
  	</target-->
  	
	<target name="db_load_vitals" description="load vitals into database">
		<echo message="about to load vitals into database ${cds.jdbc.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
			<arg line="-s"/>
			<arg line="${cds.jdbc.username}/${cds.jdbc.password}@${db.url}"/>
			<arg line="@new_vitals_load4x_arms.sql"/>
			<arg line="${num_vitals}"/>
			<arg line="${num_vpatients}"/>
			<arg line="${starting_vvpid}"/>
			<arg line="1>logs\load_vital_output.txt"/>
			<arg line="2>>logs\load_vital_logfile.log"/>
		</exec>
		<echo message="vitals for database ${cds.jdbc.username}@${db.url} load finished"/>
	</target>
	
	<target name="db_load_lab" description="load lab into database">
		<echo message="about to load lab into database ${cds.jdbc.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
			<arg line="-s"/>
			<arg line="${cds.jdbc.username}/${cds.jdbc.password}@${db.url}"/>
			<arg line="@new_lab_load4x_arms.sql"/>
			<arg line="${num_lab}"/>
			<arg line="${num_lpatients}"/>
			<arg line="${starting_lvpid}"/>
			<arg line="1>logs\load_lab_output.txt"/>
			<arg line="2>>logs\load_lab_logfile.log"/>
		</exec>
		<echo message="lab for database ${cds.jdbc.username}@${db.url} load finished"/>
	</target>

	<target name="db_clean" description="clean database out">

		<echo message="about to clean database ${cds.jdbc.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
			<arg line="-s"/>
			<arg line="${cds.jdbc.username}/${cds.jdbc.password}@${db.url}"/>
			<arg line="@clean_out_vhim4x_arms.sql"/>
			<arg line="1>logs\clean_output.txt"/>
			<arg line="2>>logs\clean_logfile.log"/>
		</exec>
		<echo message="database ${cds.jdbc.username}@${db.url} cleaned successfully"/>

		<echo message="about to reset the common sequence for ${cds.oracle.schema.common.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
		  <arg line="-s"/>
		  <arg line="${cds.oracle.schema.common.username}/${cds.oracle.schema.common.password}@${db.url}"/> 
		  <arg line="@reset_common_sequences.sql"/>
		  <arg line="1>>logs\clean_output.txt"/>
		  <arg line="2>>logs\clean_logfile.log"/>
		</exec>
		<echo message="finished resetting the common sequence for ${cds.oracle.schema.common.username}@${db.url}"/>
		
		<echo message="about to reset the allergies sequence for ${cds.oracle.schema.allergies.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
		  <arg line="-s"/>
		  <arg line="${cds.oracle.schema.allergies.username}/${cds.oracle.schema.allergies.password}@${db.url}"/>  
		  <arg line="@reset_allergies_sequences.sql"/>
		  <arg line="1>>logs\clean_output.txt"/>
		  <arg line="2>>logs\clean_logfile.log"/>
		</exec>
		<echo message="finished resetting the allergy sequence for ${cds.oracle.schema.allergies.username}@${db.url}"/>
		
		<echo message="about to reset the out-patient-pharmacy sequence for ${cds.oracle.schema.outppharm.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
		  <arg line="-s"/>
		  <arg line="${cds.oracle.schema.outppharm.username}/${cds.oracle.schema.outppharm.password}@${db.url}"/>  
		  <arg line="@reset_outppharm_sequences.sql"/>
		  <arg line="1>>logs\clean_output.txt"/>
		  <arg line="2>>logs\clean_logfile.log"/>
		</exec>
		<echo message="finished resetting the out-patient-pharmacy sequence for ${cds.oracle.schema.outppharm.username}@${db.url}"/>
		
		<echo message="about to reset the vitals sequence for ${cds.oracle.schema.vitals.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
		  <arg line="-s"/>
		  <arg line="${cds.oracle.schema.vitals.username}/${cds.oracle.schema.vitals.password}@${db.url}"/>  
		  <arg line="@reset_vitals_sequences.sql"/>
		  <arg line="1>>logs\clean_output.txt"/>
		  <arg line="2>>logs\clean_logfile.log"/>
		</exec>
		<echo message="finished resetting the vitals sequence for ${cds.oracle.schema.vitals.username}@${db.url}"/>
		
		<echo message="about to reset the lab sequence for ${cds.oracle.schema.lab.username}@${db.url}"/>
		<exec dir="${src}" executable="sqlplus" failonerror="true">
		  <arg line="-s"/>
		  <arg line="${cds.oracle.schema.lab.username}/${cds.oracle.schema.lab.password}@${db.url}"/>  
		  <arg line="@reset_lab_sequences.sql"/>
		  <arg line="1>>logs\clean_output.txt"/>
		  <arg line="2>>logs\clean_logfile.log"/>
		</exec>
		<echo message="finished resetting the lab sequence for ${cds.oracle.schema.lab.username}@${db.url}"/>

	</target>
	
	<target name="db_clean_load" depends="db_clean, db_load" description="load database after cleaning out">
		<echo message="database ${cds.jdbc.username}@${db.url} clean/load finished"/>
	</target>
</project>
