2 * Copyright (C) 2014 Kevin Yeh <kevin.y@integralemr.com> and OEMR <www.oemr.org>
4 * LICENSE: This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 3
7 * of the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @author Kevin Yeh <kevin.y@integralemr.com>
17 * @link http://www.open-emr.org
20 function toggle_code(data,event)
22 data.selected(!data.selected());
25 function codes_ok(data,event)
27 codes_choices_vm.show_choices(false);
28 var f = document.forms[0];
29 var choices=codes_choices_vm.active_category().codes();
30 for (var i = 0; i < choices.length; ++i) {
31 if (choices[i].selected()) {
32 if (f.newcodes.value) f.newcodes.value += '~';
33 f.newcodes.value += choices[i].value();
34 choices[i].selected(false);
37 if (f.newcodes.value) {
38 // top.restoreSession();
40 // This supports the option to immediately save:
46 function codes_cancel(data,event)
48 codes_choices_vm.show_choices(false);
53 function set_active_category(data,event)
55 codes_choices_vm.active_category(data);
56 codes_choices_vm.show_choices(true);
60 var codes_choices_vm={
61 categories : ko.observableArray(),
62 active_category:ko.observable(false),
63 show_choices: ko.observable(false)
66 function code_category(title)
69 this.title=ko.observable(title);
70 this.codes=ko.observableArray();
74 function code_choice(description,value)
77 this.description=ko.observable(description);
78 this.value=ko.observable(value);
79 this.selected=ko.observable(false);
83 function populate_vm_categories(idx,elem)
87 jqElem.parent().parent().hide(); // select is child of a td and a tr.
88 var title=jqElem.find("option[value='']").text();
90 var category=new code_category(title);
91 codes_choices_vm.categories().push(category);
93 var choices=jqElem.find("option:not([value=''])");
94 choices.each(function(idx,elem)
97 var description=jqChoice.text();
98 var value=jqChoice.attr("value");
99 var choice=new code_choice(description,value);
100 category.codes().push(choice);
105 function analyze_codes()
107 var code_table=$("table[width='95%']");
108 var categories=code_table.find("td[width='50%'] > select");
109 categories.each(populate_vm_categories);
110 add_code_template(code_table);
113 function add_code_template(elem)
115 var template=$("<div></div>");
116 template.attr("data-bind","template: {name: 'code-choice-options'}");
117 template.addClass("code-choices");
118 elem.before(template);
119 ko.applyBindings(codes_choices_vm,template.get(0));
120 codes_choices_vm.active_category(codes_choices_vm.categories()[1]);