diff --git a/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/AgeCohort.java b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/AgeCohort.java new file mode 100644 index 0000000000000000000000000000000000000000..34ece7f69ccaf8ccf08dfc5a3c2d06f012212e6f --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/AgeCohort.java @@ -0,0 +1,16 @@ +package edu.unl.cse.soft161.refactored.both_dry_violations; + +public class AgeCohort extends Cohort { + private int minimum; + private int maximum; + + public AgeCohort(int minimum, int maximum) { + this.minimum = minimum; + this.maximum = maximum; + } + + @Override + protected boolean includes(Patient patient) { + return minimum <= patient.getAge() && patient.getAge() <= maximum; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Cohort.java b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Cohort.java new file mode 100644 index 0000000000000000000000000000000000000000..acd09b5d4a5febae0f51428ad218b9b52d339860 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Cohort.java @@ -0,0 +1,19 @@ +package edu.unl.cse.soft161.refactored.both_dry_violations; + +import java.util.ArrayList; +import java.util.List; + +public abstract class Cohort { + protected abstract boolean includes(Patient patient); + + public List<Patient> filter(List<Patient> patients) { + List<Patient> results = new ArrayList<Patient>(); + for (Patient patient : patients) { + if (includes(patient)) { + results.add(patient); + } + } + return results; + } + +} \ No newline at end of file diff --git a/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Patient.java b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Patient.java new file mode 100644 index 0000000000000000000000000000000000000000..049775bd73e89ac047c878f25782259dd654a6e0 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/Patient.java @@ -0,0 +1,25 @@ +package edu.unl.cse.soft161.refactored.both_dry_violations; + +public class Patient { + private String name; + private String region; + private int age; + + public Patient(String name, String region, int age) { + this.name = name; + this.region = region; + this.age = age; + } + + public String getName() { + return name; + } + + public String getRegion() { + return region; + } + + public int getAge() { + return age; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/RegionalCohort.java b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/RegionalCohort.java new file mode 100644 index 0000000000000000000000000000000000000000..9ab068edd49c45449edd0487c3ec036a07058b8e --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/both_dry_violations/RegionalCohort.java @@ -0,0 +1,14 @@ +package edu.unl.cse.soft161.refactored.both_dry_violations; + +public class RegionalCohort extends Cohort { + private String region; + + public RegionalCohort(String region) { + this.region = region; + } + + @Override + protected boolean includes(Patient patient) { + return patient.getRegion().equals(region); + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Bradycardia.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Bradycardia.java new file mode 100644 index 0000000000000000000000000000000000000000..c9a53af4e78b52a8ab35e9879f38b3a419dbdd18 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Bradycardia.java @@ -0,0 +1,12 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_caller; + +public class Bradycardia implements Condition { + @Override + public boolean affects(Patient patient) { + return patient.getObservation("HR") < 60.0; + } + + public String toString() { + return "bradycardia"; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Condition.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Condition.java new file mode 100644 index 0000000000000000000000000000000000000000..ee646584eb742f583f75e65ecd47b772b57231d4 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Condition.java @@ -0,0 +1,5 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_caller; + +public interface Condition { + boolean affects(Patient patient); +} \ No newline at end of file diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Patient.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Patient.java new file mode 100644 index 0000000000000000000000000000000000000000..ce446ef5cb441af8e2c9e8a87e7da2d044c66cba --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Patient.java @@ -0,0 +1,30 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_caller; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Patient { + private String name; + private Map<String, Double>observations; + private List<Condition> monitoredConditions; + + public Patient(String name, List<Condition>monitoredConditions) { + this.name = name; + observations = new HashMap<String, Double>(); + this.monitoredConditions = monitoredConditions; + } + + public Double getObservation(String concept) { + return observations.get(concept); + } + + public void setObservation(String concept, Double value) { + observations.put(concept, value); + for (Condition condition : monitoredConditions) { + if (condition != null && condition.affects(this)) { + System.out.println("Warning: " + name + " has " + condition + "."); + } + } + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Tachycardia.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Tachycardia.java new file mode 100644 index 0000000000000000000000000000000000000000..dc5f78db3c0bd88688fb4a7a8eed6b6098215011 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_caller/Tachycardia.java @@ -0,0 +1,12 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_caller; + +public class Tachycardia implements Condition { + @Override + public boolean affects(Patient patient) { + return patient.getObservation("HR") > 100.0; + } + + public String toString() { + return "tachycardia"; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/Alert.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/Alert.java new file mode 100644 index 0000000000000000000000000000000000000000..50fd67f8f80cda42e33a2a11003cff57c7ee79e6 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/Alert.java @@ -0,0 +1,33 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_method_body; + +import java.time.ZonedDateTime; + +public class Alert { + private String type; + private String patient; + private ZonedDateTime timestamp; + private String message; + + public Alert(String type, String patient, ZonedDateTime timestamp, String message) { + this.type = type; + this.patient = patient; + this.timestamp = timestamp; + this.message = message; + } + + public String getType() { + return type; + } + + public String getPatient() { + return patient; + } + + public ZonedDateTime getTimestamp() { + return timestamp; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/SIRSAlert.java b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/SIRSAlert.java new file mode 100644 index 0000000000000000000000000000000000000000..b194503eb464b64d7f414235d30f97827c8c03a5 --- /dev/null +++ b/src/main/java/edu/unl/cse/soft161/refactored/dry_violation_in_method_body/SIRSAlert.java @@ -0,0 +1,17 @@ +package edu.unl.cse.soft161.refactored.dry_violation_in_method_body; + +import java.time.ZonedDateTime; +import java.util.List; + +public class SIRSAlert extends Alert { + private List<String> evidence; + + public SIRSAlert(String type, String patient, ZonedDateTime timestamp, String message, List<String> evidence) { + super(type, patient, timestamp, message); + this.evidence = evidence; + } + + public List<String> getEvidence() { + return evidence; + } +}