Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amanda updates #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 24 additions & 73 deletions emcalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,11 @@ class Data extends Section {
var category1 = this.calculateCategory(this.category1.find(":checked"));
var category2 = this.calculateCategory(this.category2.find(":checked"));
var category3 = this.calculateCategory(this.category3.find(":checked"));
$("#noData").prop("checked", false);
if (category2 === 0 && category3 === 0) {
if (category1 === 0 && category2 === 0 && category3 === 0 && !$("#noData").prop("checked")) {
this.level = 0;
} else if (category2 === 0 && category3 === 0) {
if (category1 < 2) {
this.level = 2;
if (category1 === 0) {
$("#noData").prop("checked", true);
}
} else if (category1 === 2 || $("#assesmentHistorian").prop("checked") === true) {
this.level = 3;
} else {
Expand All @@ -148,20 +146,25 @@ class Data extends Section {
this.headerText.text("Level: " + this.level);
overallLevel(this.name, this.level);
}
toggleNone = (e) => {
if ($(e.currentTarget).prop("checked")) {
this.clear();
this.level = 2;
this.levelHeaders.empty();
$(this.levelHeaders[this.level - 2]).html('<i class="fa-solid fa-circle-dot"></i>');
this.headerText.text("Level: " + this.level);
overallLevel(this.name, this.level);
toggleDisable = (a) => {
if ($("#noData").prop("checked")) {
this.category1.find(":checkbox").prop("disabled", true);
this.category2.find(":checkbox").prop("disabled", true);
this.category3.find(":checkbox").prop("disabled", true);
} else {
this.category1.find(":checkbox").prop("disabled", false);
this.category2.find(":checkbox").prop("disabled", false);
this.category3.find(":checkbox").prop("disabled", false);
if (this.items.find(":checked").length > 0) {
$("#noData").prop("disabled", true);
} else {
$("#noData").prop("disabled", false);
}
}
super.toggleDisable(a);
}
run() {
$("#noData").on("click", {
event
}, this.toggleNone);

super.run();
}
}
Expand All @@ -178,17 +181,11 @@ function get_JSON() {
function from_JSON(json) {
for (i in json) {
if (i !== "level") {
/*if (json[i].selected) {
for (j of json[i].selected) {
$("#" + j).prop("checked", true);
}
} else {
for (j in json[i].settings) {
$("#" + j).prop("checked", json[i].settings[j])
}
}*/
for (j in json[i].settings) {
$("#" + j).prop("checked", json[i].settings[j])
if (json[i].settings[j]) {
calculatorData.sections[i].toggleDisable($("#" + j));
}
}
calculatorData.sections[i].calculateSectionLevel();
}
Expand All @@ -205,57 +202,12 @@ function clearAll() {

function showJSON() {
var json = get_JSON();
$("#jsonText").val(JSON.stringify(json));
}

function prettyJSON() {
var json = get_JSON();
var prettyJSON = prettify(json);
$("#jsonText").val(prettyJSON);
}

function prettify(json, tabs = 0) {
var text = "";
for (i in json) {
if (typeof json[i] !== "object") {
text += "\t".repeat(tabs) + i + ": " + json[i] + "\n";
} else if (Array.isArray(json[i])) {
text += "\t".repeat(tabs) + i + ": [" + json[i] + "]\n";
} else {
text += "\t".repeat(tabs) + i + "\n" + prettify(json[i], tabs + 1);
}
};
return text;
$("#jsonText").val(JSON.stringify(json, null, 2));
}

function loadJSON() {
clearAll();
try {
var json = JSON.parse($("#jsonText").val());
} catch (e) {
var json = '{'
var text = $("#jsonText").val().split("\n").map(function(x) {
return x.split("\t");
});
for (i in text) {
var idx = parseInt(i);
var x = text[idx].length - 1;
if (idx < text.length - 2) {
if (text[idx + 1].length > text[idx].length) {
json += '"' + text[idx][x] + '": {'
} else if (text[idx + 1].length < text[idx].length) {
json += '"' + text[idx][x].replace(':', '":') + '}, '
} else {
json += '"' + text[idx][x].replace(':', '":') + ", "
}
} else {
if (text[idx][x] !== "") {
json += '"' + text[idx][x].replace(':', '":') + '}'
}
}
}
json = JSON.parse(json);
}
var json = JSON.parse($("#jsonText").val());
from_JSON(json);
}

Expand All @@ -268,7 +220,6 @@ function run() {
data: new Data()
};
$("#showJSONButton").on("click", showJSON);
$("#prettyJSONButton").on("click", prettyJSON);
$("#loadJSONButton").on("click", loadJSON);
calculatorData.sections.problems.run();
calculatorData.sections.risk.run();
Expand Down
6 changes: 4 additions & 2 deletions outpatient.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}

.calc-column {
min-width: 211.656px;
min-width: 0px;
}

.calc-column.collapse-box {
Expand Down Expand Up @@ -105,6 +105,9 @@
<div class="level-box erase bg-light d-flex align-items-center justify-content-center"><i class="fa-solid fa-eraser"></i></div>
</div>
</div>
<div class="col col-auto d-flex pe-0 calc-column">
&nbsp;
</div>
</div>
<!-- END - Problems Header -->

Expand Down Expand Up @@ -646,7 +649,6 @@
<div class="col">
<textarea rows="10" class="form-control" id="jsonText"></textarea>
<button type="button" class="btn btn-primary" id="showJSONButton">Show JSON</button>
<button type="button" class="btn btn-primary" id="prettyJSONButton">Pretty JSON</button>
<button type="button" class="btn btn-primary" id="loadJSONButton">Load JSON</button>
</div>
</div>
Expand Down