Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion docs/StudentHealthTracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ the Death Information panel will appear so you can also input the Cause of Death
sent.

View the **Cause of Death Report** and the **Student Health Report** by navigating to the Reports module and clicking
on the appropriate report title.
on the appropriate report title.

## Student Vitals Dashlet
A new dashlet is available to track the number of days students are in a given Vitals status. This dashlet leverages
the Contacts Audit table to populate a pie chart summarizing the number of days all Students in a given Super Group (or all Super Groups)
are in each Vital status.

This dashlet displays use of the Sucrose charts in a custom dashlet and is available in Home, List Views, and Record Views.

There is also an accompanying API enpoint for retrieve the data from the Student records and shows use of Sugar Query in joins
and union queries. For more information on the endpoint see <instnace>/rest/v11/help.

The pull request for the Student vitals dashlet can be viewed in [#27](https://github.com/sugarcrm/school/pull/27).
2 changes: 1 addition & 1 deletion package/pack.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
'default_value' => 'active',
'date_modified' => '2018-02-01 21:32:16',
'deleted' => '0',
'audited' => '0',
'audited' => '1',
'mass_update' => '1',
'duplicate_merge' => '1',
'reportable' => '1',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

$app_strings['LBL_STUDENT_VITAL_CHART_DESC'] = 'Pie Chart grouping combined days in vitals status';
$app_strings['LBL_STUDENT_VITAL_CHART'] = 'Student Vitals Chart';
$app_strings['LBL_VITALS_DASHLET_SELECT_TEAM'] = 'Select Super Group to view data on';
$app_strings['LBL_VITALS_DASHLET_SELECT_DATE_RANGE'] = 'Select Date Range';
74 changes: 74 additions & 0 deletions package/src/custom/clients/base/api/StudentVitalsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php


use Sugarcrm\Sugarcrm\ProcessManager\Registry;


class StudentVitalsApi extends SugarApi
{
public function registerApiRest()
{
return array(
'getStudentVitalData' => array(
'reqType' => 'GET',
'noLoginRequired' => false,
'path' => array('professorM', 'getStudentVitalData', '?'),
'pathVars' => array('', '', 'supergroup'),
'method' => 'getStudentVitalData',
'shortHelp' => 'API End point to retrieve data for vitals dashlet',
'longHelp' => 'custom/include/api/help/student_vitals_api_help.html',
),
);
}

/**
* API Endpoint for student vitals chart
* @param $api
* @param $args
*
* @return false|string
* @throws SugarQueryException
*/
public function getStudentVitalData($api, $args)
{

global $app_list_strings;
require_once('custom/include/ProfessorM/StudentVitalHelper.php');
$supergroup = $args['supergroup'];
$helper = new \Sugarcrm\ProfessorM\Helpers\StudentVitalHelper();
$status_data = $helper->getStudentVitalsByDays($supergroup);

// Sort if we have an array
if (is_array($status_data)) {
arsort($status_data);
}
$chart_data = array(

);

foreach ($status_data as $key => $value) {

$chart_data[] = array(
"key" => $app_list_strings['vitals_list'][$key],
"values" => array(
array("x"=> 1, "y"=> $value),
)
);

}
$data = array(
"properties" => array(
"title" => "Student Vitals Days Count",
),
"data"=> $chart_data


);



return json_encode($data);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="student-vital-chart">
<div class="sc-chart" data-content="chart">
<svg id="{{cid}}"></svg>
</div>
<div class="block-footer hide" data-content="nodata">{{str "LBL_NO_DATA_AVAILABLE"}}</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Your installation or use of this SugarCRM file is subject to the applicable
* terms available at
* http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
* If you do not agree to all of the applicable terms or do not have the
* authority to bind the entity as an authorized representative, then do not
* install or use this SugarCRM file.
*
* Copyright (C) SugarCRM Inc. All rights reserved.
*/
({
plugins: ['Dashlet', 'Chart'],
className: 'student-vital-chart',
chartCollection: null,
hasData: false,
total: 0,

/**
* @inheritdoc
*/
initialize: function(options) {
this._super('initialize', [options]);

this.chart = sucrose.charts.pieChart()
.donut(true)
.donutLabelsOutside(true)
.donutRatio(0.25)
.hole(false)
.showTitle(true)
.tooltips(true)
.showLegend(true)
.colorData('class')
.tooltipContent(_.bind(function(eo, properties) {

var value = parseInt(this.chart.getValue()(eo), 10);
var total = parseInt(properties.total, 10);
(total == 0) ? total = 1 : '';
var percentage = value/total * 100;
return '<h3>' + this.chart.fmtKey()(eo) + '</h3>' +
'<p>' + value + ' days</p>' +
'<p>' + percentage.toFixed(2) + '%</p>';
}, this))
.strings({
noData: app.lang.get('LBL_CHART_NO_DATA')
});
},

/**
* Override to set options for supergroup selector in config dynamically
*/
initDashlet: function() {
if (this.meta.config) {

var supergroup_value = this.meta.vitals_dashlet_supergroup ? this.meta.vitals_dashlet_supergroup : 'all';
var accounts = app.data.createBeanCollection('Accounts');
var supergroups = [];
supergroups.push({id: 'all', text:'All'})
accounts.fetch({
success: function() {
accounts.comparator = 'name';
accounts.sort({silent: true});
_.each(accounts.models, function(account){
supergroups.push({id: account.id, text: account.attributes.name});
});

$('[name="vitals_dashlet_supergroup"]').html('').select2({data: supergroups, width: '100%'});
$('[name="vitals_dashlet_supergroup"]').val(supergroup_value).trigger('change');
}
})
}

this._super('initDashlet');
},


/**
* Generic method to render chart with check for visibility and data.
* Called by _renderHtml and loadData.
*/
renderChart: function() {
var self = this;
if (!self.isChartReady()) {

return;
}


d3sugar.select(this.el).select('svg#' + this.cid)
.datum(self.chartCollection)
.call(self.chart);

this.chart_loaded = _.isFunction(this.chart.update);
this.displayNoData(!this.chart_loaded);

},

/**
* @inheritdoc
*/
loadData: function(options) {

if(this.meta.config) {

return;
}
var self = this;
var supergroup_value = this.meta.vitals_dashlet_supergroup ? this.meta.vitals_dashlet_supergroup : 'all';
url = app.api.buildURL('professorM/getStudentVitalData/' + supergroup_value);
this.hasData = false;
app.api.call('GET', url, null, {
success: function(data) {
self.hasData = true;
self.evaluateResponse(data);
self.render();
},
complete: options ? options.complete : null
});

},


evaluateResponse: function(data) {

this.total = 1;
this.hasData = true;
this.chartCollection = $.parseJSON(data);

},


})  
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

$viewdefs['base']['view']['student-vital-chart'] = array(
'dashlets' => array(
array(
'label' => 'LBL_STUDENT_VITAL_CHART',
'description' => 'LBL_STUDENT_VITAL_CHART_DESC',
'config' => array(
'date_range' => 'all',
'supergroup' => 'all',
),
'preview' => array(
),
'filter' => array(
'view' => array(
'records',
'record'
)
),

),

),
'panels' => array(
array(
'name' => 'panel_body',
'columns' => 2,
'labelsOnTop' => true,
'placeholders' => true,
'fields' => array(

array(
'name' => 'vitals_dashlet_supergroup',
'label' => 'LBL_VITALS_DASHLET_SELECT_TEAM',
'type' => 'enum',
'span' => 6,
'options' => array('all' => 'All'),
),
array(
'name' => 'vitals_dashlet_date_range',
'label' => 'LBL_VITALS_DASHLET_SELECT_DATE_RANGE',
'type' => 'enum',
'span' => 6,
'options' => array('all' => 'All Time', 'ThisYear' => 'This Year', 'LastYear' => 'Last Year'),
),
),
),
),
);
Loading