aboutsummaryrefslogtreecommitdiff
path: root/logic
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-02-06 03:19:37 +0000
committerdam <dam@gudinoff>2022-02-06 03:19:37 +0000
commit9e96569d70660cb18b2d4669e6a71efcb4f863d6 (patch)
tree7f9cad914b9c35c9db849f05a5529327c4a56198 /logic
parent5fefdacf1e69f68b3768f419e3bed826eac79865 (diff)
downloadsurgery-log-9e96569d70660cb18b2d4669e6a71efcb4f863d6.tar.zst
surgery-log-9e96569d70660cb18b2d4669e6a71efcb4f863d6.zip
WIP: Implement option sets logic.
Diffstat (limited to 'logic')
-rw-r--r--logic/database.gd3
-rw-r--r--logic/stage.gd189
2 files changed, 136 insertions, 56 deletions
diff --git a/logic/database.gd b/logic/database.gd
index d88b710..1b9ffdb 100644
--- a/logic/database.gd
+++ b/logic/database.gd
@@ -78,7 +78,8 @@ func edit_action():
staged_idx = selected_idx
self.visible = false
stage.visible = true
- stage.set_stage(db[staged_idx])
+ var staged := (db[staged_idx] as Dictionary).duplicate(true)
+ stage.set_stage(staged)
func add_action():
diff --git a/logic/stage.gd b/logic/stage.gd
index 4c1521c..0c2f97b 100644
--- a/logic/stage.gd
+++ b/logic/stage.gd
@@ -5,9 +5,22 @@ signal save # (database_entry: Dictionary)
signal discard # ()
const OPTION_SETS_FILE_PATH: String = "user://option_sets.json"
+const OPTION_SETS_NOT_AVAILABLE: String = "--"
+const OPTION_SETS_TREE_STRUCTURE := {
+ "place": null,
+ "anesthesia": null,
+ "first_assistant": null,
+ "type": {
+ "sub_type": {
+ "sub_sub_type": null,
+ "pathology": null,
+ "intervention": null,
+ }
+ }
+}
-var staged_entry := {}
var option_sets := {
+ "thing": {},
"place": {
"P0": null,
"P1": null,
@@ -47,11 +60,11 @@ var option_sets := {
"FA1": null,
"FA2": null,
},
- "anesthesia": {
- "AN0": null,
- "AN1": null,
- "AN2": null,
- },
+# "anesthesia": {
+# "AN0": null,
+# "AN1": null,
+# "AN2": null,
+# },
"type": {
"A": {
"sub_type": {
@@ -116,12 +129,20 @@ onready var is_urgency := get_node("controls/is_urgency") as Button
onready var notes := get_node("controls/notes") as LineEdit
onready var save_button := get_node("controls/save") as Button
onready var discard_button := get_node("controls/discard") as Button
-
+onready var option_sets_map := {
+ "place": place,
+ "anesthesia": anesthesia,
+ "first_assistant": first_assistant,
+ "type": type,
+ "sub_type": sub_type,
+ "sub_sub_type": sub_sub_type,
+ "pathology": pathology,
+ "intervention": intervention
+}
func _init():
exclude_controls = ["date_picker", "save", "discard"]
load_option_sets()
- store_option_sets() # @DAM Only for testing.
func _ready():
@@ -135,51 +156,62 @@ func _ready():
it.connect("focus_exited", it, "deselect")
# Map option sets buttons.
- var option_sets_map := {
- "place": place,
- "anesthesia": anesthesia,
- "first_assistant": first_assistant,
- "type": type,
- "sub_type": sub_type,
- "sub_sub_type": sub_sub_type,
- "pathology": pathology,
- "intervention": intervention
- }
+ # @DAM TEST defining he option_sets_map onready
+# var option_sets_map := {
+# "place": place,
+# "anesthesia": anesthesia,
+# "first_assistant": first_assistant,
+# "type": type,
+# "sub_type": sub_type,
+# "sub_sub_type": sub_sub_type,
+# "pathology": pathology,
+# "intervention": intervention
+# }
for key in option_sets_map:
var button := option_sets_map[key].get_node("auto") as Button
button.connect("pressed", self, "auto_populate", [key])
+func is_sub_dictionary(dictionary: Dictionary, key: String) -> bool:
+ return dictionary.has(key) && dictionary[key] is Dictionary
+
+
func get_option_sets(field: String):
var options: Array
- # @DAM WIP Improve match to check if dictionaries being accessed are not null.
+
match field:
"sub_type":
- options = option_sets["type"][type.text][field].keys()
+ if option_sets["type"].get(type.text) != null:
+ options = option_sets["type"][type.text][field].keys()
"sub_sub_type", "pathology", "intervention":
- options = option_sets["type"][type.text]["sub_type"][sub_type.text][field].keys()
+ if option_sets["type"].get(type.text) != null && option_sets["type"][type.text]["sub_type"].get(sub_type.text) != null:
+ options = option_sets["type"][type.text]["sub_type"][sub_type.text][field].keys()
_:
options = option_sets[field].keys()
+
+ if options.size() == 0:
+ options.append(OPTION_SETS_NOT_AVAILABLE)
+
return options
func auto_populate(field: String):
var stage_options = get_node("/root/main/popup_list") as Popup
stage_options.connect("item_selected", self, "auto_selected", [field], CONNECT_ONESHOT)
- # @DAM WIP Check if we can use directly the output of the get_option_sets(field).
stage_options.popup_options(get_option_sets(field))
func auto_selected(index: int, field: String):
var field_input: LineEdit = self[field]
- # @DAM WIP Check if we can use the index directly on the output of the get_option_sets(field).
field_input.text = get_option_sets(field)[index]
field_input.caret_position = field_input.text.length()
func save_action():
self.visible = false
- emit_signal("save", get_stage())
+ var staged_entry = get_stage()
+ gather_new_option_sets(staged_entry)
+ emit_signal("save", staged_entry)
func discard_action():
@@ -188,53 +220,100 @@ func discard_action():
func set_stage(entry: Dictionary):
- staged_entry = entry.duplicate(true)
- process_id.text = staged_entry.process_id
- surgery_id.text = staged_entry.surgery_id
- date.set_date(staged_entry.date_year, staged_entry.date_month, staged_entry.date_day)
- place.text = staged_entry.place
- anesthesia.text = staged_entry.anesthesia
- first_assistant.text = staged_entry.first_assistant
- type.text = staged_entry.type
- sub_type.text = staged_entry.sub_type
- sub_sub_type.text = staged_entry.sub_sub_type
- pathology.text = staged_entry.pathology
- intervention.text = staged_entry.intervention
- is_urgency.pressed = staged_entry.is_urgency
- notes.text = staged_entry.notes
+ process_id.text = entry.process_id
+ surgery_id.text = entry.surgery_id
+ date.set_date(entry.date_year, entry.date_month, entry.date_day)
+ place.text = entry.place
+ anesthesia.text = entry.anesthesia
+ first_assistant.text = entry.first_assistant
+ type.text = entry.type
+ sub_type.text = entry.sub_type
+ sub_sub_type.text = entry.sub_sub_type
+ pathology.text = entry.pathology
+ intervention.text = entry.intervention
+ is_urgency.pressed = entry.is_urgency
+ notes.text = entry.notes
self.scroll_vertical = 0
func get_stage() -> Dictionary:
- staged_entry.process_id = process_id.text
- staged_entry.surgery_id = surgery_id.text
- staged_entry.date_year = date.get_year()
- staged_entry.date_month = date.get_month()
- staged_entry.date_day = date.get_day()
- staged_entry.place = place.text
- staged_entry.anesthesia = anesthesia.text
- staged_entry.first_assistant= first_assistant.text
- staged_entry.type = type.text
- staged_entry.sub_type = sub_type.text
- staged_entry.sub_sub_type = sub_sub_type.text
- staged_entry.pathology = pathology.text
- staged_entry.intervention = intervention.text
- staged_entry.is_urgency = is_urgency.pressed
- staged_entry.notes = notes.text
- return staged_entry
+ var entry := {
+ "process_id": process_id.text,
+ "surgery_id": surgery_id.text,
+ "date_year": date.get_year(),
+ "date_month": date.get_month(),
+ "date_day": date.get_day(),
+ "place": place.text,
+ "anesthesia": anesthesia.text,
+ "first_assistant": first_assistant.text,
+ "type": type.text,
+ "sub_type": sub_type.text,
+ "sub_sub_type": sub_sub_type.text,
+ "pathology": pathology.text,
+ "intervention": intervention.text,
+ "is_urgency": is_urgency.pressed,
+ "notes": notes.text,
+ }
+ return entry
func load_option_sets(file_path: String = OPTION_SETS_FILE_PATH):
var file := File.new()
file.open(file_path, File.READ_WRITE)
var file_content = file.get_as_text()
+ file.close()
var parse_result = JSON.parse(file_content)
if parse_result.error == OK && typeof(parse_result.result) == TYPE_DICTIONARY:
option_sets = parse_result.result
else:
option_sets = {}
push_error("Failed to parse option sets file: '%s'.")
- file.close()
+
+ # @DAM Only do sanitize_option_sets_dict if file_path is no the default one.
+ sanitize_option_sets_dict(OPTION_SETS_TREE_STRUCTURE, option_sets)
+# if file_path != OPTION_SETS_FILE_PATH:
+# sanitize_option_sets()
+
+
+func sanitize_option_sets_dict(blueprint: Dictionary, test: Dictionary):
+ for key in blueprint:
+ if test.get(key) == null:
+ test[key] = {}
+ if blueprint[key] != null:
+ for sub_value in test[key]:
+ if test[key][sub_value] == null:
+ test[key][sub_value] = {}
+ sanitize_option_sets_dict(blueprint[key], test[key][sub_value])
+
+
+func gather_new_option_sets(entry: Dictionary):
+ pass
+ # @DAM TODO WIP
+# WIP WIP WIP
+ if entry["type"] != OPTION_SETS_NOT_AVAILABLE:
+ if option_sets["type"].has(entry["type"]) == false:
+
+# option_sets["type"][entry["type"]] = {}
+
+
+func sanitize_option_sets():
+ for key in OPTION_SETS_TREE_STRUCTURE:
+ if option_sets.get(key) == null:
+ option_sets[key] = {}
+
+ for type_key in option_sets["type"]:
+ var type_value := option_sets["type"][type_key] as Dictionary
+ if type_value.get("sub_type") == null:
+ type_value["sub_type"] = {}
+ else:
+ for sub_type_key in type_value["sub_type"]:
+ var sub_type_value := type_value["sub_type"][sub_type_key] as Dictionary
+ if sub_type_value.get("sub_sub_type") == null:
+ sub_type_value["sub_sub_type"] = {}
+ if sub_type_value.get("pathology") == null:
+ sub_type_value["pathology"] = {}
+ if sub_type_value.get("intervention") == null:
+ sub_type_value["intervention"] = {}
func store_option_sets(file_path: String = OPTION_SETS_FILE_PATH):