Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97146476
RequestOk.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jan 2, 22:27
Size
7 KB
Mime Type
text/x-java
Expires
Sat, Jan 4, 22:27 (2 d)
Engine
blob
Format
Raw Data
Handle
23337661
Attached To
R3229 Genome Privacy - SHCS App
RequestOk.java
View Options
package
com.example.genomicprivacy
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
FrameWork.DBconnector_mu
;
import
FrameWork.Request
;
import
FrameWork.RequestPatient
;
import
android.app.Fragment
;
import
android.graphics.Color
;
import
android.os.AsyncTask
;
import
android.os.Bundle
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View.OnClickListener
;
import
android.view.ViewGroup
;
import
android.widget.AdapterView
;
import
android.widget.AdapterView.OnItemClickListener
;
import
android.widget.ArrayAdapter
;
import
android.widget.AutoCompleteTextView
;
import
android.widget.Button
;
import
android.widget.CheckBox
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
android.widget.Toast
;
/**
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
public
class
RequestOk
extends
Fragment
{
/**
* List of all the requests who have been accepted
*/
ArrayList
<
RequestPatient
>
okRequest
=
new
ArrayList
<
RequestPatient
>();
/**
* List of all the requests who have been accepted by a specific patient
*/
ArrayList
<
RequestPatient
>
requestOnePatient
=
new
ArrayList
<
RequestPatient
>();
/**
* Ok button for searching a patient
*/
Button
ok
;
/**
* Button for performing the test
*/
Button
perfTest
;
/**
* View for entering the patient's ID
*/
TextView
idSearch
;
/**
* Layout for all the request who has been accepted by the patient
*/
LinearLayout
linCheckBoxOk
;
/**
* Check box for the request on which the test will be perform
*/
CheckBox
checkBoxOk
;
/**
* List of the result
*/
double
[][]
results
;
/**
* List of the result
*/
double
[]
resultsPDF
;
/**
* Info of the patient
*/
String
patientDisplay
;
/**
* List of the test's ID
*/
int
[]
IDs_t
;
/**
* View for display all the matches of the patient's search
*/
AutoCompleteTextView
textRequestOk
;
/**
* Adapter for displaying the result
*/
ArrayAdapter
<
String
>
adapterRequestOk
;
int
id_p
;
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
)
{
// TODO Auto-generated method stub
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_request_ok
,
container
,
false
);
textRequestOk
=
(
AutoCompleteTextView
)
view
.
findViewById
(
R
.
id
.
autoSearchReqOk
);
perfTest
=
(
Button
)
view
.
findViewById
(
R
.
id
.
performTest
);
linCheckBoxOk
=
(
LinearLayout
)
view
.
findViewById
(
R
.
id
.
linearCheckBoxesOkRequest
);
new
GetRequestPending
().
execute
();
new
getPatientName
().
execute
(
textRequestOk
.
getText
().
toString
());
textRequestOk
.
setOnItemClickListener
(
new
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
AdapterView
<?>
arg0
,
View
arg1
,
int
pos
,
long
arg3
)
{
linCheckBoxOk
.
removeAllViews
();
patientDisplay
=
arg0
.
getItemAtPosition
(
pos
).
toString
();
String
[]
patientSelected
;
patientSelected
=
arg0
.
getItemAtPosition
(
pos
).
toString
()
.
split
(
" ; "
);
id_p
=
Integer
.
parseInt
(
patientSelected
[
2
]);
searchID
();
}
});
perfTest
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
new
PerformTest
().
execute
();
}
});
return
view
;
}
/**
* Search the patient from his ID that have entered previously on the
* EditText
*/
private
void
searchID
()
{
for
(
int
i
=
0
;
i
<
okRequest
.
size
();
i
++)
{
if
(
id_p
==
okRequest
.
get
(
i
).
getId_p
())
{
requestOnePatient
.
add
(
okRequest
.
get
(
i
));
checkBoxOk
=
new
CheckBox
(
ContextApp
.
getContext
());
checkBoxOk
.
setText
(
""
+
okRequest
.
get
(
i
).
getNameTest
());
checkBoxOk
.
setTextColor
(
Color
.
BLACK
);
linCheckBoxOk
.
addView
(
checkBoxOk
);
}
}
}
/**
* Asynchrous task which send to the server for performing the test
*
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
private
class
PerformTest
extends
AsyncTask
<
Void
,
Void
,
Void
>
{
@Override
protected
Void
doInBackground
(
Void
...
params
)
{
ArrayList
<
RequestPatient
>
listSelected
=
new
ArrayList
<
RequestPatient
>();
results
=
new
double
[
linCheckBoxOk
.
getChildCount
()][
2
];
resultsPDF
=
new
double
[
linCheckBoxOk
.
getChildCount
()];
IDs_t
=
new
int
[
linCheckBoxOk
.
getChildCount
()];
for
(
int
i
=
0
;
i
<
requestOnePatient
.
size
();
i
++)
{
CheckBox
box
=
(
CheckBox
)
linCheckBoxOk
.
getChildAt
(
i
);
if
(
box
.
isChecked
())
{
listSelected
.
add
(
requestOnePatient
.
get
(
i
));
}
}
String
[]
traits
=
new
String
[
listSelected
.
size
()];
String
[]
group
=
new
String
[
listSelected
.
size
()];
HashMap
<
Integer
,
Integer
>
mapIDdisToIDGroup
=
null
;
HashMap
<
Integer
,
String
>
mapIDgroupToGroup
=
null
;
HashMap
<
Integer
,
String
>
mapIDtoDiseases
=
null
;
// OK pour ID T
try
{
mapIDdisToIDGroup
=
DBconnector_mu
.
IDDisToIDcat
();
mapIDgroupToGroup
=
DBconnector_mu
.
catIDtocatName
();
mapIDtoDiseases
=
DBconnector_mu
.
IDDisToDisease
();
}
catch
(
SQLException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
for
(
int
j
=
0
;
j
<
listSelected
.
size
();
j
++)
{
Request
r
=
createRequest
(
listSelected
.
get
(
j
));
IDs_t
[
j
]
=
r
.
getId_t
();
results
[
j
]
=
ContextApp
.
getMu
().
runTest
(
r
);
traits
[
j
]
=
mapIDtoDiseases
.
get
(
r
.
getId_t
());
group
[
j
]
=
mapIDgroupToGroup
.
get
(
mapIDdisToIDGroup
.
get
(
r
.
getId_t
()));
System
.
out
.
println
(
"RESULTAT"
+
results
[
j
][
1
]);
resultsPDF
[
j
]
=
results
[
j
][
0
];
}
ContextApp
.
getMu
().
createReport
(
resultsPDF
,
traits
,
group
,
IDs_t
);
for
(
int
i
=
0
;
i
<
results
.
length
;
i
++)
{
if
(
IDs_t
[
i
]
==
12
)
{
ContextApp
.
setResult12
(
results
[
i
][
1
]);
}
}
return
null
;
}
@Override
protected
void
onPostExecute
(
Void
result
)
{
// TODO Auto-generated method stub
super
.
onPostExecute
(
result
);
Toast
toast
=
Toast
.
makeText
(
ContextApp
.
getContext
(),
"Your PDF was created in GenomicPrivacy/PDFReports"
,
7000
);
toast
.
show
();
}
}
/**
* Asynchronous task which download all the pending's requests
*
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
private
class
GetRequestPending
extends
AsyncTask
<
Void
,
Void
,
ArrayList
<
RequestPatient
>>
{
ArrayList
<
RequestPatient
>
allRequest
=
new
ArrayList
<
RequestPatient
>();
@Override
protected
ArrayList
<
RequestPatient
>
doInBackground
(
Void
...
params
)
{
// TODO Auto-generated method stub
allRequest
=
ContextApp
.
getMu
().
checkNewRequest
();
for
(
int
i
=
0
;
i
<
allRequest
.
size
();
i
++)
{
if
(
allRequest
.
get
(
i
).
getFlag
()
==
1
)
{
okRequest
.
add
(
allRequest
.
get
(
i
));
}
}
return
okRequest
;
}
}
/**
* Create a request from a requestPatient
*
* @param request
* patient
* @return Request object
*/
public
Request
createRequest
(
RequestPatient
rp
)
{
// Request from
// RequestPatient
Request
r
=
null
;
try
{
r
=
new
Request
(
rp
.
getId_r
(),
rp
.
getId_p
(),
rp
.
getId_mu
(),
rp
.
getId_t
(),
DBconnector_mu
.
getMarkers
(
rp
.
getId_t
()),
DBconnector_mu
.
getCFs
(
rp
.
getId_t
()));
}
catch
(
SQLException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
return
r
;
}
/**
* Asynchronous task to retrieve the patients from what the user entered in
* the search box
*
* @author Serrano Kevin
* @author Weber Jeremy
*
*/
public
class
getPatientName
extends
AsyncTask
<
String
,
Void
,
ArrayList
<
String
>>
{
protected
ArrayList
<
String
>
doInBackground
(
String
...
letter
)
{
// TODO Auto-generated method stub
ArrayList
<
String
>
patientArray
=
DBconnector_mu
.
getPatientsName
(
letter
[
0
]);
return
patientArray
;
}
@Override
protected
void
onPostExecute
(
ArrayList
<
String
>
result
)
{
// TODO Auto-generated method stub
super
.
onPostExecute
(
result
);
adapterRequestOk
=
new
ArrayAdapter
<
String
>(
ContextApp
.
getContext
(),
R
.
layout
.
listitem
,
result
);
textRequestOk
.
setThreshold
(
1
);
textRequestOk
.
setAdapter
(
adapterRequestOk
);
}
}
}
Event Timeline
Log In to Comment