Diff of /static/js/dynamicHtml.js [000000] .. [314dda]

Switch to unified view

a b/static/js/dynamicHtml.js
1
/**************************************************************************************
2
 * Project     : Chest X-Ray Pathology Detection and Localization using Deep Learning
3
 * Author Name : Rammuni Ravidu Suien Silva
4
 * UoW No      : 16267097
5
 * IIT No      : 2016134
6
 * Module      : Final Year Project 20/21
7
 * Supervisor  : Mr Pumudu Fernando
8
9
 * Prototype    : Web Interface - FrontEnd
10
 * File         : JS for creation of dynamic HTML UI elements
11
 * University of Westminster, UK || IIT Sri Lanka
12
 **************************************************************************************/
13
14
// consts for DOM objects
15
const detResults = $('#result');
16
let localized = false;
17
let symptoms_json;
18
19
20
// Displaying the dynamic detection table
21
function cxrResultsDisplayTable(dataJSON) {
22
    let tableHTML = '<div class="limiter">';
23
    tableHTML += '<div class="container-table100">';
24
    tableHTML += '<div class="wrap-table100" style="margin: 20px auto auto;">';
25
    tableHTML += '<div class="table">';
26
    tableHTML += '<div class="row header">' +
27
        '<div class="cell text-dark">Pathology</div>' +
28
        '<div class="cell text-dark">Detection Rate</div>' +
29
        '</div>';
30
31
    let pathology_id = 0
32
33
    // Dynamic table creation
34
    Object.keys(dataJSON).forEach(function (key) {
35
        let pathology = key;
36
37
        $(cxrLocalizationPopup(pathology_id, pathology)).appendTo('#main-app-body');
38
        $(cxrLocalizationPrint(pathology_id, pathology)).appendTo('.loc-result-print');
39
40
41
        let detectionRate = dataJSON[pathology];
42
43
        let cxr_popup_id = "#cxrPopup-" + pathology_id;
44
45
        // Highlighting high probable diseases
46
        if (parseFloat(detectionRate.split("%")[0]) >= 50) {
47
            tableHTML += '<div class="row bg-warning det-row" data-toggle="modal" data-target="' + cxr_popup_id + '">';
48
        } else {
49
            tableHTML += '<div class="row det-row" data-toggle="modal" data-target="' + cxr_popup_id + '">';
50
        }
51
52
        tableHTML += '<div class="cell" data-title="Pathology">';
53
        tableHTML += pathology;
54
        tableHTML += '</div>';
55
        tableHTML += '<div class="cell text-dark" data-title="Detection Rate   (Max - Min)">';
56
        tableHTML += detectionRate;
57
        tableHTML += '</div>';
58
        tableHTML += '</div>';
59
60
        pathology_id += 1;
61
    });
62
63
    tableHTML += '</div>';
64
    tableHTML += '</div>';
65
    tableHTML += '</div>';
66
    tableHTML += '</div>';
67
    return tableHTML;
68
}
69
70
// Dynamic popup card builder for localized image display
71
function cxrLocalizationPopup(pathology_id, pathology) {
72
    let popupCXRHTML =
73
        '<div class="modal fade" id="cxrPopup-' + pathology_id + '" role="dialog">\n' +
74
        '        <div class="modal-dialog">\n' +
75
        cxrLocalizationPrint(pathology_id, pathology) +
76
        '        </div>\n' +
77
        '    </div>';
78
    return popupCXRHTML
79
}
80
81
// Print section UI creation
82
function cxrLocalizationPrint(pathology_id, pathology) {
83
    let locCXRPrint =
84
        '<div class="card print-cxr-card">\n' +
85
        '   <div class="card-img"><img id="cxrPopupImg-' + pathology_id +
86
        '" class="img-fluid cxr-loc-img cxrPopupImg-' + pathology_id + '" ' +
87
        '        alt="Run/Click Localization to view the Localized CXR" ' +
88
        '        style="display: block; margin-left: auto; margin-right: auto;"></div>\n' +
89
        '   <div class="card-text">\n' +
90
        '        <p>Localization Result for:</p>\n' +
91
        '        <p><b>' + pathology + '</b></p>\n' +
92
        '   </div>\n' + symptomsAdd(pathology, symptoms_json) +
93
        '</div>\n';
94
    return locCXRPrint
95
}
96
97
// Displaying possible symptoms from the Symptoms.JSON from the server
98
function symptomsAdd(pathology, symptoms_json) {
99
    let symptoms = symptoms_json[pathology]['Symptoms']
100
    let listHTML = '  ' +
101
        '<span class="list-group-item list-group-item-action flex-column align-items-start">\n' +
102
        '    <div class="d-flex w-100 justify-content-between">\n' +
103
        '      <h5 class="mb-1">Possible Symptoms</h5>\n' +
104
        '      <small class="text-muted">Confirm the findings</small>\n' +
105
        '    </div>';
106
107
    for (let i = 0; i < symptoms.length; i++) {
108
        listHTML += '<p class="mb-1">' + symptoms[i] + '</p>\n';
109
    }
110
111
    listHTML += '<small class="text-muted">These are indicative symptoms only!</small>\n' +
112
        '</span>'
113
    return listHTML;
114
}