Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

db update

  • Loading branch information...
commit 14794180092529aed6afc2928f00cafd0b6d066a 1 parent 628cfc9
liang kong authored
19 xnat_redaction/src/org/ibcb/xnat/redaction/Loader.java
View
@@ -196,8 +196,12 @@ public static void main(String args[]){
}
// download checkout user information from our database -Liang
- HashMap<String,String> subjectCheckoutInfo=overallCheckoutInfo.get(subject_id);
-
+ String uniSubjectid=null;
+ if (db.lookupSubjectid(subject_id)!=null)
+ uniSubjectid=db.lookupSubjectid(subject_id).toString();
+ HashMap<String,String> subjectCheckoutInfo=null;
+ if (uniSubjectid!=null)
+ subjectCheckoutInfo=overallCheckoutInfo.get(uniSubjectid);
// populate map of checkout fields -Liang
HashMap<String, String> requesting_user_data = subjectCheckoutInfo;
HashMap<String, String> filter_data = new HashMap<String,String>();
@@ -230,7 +234,11 @@ public static void main(String args[]){
}
}
-
+ System.out.println("Check out map for subject "+subject_id);
+ for(String key : filter_data.keySet())
+ {
+ System.out.println(key+" | "+filter_data.get(key));
+ }
// Using the above data, along with req_field_names and insert resulting data into the filter_data hashmap
// example:
// user has already checked out Age previously, and is requesting to check out Race now
@@ -263,8 +271,9 @@ public static void main(String args[]){
String req_ID=requestId.toPlainString()+";";
SubjectInfo s_info=new SubjectInfo(null,SubjectInfo.transphiData(combined_demographics),project_id,req_ID,combined_demographics.get("PatientName"),combined_demographics.get("PatientBirthdate"));
//System.out.println("phi = "+combined_demographics.toString()+" request id = "+requestId.toPlainString());
- String db_subjectid=db.insertSubjectInfo(s_info);
- subject.setNewLabel(db_subjectid);
+ BigDecimal db_subjectid=db.insertSubjectInfo(s_info);
+ db.insertSubjectidMap(db_subjectid, subject_id);
+ subject.setNewLabel(db_subjectid.toString());
//System.out.println("new id "+db_subjectid);
if (db_subjectid!=null)
{
88 xnat_redaction/src/org/ibcb/xnat/redaction/database/DBManager.java
View
@@ -38,39 +38,24 @@ public DBManager(int type_of_work,String Hostname)
this.hostname=Hostname;
datasource.setServerName(hostname);
this.type_of_work=type_of_work;
- Initializer();
+ //Initializer();
}
public DBManager(int type_of_work)
{
datasource.setServerName(hostname);
this.type_of_work=type_of_work;
- Initializer();
+ //Initializer();
}
public DBManager()
{
type_of_work=SINGLE_THREAD;
datasource.setServerName(hostname);
- Initializer();
+ //Initializer();
}
private void Initializer()
{
- //init the phi map
- PHImap= new HashMap<String,String>();
- Connection newcon = null;
- try {
- newcon = datasource.getConnection();
- stmt = newcon.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM phimap;");
- while(rs.next())
- {
- PHImap.put(rs.getString("UID"), rs.getString("PHI"));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
}
protected Connection getConnection()
@@ -249,7 +234,7 @@ private void updateCheckOutInfo(HashMap<String,HashMap<String,String>> checkout
for (String subjectid:info.getaffectedsubjects())
{
//update the checkou map for this subject id
- if (!checkoutinfo.containsKey(subjectid))
+ if (!checkoutinfo.containsKey(subjectid) || checkoutinfo.keySet()==null)
checkoutinfo.put(subjectid, getSubjectCheckOutInfo(subjectid,userid));
else
updateCheckOutInfo(checkoutinfo,subjectid,checkoutinfo.get(subjectid));
@@ -311,17 +296,17 @@ public String getSubjectID(String subjectname, String dateofbirth)
return subjectid;
}
- public String lookupSubject(SubjectInfo sinfo)
+ public BigDecimal lookupSubject(SubjectInfo sinfo)
{
Connection newcon = this.getConnection();
- String subjectid=null;
+ BigDecimal subjectid=null;
try {
stmt = newcon.createStatement();
ResultSet rs = stmt.executeQuery("SELECT subjectid FROM subjectinfo WHERE subjectname=\'"+sinfo.getSubjectname()+"\' AND dateofbirth=\'"+sinfo.getDateofbirth()+"\';");
//Check if the subject is already exist
if (rs.next())
{
- subjectid=rs.getString("subjectid");
+ subjectid=rs.getBigDecimal("subjectid");
}
if (rs.wasNull()) return null;
newcon.close();
@@ -333,11 +318,11 @@ public String lookupSubject(SubjectInfo sinfo)
}
- public String insertSubjectInfo(SubjectInfo sinfo)
+ public BigDecimal insertSubjectInfo(SubjectInfo sinfo)
{
Connection newcon = this.getConnection();
- String subjectid=lookupSubject(sinfo);
+ BigDecimal subjectid=lookupSubject(sinfo);
BigDecimal nextid = null;
ResultSet id_rs;
try {
@@ -346,13 +331,13 @@ public String insertSubjectInfo(SubjectInfo sinfo)
if (id_rs.next())
{
nextid=id_rs.getBigDecimal("nextval");
- System.out.println("VALUES ("+nextid.toString()+", \'"+sinfo.getphidata()+"\',\'"+sinfo.getProjectid()+"\',\'"+sinfo.getRequestidText()+"\',\'"+sinfo.getSubjectname()+"\',\'"+sinfo.getDateofbirth()+"\');");
+ //System.out.println("VALUES ("+nextid.toString()+", \'"+sinfo.getphidata()+"\',\'"+sinfo.getProjectid()+"\',\'"+sinfo.getRequestidText()+"\',\'"+sinfo.getSubjectname()+"\',\'"+sinfo.getDateofbirth()+"\');");
}
if (subjectid==null) {
stmt = newcon.createStatement();
stmt.execute("INSERT INTO subjectinfo (subjectid , phidata , projectid , requestids , subjectname , dateofbirth) VALUES ("+nextid.toString()+", \'"+sinfo.getphidata()+"\',\'"+sinfo.getProjectid()+"\',\'"+sinfo.getRequestidText()+"\',\'"+sinfo.getSubjectname()+"\',\'"+sinfo.getDateofbirth()+"\');");
newcon.close();
- return nextid.toString();
+ return nextid;
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
@@ -456,7 +441,7 @@ private void updateSubjectInfo(SubjectInfo sinfo)
SubjectInfo oldsinfo=null;
if (rs.next())
{
- oldsinfo=new SubjectInfo(rs.getString("subjectid"),rs.getString("phidata"),rs.getString("projectid"),rs.getString("requestids"));
+ oldsinfo=new SubjectInfo(rs.getBigDecimal("subjectid"),rs.getString("phidata"),rs.getString("projectid"),rs.getString("requestids"));
sinfo.merge(oldsinfo);
}
rs.close();
@@ -470,5 +455,54 @@ private void updateSubjectInfo(SubjectInfo sinfo)
}
}
+
+ public BigDecimal lookupSubjectid(String xnatid)
+ {
+ BigDecimal subjectid = null;
+ Connection newcon = this.getConnection();
+ try {
+ stmt = newcon.createStatement();
+ ResultSet id_rs = stmt.executeQuery("SELECT subjectid FROM subjectidmap WHERE xnatid LIKE \'%,"+xnatid+",%\'");
+ if (id_rs.next())
+ {
+ subjectid=id_rs.getBigDecimal("subjectid");
+ }
+ else
+ subjectid=null;
+ newcon.close();
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return subjectid;
+ }
+ public void insertSubjectidMap(BigDecimal subjectid,String xnatid)
+ {
+ Connection newcon = this.getConnection();
+ try {
+ stmt = newcon.createStatement();
+ ResultSet id_rs = stmt.executeQuery("SELECT subjectid,xnatid FROM subjectidmap WHERE subjectid="+subjectid);
+ if (id_rs.next())
+ {
+ String oldxnatid=id_rs.getString("xnatid");
+ //assume get only one xnatid at a time
+ //update
+ if (!oldxnatid.contains(xnatid)){
+ stmt=newcon.createStatement();
+ stmt.execute("UPDATE subjectidmap SET xnatid=\'"+oldxnatid+","+xnatid+"\' WHERE subjectid=\'"+subjectid+"\')");
+ }
+ }
+ else
+ {
+ //insert
+ stmt=newcon.createStatement();
+ stmt.execute("INSERT INTO subjectidmap(subjectid,xnatid) VALUES(\'"+subjectid+"\',\',"+xnatid+",\')");
+ }
+ newcon.close();
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
}
8 xnat_redaction/src/org/ibcb/xnat/redaction/database/DBinit.java
View
@@ -90,10 +90,10 @@ public static void setupDB(String hostname) throws SQLException{
}
else
System.out.println("Already have requestinfo table");
- if (!connection.getMetaData().getTables(null, null, "phimap", null).next())
+ if (!connection.getMetaData().getTables(null, null, "subjectidmap", null).next())
{
- System.out.println("Dont have PHImap, will create one");
- String cmd ="CREATE TABLE PHImap( UID integer, PHI char[])WITH ( OIDS=FALSE);ALTER TABLE PHImap OWNER TO "+username+";";
+ System.out.println("Dont have subjectidmap, will create one");
+ String cmd ="CREATE TABLE subjectidmap( subjectid integer NOT NULL, xnatid text, CONSTRAINT mapprimarykey PRIMARY KEY (subjectid))WITH ( OIDS=FALSE);ALTER TABLE subjectidmap OWNER TO "+username+";";
Statement stat=connection.createStatement();
try{stat.execute(cmd);}
catch(SQLException e)
@@ -104,7 +104,7 @@ public static void setupDB(String hostname) throws SQLException{
}
}
else
- System.out.println("Already have PHImap table");
+ System.out.println("Already have subjectidmap table");
}
}
public static void main(String[] argv) throws SQLException {
4 xnat_redaction/src/org/ibcb/xnat/redaction/database/RequestInfo.java
View
@@ -120,8 +120,8 @@ public void merge(RequestInfo oldrinfo)
{
//parse all the requestids
if (cinfo.length()<1) return null;
- if (!cinfo.contains(";")) return null;
- String[] Checkinfo=cinfo.split(";");
+ if (!cinfo.contains(",")) return null;
+ String[] Checkinfo=cinfo.split(",");
return Checkinfo;
}
17 xnat_redaction/src/org/ibcb/xnat/redaction/database/SubjectInfo.java
View
@@ -3,18 +3,17 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Set;
-
-
+import java.math.BigDecimal;
public class SubjectInfo {
- private String subjectid;
+ private BigDecimal subjectid;
private String phidata;
private String[] requestids;
private String projectid;
private String subjectname;
private String dateofbirth;
- public SubjectInfo(String sub,String phi,String proj,String[] req)
+ public SubjectInfo(BigDecimal sub,String phi,String proj,String[] req)
{
this.subjectid=sub;
this.requestids=req;
@@ -22,14 +21,14 @@ public SubjectInfo(String sub,String phi,String proj,String[] req)
this.phidata=phi;
}
- public SubjectInfo(String sub,String phi,String proj,String req)
+ public SubjectInfo(BigDecimal sub,String phi,String proj,String req)
{
this.subjectid=sub;
this.requestids=requestidParser(req);
this.projectid=proj;
this.phidata=phi;
}
- public SubjectInfo(String sub,String phi,String proj,String[] req,String name, String dateofbirth)
+ public SubjectInfo(BigDecimal sub,String phi,String proj,String[] req,String name, String dateofbirth)
{
this.subjectid=sub;
this.requestids=req;
@@ -39,7 +38,7 @@ public SubjectInfo(String sub,String phi,String proj,String[] req,String name, S
this.dateofbirth=dateofbirth;
}
- public SubjectInfo(String sub,String phi,String proj,String req,String name, String dateofbirth)
+ public SubjectInfo(BigDecimal sub,String phi,String proj,String req,String name, String dateofbirth)
{
this.subjectid=sub;
this.requestids=requestidParser(req);
@@ -48,10 +47,10 @@ public SubjectInfo(String sub,String phi,String proj,String req,String name, Str
this.subjectname=name;
this.dateofbirth=dateofbirth;
}
- public String getSubjectid() {
+ public BigDecimal getSubjectid() {
return subjectid;
}
- public void setSubjectid(String subjectid) {
+ public void setSubjectid(BigDecimal subjectid) {
this.subjectid = subjectid;
}
public String getphidata() {
Please sign in to comment.
Something went wrong with that request. Please try again.