Skip to content

Commit

Permalink
Merge pull request tech-by-design#247 from megin1989/main
Browse files Browse the repository at this point in the history
fix: hide recently added FHIR Submission Summary widgets in dashobard tech-by-design#244
  • Loading branch information
ratheesh-kr authored Aug 1, 2024
2 parents 06b69c5 + 1ce99c0 commit 3d80c80
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 125 deletions.
2 changes: 1 addition & 1 deletion hub-prime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>org.techbd</groupId>
<artifactId>hub-prime</artifactId>
<version>0.141.0</version>
<version>0.142.0</version>
<packaging>war</packaging>
<name>TechBD Hub (Prime)</name>
<description>TechBD Hub (Primary)</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.techbd.udi.UdiPrimeJpaConfig;
import org.techbd.udi.auto.jooq.ingress.Tables;

import com.nimbusds.oauth2.sdk.util.CollectionUtils;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand Down Expand Up @@ -216,111 +218,35 @@ private String convertToEST(String inputTime) {
return estDateTime.format(formatter);
}

@GetMapping(value = "/dashboard/stat/fhir/most-recent-interactions", produces = "text/html")
public String fetchRecentFHIRInteractions(Model model) {
@GetMapping(value = "/dashboard/stat/fhir/fhir-submission-summary", produces = "text/html")
public String fetchFHIRSubmissionSummary(Model model) {
String schemaName = "techbd_udi_ingress";
String viewName = "fhir_submission_summary";
final String DEFAULT_VALUE="0";
String totalSubmissions =DEFAULT_VALUE;
String pendingSubmissions =DEFAULT_VALUE;
String acceptedSubmissions=DEFAULT_VALUE;
String rejectedSubmissions =DEFAULT_VALUE;
try {
final var typableTable = JooqRowsSupplier.TypableTable.fromTablesRegistry(Tables.class, schemaName,
viewName);

final var typableTable = JooqRowsSupplier.TypableTable.fromTablesRegistry(Tables.class, schemaName, viewName);
List<Map<String, Object>> fhirSubmission = udiPrimeJpaConfig.dsl().selectFrom(typableTable.table())
.fetch()
.intoMaps();

if (fhirSubmission != null && !fhirSubmission.isEmpty()) {
.fetch()
.intoMaps();
if (CollectionUtils.isNotEmpty(fhirSubmission)) {
Map<String, Object> data = fhirSubmission.get(0);
model.addAttribute("totalSubmissions", data.getOrDefault("total_submissions", "0").toString());
model.addAttribute("pendingSubmissions", data.getOrDefault("pending_submissions", "0").toString());
model.addAttribute("acceptedSubmissions", data.getOrDefault("accepted_submissions", "0").toString());
model.addAttribute("rejectedSubmissions", data.getOrDefault("rejected_submissions", "0").toString());
} else {
model.addAttribute("totalSubmissions", "0");
model.addAttribute("pendingSubmissions", "0");
model.addAttribute("acceptedSubmissions", "0");
model.addAttribute("rejectedSubmissions", "0");
}
totalSubmissions =data.getOrDefault("total_submissions", DEFAULT_VALUE).toString();
pendingSubmissions = data.getOrDefault("pending_submissions", DEFAULT_VALUE).toString();
acceptedSubmissions = data.getOrDefault("accepted_submissions", DEFAULT_VALUE).toString();
rejectedSubmissions = data.getOrDefault("rejected_submissions", DEFAULT_VALUE).toString();
}
} catch (Exception e) {
LOG.error("Error fetching FHIR interactions", e);
model.addAttribute("totalSubmissions", "0");
model.addAttribute("pendingSubmissions", "0");
model.addAttribute("acceptedSubmissions", "0");
model.addAttribute("rejectedSubmissions", "0");
}

model.addAttribute("totalSubmissions", totalSubmissions);
model.addAttribute("pendingSubmissions", pendingSubmissions);
model.addAttribute("acceptedSubmissions", acceptedSubmissions);
model.addAttribute("rejectedSubmissions", rejectedSubmissions);
return "fragments/interactions :: serverTextStat";
}

@GetMapping("/dashboard/most-recent-interactions-new")
public ResponseEntity<List<InteractionData>> getMostRecentInteractions() {

// Define schema and view name
String schemaName = "techbd_udi_ingress";
String viewName = "fhir_submission_summary";

// Fetch the typable table
final var typableTable = JooqRowsSupplier.TypableTable.fromTablesRegistry(Tables.class, schemaName, viewName);

// Query the view and fetch the results
List<Map<String, Object>> fhirSubmission = udiPrimeJpaConfig.dsl().selectFrom(typableTable.table())
.fetch()
.intoMaps();

// Initialize list to hold the results
List<InteractionData> interactions = new ArrayList<>();

// Check if data is available
if (fhirSubmission != null && !fhirSubmission.isEmpty()) {
Map<String, Object> data = fhirSubmission.get(0);

// Populate the list with data
interactions.add(new InteractionData("Total Submissions",
Integer.parseInt(data.getOrDefault("total_submissions", "0").toString())));
interactions.add(new InteractionData("Pending Submissions",
Integer.parseInt(data.getOrDefault("pending_submissions", "0").toString())));
interactions.add(new InteractionData("Accepted Submissions",
Integer.parseInt(data.getOrDefault("accepted_submissions", "0").toString())));
interactions.add(new InteractionData("Rejected Submissions",
Integer.parseInt(data.getOrDefault("rejected_submissions", "0").toString())));
} else {
// Default values if no data found
interactions.add(new InteractionData("Total Submissions", 0));
interactions.add(new InteractionData("Pending Submissions", 0));
interactions.add(new InteractionData("Accepted Submissions", 0));
interactions.add(new InteractionData("Rejected Submissions", 0));
}
// Return the data with HTTP status OK
return ResponseEntity.ok().body(interactions);

}

// Example class representing interaction data
public class InteractionData {
private String label;
private int count;

// Constructor
public InteractionData(String label, int count) {
this.label = label;
this.count = count;
}

// Getters and Setters
public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
<!-- Total Submissions Widget -->
<div class="bg-white p-6 rounded-lg shadow-md">
<h2 class="text-xl font-semibold mb-2">Total Submissions</h2>
<p class="text-4xl font-bold" th:text="${totalSubmissions}">0</p>
<p id="totalSubmissionsP" class="text-4xl font-bold" th:text="${totalSubmissions}">0</p>
</div>

<!-- Pending Submissions Widget -->
<div class="bg-white p-6 rounded-lg shadow-md">
<h2 class="text-xl font-semibold mb-2">Pending Submissions</h2>
<p class="text-4xl font-bold" th:text="${pendingSubmissions}">0</p>
<p id="pendingSubmissionsP" class="text-4xl font-bold" th:text="${pendingSubmissions}">0</p>
</div>

<!-- Accepted Submissions Widget -->
<div class="bg-white p-6 rounded-lg shadow-md">
<h2 class="text-xl font-semibold mb-2">Accepted Submissions</h2>
<p class="text-4xl font-bold" th:text="${acceptedSubmissions}">0</p>
<p id="acceptedSubmissionsP" class="text-4xl font-bold" th:text="${acceptedSubmissions}">0</p>
</div>

<!-- Rejected Submissions Widget -->
<div class="bg-white p-6 rounded-lg shadow-md">
<h2 class="text-xl font-semibold mb-2">Rejected Submissions</h2>
<p class="text-4xl font-bold" th:text="${rejectedSubmissions}">0</p>
<p id="rejectedSubmissionsP" class="text-4xl font-bold" th:text="${rejectedSubmissions}">0</p>
</div>

</body>
</html>
51 changes: 28 additions & 23 deletions hub-prime/src/main/resources/templates/page/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ <h1 class="text-3xl font-bold mb-4 text-center">Welcome to Technology-by-Design'
</dl>
</div>

<div class="mt-12 w-full grid grid-cols-4 gap-8" id="dashboard-container">
<!-- <div class="mt-12 w-full grid grid-cols-4 gap-8" id="dashboard-container">
<div th:replace="fragments/interactions :: serverTextStat"></div>
</div>
<div class="mt-12 w-full grid grid-cols-2 gap-8">
<div>
<h3 class="text-xl font-bold mb-4">FHIR Submission Summary</h3>
<pre class=" bg-white p-4 rounded-lg shadow-md">
<dl id="pie-chart" class=" pie-chart-item ">
<dl id="pie-chart" class=" pie-chart-item flex justify-center items-center pt-12">
</dl>
</pre>
</div>
</div>
</div> -->

<div class="mt-12 w-full grid grid-cols-2 gap-8">
<div>
Expand Down Expand Up @@ -172,24 +172,42 @@ <h3 class="text-xl font-bold mb-4">Production (flat files)</h3>
<script th:inline="javascript">
/*<![CDATA[*/
// Optional: Use JavaScript to fetch data dynamically if needed
async function fetchRecentData(days) {
async function fetchRecentData() {
try {
const response = await fetch(`/dashboard/stat/fhir/most-recent-interactions`);
const response = await fetch(`/dashboard/stat/fhir/fhir-submission-summary`);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.text();
document.getElementById('dashboard-container').innerHTML = data;
const pieChartData = [
{
count: document.getElementById("totalSubmissionsP") ? document.getElementById("totalSubmissionsP").textContent : 0,
label: "Total Submissions"
},
{
count: document.getElementById("pendingSubmissionsP") ? document.getElementById("pendingSubmissionsP").textContent : 0,
label: "Pending Submissions"
},
{
count: document.getElementById("acceptedSubmissionsP") ? document.getElementById("acceptedSubmissionsP").textContent :0,
label: "Accepted Submissions"
},
{
count: document.getElementById("rejectedSubmissionsP") ? document.getElementById("rejectedSubmissionsP").textContent : 0,
label: "Rejected Submissions"
}
];
createPieChart(pieChartData);
} catch (error) {
console.error('Error fetching recent data:', error);
}
}

// Example usage on page load or user interaction
window.onload = function () {
fetchRecentData(7); // Fetch data for the last 7 days
fetchPieChartData();
}
// window.onload = function () {
// fetchRecentData(); // Fetch data for the last 7 days
// }
function createPieChart(interactions) {
const width = 500; // Further increase width
const height = 500; // Further increase height
Expand All @@ -208,7 +226,7 @@ <h3 class="text-xl font-bold mb-4">Production (flat files)</h3>

const svg = d3.select("#pie-chart")
.append("svg")
.attr("class", "inline-block align-middle w-[70%] mt-[-45px]") // Add Tailwind classes for width and height
.attr("class", " align-middle w-[70%] mt-[-45px]") // Add Tailwind classes for width and height
.attr("viewBox", `0 0 ${width + 300} ${height}`) // Further increase width to make room for the legend
.append("g")
.attr("transform", `translate(${width / 2},${height / 2})`);
Expand Down Expand Up @@ -249,19 +267,6 @@ <h3 class="text-xl font-bold mb-4">Production (flat files)</h3>
.text(d => d.label)
.attr('dy', '0.35em'); // Adjust text vertical alignment
}

function fetchPieChartData() {
// Fetch data from server-side using Thymeleaf
fetch('/dashboard/most-recent-interactions-new')
.then(response => response.json())
.then(data => {
// Call the pie chart creation function once with fetched data
createPieChart(data);
})
.catch(error => {
console.error('Error fetching interactions data:', error);
});
}
/*]]>*/
</script>
</div>
Expand Down

0 comments on commit 3d80c80

Please sign in to comment.