consumerportal
Version:
mydna Custimised for you
106 lines (90 loc) • 2.67 kB
text/typescript
/// <reference path="../../includes.ts" />
module medsSearchCtrl {
interface IMedsSearchController {
getMeds(): any;
selectedMedicine(itm: any): any;
searchMedicine(): any;
}
interface IMedsSearchScope extends angular.IScope {
medicinesrch: any;
$sce: angular.ISCEService;
}
class MedsSearchController implements IMedsSearchController{
static $inject = [
'apiSrvc',
'errorHandlerSrvc',
'$scope',
'mydnaApis',
'locationSrvc',
'authenSrvc',
'$sce'
];
LoadingInProgress: boolean;
medicinesrch: any;
Medicines: any;
Medication: any;
showSection: boolean;
MedicationToSearch: string;
Disclaimer: string;
constructor(
private apiSrvc: apiSrvc.IApiService,
private errorHandlerSrvc: errorHandlerSrvc.IErrorHandlerService,
private $scope: IMedsSearchScope,
private mydnaApis: ImyDNAApis,
private locationSrvc: locationSrvc.ILocationService,
private authenSrvc: authenSrvc.IAuthenService,
private $sce: angular.ISCEService
){
var vm = this;
this.Medication = {};
vm.LoadingInProgress = false;
vm.showSection = false;
vm.MedicationToSearch = "";
vm.Disclaimer = "";
$scope.$sce = $sce;
var UrlParams = vm.locationSrvc.getParams();
if("MedicationId" in UrlParams){
vm.MedicationToSearch = UrlParams.MedicationId;
vm.searchMedicine();
}
}
getMeds() {
if (this.$scope.medicinesrch.length > 2) {
this.LoadingInProgress = true;
this.apiSrvc.get_request_params(
this.mydnaApis.Medicines + '?MedicationSearchQuery=' + this.$scope.medicinesrch
, "")
.then(data => {
this.Medicines = data;
this.LoadingInProgress = false;
}, err => {
this.errorHandlerSrvc.errorHandler(err, 'debug', '');
});
}
}
selectedMedicine(itm){
this.MedicationToSearch = itm.id;
this.locationSrvc.goto("meds/search",{
MedicationId : itm.id
});
this.searchMedicine();
}
searchMedicine(){
this.$scope.$emit("disable-on-save-on");
this.apiSrvc.get_request_params(
this.mydnaApis.PatientMedications + '?MedicationId=' + this.MedicationToSearch
, "")
.then(data => {
this.Medication = data;
this.showSection = true;
this.$scope.medicinesrch = null;
this.$scope.$emit("disable-on-save-off");
this.Disclaimer = this.mydnaApis.MedsDisclaimer;
}, err => {
this.$scope.$emit("disable-on-save-off");
this.errorHandlerSrvc.errorHandler(err, 'debug', '');
});
}
}
angular.module('app').controller('medsSearchCtrl', MedsSearchController);
}