Patient image fixups (#931)
[openemr.git] / interface / main / tabs / js / patient_data_view_model.js
blob64f55c4d139c228e98ee8a116bf77f2f2d4cbafd
1 /**
2  * Copyright (C) 2016 Kevin Yeh <kevin.y@integralemr.com>
3  *
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>;.
14  *
15  * @package OpenEMR
16  * @author  Kevin Yeh <kevin.y@integralemr.com>
17  * @link    http://www.open-emr.org
18  */
20 function encounter_data(id,date,category)
22     var self=this;
23     self.id=ko.observable(id);
24     self.date=ko.observable(date);
25     self.category=ko.observable(category);
26     return this;
29 function patient_data_view_model(pname,pid,pubpid,str_dob)
31     var self=this;
32     self.pname=ko.observable(pname);
33     self.pid=ko.observable(pid);
34     self.pubpid=ko.observable(pubpid);
35     self.str_dob=ko.observable(str_dob);
36     self.patient_picture=ko.computed(function(){
37       return webroot_url + '/controller.php' +
38              '?document&retrieve' +
39              '&patient_id=' + pubpid +
40              '&document_id=-1' +
41              '&as_file=false' +
42              '&original_file=true' +
43              '&disable_exit=false' +
44              '&show_original=true' +
45              '&context=patient_picture';
46     }, self);
48     self.encounterArray=ko.observableArray();
49     self.selectedEncounterID=ko.observable();
50     self.selectedEncounter=ko.observable();
51     self.selectedEncounterID.extend({notify: 'always'});
52     self.selectedEncounterID.subscribe(function(newVal)
53     {
54        for(var encIdx=0;encIdx<self.encounterArray().length;encIdx++)
55        {
56            var curEnc=self.encounterArray()[encIdx];
57            if(curEnc.id()===newVal)
58            {
60                self.selectedEncounter(curEnc);
61                return;
62            }
63        }
64        // No valid encounter ID found, so clear selected encounter;
65        self.selectedEncounter(null);
66     });
67     return this;