aboutsummaryrefslogtreecommitdiff
path: root/logic/database_entry.gd
blob: 496b752fe760fb09bbc94263c4245aa05f2d2daa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
extends Reference
class_name DatabaseEntry

const DATE_SEPARATOR: String = "-"
const DATE_FORMAT: String = "%04d-%02d-%02d"
const ENTRY_PROTOTYPE: Dictionary = {
	"process_id":		"",
	"surgery_id":		"",
	"date_year":		0,
	"date_month":		0,
	"date_day":			0,
	"place":			"",
	"anesthesia":		"",
	"first_assistant":	"",
	"type":				"",
	"sub_type":			"",
	"sub_sub_type":		"",
	"pathology":		"",
	"intervention":		"",
	"is_urgency":		false,
	"notes":			"",
}


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", "")
	
	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.place				= params.get("place", "")
	new_entry.anesthesia		= params.get("anesthesia", "")
	new_entry.first_assistant	= params.get("first_assistant", "")
	new_entry.type				= params.get("type", "")
	new_entry.sub_type			= params.get("sub_type", "")
	new_entry.sub_sub_type		= params.get("sub_sub_type", "")
	new_entry.pathology			= params.get("pathology", "")
	new_entry.intervention		= params.get("intervention", "")
	new_entry.is_urgency		= params.get("is_urgency", false)
	new_entry.notes				= params.get("notes", "")
	
	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]


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_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))