diff options
| -rw-r--r-- | logic/stage.gd | 233 | ||||
| -rw-r--r-- | menu/menu.gd | 5 | ||||
| -rw-r--r-- | readme.md | 5 |
3 files changed, 67 insertions, 176 deletions
diff --git a/logic/stage.gd b/logic/stage.gd index 0c2f97b..1352816 100644 --- a/logic/stage.gd +++ b/logic/stage.gd @@ -19,100 +19,7 @@ const OPTION_SETS_TREE_STRUCTURE := { } } -var option_sets := { - "thing": {}, - "place": { - "P0": null, - "P1": null, - "P2": null, - "xpto_01": null, - "xpto_02": null, - "xpto_03": null, - "xpto_04": null, - "xpto_05": null, - "xpto_06": null, - "xpto_07": null, - "xpto_08": null, - "xpto_09": null, - "xpto_10": null, - "xpto_11": null, - "xpto_12": null, - "xpto_13": null, - "xpto_14": null, - "xpto_15": null, - "xpto_16": null, - "xpto_17": null, - "xpto_18": null, - "xpto_19": null, - "xpto_20": null, - "xpto_21": null, - "xpto_22": null, - "xpto_23": null, - "xpto_24": null, - "xpto_25": null, - "xpto_26": null, - "xpto_27": null, - "xpto_28": null, - "xpto_29": null, - }, - "first_assistant": { - "FA0": null, - "FA1": null, - "FA2": null, - }, -# "anesthesia": { -# "AN0": null, -# "AN1": null, -# "AN2": null, -# }, - "type": { - "A": { - "sub_type": { - "aA": { - "sub_sub_type": { - "aaA": null, - "aaB": null, - "aaC": null, - }, - "pathology": { - "aaP0": null, - "aaP1": null, - "aaP2": null, - }, - "intervention": { - "aaI0": null, - "aaI1": null, - "aaI2": null, - }, - }, - "aB": { - "sub_sub_type": { - "abA": null, - "abB": null, - "abC": null, - }, - "pathology": { - "abP0": null, - "abP1": null, - "abP2": null, - }, - "intervention": { - "abI0": null, - "abI1": null, - "abI2": null, - }, - }, - }, - }, - "B": { - "sub_type": { - "bA": null, - "bB": null, - }, - }, - "C": null, - }, -} +var option_sets: Dictionary onready var process_id := get_node("controls/process_id") as LineEdit onready var surgery_id := get_node("controls/surgery_id") as LineEdit @@ -129,16 +36,7 @@ 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"] @@ -156,38 +54,31 @@ func _ready(): it.connect("focus_exited", it, "deselect") # Map option sets buttons. - # @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 -# } + 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 match field: "sub_type": - if option_sets["type"].get(type.text) != null: - options = option_sets["type"][type.text][field].keys() + options = option_sets.get("type", {}).get(type.text, {}).get(field, {}).keys() "sub_sub_type", "pathology", "intervention": - 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.get("type", {}).get(type.text, {}).get("sub_type", {}).get(sub_type.text, {}).get(field, {}).keys() _: - options = option_sets[field].keys() + options = option_sets.get(field, {}).keys() if options.size() == 0: options.append(OPTION_SETS_NOT_AVAILABLE) @@ -209,8 +100,9 @@ func auto_selected(index: int, field: String): func save_action(): self.visible = false - var staged_entry = get_stage() - gather_new_option_sets(staged_entry) + var staged_entry := get_stage() + gather_option_sets(staged_entry) + store_option_sets() emit_signal("save", staged_entry) @@ -257,6 +149,49 @@ func get_stage() -> Dictionary: return entry +func sanitize_option_sets(entry: Dictionary, blueprint: Dictionary = OPTION_SETS_TREE_STRUCTURE): + # Delete extra keys. + var keys_to_delete: Array + for key in entry: + if blueprint.has(key) == false: + keys_to_delete.append(key) + for key in keys_to_delete: + entry.erase(key) + + for key in blueprint: + # Add missing keys. + if typeof(entry.get(key)) != TYPE_DICTIONARY: + entry[key] = {} + # Process sub-keys + if blueprint[key] != null: + for sub_key in entry[key]: + if typeof(entry[key][sub_key]) != TYPE_DICTIONARY: + entry[key][sub_key] = {} + sanitize_option_sets(entry[key][sub_key], blueprint[key]) + + +func gather_option_sets(entry: Dictionary, target: Dictionary = option_sets, blueprint: Dictionary = OPTION_SETS_TREE_STRUCTURE): + for key in blueprint: + if target.get(key) == null: + target[key] = {} + + var value := (entry[key] as String).strip_edges() + if value == "" || value == OPTION_SETS_NOT_AVAILABLE: + continue + + if target[key].has(value) == false: + target[key][value] = null if blueprint[key] == null else {} + + if blueprint[key] != null: + gather_option_sets(entry, target[key][value], blueprint[key]) + + +func import_option_sets(file_path: String = OPTION_SETS_FILE_PATH): + load_option_sets(file_path) + sanitize_option_sets(option_sets) + store_option_sets() + + func load_option_sets(file_path: String = OPTION_SETS_FILE_PATH): var file := File.new() file.open(file_path, File.READ_WRITE) @@ -269,52 +204,6 @@ func load_option_sets(file_path: String = OPTION_SETS_FILE_PATH): option_sets = {} push_error("Failed to parse option sets file: '%s'.") - # @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): var file := File.new() diff --git a/menu/menu.gd b/menu/menu.gd index 639a99b..1df6f28 100644 --- a/menu/menu.gd +++ b/menu/menu.gd @@ -42,7 +42,8 @@ func _menu_import_option_sets_action(): file_picker.mode = FileDialog.MODE_OPEN_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters[0] = "*.json" - file_picker.connect("file_selected", stage, "load_option_sets", [], CONNECT_ONESHOT) + file_picker.current_file = "" + file_picker.connect("file_selected", stage, "import_option_sets", [true], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() @@ -52,6 +53,7 @@ func _menu_export_option_sets_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters[0] = "*.json" + file_picker.current_file = "" file_picker.connect("file_selected", stage, "store_option_sets", [], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() @@ -69,6 +71,7 @@ func _menu_export_data_action(): file_picker.mode = FileDialog.MODE_SAVE_FILE file_picker.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS) file_picker.filters[0] = "*.csv" + file_picker.current_file = "" file_picker.connect("file_selected", database, "store_database", [], CONNECT_ONESHOT) file_picker.show_modal(true) file_picker.invalidate() @@ -3,8 +3,6 @@ Surgery Log # Notes - Location of `user://`: `~/.local/share/godot/app_userdata/`. -- null: 16528 -- {}: # ToDo - [x] Datepicker: On click (without drag) reset velocity to 0; show and focus 'input' to allow introducing value. @@ -22,10 +20,11 @@ Surgery Log - [x] split touch logic from stage (create TouchVerticalContainer); - [x] load/store filters JSON file; - [x] import/export filters to CSV file; -- [ ] add auto-fill buttons on stage screen: +- [x] add option_sets buttons on stage screen: - should show a pop-up with multiple options filtered according to current filters; - allow options to be scrolled by dragging; - selecting option puts that text on the associated LineEdit; +- [ ] check if import_option_sets, store_option_sets, store_database require the parameter save_changes; this requires changes on databse, stage and menu scripts; - [ ] Implement file access permission check on Android: ```py if OS.get_name() == "Android": |
