
%include "&_sasusrws_/P21/CLI/Enterprise/macros/setup.sas";

%macro openEnt(Params=, debug=%str(N));

%let _debug = %sysfunc(upcase(%sysfunc(strip(&debug.))));

 * Parse supplied parameter string and quote each parameter value;
%let i=1;
%let curparam=%sysfunc(quote(%scan(%nrbquote(&Params.),&i.,%str(,))));

%if (&_debug=%str(Y)) %then
  %put curparam = &curparam.; * --> debug INFO;

* Start creating command text to be passed to the Java Object;
%let cmd=%str();
%let cmd = %sysfunc(strip(&cmd.)) %sysfunc(strip(&curparam.)) %str(,);

* Iterate Parameter list;
%do %while(%length(&curparam.)>0);
  %let i=%eval(&i. + 1);
  %let curparam=%scan(%nrbquote(&Params.),&i.,%str(,));
  * Quote each paramter param=value pair;
  %if %length(&curparam.)>0 %then %do;
     %let curparam=%sysfunc(quote(&curparam.));

     %if (&_debug=%str(Y)) %then
       %put curparam = &curparam.; * --> debug INFO;

    * Concatenate it with Command String;
     %let cmd = %sysfunc(strip(&cmd.)) %sysfunc(strip(&curparam.)) %str(,);
  %end;
%end;

* Reduce the i count by 1 since it is incremented by 1 because of do while loop;
%let i = %eval(&i.-1);
%if (&_debug=%str(Y)) %then
   %put i (variable count) = &i.; * --> debug INFO;

* Remove extra comma(,) from the string at the end;
%let cmd=%substr(%nrbquote(&cmd.),1,%length(%nrbquote(&cmd.))-1);
%if (&_debug=%str(Y)) %then
   %put cmd (Command String) = &cmd.; * --> debug INFO;

data _pinnacle21_cli;
   dcl javaobj jCmd("net/pinnacle21/oce/utils/ProcessUtils");

   length exitCode 8.;
   array s{&i.} $200 (&cmd.);
   jCmd.callStaticVoidMethod("startFromCommandLine",s);

   jCmd.callStaticIntMethod("exit", exitCode);
   put exitCode=;

run;


%mend openEnt;

%let OGRoot = %str(&_sasusrws_/P21/CLI/Enterprise);
%let study_path = %str(&_sasusrws_/P21/CLI/Study-101);
%let xlfile=&study_path./results/Enterprise_Results_%SYSFUNC(translate(%SYSFUNC(datetime(), E8601DT.),'-',':')).xlsx;


PROC EXPORT
   DATA=sashelp.class
   DBMS=xlsx
   OUTFILE="&xlfile." REPLACE;
   SHEET="Sheet1";
run;

* Initialize the Classpath;
%init_classpath_update;

* Add the jar file to the Classpath;
%add_to_classpath(&OGRoot/macros/p21-client-2.7.0.jar);

* Validate SDTM datasets;

options nomprint;

%openEnt(Params=%nrbquote(
           --project=test_prj,
           --study=test-study,
           --standard=sdtm,
           --standard.version=3.1.1,
           --meddra=19.0,
           --cdisc.ct.sdtm=2017-03-31,
           --snomed.version=2016-09-01,
           --unii.version=2016-09-06,
           --ndf-rt.version=2016-10-03,
           --group=enterprise_cli,
           --source.sdtm="lsaf:///SAS/Files/P21/CLI/Study-101/xpt",
           --report=&xlfile
           ),
           debug=Y);

*Reset to Original ClassPath;
%reset_classpath;
