1 /* This is a small demo of the high-performance GUIX graphics framework. */
2 
3 #include <stdio.h>
4 #include <time.h>
5 #include "gx_api.h"
6 
7 #include "guix_medical_resources.h"
8 #include "guix_medical_specifications.h"
9 
10 #include "demo_guix_medical.h"
11 
12 int selected_patient_index = 0;
13 
14 /* Define constants for patients screen.  */
15 #define PATIENT_LIST_VISIBLE_ROWS               10
16 #define PATIENT_LIST_ROW_HEIGHT                 34
17 #define MAX_STRING_LENGTH                       20
18 
19 #include "guix_medical_resources.h"
20 #include "guix_medical_specifications.h"
21 
22 /* Define patient row structure.  */
23 typedef struct PATIENT_ROW_STRUCT {
24     GX_WIDGET background;
25     GX_PROMPT name;
26     GX_PROMPT dob;
27     GX_PROMPT room_num;
28     GX_PROMPT admit_date;
29     GX_PROMPT mr_num;
30 } PATIENT_ROW;
31 
32 /* Define patient information structure.  */
33 typedef struct PATIENT_DATA_STRUCT {
34     char *name;
35     char *dob;
36     char *room_num;
37     char *admit_date;
38     char* mr_num;
39 } PATIENT_DATA;
40 
41 /* Define patinet data.  */
42 PATIENT_DATA patient_list[] = {
43 {"Anderson, Fionna",      "7/22/1953",  "1B107", "May 23, 2020", "MRN125"},
44 {"Abramson, Frank",       "3/18/1967",  "1D205", "Apr 30, 2020", "MRN117"},
45 {"Adderiy, James",        "7/5/1954",   "1D208", "Dec 25, 2019", "MRN093"},
46 {"Adrian, Michaela",      "11/16/1976", "2B204", "Jun 15, 2020", "MRN043"},
47 {"Aldridge, Robert",      "6/30/1947",  "2B214", "May 07, 2020", "MRN108"},
48 {"Alsopp, Antony",        "9/20/1991",  "3A455", "May 31, 2020", "MRN071"},
49 {"Babcock, Margarita",    "7/11/1962",  "1D310", "Feb 24, 2020", "MRN055"},
50 {"Baldwin, Susan",        "4/25/1958",  "3A523", "May 30, 2020", "MRN114"},
51 {"Barnes, Fionna",        "12/6/1974",  "1B107", "May 23, 2020", "MRN125"},
52 {"Bawerman, Frank",       "5/30/1951",  "1D205", "Apr 30, 2020", "MRN117"},
53 {"Benson, James",         "11/4/1973",  "1D208", "Dec 25, 2019", "MRN093"},
54 {"Birch, Michaela",       "4/20/1944",  "2B204", "Jun 15, 2020", "MRN043"},
55 {"Calhoun, Robert",       "8/2/1990",   "2B214", "May 07, 2020", "MRN108"},
56 {"Carey, Antony",         "3/26/1980",  "3A455", "May 31, 2020", "MRN071"},
57 {"Carroll, Margarita",    "9/7/1961",   "1D310", "Feb 24, 2020", "MRN055"},
58 {"Chandter, Susan",       "7/30/1955",  "3A523", "May 30, 2020", "MRN114"},
59 {"Charlson, Frank",       "1/30/1995",  "1D205", "Apr 30, 2020", "MRN117"},
60 {"Daniels, James",        "8/18/1981",  "1D208", "Dec 25, 2019", "MRN093"},
61 {"Day, Michaela",         "3/11/1949",  "2B204", "Jun 15, 2020", "MRN043"},
62 {"Derrick, Robert",       "12/5/1953",  "2B214", "May 07, 2020", "MRN108"},
63 {"Dodson, Antony",        "9/19/1992",  "3A455", "May 31, 2020", "MRN071"},
64 {"Eddington, Margarita",  "2/23/1985",  "1D310", "Feb 24, 2020", "MRN055"},
65 {"Ellington, Susan",      "6/17/1979",  "3A523", "May 30, 2020", "MRN114"},
66 {"Faber, Fionna",         "5/27/1977",  "1B107", "May 23, 2020", "MRN125"},
67 {"Farmer, Frank",         "11/4/1946",  "1D205", "Apr 30, 2020", "MRN117"},
68 {"Ferguson, James",       "8/20/1964",  "1D208", "Dec 25, 2019", "MRN093"},
69 {"Fisher, Michaela",      "5/13/1972",  "2B204", "Jun 15, 2020", "MRN043"},
70 {"Flannagan, Robert",     "7/8/1959",   "2B214", "May 07, 2020", "MRN108"},
71 {"Galbraith, Antony",     "11/18/1957", "3A455", "May 31, 2020", "MRN071"},
72 {"Garrison, Margarita",   "4/13/1940",  "1D310", "Feb 24, 2020", "MRN055"},
73 {"Gerald, Susan",         "2/14/1960",  "3A523", "May 30, 2020", "MRN114"},
74 {"Gilbert, Frank",        "3/25/1947",  "1D205", "Apr 30, 2020", "MRN117"},
75 {"Hailey, James",         "9/10/1953",  "1D208", "Dec 25, 2019", "MRN093"},
76 {"Hancock, Michaela",     "11/24/1939", "2B204", "Jun 15, 2020", "MRN043"},
77 {"Harrison, Robert",      "3/5/1970",   "2B214", "May 07, 2020", "MRN108"},
78 {"Jacobson, Antony",      "5/19/1957",  "3A455", "May 31, 2020", "MRN071"},
79 {"Jeff, Margarita",       "4/25/1976",  "1D310", "Feb 24, 2020", "MRN055"},
80 {"Keat, Susan",           "12/27/1979", "3A523", "May 30, 2020", "MRN114"},
81 {"Kendal, Fionna",        "4/23/1968",  "1B107", "May 23, 2020", "MRN125"},
82 {"Laird, Frank",          "4/17/1974",  "1D205", "Apr 30, 2020", "MRN117"},
83 {"Larkins, James",        "11/16/1954", "1D208", "Dec 25, 2019", "MRN093"},
84 {"Leapman, Michaela",     "5/15/1980",  "2B204", "Jun 15, 2020", "MRN043"},
85 {"MacAdam, Robert",       "3/10/1987",  "2B214", "May 07, 2020", "MRN108"},
86 {"MacDonald, Antony",     "12/1/1973",  "3A455", "May 31, 2020", "MRN071"},
87 {"Parkinson, Margarita",  "7/18/1988",  "1D310", "Feb 24, 2020", "MRN055"},
88 {"Samuels, Susan",        "5/30/1990",  "3A523", "May 30, 2020", "MRN114"},
89 { GX_NULL, GX_NULL, GX_NULL, GX_NULL, GX_NULL}
90 };
91 
92 PATIENT_ROW row_memory[PATIENT_LIST_VISIBLE_ROWS + 1];
93 
94 /* Declare prototypes.  */
95 VOID patient_list_children_create(PATIENTS_SCREEN_CONTROL_BLOCK* win);
96 VOID GetPatientName(GX_STRING* string);
97 VOID GetPatientDOB(GX_STRING* string);
98 VOID GetPatientAge(INT* age);
99 
100 /******************************************************************************************/
101 /* Calculate string length.                                                               */
102 /******************************************************************************************/
string_length_get(GX_CONST GX_CHAR * input_string,UINT max_string_length)103 static UINT string_length_get(GX_CONST GX_CHAR* input_string, UINT max_string_length)
104 {
105 UINT length = 0;
106 
107     if (input_string)
108     {
109         /* Traverse the string.  */
110         for (length = 0; input_string[length]; length++)
111         {
112             /* Check if the string length is bigger than the max string length.  */
113             if (length >= max_string_length)
114             {
115                 break;
116             }
117         }
118     }
119 
120     return length;
121 }
122 
123 /******************************************************************************************/
124 /* Custom widget drawing function for background widgets in patient list.                 */
125 /******************************************************************************************/
patient_background_draw(GX_WIDGET * widget)126 static VOID patient_background_draw(GX_WIDGET* widget)
127 {
128 
129     gx_widget_draw(widget);
130 
131     /* Draw a line to the bottom of the widget.  */
132     gx_context_brush_width_set(1);
133     gx_context_line_color_set(GX_COLOR_ID_PATIENTS_HORZ_LINE);
134     gx_canvas_line_draw(widget->gx_widget_size.gx_rectangle_left, widget->gx_widget_size.gx_rectangle_bottom,
135                         widget->gx_widget_size.gx_rectangle_right, widget->gx_widget_size.gx_rectangle_bottom);
136 }
137 
138 /******************************************************************************************/
139 /* Custom prompt drawing function for prompt widgets in patient list.                     */
140 /******************************************************************************************/
patient_prompt_draw(GX_PROMPT * prompt)141 static VOID patient_prompt_draw(GX_PROMPT* prompt)
142 {
143 
144     /* Assume the style of the background before drawing.  */
145     if (prompt->gx_widget_parent)
146     {
147         if (prompt->gx_widget_parent->gx_widget_style & GX_STYLE_DRAW_SELECTED)
148         {
149             prompt->gx_widget_style |= GX_STYLE_DRAW_SELECTED;
150         }
151         else
152         {
153             prompt->gx_widget_style &= ~GX_STYLE_DRAW_SELECTED;
154         }
155     }
156     gx_prompt_draw(prompt);
157 }
158 
159 /******************************************************************************************/
160 /* Create a row for patient list.                                                          */
161 /******************************************************************************************/
patient_row_create(GX_VERTICAL_LIST * list,GX_WIDGET * widget,INT index)162 VOID patient_row_create(GX_VERTICAL_LIST *list, GX_WIDGET *widget, INT index)
163 {
164 GX_RECTANGLE childsize;
165 PATIENT_ROW *row = (PATIENT_ROW *) widget;
166 GX_BOOL      result;
167 GX_STRING    string;
168 
169     /* Test if the widget is already created.  */
170 	gx_widget_created_test(&row -> background, &result);
171 
172     if (!result)
173     {
174         /* Create and configure background widget.  */
175         gx_utility_rectangle_define(&childsize, list->gx_window_client.gx_rectangle_left, 0,
176                                                 list->gx_window_client.gx_rectangle_right, PATIENT_LIST_ROW_HEIGHT);
177         gx_widget_create(&row->background, NULL, list, GX_STYLE_ENABLED, GX_ID_NONE, &childsize);
178         gx_widget_fill_color_set(&row->background, GX_COLOR_ID_BLACK, GX_COLOR_ID_YELLOW, GX_COLOR_ID_BLACK);
179         gx_widget_draw_set(&row->background, patient_background_draw);
180 
181         /* Create and configure name prompt.  */
182         childsize.gx_rectangle_left = patients_screen.patients_screen_patient_name_label.gx_widget_size.gx_rectangle_left;
183         childsize.gx_rectangle_right = patients_screen.patients_screen_DOB_label.gx_widget_size.gx_rectangle_left - 1;
184         gx_prompt_create(&row->name, NULL, &row->background, 0, GX_STYLE_TRANSPARENT|GX_STYLE_TEXT_LEFT | GX_STYLE_ENABLED, 0, &childsize);
185         gx_widget_draw_set(&row->name, patient_prompt_draw);
186         gx_prompt_text_color_set(&row->name, GX_COLOR_ID_WHITE, GX_COLOR_ID_BLACK, GX_COLOR_ID_WHITE);
187 
188         /* Create and configure date of birth prompt.  */
189         childsize.gx_rectangle_left = childsize.gx_rectangle_right + 1;
190         childsize.gx_rectangle_right = patients_screen.patients_screen_room_label.gx_widget_size.gx_rectangle_left - 1;
191         gx_prompt_create(&row->dob, NULL, &row->background, 0, GX_STYLE_TRANSPARENT|GX_STYLE_TEXT_LEFT | GX_STYLE_ENABLED, 0, &childsize);
192         gx_widget_draw_set(&row->dob, patient_prompt_draw);
193         gx_prompt_text_color_set(&row->dob, GX_COLOR_ID_WHITE, GX_COLOR_ID_BLACK, GX_COLOR_ID_WHITE);
194 
195         /* Create and configure room number prompt.  */
196         childsize.gx_rectangle_left = childsize.gx_rectangle_right + 1;
197         childsize.gx_rectangle_right = patients_screen.patients_screen_admission_date_label.gx_widget_size.gx_rectangle_left - 1;
198         gx_prompt_create(&row->room_num, NULL, &row->background, 0, GX_STYLE_TRANSPARENT|GX_STYLE_TEXT_LEFT | GX_STYLE_ENABLED, 0, &childsize);
199         gx_widget_draw_set(&row->room_num, patient_prompt_draw);
200         gx_prompt_text_color_set(&row->room_num, GX_COLOR_ID_WHITE, GX_COLOR_ID_BLACK, GX_COLOR_ID_WHITE);
201 
202         /* Create and configure admission date prompt.  */
203         childsize.gx_rectangle_left = childsize.gx_rectangle_right + 1;
204         childsize.gx_rectangle_right = patients_screen.patients_screen_pa_num_label.gx_widget_size.gx_rectangle_left - 1;
205         gx_prompt_create(&row->admit_date, NULL, &row->background, 0, GX_STYLE_TRANSPARENT|GX_STYLE_TEXT_LEFT | GX_STYLE_ENABLED, 0, &childsize);
206         gx_widget_draw_set(&row->admit_date, patient_prompt_draw);
207         gx_prompt_text_color_set(&row->admit_date, GX_COLOR_ID_WHITE, GX_COLOR_ID_BLACK, GX_COLOR_ID_WHITE);
208 
209         /* Create and configure mr number prompt.  */
210         childsize.gx_rectangle_left = childsize.gx_rectangle_right + 1;
211         childsize.gx_rectangle_right = list->gx_window_client.gx_rectangle_right;
212         gx_prompt_create(&row->mr_num, NULL, &row->background, 0, GX_STYLE_TRANSPARENT | GX_STYLE_TEXT_LEFT | GX_STYLE_ENABLED, 0, &childsize);
213         gx_widget_draw_set(&row->mr_num, patient_prompt_draw);
214         gx_prompt_text_color_set(&row->mr_num, GX_COLOR_ID_WHITE, GX_COLOR_ID_BLACK, GX_COLOR_ID_WHITE);
215     }
216 
217     /* Update patinet name.  */
218     string.gx_string_ptr = patient_list[index].name;
219     string.gx_string_length = string_length_get(string.gx_string_ptr, MAX_STRING_LENGTH);
220     gx_prompt_text_set_ext(&row->name, &string);
221 
222     /* Update date of birth.  */
223     string.gx_string_ptr = patient_list[index].dob;
224     string.gx_string_length = string_length_get(string.gx_string_ptr, MAX_STRING_LENGTH);
225     gx_prompt_text_set_ext(&row->dob, &string);
226 
227     /* Update rom number.  */
228     string.gx_string_ptr = patient_list[index].room_num;
229     string.gx_string_length = string_length_get(string.gx_string_ptr, MAX_STRING_LENGTH);
230     gx_prompt_text_set_ext(&row->room_num, &string);
231 
232     /* Update admission date.  */
233     string.gx_string_ptr = patient_list[index].admit_date;
234     string.gx_string_length = string_length_get(string.gx_string_ptr, MAX_STRING_LENGTH);
235     gx_prompt_text_set_ext(&row->admit_date, &string);
236 
237     /* Update mr number.  */
238     string.gx_string_ptr = patient_list[index].mr_num;
239     string.gx_string_length = string_length_get(string.gx_string_ptr, MAX_STRING_LENGTH);
240     gx_prompt_text_set_ext(&row->mr_num, &string);
241 }
242 
243 /******************************************************************************************/
244 /* Create children for patient list.                                                      */
245 /******************************************************************************************/
patient_list_children_create(PATIENTS_SCREEN_CONTROL_BLOCK * win)246 VOID patient_list_children_create(PATIENTS_SCREEN_CONTROL_BLOCK *win)
247 {
248 INT               count;
249 GX_VERTICAL_LIST *list = &win ->patients_screen_patient_list;
250 
251     for (count = 0; count <= PATIENT_LIST_VISIBLE_ROWS; count++)
252     {
253 
254         /* Create one patient row.  */
255         patient_row_create(list, (GX_WIDGET *) &row_memory[count], count);
256     }
257 }
258 
259 /******************************************************************************************/
260 /* Override the default event processing of "patients_screen" to handle signals from my   */
261 /* child widgets.                                                                         */
262 /******************************************************************************************/
patients_screen_event_handler(GX_WINDOW * window,GX_EVENT * myevent)263 UINT patients_screen_event_handler(GX_WINDOW *window, GX_EVENT *myevent)
264 {
265     switch(myevent->gx_event_type)
266     {
267     case GX_SIGNAL(ID_PATIENT_LIST, GX_EVENT_LIST_SELECT):
268 
269         /* Update selected patient index.  */
270         gx_vertical_list_selected_index_get(&patients_screen.patients_screen_patient_list, &selected_patient_index);
271         break;
272 
273     default:
274         break;
275     }
276 
277     /* Pass the event to the even handler of the template on which the patients screen is based.  */
278     return template_event_handler(window, myevent);;
279 }
280 
281 /******************************************************************************************/
282 /* Get the name of the selected patient.                                                  */
283 /******************************************************************************************/
GetPatientName(GX_STRING * string)284 VOID GetPatientName(GX_STRING* string)
285 {
286     string->gx_string_ptr = patient_list[selected_patient_index].name;
287     string->gx_string_length = string_length_get(string->gx_string_ptr, MAX_STRING_LENGTH);
288 }
289 
290 /******************************************************************************************/
291 /* Get the date of birth of the selected patient.                                         */
292 /******************************************************************************************/
GetPatientDOB(GX_STRING * string)293 VOID GetPatientDOB(GX_STRING* string)
294 {
295     string->gx_string_ptr = patient_list[selected_patient_index].dob;
296     string->gx_string_length = string_length_get(string->gx_string_ptr, MAX_STRING_LENGTH);
297 }
298 
299 /******************************************************************************************/
300 /* Get the age of the selected patient.                                                   */
301 /******************************************************************************************/
GetPatientAge(INT * age)302 VOID GetPatientAge(INT* age)
303 {
304 time_t     now;
305 struct tm *ts;
306 INT        year;
307 GX_STRING  string;
308 UINT       index;
309 
310     GetPatientDOB(&string);
311     index = string.gx_string_length - 4;
312 
313     year = 0;
314 
315     while (index < string.gx_string_length)
316     {
317         year = year * 10;
318         year += (string.gx_string_ptr[index] - '0');
319         index++;
320     }
321 
322     now = time(NULL);
323     ts = localtime(&now);
324     (*age) = ts->tm_year + 1900 - year;
325 }