-
Notifications
You must be signed in to change notification settings - Fork 1
/
medical.singkong
257 lines (227 loc) · 8.24 KB
/
medical.singkong
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#
medical.singkong
System.jar client application
Medical Record
(c) Noprianto <nopri.anto@icloud.com>, 2020
Written in Singkong Programming Language: https://nopri.github.io
License: public domain
System.jar
Download: https://nopri.github.io/System.jar
License: Free for personal use only, unsupported software, no warranty
Registration key: https://nopri.github.io/System.registration.txt
Requires: Java Runtime Environment 8 or later
Help:
java -jar System.jar
(click Help button)
Help:
java -jar System.jar info
Singkong.jar
Download: https://nopri.github.io/Singkong.jar
License: Free to use or redistribute
Requires: Java Runtime Environment 5.0 or later
Help:
java -jar Singkong.jar
(Help tab)
How to run System.jar API:
java -jar System.jar api <database>
example:
java -jar System.jar api ./test
How to run medical.singkong:
java -jar Singkong.jar medical.singkong
Please change the url variable accordingly
;
# configuration;
var url = "http://localhost:8080"
var title_app = "System (Medical Record)"
var label_username = "Username"
var label_passwd = "Password"
var privilege = "medical/all"
var fields = "ID,Patient ID,Patient,Time,Type,Note,State,Reference"
var confirm_quit = "Are you sure you want to quit this application?"
var confirm_cancel = "Are you sure you want to close without saving?"
var title_confirm = "Please confirm"
var label_reload = "Reload"
var label_open = "Open"
var label_save = "Save"
var label_cancel = "Cancel"
var label_appointment = "Appointment"
var message_save_ok = "Medical record saved"
var message_save_error = "Error saving medical record"
var error_singkong_version = "This application requires Singkong version 2.8 or later"
var error_server = "Cannot connect to " + url
# username, password, template;
var u = {"u": "", "p": "", "t": ""}
# reset GUI, set title, add closing confirmation dialog;
reset()
title(title_app)
closing(confirm_quit, title_confirm)
# functions;
var check_response_ok = fn(res, key) {
if (res[1] == 200) {
var res = parse_hash(res[2])
var test = res[key]
return test
}
return null
}
var check_response_null = fn(res) {
if (res == null) {
message(error_server, title_app)
exit()
}
}
var do_login = fn() {
repeat {
var login = login_dialog(title_app, label_username, label_passwd)
if (len(login) == 2) {
var input_user = login[0]
var input_passwd = login[1]
var data = "username=" + input_user + "&password=" + input_passwd + "&privilege=" + privilege
var res = http_post(url + "/login", data)
check_response_null(res)
var test = check_response_ok(res, "login")
if (is(test, "STRING")) {
if (test != "") {
return [test, input_passwd]
}
}
} else {
return null
}
}
}
var get_template = fn() {
var data = "username=" + u["u"] + "&password=" + u["p"] + "&privilege=" + privilege
var res = http_post(url + "/appointment/template", data)
check_response_null(res)
var test = check_response_ok(res, "template")
if (is(test, "STRING")) {
return replace(test, "\r\n", cr() + lf())
}
return ""
}
var do_reload = fn(date_appointment, table) {
var input_date = get(date_appointment, "contents")
var data = "username=" + u["u"] + "&password=" + u["p"] + "&privilege=" + privilege + "&date=" + format_date(input_date)
var res = http_post(url + "/appointment/list", data)
check_response_null(res)
var test = check_response_ok(res, "list")
if (is(test, "ARRAY")) {
var appointments = []
each(test, fn(i, counter) {
set(i, 2, replace(i[2], "\",""))
var appointments = appointments + i
})
config(table, "contents", appointments)
}
}
var open_medical_record = fn(table) {
var contact = get(table, "contents")[get(table, "active")]
if (contact == null) {
return contact
}
var edit_record = component("edit", "")
config(edit_record, "contents", u["t"])
var view_record = component("view", "")
var view_check_up = component("view", "")
var button_add = component("button", label_save)
var button_cancel = component("button", label_cancel)
var data = "username=" + u["u"] + "&password=" + u["p"] + "&privilege=" + privilege + "&contact_id=" + contact[1]
var res = http_post(url + "/medical/record/get", data)
check_response_null(res)
var test = check_response_ok(res, "record")
if (is(test, "STRING")) {
var test = replace(test, "\r", cr())
var test = replace(test, "\n", lf())
var test = replace(test, "\", "")
config(view_record, "contents", test)
}
var data = "username=" + u["u"] + "&password=" + u["p"] + "&privilege=" + privilege + "&contact_id=" + contact[1]
var res = http_post(url + "/medical/checkup/get", data)
check_response_null(res)
var test = check_response_ok(res, "record")
if (is(test, "STRING")) {
var test = replace(test, "\r", cr())
var test = replace(test, "\n", lf())
var test = replace(test, "\", "")
config(view_check_up, "contents", test)
}
var check_next = component("checkbox", label_appointment)
var date_next = component("date", "EEEE, yyyy-MMMM-dd")
clear()
add([edit_record, view_record, view_check_up])
add_s([check_next, date_next, button_add, button_cancel])
var u = u
var privilege = privilege
var url = url
var message_save_ok = message_save_ok
var message_save_error = message_save_error
var title_app = title_app
var check_response_ok = check_response_ok
var check_response_null = check_response_null
var show_appointments = show_appointments
event(button_add, fn() {
var input_appointment = get(check_next, "active")
var input_date = get(date_next, "contents")
var input_record = get(edit_record, "contents")
if (input_appointment == true) {
var data = "username=" + u["u"] + "&password=" + u["p"] + "&privilege=" + privilege + "&contact_id=" + contact[1] + "&appointment_id=" + contact[0] + "&date=" + format_date(input_date) + "&record=" + url_encode(input_record)
} else {
var data = "username=" + u["u"] + "&password=" + u["p"] + "&privilege=" + privilege + "&contact_id=" + contact[1] + "&appointment_id=" + contact[0] + "&record=" + url_encode(input_record)
}
var res = http_post(url + "/medical/record/add", data)
check_response_null(res)
var test = check_response_ok(res, "add")
if (is(test, "NUMBER")) {
message(message_save_ok, title_app)
show_appointments()
} else {
message(message_save_error, title_app)
}
})
var title_confirm = title_confirm
var confirm_cancel = confirm_cancel
var show_appointments = show_appointments
event(button_cancel, fn() {
if (confirm(confirm_cancel, title_confirm) == "OK") {
show_appointments()
}
})
show()
}
var show_appointments = fn() {
clear()
var label_user = component("label", u["u"])
var date_appointment = component("date", "EEEE, yyyy-MMMM-dd")
var button_reload = component("button", label_reload)
var table = component("table", fields, true)
var button_open = component("button", label_open)
add_n([label_user, date_appointment, button_reload])
add(table)
add_s(button_open)
var f_reload = do_reload
event(button_reload, fn() {
f_reload(date_appointment, table)
})
var f_open = open_medical_record
event(button_open, fn() {
f_open(table)
})
do_reload(date_appointment, table)
show()
}
# main program;
var main = fn() {
if (singkong()["version"] < 2.8) {
message(error_singkong_version, title_app)
exit()
}
var res = do_login()
if (res != null) {
set(u, "u", res[0])
set(u, "p", res[1])
set(u, "t", get_template())
show_appointments()
}
}
main()