<commit_before>/*
 * Copyright (C) 2011 Callista Enterprise AB <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
NC.PatientSchema = function(descriptionId, tableId) {
	
	var _baseUrl = "/netcare-web/api/patient/";
	var _schemaCount = 0;
	
	var _descriptionId = descriptionId;
	var _tableId = tableId;
	var _lastUpdatedId = -1;
	
	var _updateDescription = function() {
		console.log("Updating schema table description");
		if (_schemaCount == 0) {
			$('#' + _descriptionId).html('Inga aktuella aktiviteter').show();
			$('#' + _tableId).hide();
		} else {
			$('#' + _descriptionId).hide();
			$('#' + _tableId).show();
		}
	}
	
	var public = {
		
		init : function() {
			_updateDescription();
		},
		
		focus : function() {
			console.log('set focus : ' + _lastUpdatedId);
			if (_lastUpdatedId != -1) {
				$('#rep-' + _lastUpdatedId).focus();
			}
		},
		
		list : function() {
			console.log("Load activitues for the patient");
			var today = $.datepicker.formatDate( 'yy-m-d', new Date(), null );
			var curDay = '';
			var curActivity = '';
			var util = NC.Util();
			$.ajax({
				url : _baseUrl + 'schema',
				dataType : 'json',
				success : function(data) {
					console.log("Success. Processing results...");
					
					/* Empty the result list */
					$('#' + tableId + ' tbody > tr').empty();
					
					$.each(data.data, function(index, value) {
						console.log("Processing index " + index + " value: " + value.reported + ", " + value.actual);
												
						var reportField = $('<div>');
						var inputValue;
						
						if (value.definition.type.code != 'NONE') {
							inputValue = $('<input>');
							inputValue.val((value.reported != null) ? value.actual : '');
							inputValue.attr('size', 4);
							inputValue.attr('id', 'rep-' + value.id);

							if (today == value.date) {
								inputValue.css('background', 'lightgreen');
							} else {
								inputValue.css('background', (!value.due) ? 'lightpink' : 'lightyellow');
//								XXX: Disable up-coming days.	
								if (value.due) {
									inputValue.attr('disabled', true);
								}
							}
							
							inputValue.change(function() {
								public.accept(value.id, inputValue.val());
							});
							inputValue.appendTo(reportField);

							if (!value.due) {
								var editIcon = util.createIcon('bullet_accept', null);
								editIcon.css('align', 'right');
								reportField.append(editIcon);
							}
						} else {
							inputValue = '&nbsp;';
							inputValue.appendTo(reportField);
						}						
						
						if (curDay != value.day.value) {
							curDay = value.day.value;
							dayField = curDay + '<br/>' + value.date;
						} else {
							dayField = '-&nbsp;"&nbsp;-';
						}
						
						var activity = value.definition.type.name + "<br/>" + value.definition.goal + '&nbsp;' + value.definition.type.unit.value;
						if (curActivity != activity) {
							curActivity = activity;
							activityField = curActivity;
						} else {
							activityField = '-&nbsp;"&nbsp;-';
						}
						
						$('#' + tableId + ' tbody').append(
								$('<tr>').append(
										$('<td>').html(dayField)).append(
												$('<td>').html(value.time)).append(
														$('<td>').css('text-align', 'center').html(activityField)).append(
																$('<td>').html(reportField)));
					});
					
					console.log("Updating ordination count to: " + data.data.length);
					_schemaCount = data.data.length;
					
					console.log("Updating description");
					_updateDescription();
				}
			});
		},
	
		
		/**<commit_msg>minor<commit_after>/*
 * Copyright (C) 2011 Callista Enterprise AB <<EMAIL>>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
NC.PatientSchema = function(descriptionId, tableId) {
	
	var _baseUrl = "/netcare-web/api/patient/";
	var _schemaCount = 0;
	
	var _descriptionId = descriptionId;
	var _tableId = tableId;
	var _lastUpdatedId = -1;
	
	var _updateDescription = function() {
		console.log("Updating schema table description");
		if (_schemaCount == 0) {
			$('#' + _descriptionId).html('Inga aktuella aktiviteter').show();
			$('#' + _tableId).hide();
		} else {
			$('#' + _descriptionId).hide();
			$('#' + _tableId).show();
		}
	}
	
	var public = {
		
		init : function() {
			_updateDescription();
		},
		
		focus : function() {
			console.log('set focus : ' + _lastUpdatedId);
			if (_lastUpdatedId != -1) {
				$('#rep-' + _lastUpdatedId).focus();
			}
		},
		
		list : function() {
			console.log("Load activitues for the patient");
			var today = $.datepicker.formatDate( 'yy-m-d', new Date(), null );
			var curDay = '';
			var curActivity = '';
			var util = NC.Util();
			$.ajax({
				url : _baseUrl + 'schema',
				dataType : 'json',
				success : function(data) {
					console.log("Success. Processing results...");
					
					/* Empty the result list */
					$('#' + tableId + ' tbody > tr').empty();
					
					$.each(data.data, function(index, value) {
						console.log("Processing index " + index + " value: " + value.reported + ", " + value.actual);
												
						var reportField = $('<div>');
						var inputValue;
						
						if (value.definition.type.code != 'NONE') {
							inputValue = $('<input>');
							inputValue.val((value.reported != null) ? value.actual : '');
							inputValue.attr('size', 4);
							inputValue.attr('id', 'rep-' + value.id);

							if (today == value.date) {
								inputValue.css('background', 'lightgreen');
							} else {
								inputValue.css('background', (!value.due) ? 'lightpink' : 'lightyellow');
//								XXX: Disable up-coming days.	
								if (value.due) {
									inputValue.attr('disabled', true);
								}
							}
							
							inputValue.change(function() {
								public.accept(value.id, inputValue.val());
							});
							inputValue.appendTo(reportField);

							if (!value.due) {
								var editIcon = util.createIcon('bullet_accept', null);
								editIcon.css('align', 'right');
								reportField.append(editIcon);
							}
						} else {
							inputValue = '&nbsp;';
							inputValue.appendTo(reportField);
						}						
						
						if (curDay != value.day.value) {
							curDay = value.day.value;
							if (value.day.value == today) {
								dayField = '<b>' + curDay + '<br/>' + value.date + '</b>';								
							} else {
								dayField = curDay + '<br/>' + value.date;
							}
						} else {
							dayField = '-&nbsp;"&nbsp;-';
						}
						
						var activity = value.definition.type.name + "<br/>" + value.definition.goal + '&nbsp;' + value.definition.type.unit.value;
						if (curActivity != activity) {
							curActivity = activity;
							activityField = curActivity;
						} else {
							activityField = '-&nbsp;"&nbsp;-';
						}
						
						$('#' + tableId + ' tbody').append(
								$('<tr>').append(
										$('<td>').html(dayField)).append(
												$('<td>').html(value.time)).append(
														$('<td>').css('text-align', 'center').html(activityField)).append(
																$('<td>').html(reportField)));
					});
					
					console.log("Updating ordination count to: " + data.data.length);
					_schemaCount = data.data.length;
					
					console.log("Updating description");
					_updateDescription();
				}
			});
		},
	
		
		/**
{'fraction_non_alphanumeric': 0.16234378684272577, 'fraction_numerical': 0.002357934449422306, 'mean_word_length': 2.4455727051177902, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2556493', 'n_tokens_mistral': 3577, 'n_tokens_neox': 2532, 'n_words': 626}