diff options
| author | dam <dam@gudinoff> | 2022-01-06 15:42:44 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-01-06 15:42:44 +0000 |
| commit | 431f042390ad36297a5ec986772c77da23b7fb67 (patch) | |
| tree | ce37ed802cf816aa0811bcd90c2b278645d7da33 /logic/database_entry.gd | |
| parent | 0eeacf3d142b40427ea5ca5b2806fe714c00f9b4 (diff) | |
| download | surgery-log-431f042390ad36297a5ec986772c77da23b7fb67.tar.zst surgery-log-431f042390ad36297a5ec986772c77da23b7fb67.zip | |
Remove date field and reduce usage of dictionary instances.
Diffstat (limited to 'logic/database_entry.gd')
| -rw-r--r-- | logic/database_entry.gd | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/logic/database_entry.gd b/logic/database_entry.gd index 19f2255..496b752 100644 --- a/logic/database_entry.gd +++ b/logic/database_entry.gd @@ -6,11 +6,10 @@ const DATE_FORMAT: String = "%04d-%02d-%02d" const ENTRY_PROTOTYPE: Dictionary = { "process_id": "", "surgery_id": "", - "place": "", - "date": "", "date_year": 0, "date_month": 0, "date_day": 0, + "place": "", "anesthesia": "", "first_assistant": "", "type": "", @@ -27,14 +26,13 @@ static func instance_entry(params: Dictionary = {}) -> Dictionary: var new_entry := ENTRY_PROTOTYPE.duplicate(true) new_entry.process_id = params.get("process_id", "") new_entry.surgery_id = params.get("surgery_id", "") - new_entry.place = params.get("place", "") var today = OS.get_date() new_entry.date_year = params.get("date_year", today.year) new_entry.date_month = params.get("date_month", today.month) new_entry.date_day = params.get("date_day", today.day) - new_entry.date = params.get("date", get_entry_date(new_entry)) # @DAM We should store only one version of the date. + new_entry.place = params.get("place", "") new_entry.anesthesia = params.get("anesthesia", "") new_entry.first_assistant = params.get("first_assistant", "") new_entry.type = params.get("type", "") @@ -48,6 +46,19 @@ static func instance_entry(params: Dictionary = {}) -> Dictionary: return new_entry +static func is_valid_entry(entry: Dictionary) -> bool: + var is_valid: bool + + is_valid = entry.has_all(ENTRY_PROTOTYPE.keys()) && ENTRY_PROTOTYPE.keys().size() == entry.keys().size() + + for it in ENTRY_PROTOTYPE.keys(): + if typeof(ENTRY_PROTOTYPE[it]) != typeof(entry[it]): + is_valid = false + break + + return is_valid + + static func get_entry_date(entry: Dictionary) -> String: return DATE_FORMAT % [entry.date_year, entry.date_month, entry.date_day] @@ -56,7 +67,6 @@ static func set_entry_date(entry: Dictionary, date: String): date = date.strip_edges().replace(" ", DATE_SEPARATOR).replace("/", DATE_SEPARATOR).replace("\\", DATE_SEPARATOR) var year_month_idx := date.find(DATE_SEPARATOR) var month_day_idx := date.find(DATE_SEPARATOR, year_month_idx + 1) - entry.date = date entry.date_year = int(date.substr(0, year_month_idx)) entry.date_month = int(date.substr(year_month_idx + 1, month_day_idx - year_month_idx - 1)) entry.date_day = int(date.substr(month_day_idx + 1)) |
