warfarin_PK_BOV_design = designObj{
  DECLARED_VARIABLES{
  	INPUT_KA :: dosingTarget
  	Y ::observation
  	OCC::varLevel
  }

  INTERVENTION{
 	admin1 : {type is bolus, input=INPUT_KA, amount=100, doseTime=[0] }
  }
  SAMPLING{
	window1 : {type is simple, sampleTime = [0.0001, 24, 36, 48, 72, 96, 120], outcome=Y }
  }
  STUDY_DESIGN{
	arm1 : {
		armSize=33,
		interventionSequence=[{
			admin=[admin1,admin1],
			start=0
		}],
		samplingSequence=[{
			sample=[window1,window1],
			start=0
		}],
		occasionSequence={
			occasion=[1,2],
			level=OCC,
			start=[0, 60]
		}
	}
  }
}

# EVALUATE task - implicit version
warfarin_PK_BOV_taskEval = taskObj {
	EVALUATE{ 
	}
} # end of task object

warfarin_PK_BOV_par = parObj{
   STRUCTURAL{
      POP_CL:{value=0.1, lo=0.001} # L/h/70kg
      POP_V:{value=8, lo=0.001} # L/70kg
      POP_KA:{value=2, lo=0.001} # h-1
      POP_TLAG:{value=1, lo=0.001} # h
	  BETA_CL_WT : { value = 0.75, fix = true }
	  BETA_V_WT : { value = 1, fix = true } 
   }# end STRUCTURAL

   VARIABILITY{
      BSV_CL : {  value=0.1 }
      BSV_V : { value=0.1 }
	  COV_BSV_CL_V : { value = 0.01 }

      BOV_CL : { value=0.1}
      BOV_V : { value=0.1}

      BSV_KA:{value=0.1}
      BSV_TLAG:{value=0.01, fix=true}

      RUV_PROP:{value=0.1, lo=0}
      RUV_ADD:{value=0.224, lo=0} # mg/L
   }# end VARIABILITY

} # end of parameter object

warfarin_PK_BOV_mdl = mdlObj{
   IDV { T }

   COVARIATES{
	WT
	logtWT = ln(WT/70)
   }

   VARIABILITY_LEVELS(reference=ID){
	ID : { level=3, type  is parameter }
	OCC : { level=2, type  is parameter }
   	DV : { level=1, type  is observation }
   }

   STRUCTURAL_PARAMETERS{
      #THETA
      POP_CL
      POP_V
      POP_KA
      POP_TLAG
	  BETA_CL_WT
	  BETA_V_WT
   }# end STRUCTURAL_PARAMETERS

   VARIABILITY_PARAMETERS{
      #OMEGA
      BSV_CL
      BSV_V
 	  COV_BSV_CL_V     
      BOV_CL
      BOV_V
      BSV_KA
      BSV_TLAG
      RUV_PROP
      RUV_ADD
   }# end VARIABILITY_PARAMETERS

   RANDOM_VARIABLE_DEFINITION(level=ID){
      eta_BSV_CL~ Normal(mean=0, var=BSV_CL)
      eta_BSV_V~ Normal(mean=0, var=BSV_V)
	  :: {type is covariance, rv1=eta_BSV_CL, rv2=eta_BSV_V, value=COV_BSV_CL_V}
	  eta_BSV_KA~ Normal(mean=0, var=BSV_KA)
      eta_BSV_TLAG~ Normal(mean=0, var=BSV_TLAG)
   }# end RANDOM_VARIABLE_DEFINITION

   RANDOM_VARIABLE_DEFINITION(level=OCC){
      eta_BOV_CL~ Normal(mean=0, var=BOV_CL)
      eta_BOV_V~ Normal(mean=0, var=BOV_V)
   }# end RANDOM_VARIABLE_DEFINITION

   INDIVIDUAL_VARIABLES{
      # Individual parameters
		CL : {type is linear, trans is ln, pop = POP_CL, fixEff = {coeff=BETA_CL_WT, cov=logtWT} , ranEff = [eta_BSV_CL, eta_BOV_CL ]}
		V :  {type is linear, trans is ln, pop = POP_V, fixEff = {coeff=BETA_V_WT, cov=logtWT} , ranEff = [eta_BSV_V, eta_BOV_V] }
	    KA : {type is linear, trans is ln, pop = POP_KA, ranEff = eta_BSV_KA }
	    TLAG : {type is linear, trans is ln, pop = POP_TLAG, ranEff = eta_BSV_TLAG }
      }# end INDIVIDUAL_VARIABLES

	MODEL_PREDICTION {
		COMPARTMENT {
			INPUT_KA      : {type is depot, modelCmt=1, to=CENTRAL, ka=KA, tlag=TLAG}
#			INPUT_CENTRAL : {type is direct, to = CENTRAL}
			CENTRAL       : {type is compartment, modelCmt=2}
                     	 :: {type is elimination, modelCmt=2, from=CENTRAL, v=V, cl=CL}
   		}# end COMPARTMENT

	    CC = CENTRAL / V 
	} # end MODEL_PREDICTION

	RANDOM_VARIABLE_DEFINITION(level=DV) {
		EPS_Y ~ Normal(mean = 0, var = 1) 
	} # end RANDOM_VARIABLE_DEFINITION 
	
	OBSERVATION {
	    Y : {type is combinedError1, additive = RUV_ADD, proportional = RUV_PROP, eps = EPS_Y, prediction = CC }
	} # end OBSERVATION

} # end of model object


# EVALUATE task - explicit version
warfarin_PK_ODE_taskOpt_Explicit = taskObj{ # Here we define explicitly all options for optimisation with PFIM & FW algorithm
        OPTIMISE {
			set optAlgo is simplex,
			fim = "P",
			previousFim = "",
			
# Suggested names of common options (options that would make sense to different software) - Options for methods (what we want the software to compute, 
# and the settings/options for these computations)
        graphOnly = false,
        typeIError = 0.05,
        powerComparison = false,
        nSubjectsComparison = false,
        equivalenceRange = [ln(0.8),ln(1.25)],
        powerEquivalence = false,
        nSubjectsEquivalence = false,
        typeIIError = 0.9,
        
# Graphical options (can be moved to SETTINGS if they only make sense to PFIM)     - Options for graphs   
        graphLogical = true,
        logLogical = false, 
 		namesDataX = ["Time"],
 		namesDataY = ["Concentration"],
		graphInfA=[0],
		graphSupA=[360] /#,
        y.rangeA = NULL #/
        
#			FEATURES{
#				sampleTime,
#				numberTimes=4
#			}
        
		# Define tool specific settings in block
		TARGET_SETTINGS(target = "PFIM"){ # here we explicit all elements of the task
			set project = "warfarin_PK_ODE_optimise",
			output = "Stdout_warfarin_PK_ODE_optimise.R",
			outputFIM = "",			
			option = 1,
			subjectsInput = 1,
			covariateModel = false,
			covariate_occModel = false
			}
		}
}

# EVALUATE MOG
warfarin_PK_BOV_mog = mogObj {
	OBJECTS{
		warfarin_PK_BOV_design : { type is designObj }
		warfarin_PK_BOV_mdl : { type is mdlObj }
		warfarin_PK_BOV_par : { type is parObj }
		warfarin_PK_BOV_taskEval : { type is taskObj }
	}
}
