import java.util.ArrayList;
import java.util.Iterator;
public class EWS_Engine {
///Task 2.1
public int EWS(int hr, float bp, float temp, int rr, int spo2){
//RR
int ews=0;
if ( rr <= 8)
{
ews = +3;
}
else if ( rr <=11)
{
ews = +1;
}
else if ( rr <=24)
{
ews = +2;
}
else if ( rr >= 25)
{
ews = +3;
}
//SPO2
if ( spo2 <=91)
{
ews = +3;
}
else if (spo2 <=93){
ews = +2;
}
else if (spo2 <=95){
ews = +1;
}
//HR
if ( hr <=40)
{
ews = +3;
}
else if (hr <=50){
ews = +1;
}
if (hr >=131){
ews = +3;
}
else if (hr >=111){
ews = +2;
}
else if (hr >=91){
ews = +1;
}
//BP
if ( bp <=90)
{
ews = +3;
}
else if (bp <=100){
ews = +2;
}
else if (bp <=110){
ews = +1;
}
else if (bp <=220){
ews = +3;
}
//Temp
if ( temp <=35)
{
ews = +3;
}
else if (temp <=36){
ews = +1;
}
if (temp >=38.1){
ews = +1;
}
else if (temp >=39.1){
ews= +2;
}
return ews;
}
//Task 2.2
public int EWS(VitalSign data){
//input correct variables into other ews method
return EWS(data.getHr(),data.getBp(),data.getTemp(), data.getRr(), data.getSpo2());
}
}
return EWS(data.getHr(), data.getBp(), data.getTemp(), data.getRr(), data.getSpo2());
}
//Task 2.3
public ArrayList<String> fuzzyEWS(ArrayList<VitalSign> data) {
ArrayList<String> traffic = new ArrayList<String>();
for(int i =0;i < data.size();i++) {
if (EWS(data.get(i)) <= 1) {
traffic.add("Green");
}
else if (EWS(data.get(i)) <5) {
traffic.add("Amber");
}
else if (EWS(data.get(i)) >= 5) {
traffic.add("Red");
}
}
return traffic;
}
public boolean testFuzzyEWS(ArrayList<VitalSign> data,ArrayList<String> correct_answers) {
boolean test = true;
fuzzyEWS(data);
for (int i =0; i<data.size();i++){
if (!data.get(i).equals(correct_answers.get(i))) { test = false;}
}
return test;
}
}
//Task 2.4
public void assignTimestamp(int interval, ArrayList<VitalSign> data) {
for (int i =0;i<data.size();i++){
data.get(i).setTimestamp(i * interval);
}
}
public void printEWSMessage(String path, int interval, long start, long end) {
ArrayList<VitalSign> samples = DataImporter.importFromDataFile(path);
ArrayList<VitalSign> sampleinterval = new ArrayList<VitalSign>();
assignTimestamp(interval, samples);
//Changes start and end to the index of the array it corresponds to
start = start + (start%interval);
start = start / interval;
end = end - (end % interval);
end = end /interval;
if (start>end){
long whatstartwas = start;
start = end;
end = whatstartwas;
}
// If end is larger than array size
if (end>samples.size()){
end = samples.size();
}
else if (end <0) {
end = 0;
}
if (start < 0){
start = 0;
}
else if (start > samples.size()){
start = samples.size();
}
for (int i=(int)start;i<end;i++){
sampleinterval.add(samples.get(i));
}
ArrayList<String> traffic = fuzzyEWS(sampleinterval);
for (int i=(int)start;i<end;i++){
System.out.println(traffic.get(i));
}
}
}