0% found this document useful (0 votes)
68 views15 pages

Java Sample Import and Validation Code

This document contains code for importing sample and subject data from a file into a database. It: 1) Defines variables to store the field values from the file. 2) Creates a dataset to store the field values. 3) Validates that the sample and subject aliases exist by querying the database and comparing to the file data. 4) For aliases that don't exist, it prepares to insert new subjects into the database.

Uploaded by

rajkumarmodi9832
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views15 pages

Java Sample Import and Validation Code

This document contains code for importing sample and subject data from a file into a database. It: 1) Defines variables to store the field values from the file. 2) Creates a dataset to store the field values. 3) Validates that the sample and subject aliases exist by querying the database and comparing to the file data. 4) For aliases that don't exist, it prepares to insert new subjects into the database.

Uploaded by

rajkumarmodi9832
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import java.text.

SimpleDateFormat;
import sapphire.util.DataSet;
import sapphire.util.SafeSQL;
import sapphire.xml.PropertyList;
import sapphire.SapphireException;
import sapphire.util.StringUtil;

logger.info("######### Starting Frontage File Import DFD #########");

String samplealias = fields.samplealias;


String samplealiastype = fields.samplealiastype;
String primary = fields.primary;
String sstudy = fields.studyid;
String protocol = fields.protocolid;
String subjectalias = fields.subjectaliasid;
String gender = fields.gender;
String dateofbirth = fields.dateofbirth;
String externalparticipantid = fields.externalparticipantid;
String cohort = fields.cohortid;
String sampletype = fields.sampletypeid;
String containertype = fields.containertypeid;
String samplecondition = fields.samplecondition;
String visit = fields.visitlabel;
String timepoint = fields.timepointlabel;
String collectiondt = fields.collectiondate;
String receivedt = fields.receivedate;
String qtyvalue = fields.quantity;
String qtyunit = fields.units;
String studysitedesc = fields.studysitedesc;
String treatment = fields.drugname;
String storage = fields.storageid;
String pkgtracking = fields.pkgtrackingno;
String kitid = fields.kitid;

//// Dataset for all the fields


DataSet valuesds=new DataSet();
valuesds.addColumnValues("samplealias", DataSet.STRING, samplealias, ";", "");
valuesds.addColumnValues("samplealiastype", DataSet.STRING, samplealiastype, ";",
"");
valuesds.addColumnValues("primary", DataSet.STRING, primary, ";", "");
valuesds.addColumnValues("sstudy", DataSet.STRING, sstudy, ";", "");
valuesds.addColumnValues("protocol", DataSet.STRING, protocol, ";", "");
valuesds.addColumnValues("subjectalias", DataSet.STRING, subjectalias, ";", "");
valuesds.addColumnValues("gender", DataSet.STRING, gender, ";", "");
valuesds.addColumnValues("dateofbirth", DataSet.STRING, dateofbirth, ";", "");
valuesds.addColumnValues("externalparticipantid", DataSet.STRING,
externalparticipantid, ";", "");
valuesds.addColumnValues("cohort", DataSet.STRING, cohort, ";", "");
valuesds.addColumnValues("sampletype", DataSet.STRING, sampletype, ";", "");
valuesds.addColumnValues("containertype", DataSet.STRING, containertype, ";", "");
valuesds.addColumnValues("samplecondition", DataSet.STRING, samplecondition, ";",
"");
valuesds.addColumnValues("visit", DataSet.STRING, visit, ";", "");
valuesds.addColumnValues("timepoint", DataSet.STRING, timepoint, ";", "");
valuesds.addColumnValues("collectiondt", DataSet.STRING, collectiondt, ";", "");
valuesds.addColumnValues("receivedt", DataSet.STRING, receivedt, ";", "");
valuesds.addColumnValues("qtyvalue", DataSet.STRING, qtyvalue, ";", "");
valuesds.addColumnValues("qtyunit", DataSet.STRING, qtyunit, ";", "");
valuesds.addColumnValues("studysitedesc", DataSet.STRING, studysitedesc, ";", "");
valuesds.addColumnValues("treatment", DataSet.STRING, treatment, ";", "");
valuesds.addColumnValues("storage", DataSet.STRING, storage, ";", "");
valuesds.addColumnValues("pkgtracking", DataSet.STRING, pkgtracking, ";", "");
valuesds.addColumnValues("kitid", DataSet.STRING, kitid, ";", "");
valuesds.addColumn("subjectid", DataSet.STRING);
valuesds.addColumn("participantid", DataSet.STRING);
valuesds.addColumn("useflag", DataSet.STRING);

StringBuffer subaliassb = new StringBuffer();


StringBuffer gendersb = new StringBuffer();
StringBuffer dobsb = new StringBuffer();
StringBuffer neubjectidsb = new StringBuffer();
StringBuffer studyidsb = new StringBuffer();
StringBuffer studysiteidsb = new StringBuffer();
StringBuffer cpcohortb = new StringBuffer();
StringBuffer expartidb = new StringBuffer();
int flag=0;
int counter=0;

DataSet subjectIDds=new DataSet();

String studyid;
String sampleid;

SafeSQL sf = new SafeSQL();

ConnectionProcessor conp = new


ConnectionProcessor( queryProcessor.getConnectionid());
String deptid = conp.getConnectionInfo().getDefaultDepartment();
String userid = conp.getConnectionInfo().getSysuserId();
logger.info("User ID : "+userid);
logger.info("Department ID : "+deptid);

// Checking Sample and Subject Alias is present or not.


logger.info("####### Starting Validation of Sample and Subject Alias Field
#######");

String sql = "with allsamleps as( \n" +


"select rownum as rno, column_value as allsamples from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("samplealias", ";"),
";") + ")) \n" +
"), allsubjects as( \n" +
"select rownum as rno, column_value as allsubjects from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("subjectalias", ";"),
";") + ")) \n" +
"), alldob as( \n" +
"select rownum as rno, column_value as alldobs from TABLE (sys.odcivarchar2list(" +
sf.addIn(valuesds.getColumnValues("dateofbirth", ";"), ";") + ")) \n" +
"), samplealiases as( \n" +
"select alls.rno, sdcid, keyid1, aliasid, aliastype \n" +
"from sdialias, allsamleps alls \n" +
"where sdcid='Sample' \n" +
"and aliastype in (" + sf.addIn(valuesds.getColumnValues("samplealiastype", ";"),
";") + ") \n" +
"and aliasid in (alls.allsamples) \n" +
"), subjectaliases as( \n" +
"select allsub.rno, sdcid, keyid1, aliasid, aliastype \n" +
"from sdialias, allsubjects allsub \n" +
"where sdcid='LV_Subject' \n" +
"and lower(aliastype)=lower('Patient Id') \n" +
"and aliasid in (allsub.allsubjects) \n" +
"), allstudy as ( \n" +
"select rownum as rno, column_value as allstudies from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("sstudy", ";"), ";") +
")) \n" +
"), allparticipant as( \n" +
"select rownum as rno, column_value as allparticipants from TABLE
(sys.odcivarchar2list(" +
sf.addIn(valuesds.getColumnValues("externalparticipantid", ";"), ";") + ")) \n" +
"), isstudyp as ( \n" +
"select rownum as rno, s_studyid, clinicalflag \n" +
"from s_study, allstudy als \n" +
"where s_studyid in (als.allstudies) \n" +
"), participantdt as ( \n" +
"select ap.rno, isp.s_studyid, isp.clinicalflag, p.s_participantid,
p.externalparticipantid, \n" +
"p.sstudyid, p.studysiteid, p.clinicalprotocolid, p.cpcohortid, p.subjectid \n" +
"from s_participant p, isstudyp isp, allparticipant ap \n" +
"where p.sstudyid = isp.s_studyid \n" +
"and p.externalparticipantid in (ap.allparticipants) \n" +
"and ap.rno = isp.rno \n" +
") \n" +
"select distinct alls.rno, alls.allsamples, allsub.allsubjects, sa.keyid1 sampleid,
suba.keyid1 subid, \n" +
"(case when (length(ad.alldobs)=4) then (to_char(trunc(to_date(ad.alldobs, 'yyyy'),
'YEAR'), 'mm/dd/yyyy')) else (to_char(to_date(ad.alldobs, 'mm/dd/yyyy'),
'mm/dd/yyyy')) end) dob, \n" +
"(select count(aliasid) from samplealiases sa1 where sa1.rno=alls.rno) as
samplefound, \n" +
"(select count(aliasid) from subjectaliases suba1 where suba1.rno=allsub.rno) as
subjectfound, \n" +
"(select suba1.keyid1 from subjectaliases suba1 where suba1.rno=allsub.rno) as
subjectid, \n" +
"st.s_studyid, st.clinicalflag, pa.studysiteid, nvl(pa.s_participantid, '0')
participantid, \n" +
"pa.externalparticipantid, pa.clinicalprotocolid, pa.cpcohortid, pa.subjectid
partsubjectid \n" +
"from allsamleps alls \n" +
"inner join allsubjects allsub \n" +
"on allsub.rno = alls.rno \n" +
"inner join isstudyp st \n" +
"on st.rno = alls.rno \n" +
"inner join alldob ad \n" +
"on ad.rno = alls.rno \n" +
"left outer join samplealiases sa \n" +
"on sa.rno = alls.rno \n" +
"left outer join subjectaliases suba \n" +
"on suba.rno = allsub.rno \n" +
"left outer join participantdt pa \n" +
"on pa.sstudyid = st.s_studyid \n" +
"and pa.rno = st.rno \n" +
"order by alls.rno";
logger.info("*****## Sample and Subject Alias Validation sql : "+sql);

DataSet ds = queryProcessor.getPreparedSqlDataSet(sql, sf.getValues());


sf.reset();
if(ds!=null && ds.getRowCount()>0){
ds.addColumn("useflag", DataSet.STRING);
int smpfound=0;
for(int i=0; i<ds.getRowCount(); i++) {
smpfound=ds.getInt(i, "samplefound", 0);
if((smpfound>0) && (valuesds.getString(i,
"samplealias").equals(ds.getString(i, "allsamples")))){
logger.info("*****!! Sample Alias "+ds.getString(i, "allsamples")
+" already present. Hence Skipping !!*****");
valuesds.setValue(i, "useflag", "S");
ds.setValue(i, "useflag", "S");
}
else {
valuesds.setValue(i, "useflag", "A");
ds.setValue(i, "useflag", "A");
if((0==(ds.getInt(i, "subjectfound"))) && (valuesds.getString(i,
"subjectalias").equals(ds.getString(i, "allsubjects")))){
subaliassb.append(";" + valuesds.getString(i,
"subjectalias", ""));
gendersb.append(";" + valuesds.getString(i, "gender", ""));
dobsb.append(";" + ds.getValue(i, "dob", ""));
studyidsb.append(";" + valuesds.getString(i, "sstudy",
""));
studysiteidsb.append(";" + valuesds.getString(i,
"studysitedesc", ""));
cpcohortb.append(";" + valuesds.getString(i, "cohort",
""));
expartidb.append(";" + valuesds.getString(i,
"externalparticipantid", ""));
flag=1;
counter=counter+1;
}
else{
valuesds.setValue(i, "subjectid", ds.getString(i,
"subjectid", ""));
valuesds.setValue(i, "participantid", ds.getString(i,
"participantid", ""));
logger.info("*****!! Subject Alias "+ds.getString(i,
"allsubjects")+" already present !!*****");
}
}

HashMap hm = new HashMap<>();


hm.put("useflag", "A");

valuesds = valuesds.getFilteredDataSet(hm);
ds = ds.getFilteredDataSet(hm);

if(flag==1){
logger.info("*****!! Subject Alias
"+subaliassb.toString().substring(1)+" not present !!*****");
logger.info("*****!! Creating New Subject with Alias
"+subaliassb.toString().substring(1)+" !!*****");
logger.info("*****!! Gender : "+gendersb.toString().substring(1)+".");
logger.info("*****!! DOB : "+dobsb.toString().substring(1)+".");
//// Creating Subject here

def propsforSubject=[
sdcid: "LV_Subject",
keyid1: "",
keyid2: "",
keyid3: "",
overrideautokey: "N",
genderflag: gendersb.toString().substring(1),
birthdt: dobsb.toString().substring(1),
u_group: cpcohortb.toString().substring(1),
copies: counter,
propsmatch: "Y",
newkeyid1: ""
]
logger.info( "Calling AddSDDI with properties: " +
propsforSubject.toString());
processAction( "AddSDI", propsforSubject);

neubjectidsb.append(";" + propsforSubject.get("newkeyid1"));

def AddSDIAliasprops=[
sdcid: "LV_Subject",
keyid1: neubjectidsb.toString().substring(1),
keyid2: "",
keyid3: "",
aliasid: subaliassb.toString().substring(1),
aliastype: "Patient ID"
]
logger.info( "Calling AddSDIAlias with properties: " +
AddSDIAliasprops.toString())
processAction( "AddSDIAlias", AddSDIAliasprops );

subjectIDds.addColumnValues("subjectid", DataSet.STRING,
AddSDIAliasprops.get("keyid1"), ";", "");
subjectIDds.addColumnValues("subaliasid", DataSet.STRING,
AddSDIAliasprops.get("aliasid"), ";", "");

for(int i=0; i<subjectIDds.getRowCount(); i++) {


valuesds.setValue(valuesds.findRow("subjectalias",
subjectIDds.getString(i, "subaliasid")), "subjectid", subjectIDds.getString(i,
"subjectid", ""));
}
}

logger.info("####### Completed Validation of Sample and Subject Alias Field


#######");

//Checking Participant using external participantid. If not present Enrolling


the subject. Also enrolling the new subjects
logger.info("####### Starting Validation of Participant Field #######");

String isProtocol;
String protocolid;
String cpcohort;
String partid;
for(int i=0; i<ds.getRowCount(); i++) {
isProtocol = ds.getString(i, "clinicalflag", "");
partid = ds.getString(i, "participantid", "0");
if(!("0".equalsIgnoreCase(partid))){
if("Y".equalsIgnoreCase(isProtocol)){
cpcohort = ds.getString(i, "cpcohortid");
protocolid = ds.getString(i, "clinicalprotocolid");
if(!(cpcohort.equals(valuesds.getString(i, "cohort")))){
logger.info("*****!! External Participant
"+ds.getValue(i, "externalparticipantid")+" present for the Study "+ds.getValue(i,
"s_studyid")+". But Mismatch Cohort !!*****");
}
if(!(protocolid.equals(valuesds.getString(i, "protocol"))))
{
logger.info("*****!! External Participant
"+ds.getValue(i, "externalparticipantid")+" present for the Study "+ds.getValue(i,
"s_studyid")+". But Mismatch Protocol !!*****");
//logger.info("####### Completed Validation of
Participant Field #######");
valuesds.setValue(i, "useflag", "S");
ds.setValue(i, "useflag", "S");
//throw new
SapphireException(SapphireException.TYPE_FAILURE, "Protocol "+valuesds.getString(i,
"protocol")+" mismatch for External Participant "+ds.getValue(i,
"externalparticipantid")+".");
}
}
}

logger.info("####### Completed Validation of Participant Field


#######");

if(("0".equalsIgnoreCase(partid)) && ds.getInt(i, "subjectfound")!=0 &&


"A".equalsIgnoreCase(ds.getString(i, "useflag"))){
flag = 1;
neubjectidsb.append(";" + ds.getString(i, "subid", ""));
studyidsb.append(";" + ds.getString(i, "s_studyid", ""));
studysiteidsb.append(";" + valuesds.getString(i, "studysitedesc",
""));
cpcohortb.append(";" + valuesds.getString(i, "cohort", ""));
expartidb.append(";" + valuesds.getString(i,
"externalparticipantid", ""));
}
}

valuesds = valuesds.getFilteredDataSet(hm);
ds = ds.getFilteredDataSet(hm);

if(flag==1){
logger.info("*****!! Enrolling Participants for newly created Subjects
or not Enrolled subjects "+neubjectidsb.toString().substring(1)+" !!*****");

//// Enrolling Participant here


logger.info("*****!! Enrolling Participants for newly created Subjects
or not Enrolled subjects "+neubjectidsb.toString().substring(1)+" !!*****");

def AddUpdateParticipantprops=[
studyid: studyidsb.toString().substring(1),
studycode: "",
siteid: "",
sitename: studysiteidsb.toString().substring(1),
departmentid: "",
protocolrevision: "",
cohortid: cpcohortb.toString().substring(1),
participantid: "",
externalparticipantid: expartidb.toString().substring(1),
subjectid: neubjectidsb.toString().substring(1),
autopartenrollment: "Y",
participantenrollmentdt: "n",
mode: "add",
auditreason: "",
auditactivity: "",
auditsignedflag: "",
newparticipantid: "",
propsmatch: "Y"
]
logger.info( "Calling AddUpdateParticipant with properties: " +
AddUpdateParticipantprops.toString())
processAction( "AddUpdateParticipant", AddUpdateParticipantprops );

subjectIDds.addColumnValues("participant", DataSet.STRING,
AddUpdateParticipantprops.get("newparticipantid"), ";", "");

for(int i=0; i<subjectIDds.getRowCount(); i++) {


valuesds.setValue(valuesds.findRow("subjectalias",
subjectIDds.getString(i, "subaliasid")), "participantid", subjectIDds.getString(i,
"participant", ""));
}
}

//Checking Visit, Timepont and Clinical Event against a study.


logger.info("####### Starting Validation of Visit, Timepont and Clinical Event
against a study #######");

sql = "with allstudy as ( \n" +


"select rownum as rno, column_value as allstudies from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("sstudy", ";"), ";") +
")) \n" +
"), allsite as ( \n" +
"select rownum as rno, column_value as allsites from TABLE (sys.odcivarchar2list("
+ sf.addIn(valuesds.getColumnValues("studysitedesc", ";"), ";") + ")) \n" +
"), allprotocol as ( \n" +
"select rownum as rno, column_value as allprotocols from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("protocol", ";"), ";")
+ ")) \n" +
"), allcohort as ( \n" +
"select rownum as rno, column_value as allcohorts from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("cohort", ";"), ";") +
")) \n" +
"), allvisit as ( \n" +
"select rownum as rno, column_value as allvisits from TABLE (sys.odcivarchar2list("
+ sf.addIn(valuesds.getColumnValues("visit", ";"), ";") + ")) \n" +
"), alltimepoint as ( \n" +
"select rownum as rno, nvl(column_value, 'NA') as alltimepoints from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("timepoint", ";"), ";")
+ ")) \n" +
"), isstudyp as ( \n" +
"select rownum as rno, s_studyid, clinicalflag \n" +
"from s_study, allstudy als \n" +
"where s_studyid in (als.allstudies) \n" +
"), peventtimepoint as ( \n" +
"select st.rno, cp.s_clinicalprotocolid, cp.s_clinicalprotocolversionid,
cp.s_clinicalprotocolrevision, ed.s_eventdefid, ed.eventdeflabel,
nvl(ed.parenteventdeflabel, 'NA') timepoint \n" +
" from isstudyp st, allsite ast, allprotocol ap, allcohort ac, allvisit av,
alltimepoint atp, s_clinicalprotocol cp, s_studysite sts, s_eventdef ed \n" +
" where ast.rno = st.rno \n" +
" and ap.rno = st.rno \n" +
" and ac.rno = st.rno \n" +
" and av.rno = st.rno \n" +
" and atp.rno = st.rno \n" +
" and st.clinicalflag = 'Y' \n" +
" and sts.sstudyid = st.s_studyid \n" +
" and sts.studysitedesc = ast.allsites \n" +
" and sts.clinicalprotocolrevision = ap.allprotocols \n" +
" and cp.sstudyid = sts.sstudyid \n" +
" and cp.s_clinicalprotocolid = sts.clinicalprotocolid \n" +
" and cp.s_clinicalprotocolrevision = sts.clinicalprotocolrevision \n" +
" and cp.versionstatus = 'C' \n" +
" and ed.clinicalprotocolid = cp.s_clinicalprotocolid \n" +
" and ed.clinicalprotocolversionid = cp.s_clinicalprotocolversionid \n" +
" and ed.clinicalprotocolrevision = cp.s_clinicalprotocolrevision \n" +
" and ed.cohortid = ac.allcohorts \n" +
" and ((nvl(ed.parenteventdeflabel, 'NA') = av.allvisits \n" +
" and ed.eventdeflabel = atp.alltimepoints)) \n" +
"), noncpevent as ( \n" +
"select st.rno, ce.clinicaleventdesc \n" +
" from isstudyp st, allvisit npce, s_clinicalevent ce \n" +
" where npce.rno = st.rno \n" +
" and ce.sstudyid = st.s_studyid \n" +
" and st.clinicalflag = 'N' \n" +
" and ce.clinicaleventdesc = npce.allvisits \n" +
") \n" +
"select st.rno, st.s_studyid, st.clinicalflag, ast.allsites, npce.allvisits
clinicalevents, pet.s_eventdefid, \n" +
"(select s_studysiteid from s_studysite where s_studysite.sstudyid = st.s_studyid
and s_studysite.studysitedesc=ast.allsites) studysiteid, \n" +
"(case when st.clinicalflag = 'Y' then pet.s_clinicalprotocolid else null end)
clinicalpid, \n" +
"(case when st.clinicalflag = 'Y' then pet.s_clinicalprotocolversionid else null
end) clinicalpverid, \n" +
"(case when st.clinicalflag = 'Y' then pet.s_clinicalprotocolrevision else null
end) clinicalprev, \n" +
"(case when pet.eventdeflabel is not null then 1 else 0 end) eventfound, \n" +
"(case when pet.timepoint is not null then 1 else 0 end) timepointfound, \n" +
"pet.eventdeflabel pevent, pet.timepoint ptimepoint, \n" +
"(case when npe.clinicaleventdesc is not null then 1 else 0 end) npeventfound, \n"
+
"npe.clinicaleventdesc npevent \n" +
"from isstudyp st \n" +
"left outer join allsite ast \n" +
"on ast.rno = st.rno \n" +
"left outer join allvisit npce \n" +
"on npce.rno = st.rno \n" +
"left outer join peventtimepoint pet \n" +
"on pet.rno = st.rno \n" +
"left outer join noncpevent npe \n" +
"on npe.rno = st.rno \n" +
"order by st.rno";
logger.info("*****## Visit, Timepoint, Clinical Event Validation sql : "+sql);

DataSet ds1 = queryProcessor.getPreparedSqlDataSet(sql, sf.getValues());


sf.reset();

if(ds1!=null && ds1.getRowCount()>0){

for(int i=0; i<ds1.getRowCount(); i++) {

if(("Y".equals(ds1.getString(i, "clinicalflag")))){
if(((ds1.getInt(i, "eventfound", 0))==1) && ((ds1.getInt(i,
"timepointfound", 0))==1)){
logger.info("*****## Event, Timepoint matches ##*****");
}
else {
logger.info("*****!! Event, Timepoint mismatch !!*****");
throw new SapphireException(SapphireException.TYPE_FAILURE,
"Event, Timepoint mismatch !");
}
}
else {
if(((ds1.getInt(i, "npeventfound", 0))==1)){
logger.info("*****## Clinical Event matches ##*****");
}
else {
logger.info("*****!! Clinical Event mismatch !!*****");
throw new SapphireException(SapphireException.TYPE_FAILURE,
"Clinical Event mismatch !");
}
}
}

////////////// Sample Creation //////////////////


logger.info("####### Creating Sample and adding Alias #######");

if(valuesds.getRowCount()>0 && valuesds!=null){

sql="with allqtyunit as ( \n" +


"select rownum as rno, column_value as allqtyunits from TABLE
(sys.odcivarchar2list("+ sf.addIn(valuesds.getColumnValues("qtyunit", ";"), ";")
+")) \n" +
"), allsampletype as ( \n" +
"select rownum as rno, column_value as allsampletypes from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("sampletype", ";"),
";") + ")) \n" +
"), allkit as ( \n" +
"select rownum as rno, column_value as allkits from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("kitid", ";"), ";") +
")) \n" +
"), allpkgtrack as ( \n" +
"select rownum as rno, column_value as allpkgtracks from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("pkgtracking", ";"),
";") + ")) \n" +
"), allstorage as ( \n" +
"select rownum as rno, column_value as allstorages from TABLE
(sys.odcivarchar2list(" + sf.addIn(valuesds.getColumnValues("storage", ";"), ";") +
")) \n" +
"), pkgstorage as ( \n" +
"select ap.rno, sp.s_packageid, su.storageunitid, sp.trackingnumber \n" +
"from allpkgtrack ap, s_package sp, storageunit su \n" +
"where sp.trackingnumber in (ap.allpkgtracks) \n" +
"and su.linksdcid = 'LV_Package' \n" +
"and su.linkkeyid1 = sp.s_packageid \n" +
") \n" +
"select aq.rno, ci.categoryid, ak.allkits, \n" +
"(select u_lab_code from s_sampletype where s_sampletypeid =
ast.allsampletypes) labcode, \n" +
"(select count(t.trackitemid) from trackitem t where t.trackitemlabel =
ak.allkits) haskit, \n" +
"(select t.trackitemid from trackitem t where t.trackitemlabel = ak.allkits)
kittrackitem, \n" +
"(select ps.s_packageid from pkgstorage ps where ps.rno = ap.rno)
packagestorageid, \n" +
"(select count(su.storageunitid) from storageunit su where su.labelpath =
als.allstorages and su.spaceavailflag = 'Y' and maxtiallowed > 0)
storagavailableflag, \n" +
"(select su.storageunitid from storageunit su where su.labelpath =
als.allstorages and su.spaceavailflag = 'Y' and maxtiallowed > 0) storageunitid \n"
+
"from allqtyunit aq, allsampletype ast, allkit ak, allpkgtrack ap, allstorage
als, categoryitem ci \n" +
"where ast.rno = aq.rno \n" +
"and ak.rno = aq.rno \n" +
"and ap.rno = aq.rno \n" +
"and als.rno = aq.rno \n" +
"and ci.sdcid = 'Units' \n" +
"and ci.keyid1 in (aq.allqtyunits) \n" +
"and ci.categoryid in ('MassUnits', 'VolumeUnits', 'ConcUnits') \n" +
"order by aq.rno";
logger.info("*****## Qualtity and Labcode sql : "+sql);

ds.reset();
ds = queryProcessor.getPreparedSqlDataSet(sql, sf.getValues());
sf.reset();

StringBuffer inivolb = new StringBuffer();


StringBuffer inivolunitb = new StringBuffer();
StringBuffer inimassb = new StringBuffer();
StringBuffer inimassunitb = new StringBuffer();
StringBuffer iniconcb = new StringBuffer();
StringBuffer iniconcunitb = new StringBuffer();
StringBuffer custodialuser = new StringBuffer();
StringBuffer custodialdept = new StringBuffer();
int kitfnpflag = 0;
int storageflag = 0;

if(ds!=null && ds.getRowCount()>0){

for(int i=0; i<ds.getRowCount(); i++) {


String qtytype = ds.getString(i, "categoryid", "");
int kitflag = ds.getInt(i, "haskit", 0);
int storageavlflag = ds.getInt(i, "storagavailableflag", 0);
logger.info("*****!! storageavlflag : "+storageavlflag);

if("MassUnits".equalsIgnoreCase(qtytype)){
inimassb.append(";" + valuesds.getString(i, "qtyvalue",
""));
inimassunitb.append(";" + valuesds.getString(i, "qtyunit",
""));
}
else {
inimassb.append(";");
inimassunitb.append(";");
}
if("VolumeUnits".equalsIgnoreCase(qtytype)){
inivolb.append(";" + valuesds.getString(i, "qtyvalue",
""));
inivolunitb.append(";" + valuesds.getString(i, "qtyunit",
""));
}
else {
inivolb.append(";");
inivolunitb.append(";");
}
if("ConcUnits".equalsIgnoreCase(qtytype)){
iniconcb.append(";" + valuesds.getString(i, "qtyvalue",
""));
iniconcunitb.append(";" + valuesds.getString(i, "qtyunit",
""));
}
else {
iniconcb.append(";");
iniconcunitb.append(";");
}

if(kitflag==0){
logger.info("*****!! Kit "+ds.getString(i, "allkits", "")+"
not present !!*****");
}
else {
kitfnpflag = 1;
}

if(storageavlflag==0){
custodialuser.append(";" + userid);
custodialdept.append(";" + deptid);
logger.info("*****!! Custodial User :
"+custodialuser.toString().substring(1)+" !!*****");
logger.info("*****!! Custodial Department :
"+custodialdept.toString().substring(1)+" !!*****");
}
else {
storageflag = 1;
custodialuser.append(";");
custodialdept.append(";");
}
}
}

def AddSDIprops=[
sdcid: "Sample",
templateid: "",
overrideautokey: "",
copies: valuesds.getRowCount(),
keyid1: "",
keyid2: "",
keyid3: "",
eventnotify: "",
auditreason: "",
adduserroles: "",
addtemplateroles: "",
applyworkitems: "Y",
forcenew: "",
newkeyid1: "",
usetemplatedepartment: "",
auditactivity: "",
auditsignedflag: "",
auditdt: "",
templatekeyid1: "",
templatekeyid2: "",
templatekeyid3: "",
templateflag: "",
copyattachment: "",
copyattachmentmode: "",
checkinsdiflag: "",
newkeyid2: "",
newkeyid3: "",
sstudyid: valuesds.getColumnValues("sstudy", ";"),
u_primary: valuesds.getColumnValues("primary", ";"),
sampletypeid: valuesds.getColumnValues("sampletype", ";"),
u_lab_code_sampletype: ds.getColumnValues("labcode", ";"),
u_condition: valuesds.getColumnValues("samplecondition", ";"),
collectiondt: valuesds.getColumnValues("collectiondt", ";"),
receiveddt: valuesds.getColumnValues("receivedt", ";"),
storagestatus: "Received",
concentration: iniconcb.toString().substring(1),
concentrationunits: iniconcunitb.toString().substring(1),
__samplefamily_initialmass: inimassb.toString().substring(1),
__samplefamily_initialmassunits: inimassunitb.toString().substring(1),
__samplefamily_initialvolume: inivolb.toString().substring(1),
__samplefamily_initialvolumeunits: inivolunitb.toString().substring(1),
__samplefamily_collectiondt: valuesds.getColumnValues("collectiondt",
";"),
__samplefamily_studysiteid: ds1.getColumnValues("studysiteid", ";"),
__samplefamily_subjectid: valuesds.getColumnValues("subjectid", ";"),
__samplefamily_externalsubject:
valuesds.getColumnValues("externalparticipantid", ";"),
__samplefamily_participantid: valuesds.getColumnValues("participantid",
";"),
__samplefamily_clinicalevent: valuesds.getColumnValues("visit", ";"),
__samplefamily_clinicalprotocolid: ds1.getColumnValues("clinicalpid",
";"),
__samplefamily_clinicalprotocolversionid:
ds1.getColumnValues("clinicalpverid", ";"),
__samplefamily_clinicalprotocolrevision:
ds1.getColumnValues("clinicalprev", ";"),
__samplefamily_eventdefid: ds1.getColumnValues("s_eventdefid", ";"),
__samplefamily_kittrackitem: ds.getColumnValues("kittrackitem", ";"),
__samplefamily_initialpackageid: ds.getColumnValues("packagestorageid",
";"),
__trackitem_containertypeid: valuesds.getColumnValues("containertype",
";"),
__trackitem_qtycurrent: valuesds.getColumnValues("qtyvalue", ";"),
__trackitem_qtyunits: valuesds.getColumnValues("qtyunit", ";"),
__trackitem_custodialuserid: custodialuser.toString().substring(1),
__trackitem_custodialdepartmentid:
custodialdept.toString().substring(1),
propsmatch: "Y"
]

logger.info( "Calling AddSDI with properties: " + AddSDIprops.toString());


processAction( "AddSDI", AddSDIprops );

sampleid = AddSDIprops.get("newkeyid1");

def AddSDIAliasprops=[
sdcid: "Sample",
keyid1: sampleid,
keyid2: "",
keyid3: "",
aliasid: valuesds.getColumnValues("samplealias", ";"),
aliastype: valuesds.getColumnValues("samplealiastype", ";"),
propsmatch: "Y"
]
logger.info( "Calling AddSDIAlias with properties: " +
AddSDIAliasprops.toString());
processAction( "AddSDIAlias", AddSDIAliasprops );

def AddSDIDetailprops=[
sdcid: "Sample",
keyid1: sampleid,
keyid2: "",
keyid3: "",
linkid: "SampleDetail",
detailtype: "Treatment",
detailvalue: valuesds.getColumnValues("treatment", ";"),
detailsdcid: "LV_Treatment",
applylock: "",
detailkeyid1: valuesds.getColumnValues("treatment", ";"),
eventnotify: "",
auditreason: "Drug Name Added via DFD",
auditactivity: "Add",
auditsignedflag: "N",
separator: ";"
]
logger.info( "Calling AddSDIDetail with properties: " +
AddSDIDetailprops.toString());
processAction( "AddSDIDetail", AddSDIDetailprops );

if(kitfnpflag != 0){
// Update Kit status as Used.
logger.info("####### Update Kit status as Used. #######");
def EditSDIprops=[
sdcid: "TrackItemSDC",
keyid1: ds.getColumnValues("kittrackitem", ";"),
keyid2: "",
keyid3: "",
auditreason: "Kit marked as used via DFD",
eventnotify: "",
applylock: "",
auditactivity: "Update",
auditsignedflag: "N",
auditdt: "",
trackitemstatus: "Used"
]
logger.info( "Calling EditSDI with properties: " +
EditSDIprops.toString());
processAction( "EditSDI", EditSDIprops );
}

// File Samples to the Package


/*logger.info("####### File Samples to the Package. #######");
def AssignPKGStrgprops=[
storageunitid: ds.getColumnValues("packagestorageid", ";"),
sdcid: "Sample",
keyid1: sampleid,
keyid2: "",
keyid3: "",
makeretain: "",
trackitemid: "",
istrackitem: "",
clearstorage: "",
applylock: ""
]
logger.info( "Calling AssignStrgAndReceive with properties: " +
AssignPKGStrgprops.toString())
processAction( "AssignStrgAndReceive", AssignPKGStrgprops );
*/

// File Samples to the Storage Unit


logger.info("####### File Samples to the Storage Unit. #######");

if(storageflag != 0){
def AssignStrgAndReceiveprops=[
storageunitid: ds.getColumnValues("storageunitid", ";"),
sdcid: "Sample",
keyid1: sampleid,
keyid2: "",
keyid3: "",
makeretain: "",
trackitemid: "",
istrackitem: "",
clearstorage: "",
applylock: ""
]
logger.info( "Calling AssignStrgAndReceive with properties: " +
AssignStrgAndReceiveprops.toString())
processAction( "AssignStrgAndReceive", AssignStrgAndReceiveprops );
}

}
else {
logger.info("*****!! No Samples to create !!*****");
}

You might also like