consumerportal
Version:
mydna Custimised for you
85 lines (72 loc) • 3.05 kB
text/typescript
/// <reference path="../../includes.ts" />
module app {
import IUser = services.IUser;
import IPatientCase = services.IPatientCase;
class DietDashboardController {
public reportLabel: string;
public details: any;
public selected: any;
public loaded: boolean = false;
private patientCase: IPatientCase;
public navigation: any[];
private downloading: boolean = false;
public downloadMessage: string = "Download Your Report";
static $inject = [
'$scope',
'$routeParams',
'$timeout',
'patientService',
'dietService',
'user'
];
constructor(
$scope: angular.IScope,
private $routeParams: angular.route.IRouteParamsService,
private $timeout: angular.ITimeoutService,
private patientService: services.IPatientService,
private dietService: services.IDietService,
public user: IUser
) {
this.navigation = this.dietService.navigation($routeParams.type);
$scope.$on('dietMetricsChanged', (ev: any, details: any) => {
this.details = details;
this.selected = this.details[this.details.goal];
});
patientService.cases().then((cases: IPatientCase[]) => {
this.patientCase = cases.filter((c: IPatientCase) => { return c.TestName === $routeParams.type})[0];
this.reportLabel = this.dietService.getWeightOverride($routeParams.type);
dietService.details($routeParams.type).then((value: any) => {
this.details = value;
this.selected = this.details[this.details.goal];
this.loaded = true;
});
});
}
download() {
if (!this.downloading) {
this.downloading = true;
this.downloadMessage = "Downloading...";
this.patientService.download(this.patientCase.OrderNumber, this.patientCase.OrderNumber).then(
() => {
this.downloading = false;
this.downloadMessage = 'Download Complete';
this.$timeout(() => {
this.downloadMessage = 'Download Your Report';
}, 5000);
},
() => {
this.downloading = false;
this.downloadMessage = 'Download Failed. Try Again?';
}
);
}
}
openSection(page: string) {
this.open('#/diet/' + this.$routeParams.type + '/' + page);
}
open(hash: string) {
window.location.hash = hash;
}
}
angular.module('app').controller('dietDashboardCtrl', DietDashboardController);
}