File size: 4,419 Bytes
cf0f72e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
define(function(require) {
	var system = require('durandal/system');
	var Backend = require('modules/diagnosis');
	var Structures = require('modules/patientStructures');
	var backend = new Backend(); 
	var self; 
	
	var DiagnosisLetter = function(title,patientId,practiceId,date,options) { 
		self = this; 
		this.title = title || DiagnosisLetter.defaultTitle; 
		this.patientId = patientId || DiagnosisLetter.patientId; 
		this.practiceId = practiceId || DiagnosisLetter.practiceId; 
		this.date = date || DiagnosisLetter.date; 
		this.options = options || DiagnosisLetter.defaultOptions;
		this.text = ko.observable(); 
		this.letter = ko.observable();
		this.getPhysician();
		
	};
	
	// /**********************************************************************************************
	 // * Retrieve data for physician
	 // *********************************************************************************************/
	
	DiagnosisLetter.prototype.getPhysician = function(data) {
		  var isEmpty = false; 
		  backend.getLetter(self.patientId,self.practiceId,self.date).success(function(data) { 
			if(data.length > 0) { 
				var d = $.map(data, function(item) {
                     self.text(item.diagnosis_letter); 
					if(self.text() == '') {
						var letter = '';
						backend.getReferringPhysician(self.patientId,self.practiceId).success(function(data) { 
							if(data.length > 0) { 
								var d = $.map(data, function(item) {
									letter += item.first_name +  ' ' + item.last_name + ',' + item.degree + '\n\n'; 
								});
								backend.getPatient(self.patientId).success(function(data) { 
									if(data.length > 0) { 
										var d = $.map(data, function(item) {
											letter += 'RE :' + item.first_name +  ' ' + item.last_name + ', DOB: '
											+ item.date_of_birth + '\n'; 
										}); 
									
										backend.getServiceRecord(self.date,self.patientId,self.practiceId).success(function(data) { 
											if(data.length > 0) { 
												var d = $.map(data, function(item) { 
													letter+= 'Dear Dr.  \n\n I saw the above patient in the office on ' + self.date + 
															  ' for ' + item.systems_comment + ' evaluation of - \n'; 
												}); 
											
												backend.getDiagnosis(self.patientId,self.practiceId,self.date).success(function(data) { 
														var diagnosis = ''; 
														if(data.length > 0) { 
															var d = $.map(data, function(item) { 
																 diagnosis+= item.diagnosis + '\n';
															}); 
															letter += diagnosis + '\n';
															 letter+= 'My Recommendations are as follows: \n\n\n';
															 letter+= 'I appreciate your trust in our service. If you have any questions, do not hesitate to call me \n\n'; 
															letter+= 'Thank You \n\n'; 
															letter+= 'Sincerely \n';
															backend.getPhysician(self.patientId,self.practiceId,self.date).success(function(data) { 
															   var m = '';
																if(data.length > 0) { 
																	var d = $.map(data, function(item) {
																	letter += item.first_name +  ' ' + item.last_name + ',' + item.degree + '\n\n'; 
																	 self.text(letter);
																	});
																}
														   });
														   
														   
														}       
												});
											 
											}
										});
									}
								});
							}
						});
					}
				});
		    }
		  });	
	}
	DiagnosisLetter.prototype.printLetter  = function(data) { 
		backend.saveLetter(self.patientId, self.practiceId,self.date,self.text); 
		var height = $('.flowHolder').height();
		var settings = 'directories=no, height=' + height + ', width=800, location=yes, ' +
				   'menubar=no, status=no, titlebar=no, toolbar=no';
		var win = window.open(
				'php/printLetter.php/?patientId=' + self.patientId + '&practiceId=' + 
				self.practiceId + '&date=' + self.date				
				,					
				'',
				settings
			);
	}; 
  
    
	DiagnosisLetter.prototype.selectOption = function(dialogResult) {
		this.modal.close(dialogResult);
	};
 
    DiagnosisLetter.prototype.closeWindow = function(data) {
		this.modal.close('close');
	};
	
	DiagnosisLetter.defaultTitle = '';
	DiagnosisLetter.defaultOptions = ['Save','Cancel'];
	
	return DiagnosisLetter;	
});