-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedicalTestResult.java
More file actions
89 lines (72 loc) · 3.38 KB
/
MedicalTestResult.java
File metadata and controls
89 lines (72 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.util.*;
class MedicalTestResult {
double resultValue;
public MedicalTestResult(double resultValue) {
this.resultValue = resultValue;
}
public double getResultValue() {
return resultValue;
}
}
public class medicalTestAnalyzer {
public static Map<String, Integer> countPatientsByResultRange(List<MedicalTestResult> resultsList) {
Map<String, Integer> countByResultRange = new HashMap<>();
for (MedicalTestResult result : resultsList) {
String resultRange = getResultRange(result.resultValue);
countByResultRange.put(resultRange, countByResultRange.getOrDefault(resultRange, 0) + 1);
}
return countByResultRange;
}
public static Map<String, Double> calculateAverageValueByResultRange(List<MedicalTestResult> resultsList) {
Map<String, Double> avgValueByResultRange = new HashMap<>();
Map<String, Double> totalValueByResultRange = new HashMap<>();
Map<String, Integer> countByResultRange = new HashMap<>();
for (MedicalTestResult result : resultsList) {
String resultRange = getResultRange(result.resultValue);
double currentValue = result.getResultValue();
double totalValue = totalValueByResultRange.getOrDefault(resultRange, 0.0);
int count = countByResultRange.getOrDefault(resultRange, 0);
totalValueByResultRange.put(resultRange, totalValue + currentValue);
countByResultRange.put(resultRange, count + 1);
}
for (Map.Entry<String, Integer> entry : countByResultRange.entrySet()) {
String resultRange = entry.getKey();
int count = entry.getValue();
double totalValue = totalValueByResultRange.get(resultRange);
avgValueByResultRange.put(resultRange, totalValue / count);
}
return avgValueByResultRange;
}
public static String getResultRange(double resultValue) {
if (resultValue < 10) {
return "Normal";
} else if (resultValue < 20) {
return "Borderline";
} else {
return "High";
}
}
public static void main(String[] args) {
// Sample medical test results
List<MedicalTestResult> resultsList = new ArrayList<>();
resultsList.add(new MedicalTestResult(5));
resultsList.add(new MedicalTestResult(15));
resultsList.add(new MedicalTestResult(25));
resultsList.add(new MedicalTestResult(8));
resultsList.add(new MedicalTestResult(18));
// Count patients by result range
Map<String, Integer> patientsByResultRange = countPatientsByResultRange(resultsList);
// Calculate average value by result range
Map<String, Double> avgValueByResultRange = calculateAverageValueByResultRange(resultsList);
// Display results
System.out.println("Number of patients with results within each range:");
for (Map.Entry<String, Integer> entry : patientsByResultRange.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue() + " patients");
}
System.out.println("\nAverage value for each result range:");
for (Map.Entry<String, Double> entry : avgValueByResultRange.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}
74 changes: 74 additions & 0 deletions74