Skip to content

Commit

Permalink
add flowsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
zxmeng committed Apr 3, 2018
1 parent 5d36766 commit 683416d
Show file tree
Hide file tree
Showing 14 changed files with 398 additions and 29 deletions.
2 changes: 2 additions & 0 deletions initial/cmd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ curl 'localhost:8080/lab?pid=100A&labName=ACR&labValue=300&labUnit=&date=2017032
curl 'localhost:8080/lab?pid=100A&labName=ACR&labValue=403&labUnit=&date=20170320&labUnit=%B5g%2Fmg'
curl 'localhost:8080/lab?pid=100A&labName=ACR&labValue=324&labUnit=&date=20170318&labUnit=%B5g%2Fmg'

curl 'localhost:8080/lab?pid=100A&labName=ACR&labValue=324&labUnit=&date=20170311&labUnit=%B5g%2Fmg'


MKCK (pre-dialysis patients) eGFR > 15
PD (peritoneal dialysis patients)
Expand Down
50 changes: 50 additions & 0 deletions initial/src/main/java/KW/FlowSheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package KW;

import java.util.*;
import java.text.*;
import java.lang.*;

public class FlowSheet implements Comparable<FlowSheet> {

private String testDate;
private Double egfr;
private Double acr;
private Double srcr;

public String getTestDate() {return this.testDate;}
public void setTestDate(String testDate) {this.testDate = testDate;}

public Double getEgfr() {return this.egfr;}
public void setEgfr(Double egfr) {this.egfr = egfr;}

public Double getAcr() {return this.acr;}
public void setAcr(Double acr) {this.acr = acr;}

public Double getSrcr() {return this.srcr;}
public void setSrcr(Double srcr) {this.srcr = srcr;}

public int compareTo(FlowSheet compareLabTest) {
Date testDate = new Date();

try {
testDate = new SimpleDateFormat("yyyy-MM-dd").parse(((FlowSheet) compareLabTest).getTestDate());
} catch (Exception e) {

}
int compareQuantity = Integer.parseInt(new SimpleDateFormat("yyyyMMdd").format(testDate));

try {
testDate = new SimpleDateFormat("yyyy-MM-dd").parse(this.testDate);
} catch (Exception e) {

}
int thisQuantity = Integer.parseInt(new SimpleDateFormat("yyyyMMdd").format(testDate));

//descending order
return compareQuantity - thisQuantity;
//descending order
//return compareQuantity - this.quantity;

}

}
91 changes: 90 additions & 1 deletion initial/src/main/java/KW/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import KW.PatientRepository;
import KW.LabTest;
import KW.LabTestRepository;
import KW.FlowSheet;


@Controller
Expand Down Expand Up @@ -49,6 +50,9 @@ public String home(Model model) {
int[] scoreDis = getScoreDistribution();
model.addAttribute("scoreDis", scoreDis);

int[] stage = countPatientByStage();
model.addAttribute("stage", stage);

return "home";
}

Expand Down Expand Up @@ -131,7 +135,7 @@ public String individual(Model model, @RequestParam String pid
labTests = getLabTestsByPid(pid);
}
Collections.sort(labTests);
model.addAttribute("labTests", labTests);
// model.addAttribute("labTests", labTests);

List<String> egfrDateLabels = new ArrayList<>();
List<String> acrDateLabels = new ArrayList<>();
Expand All @@ -151,6 +155,37 @@ public String individual(Model model, @RequestParam String pid
model.addAttribute("acrDateLabels", acrDateLabels);
model.addAttribute("acrValues", acrValues);

Map<String, FlowSheet> map = new HashMap<String, FlowSheet>();
for (LabTest lt: labTests) {
String key = lt.getTestDate();
if (map.containsKey(key)) {
FlowSheet temp = map.get(lt.getTestDate());
if (lt.getLabName().equalsIgnoreCase("egfr")) {
temp.setEgfr(lt.getLabValue());
} else if (lt.getLabName().equalsIgnoreCase("acr")) {
temp.setAcr(lt.getLabValue());
} else if (lt.getLabName().equalsIgnoreCase("srcr")) {
temp.setSrcr(lt.getLabValue());
}
map.put(key, temp);
} else {
FlowSheet temp = new FlowSheet();
temp.setTestDate(key);
if (lt.getLabName().equalsIgnoreCase("egfr")) {
temp.setEgfr(lt.getLabValue());
} else if (lt.getLabName().equalsIgnoreCase("acr")) {
temp.setAcr(lt.getLabValue());
} else if (lt.getLabName().equalsIgnoreCase("srcr")) {
temp.setSrcr(lt.getLabValue());
}
map.put(key, temp);
}

}
List<FlowSheet> flowSheets = new ArrayList<>(map.values());
Collections.sort(flowSheets);
model.addAttribute("flowSheets", flowSheets);

return "individual";
} catch (Exception e) {

Expand Down Expand Up @@ -180,6 +215,9 @@ public String mkck(Model model) {
int[] scoreDis = getScoreDistributionByCategory("MKCK");
model.addAttribute("scoreDis", scoreDis);

int[] stage = countPatientByStageForMKCK();
model.addAttribute("stage", stage);

return "mkck";
}

Expand Down Expand Up @@ -469,6 +507,57 @@ public int[] countPatientsByGenderByCategory(String gender) {
return new int[] {patientsMKCK.size(), patientsPD.size(), patientsHD.size(), patientsAHD.size()};
}

public int[] countPatientByStage(){
List<Patient> stage_1 = new ArrayList<>();
List<Patient> stage_2 = new ArrayList<>();
List<Patient> stage_3a = new ArrayList<>();
List<Patient> stage_3b = new ArrayList<>();
List<Patient> stage_4 = new ArrayList<>();
List<Patient> stage_5 = new ArrayList<>();

Iterable<Patient> iterator = patientRepository.findAll();
for(Patient p: iterator) {
if (p.getEgfr() < 15) {
stage_5.add(p);
} else if (p.getEgfr() < 30) {
stage_4.add(p);
} else if (p.getEgfr() < 45) {
stage_3b.add(p);
} else if (p.getEgfr() < 60) {
stage_3a.add(p);
} else if (p.getEgfr() < 90) {
stage_2.add(p);
} else {
stage_1.add(p);
}
}
return new int[] {stage_1.size(), stage_2.size(), stage_3a.size(), stage_3b.size(), stage_4.size(), stage_5.size()};
}

public int[] countPatientByStageForMKCK(){
List<Patient> stage_1 = new ArrayList<>();
List<Patient> stage_2 = new ArrayList<>();
List<Patient> stage_3a = new ArrayList<>();
List<Patient> stage_3b = new ArrayList<>();
List<Patient> stage_4 = new ArrayList<>();

Iterable<Patient> iterator = patientRepository.findAll();
for(Patient p: iterator) {
if (p.getEgfr() < 30) {
stage_4.add(p);
} else if (p.getEgfr() < 45) {
stage_3b.add(p);
} else if (p.getEgfr() < 60) {
stage_3a.add(p);
} else if (p.getEgfr() < 90) {
stage_2.add(p);
} else {
stage_1.add(p);
}
}
return new int[] {stage_1.size(), stage_2.size(), stage_3a.size(), stage_3b.size(), stage_4.size()};
}

public int[] getScoreDistribution() {
int[] scoreCount = {0, 0, 0, 0, 0, 0, 0, 0, 0};
Iterable<Patient> iterator = patientRepository.findAll();
Expand Down
55 changes: 49 additions & 6 deletions initial/src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@
};
barChartData2.datasets[0].data = /*[[${scoreDis}]]*/;

var barChartData3 = {
labels: ['Stage 1', 'Stage 2', 'Stage 3A', 'Stage 3B', 'Stage 4', 'Stage 5'],
datasets: [{
label: 'Number of Patients',
backgroundColor: '#B7D3F2',
// borderColor: window.chartColors.red,
// borderWidth: 1,
data: []
}]

};
barChartData3.datasets[0].data = /*[[${stage}]]*/;

window.onload = function() {
var ctx = document.getElementById('canvas-dist').getContext('2d');
window.myBar = new Chart(ctx, {
Expand All @@ -115,7 +128,7 @@
options: {
title: {
display: true,
text: 'General Distribution of the Population'
text: 'General Distribution of Patients'
},
tooltips: {
mode: 'index',
Expand All @@ -141,7 +154,33 @@
options: {
title: {
display: true,
text: 'Score Distribution of the Population'
text: 'Score Distribution of Patients'
},
tooltips: {
mode: 'index',
intersect: false
},
responsive: true,
scales: {
xAxes: [{
// stacked: true,
barThickness : 65,
}],
yAxes: [{
// stacked: true
}]
}
}
});

var ctx3 = document.getElementById('canvas-dist3').getContext('2d');
window.myBar3 = new Chart(ctx3, {
type: 'bar',
data: barChartData3,
options: {
title: {
display: true,
text: 'Stage Distribution of Patients'
},
tooltips: {
mode: 'index',
Expand Down Expand Up @@ -189,12 +228,12 @@ <h1 id="fh5co-logo"><a href="/home"><img src="images/logo.jpg" alt="KidneyWatch"
</aside>

<div id="fh5co-main">

<div class="fh5co-narrow-content">
<h2 class="fh5co-heading animate-box" data-animate-effect="fadeInLeft">Welcome to KidneyWatch</h2>

</div>
<div class="row">
<h2 class="fh5co-heading animate-box" data-animate-effect="fadeInLeft">Welcome to KidneyWatch</h2>
</div>

<div class="fh5co-narrow-chart fh5co-border-bottom">
<div class="row animate-box" data-animate-effect="fadeInLeft">
<div name="mkck intro" class="row">
<li th:text="${total} + ' patients in total (Male: ' + ${male} + '; Female: ' + ${female} + ')'"/>
Expand All @@ -208,6 +247,10 @@ <h2 class="fh5co-heading animate-box" data-animate-effect="fadeInLeft">Welcome t
<canvas id="canvas-dist"></canvas>
</div>

<div name="mkck main table" id="individual-report" class="fh5co-narrow-chart fh5co-border-bottom row animate-box" data-animate-effect="fadeInLeft">
<canvas id="canvas-dist3"></canvas>
</div>

<div name="mkck main table" id="individual-report" class="fh5co-narrow-chart fh5co-border-bottom row animate-box" data-animate-effect="fadeInLeft">
<canvas id="canvas-dist2"></canvas>
</div>
Expand Down
22 changes: 15 additions & 7 deletions initial/src/main/resources/templates/individual.html
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,26 @@ <h2 class="fh5co-heading animate-box" data-animate-effect="fadeInLeft">Welcome t
<table class="pop-table" border="0">
<thead>
<tr>
<th>Lab Name</th>
<th>Date</th>
<th>Value</th>
<th>Unit</th>
<th>eGFR</th>
<th>ACR</th>
<th>SrCr</th>
<th>Test A</th>
<th>Test B</th>
<th>Test C</th>
<th>Test D</th>
</tr>
</thead>
<tbody>
<tr th:each="re:${labTests}">
<td th:text="${re.labName}" />
<tr th:each="re:${flowSheets}">
<td th:text="${re.testDate}" />
<td th:text="${re.labValue}" />
<td th:text="${re.labUnit}" />
<td th:text="${re.egfr}" />
<td th:text="${re.acr}" />
<td th:text="${re.srcr}" />
<td />
<td />
<td />
<td />
</tr>
</tbody>
</table>
Expand Down
45 changes: 44 additions & 1 deletion initial/src/main/resources/templates/mkck.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@
};
barChartData.datasets[0].data = /*[[${scoreDis}]]*/;

var barChartData2 = {
labels: ['Stage 1', 'Stage 2', 'Stage 3A', 'Stage 3B', 'Stage 4'],
datasets: [{
label: 'Number of Patients',
backgroundColor: '#B7D3F2',
// borderColor: window.chartColors.red,
// borderWidth: 1,
data: []
}]

};
barChartData2.datasets[0].data = /*[[${stage}]]*/;

window.onload = function() {
makeAllSortable();

Expand All @@ -178,7 +191,33 @@
options: {
title: {
display: true,
text: 'Score Distribution of the Population'
text: 'Score Distribution of Patients'
},
tooltips: {
mode: 'index',
intersect: false
},
responsive: true,
scales: {
xAxes: [{
// stacked: true,
barThickness : 65,
}],
yAxes: [{
// stacked: true
}]
}
}
});

var ctx2 = document.getElementById('canvas-dist2').getContext('2d');
window.myBar2 = new Chart(ctx2, {
type: 'bar',
data: barChartData2,
options: {
title: {
display: true,
text: 'Stage Distribution of Patients'
},
tooltips: {
mode: 'index',
Expand Down Expand Up @@ -250,6 +289,10 @@ <h2 class="fh5co-heading animate-box" data-animate-effect="fadeInLeft">MKCK (pre
</div>
</div>

<div name="mkck main table" id="individual-report" class="fh5co-narrow-chart fh5co-border-bottom row animate-box" data-animate-effect="fadeInLeft">
<canvas id="canvas-dist2"></canvas>
</div>

<div name="mkck main table" id="individual-report" class="fh5co-narrow-chart fh5co-border-bottom row animate-box" data-animate-effect="fadeInLeft">
<canvas id="canvas-dist"></canvas>
</div>
Expand Down
Binary file added initial/target/classes/KW/FlowSheet.class
Binary file not shown.
Binary file modified initial/target/classes/KW/MainController.class
Binary file not shown.
Loading

0 comments on commit 683416d

Please sign in to comment.