var appServices=angular.module("app.services",[]),app,appDirectives,mcAutocomplete,accent_map,accent_fold;appServices.factory("authInterceptorService",["$q","$location","tokenService","eOrdersSettings","$rootScope","$injector",function(n,t,i,r,u,f){return{request:function(n){u.APIavailable=!0;n.headers=n.headers||{};var t=i.tokenData||"";return n.url.indexOf(r.apiUri)==0&&t!=""&&(n.headers.Authorization=t.tokenType+" "+t.value),n},response:function(n){u.FirstRetry=!1;var t=n.Success||!0;return t==!1&&console.log("Didn't get success!",n),n},requestError:function(t){return console.log("%c OHOH SPOGETTI-O!! - error with request","color:#00BFEF"),n.reject(t)},responseError:function(t){var r,e,o;if(t.status===401)i.tokenData=null,console.log("%c AuthInterceptorService - RESPONSE UNAUTHORISED!!","color:#00AFFF;background-color:#8F0000"),u.APIavailable=!1;else if(t.status!=0)if(r=t.config.method,e=t.config.url,console.log("%c TODO: show some kind of error message and ask the user to retry "+r+": "+e+" or switch to manual mode.","color:#00BFEF"),console.log(t),u.FirstRetry)u.FirstRetry=!1,u.APIavailable=!1;else return u.FirstRetry=!0,o=f.get("$http"),o(t.config);return n.reject(t)}}}]);appServices.factory("authService",["$http","$q","tokenService","eOrdersSettings","localDataService",function(n,t,i,r,u){return{Login:function(t){var f=r.apiUri+"/Token",e=u.getProductName().replace(/\s+/g,"_"),o="grant_type=password&username="+e+"&password="+t;return n({url:f,method:"POST",cache:!1,headers:{"Content-Type":"application/x-www-form-urlencoded"},data:o}).then(function(n){i.tokenData={value:n.data.access_token,tokenType:n.data.token_type,expires:n.data.expires_in}})},CheckUser:function(){return n({url:r.apiUri+"/favourite/checkuser",method:"POST",cache:!1,data:{ApplicationId:u.getProductName(),SiteId:u.getPractice().PracticeID,DoctorId:u.getLoggedInUser().PrescriberNo}})}}}]);appServices.factory("clinicalNotesService",["$http","$rootScope","localDataService",function(n,t,i){var r="";return{AppendToClinicalNotes:function(n){n!=null&&(r.length<this.ExceedLimit&&(r=r.trim(),r+=" "+n,r=r.trim()),r.length>this.ExceedLimit&&(r=r.substr(0,this.ExceedLimit)),t.$broadcast("ClinicalNotesUpdated"))},SetClinicalNotes:function(n){r=n;t.$broadcast("ClinicalNotesUpdated")},GetClinicalNotes:function(){return r},ExceedLimit:2e3,AvailableCharacters:function(){return r.length>0?this.ExceedLimit-r.length-1:this.ExceedLimit},HaveProgressNotesChanged:function(){return i.watchData.hasProgressNotesChanged}}}]);appServices.factory("copyToDoctorService",["$http","$rootScope","localDataService","eOrdersSettings","toolsService","$q",function(n,t,i,r,u,f){function b(n){this.SearchTerms=n;this.BuCode=w}function y(){t.$broadcast("SelectedDoctorsChanged",e.length)}function k(n){for(var i=-1,t=0;t<e.length;t++)if(e[t].Id===n){i=t;break}return i}function s(n,t,i){var r="";return n&&(r=n),t&&(r!=""&&(r+=" "),r+=t),i&&(r!=""&&(r+=" "),r+=i),r}function d(n){var t={};return t.Id=n.Id,t.DrCode=n.DrCode,t.Title=n.Title,t.FirstName=n.FirstName,t.Surname=n.Surname,t.HicCode=n.HicCode,t.SurgeryCode=n.SurgeryCode,t.Postcode=n.Postcode,t.Address=s(n.Addr1,n.Addr2,n.Addr3),t.Suburb=n.Suburb,t.State=n.State,t.Tel=n.WorkPhone,t.FaxNumber=n.WorkFax,t.Provider=n.Provider,t.Status=n.Status,t.Category=n.HicCode,t.selected=h(t.Id),t}function g(n){var t={};return t.Id="MD"+n.AddressBookId,t.Title="",t.FirstName=n.FirstName,t.Surname=n.Surname,t.HicCode=null,t.SurgeryCode=null,t.Postcode=n.Postcode,t.Address=s(n.StreetLine1,n.StreetLine2,n.StreetLine3),t.Suburb=n.City,t.State=n.State,t.Tel=n.WorkPhone,t.FaxNumber=n.WorkFax,t.Provider=n.ProviderNumber,t.Category=n.Category,t.selected=h(t.Id),t}function nt(n){if(n.Type==="Person"||n.Type==="InternalPerson"){var t={};return t.Id="BS"+n.Id,t.BSId=n.Id,t.Title=n.Title,t.FirstName=n.GivenName,t.Surname=n.Surname,t.HicCode=null,t.SurgeryCode=null,t.Postcode=n.PostalAddress.Postcode,t.Address=s(n.PostalAddress.Street1,n.PostalAddress.Street2),t.Suburb=n.PostalAddress.Suburb,t.State=n.PostalAddress.State,t.Tel=n.Phone,t.FaxNumber=n.Fax,t.Provider=null,t.Category=null,t.selected=h(t.Id),t.speciality=n.Speciality.Description?n.Speciality.Description:null,t}return null}function tt(n,t,i,r,f,e){n=u.RemoveNonStandardChars(n);t=u.RemoveNonStandardChars(t);i=u.RemoveNonStandardChars(i);r=u.RemoveNonStandardChars(r);f=u.RemoveNonStandardChars(f);e=u.RemoveNonStandardChars(e);var o={},s=it();return o.Id=s,o.DrCode="",o.Title="",o.FirstName=n,o.Surname="",o.HicCode="",o.SurgeryCode="",o.Postcode=r,o.Address=t,o.Suburb=i,o.State="",o.Tel=f,o.FaxNumber=e,o.Provider="",o.Status="",o.Category="",o.selected=!0,o}function h(n){for(var t=0;t<e.length;t++)if(e[t].Id===n)return!0;return!1}function it(){for(var i="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",r="",t,n=0;n<4;n++)t=Math.floor(Math.random()*i.length),r+=i.substring(t,t+1);return r}function rt(n){return function(t,i){return t[n]>i[n]?1:t[n]<i[n]?-1:0}}function c(){var n=arguments;return function(t,i){for(var r=0,u=0,f=n.length;u===0&&r<f;)u=rt(n[r])(t,i),r++;return u}}var p=r.apiUri,l,e=[],a=5,w=i.getLabCode(),v=!1,o=100;return{MAX_SEARCH_RESULTS:o,setSearchParams:function(n){l=new b(n)},searchUltraDoctors:function(){return n({url:p+"/ultradoctor/search",method:"POST",cache:!1,data:l}).then(function(n){var i=n.data.Data,r,u,t;if(i){for(r=[],u=Math.min(o+1,i.length),t=0;t<u;t++)r.push(d(i[t]));return r.sort(c("Surname","FirstName","Postcode","Suburb"))}return null})},searchLocalAddressBook:function(n){var t=i.getLocalAddressBookDoctors(n)||"",u=i.getHost(),r;return u===2?t.then(function(n){var u=[],t,i;for(r=Math.min(o+1,n.length),t=0;t<r;t++)i=nt(n[t]),i!=null&&u.push(i);return u.sort(c("Surname","FirstName","Postcode","Suburb"))}):t?f(function(n){setTimeout(function(){var u=[],i;for(r=Math.min(o+1,t.length),i=0;i<r;i++)u.push(g(t[i]));n(u.sort(c("Surname","FirstName","Postcode","Suburb")))},100)}):void 0},addDoctorToSelected:function(n){if(n.highlighted=!1,e.length>=a)return!1;for(var t=0;t<e.length;t++)if(e[t].Id==n.Id)return!1;return e.unshift(n),y(),!0},RemoveDoctorFromSelected:function(n){var i=k(n);i>-1&&(e.splice(i,1),t.$broadcast("SelectedDoctorRemoved",n),y())},SelectedDoctors:e,SelectedDoctorsLimit:a,CreateNewDoctorObject:function(n,t,i,r,u,f){return tt(n,t,i,r,u,f)},SetShowCopyToDoctor:function(n){v=n;n===!0&&t.$broadcast("CopyToDoctorSearchInitialised")},ShowCopyToDoctors:function(){return v}}}]);appServices.factory("currentRxService",["$http","localDataService",function(n,t){var i;return{ImportCurrentRx:function(){return i=t.getCurrentRx(),t.watchData.hasCurrentRxChanged=!1,i},GetCurrentRx:function(){return i},SetCurrentRx:function(n){i=n},CanImportRx:function(){return t.watchData.hasCurrentRxChanged}}}]);appServices.factory("eOrderService",["$http","testService","clinicalNotesService","localDataService","eOrdersSettings","patientService","$rootScope","$filter","copyToDoctorService","currentRxService","histologyService","pregnancyService","toolsService",function(n,t,i,r,u,f,e,o,s,h,c,l,a){function ut(n,t){var i=t.getTime()-n.getTime();return Math.ceil(i/864e5)}function b(n,t,i){var u=typeof i!="undefined"?i:"0",r=new Array(1+t).join(u);return(r+n).slice(-r.length)}function d(n){var t=p.isValidDate(n);return t&&!t.hour?b(t.day,2)+"/"+b(t.month,2)+"/"+b(t.year,4):t?b(t.day,2)+"/"+b(t.month,2)+"/"+b(t.year,4)+" "+b(t.hour,2)+":"+b(t.minute,2):""}function ot(){this.OrderId=null;this.EOrderNumber=null;this.RequestDate=p.GetRequestDate();this.RequestDate=p.isValidRequestDate(this.RequestDate)?d(this.RequestDate):"";this.Patient=p.GetPatient();this.RequestingDoctor=p.GetRequestingDoctor();this.CopyToDoctors=lt();this.ReferringPractice=p.GetSendingFacility();this.TestsOrdered=p.GetRequestedTests();this.BillingOptions=p.GetBillingObject();this.ClinicalData=p.GetClinicalInfo();this.ClinicalData.LMP=d(this.ClinicalData.LMP);this.ClinicalData.EDC=d(this.ClinicalData.EDC);this.ClinicalData.UrgentByDateTime=p.isValidUrgentDate(this.ClinicalData.UrgentByDateTime)?d(this.ClinicalData.UrgentByDateTime):"";this.CytologyData=p.GetCytologyInfo();this.CytologyData.LatestAbnormality=d(this.CytologyData.LatestAbnormality);this.HistologySpecimens=c.getSelected();this.CurrentRx=h.GetCurrentRx();this.ReferringApplication=r.getProductName();this.ReferringApplicationVersion=r.getAuthenticationDetails().ReferringApplicationVersion;this.BusinessUnitCode=r.getLabCode()}function st(n){if(y.LabName=r.getLabCode(),y.Tests=n.TestsOrdered,y.OrderId=n.EOrderNumber,y.Id=n.OrderId,y.CopyToDoctors=n.CopyToDoctors,y.RequestDate=n.RequestDate,y.BillingOptions=n.BillingOptions,y.ClinicalData=n.ClinicalData,t.IsGynaeTestSelected()&&!k.RegisterPapTest){var i="OPTED OFF PAP TEST REGISTER";(y.ClinicalNotesPrintString==undefined||y.ClinicalNotesPrintString.length==0)&&(y.ClinicalNotesPrintString=i);y.ClinicalNotesPrintString+="; "+i}y.CytologyData=n.CytologyData;y.HistologySpecimens=n.HistologySpecimens;y.RequestingDoctor=n.RequestingDoctor;y.Patient=n.Patient;y.ReferringPractice=n.ReferringPractice;y.CurrentRx=n.CurrentRx}function ht(n){return this.PatientId=n.PatientId,this.Title=null,this.GivenName=a.RemoveNonStandardChars(n.FirstName),this.LastName=a.RemoveNonStandardChars(n.LastName),this.DateOfBirth=n.DateOfBirth,this.GenderCode=a.RemoveNonStandardChars(n.GenderCode),this.Address1=a.RemoveNonStandardChars(n.StreetAddress),this.Address2=null,this.Suburb=a.RemoveNonStandardChars(n.City),this.State=a.RemoveNonStandardChars(n.State),this.PostCode=a.RemoveNonStandardChars(n.PostCode),this.Country=null,this.HomePhone=a.RemoveNonStandardChars(n.HomePhone),this.MobilePhone=a.RemoveNonStandardChars(n.MobilePhone),this.WorkPhone=a.RemoveNonStandardChars(n.WorkPhone),this.MedicareNo=a.RemoveNonStandardChars(n.MedicareNo),this.MedicareIndex=a.RemoveNonStandardChars(n.MedicareIndex),this.PensionCode=a.RemoveNonStandardChars(n.PensionCode),this.PensionNo=a.RemoveNonStandardChars(n.PensionNo),this.IHI=a.RemoveNonStandardChars(n.IHI),this.DVANo=a.RemoveNonStandardChars(n.DVANo),this.HealthFundName=a.RemoveNonStandardChars(n.HealthFundName),this.HealthFundNo=a.RemoveNonStandardChars(n.HealthFundNo),this.UrNo=a.RemoveNonStandardChars(n.UrNo),this}function ct(n,t){return $.grep(n,function(n){return n}).join(t)}function ft(n){return n.BSId&&(this.Id=n.BSId),this.LISDoctorCode=a.RemoveNonStandardChars(n.DrCode),this.Title=a.RemoveNonStandardChars(n.Title),this.GivenName=a.RemoveNonStandardChars(n.FirstName),this.LastName=a.RemoveNonStandardChars(n.Surname),this.Name=a.RemoveNonStandardChars(n.Name),this.Email=a.RemoveNonStandardChars(n.Email),this.ProviderNumber=a.RemoveNonStandardChars(n.ProviderNumber),this.HPII=a.RemoveNonStandardChars(n.HPII),this.DoctorId=n.DoctorId,this.Phone=n.PhoneNumber?n.PhoneNumber:n.Tel,this.Address=n.Address?a.RemoveNonStandardChars(n.Address):a.RemoveNonStandardChars(ct([n.Address1,n.Address2,n.Address3]," ")),this.City=n.City?a.RemoveNonStandardChars(n.City):a.RemoveNonStandardChars(n.Suburb),this.State=a.RemoveNonStandardChars(n.State),this.Postcode=a.RemoveNonStandardChars(n.Postcode),this.FaxNumber=a.RemoveNonStandardChars(n.FaxNumber),this.PrescriberNo=a.RemoveNonStandardChars(n.PrescriberNo),this}function lt(){var t=s.SelectedDoctors,i=[],n,r,u;if(t)for(n=0;n<t.length;n++)r=t[n],u=new ft(r),i.push(u);return i}function at(n){function r(n){this.Id=n.Id;this.TestCode=n.Code;this.TestName=n.TestName;this.AdditionalSiteInfo=n.ExtraDetails;this.Status="NW";this.R3eStatement=n.R3eStatement;this.IsCytologyTest=n.Tags&&n.Tags.indexOf("Cytology")>-1;this.JSONTags=n.JSONTags}for(var i=[],t=0;t<n.length;t++)i.push(new r(n[t]));return i}function vt(n){this.PracticeId=n.PracticeID;this.Name=n.Name;this.Address1=n.Address;this.Address2=null;this.Suburb=n.Suburb;this.PostCode=n.Postcode;this.State=n.State;this.HPIO=n.HPIO;this.Phone=n.Phone}function yt(n){var i={},t;return n?(t=n.match(/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/),t)?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt("20"+t[3],10),i):(t=n.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/),t)?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt(t[3],10),i):(t=n.match(/^(\d{2})(\d{2})(\d{4})$/),t)?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt(t[3],10),i):(t=n.match(/^(\d{1,2})\/(\d{1,2})\/(\d{2})\s(\d{1,2})\:(\d{1,2})$/),t)?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt("20"+t[3],10),i.hour=parseInt(t[4],10),i.minute=parseInt(t[5],10),i):(t=n.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})\s(\d{1,2})\:(\d{1,2})$/),t)?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt(t[3],10),i.hour=parseInt(t[4],10),i.minute=parseInt(t[5],10),i):(t=n.match(/^(\d{2})(\d{2})(\d{4})\s(\d{1,2})\:(\d{1,2})$/),t)?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt(t[3],10),i.hour=parseInt(t[4],10),i.minute=parseInt(t[5],10),i):null:i}function pt(n,t,i){if(i<1900||i>3e3||t==0||t>12)return!1;var r=[31,28,31,30,31,30,31,31,30,31,30,31];return(i%400==0||i%100!=0&&i%4==0)&&(r[1]=29),n>0&&n<=r[t-1]}function wt(n){for(var r="",u="; ",i=[],t=0;t<n.length;t++)n[t].ParentId!=null&&i.push(n[t].Name);if(i.length>0)return r+(r+i.join(u)+u)}function bt(n){var u="",f=[],e,o,i,r,s;for(v.Confidential&&(u+="CONFIDENTIAL - "),e=wt(t.GetSelectedConditions()),e!=undefined&&(u+=e),o=c.getSelected(),i=0;i<n.length;i++)if(n[i].Code.indexOf("HIS-Spec")==0)for(r=0;r<o.length;r++)s=o[r],s.Code==n[i].Code&&f.push(s.PrintString);else f.push(n[i].TestName);return u+f.join("; ")}function tt(){var n=[],t=i.GetClinicalNotes(),r=dt(),u=gt(k),f=kt(w);return t&&n.push(t),r&&n.push(r),u&&n.push(u),f!=""&&n.push(f),n.join("; ")}function kt(n){for(var t=[],i=0;i<n.length;i++)switch(n[i]){case"bulk":t.push("Bulk Bill");break;case"inpatient":t.push("Inpatient");break;case"schedule":t.push("Schedule");break;case"private":t.push("Private");break;case"repat":t.push("Repat");break;case"other":t.push("Other")}return t!=""?"Billing - "+t:null}function dt(){return v.Diabetic?"Diabetes":null}function gt(n){var t=[],f="",e,r,u,h,i,o,s;n.Site.Other&&(f+="Other",n.Site.OtherDescription&&(f+=" - "+n.Site.OtherDescription),t.push(f));e="";r=[];for(u in n.PreviousAbnormal)n.PreviousAbnormal.hasOwnProperty(u)&&(h=n.PreviousAbnormal[u],h&&(String.prototype.capitalizeFirstChar=function(){return this.charAt(0).toUpperCase()+this.slice(1)},r.push(" "+u.capitalizeFirstChar())));return r.length>0&&(e+="Previous Abnormal - "+r.join(),t.push(e)),i=d(n.LatestAbnormality),i&&(i="Latest Abnormal - "+i,t.push(i)),o="",n.OralContraceptive&&(o+="On oral contraceptive",t.push(o)),s="",n.Hysterectomy&&(s+="Has had Hysterectomy",t.push(s)),t.join("; ")}var w=[],et=u.apiUri,it=!1,g=null,rt="",y={LabName:"",Tests:[],OrderId:null,Id:null,CopyToDoctors:[],RequestDate:null,Billing:null,ClinicalData:null,CytologyData:null,HistologyData:null,TestRequestedPrintString:"",ClinicalNotesPrintString:"",RequestingDoctor:{},Patient:{},ReferringPractice:{}},k={Site:{Cervix:!1,VaginalVault:!1,Endometrium:!1,Other:!1,OtherDescription:null},Appearance:{Benign:!1,Suspicious:!1},PreviousAbnormal:{High:!1,Low:!1,Inconclusive:!1},LatestAbnormality:null,PostNatal:!1,PostMenopausal:!1,HormoneTherapy:!1,OralContraceptive:!1,Hysterectomy:!1,AbnormalBleeding:!1,RadioTherapy:!1,IUCD:!1,RegisterPapTest:!1},v={Pregnant:!1,LMP:"",EDC:"",Fasting:!1,Diabetic:!1,Urgent:!1,UrgentByDateTime:null,PhoneTo:"",FaxTo:"",Confidential:!1,ClinicalNotes:""},nt=f.getPatientData(),p={BillingOptions:function(n){w=n;e.$broadcast("BillingOptionsChanged",w.length)},GetClinicalNotes:function(){return a.RemoveNonStandardCharsAndCarriageReturn(i.GetClinicalNotes())},GetClinicalNotesPrintString:function(){return tt()},GetPatient:function(){return new ht(nt)},GetRequestingDoctor:function(){return new ft(r.getLoggedInUser())},GetBillingOptions:function(){return w},GetBillingObject:function(){var n={};return n.BulkBill=w.indexOf("bulk")>=0,n.Schedule=w.indexOf("schedule")>=0,n.Private=w.indexOf("private")>=0,n.Repat=w.indexOf("repat")>=0,n.InPatient=w.indexOf("inpatient")>=0,n.Rule3Ex=w.indexOf("rule3ex")>=0,n.Other=w.indexOf("other")>=0,n},GetRequestedTests:function(){return y.TestRequestedPrintString=bt(t.GetSelectedTests()),y.ClinicalNotesPrintString=tt(),new at(t.GetSelectedTests())},GetSendingFacility:function(){return new vt(r.getPractice())},SetPregnant:function(n){v.Pregnant=n;e.$broadcast("PregnantChanged",v.Pregnant)},GetPregnant:function(){return v.Pregnant},SetLmp:function(n){v.LMP=n;e.$broadcast("LmpChanged",v.LMP)},GetLmp:function(){return v.LMP},SetCytoLmpFocused:function(n){e.$broadcast("CytoLmpFocused",n)},SetCiLmpFocused:function(n){e.$broadcast("CiLmpFocused",n)},SetEdc:function(n){v.EDC=n;e.$broadcast("EdcChanged",v.EDC)},GetEdc:function(){return v.EDC},SetCytoEdcFocused:function(n){e.$broadcast("CytoEdcFocused",n)},SetCiEdcFocused:function(n){e.$broadcast("CiEdcFocused",n)},SetFasting:function(n){v.Fasting=n},GetFasting:function(){return v.Fasting},SetDiabetic:function(n){v.Diabetic=n},GetDiabetic:function(){return v.Diabetic},IsPregnantDisabled:function(){return nt.GenderText==="Male"||it},SetPregnantDisabled:function(n){it=n},isLmpDisabled:function(){return nt.GenderText==="Male"},GetClinicalInfo:function(){return v.ClinicalNotes=tt(),v},GetCytologyInfo:function(){return k.Site.OtherDescription&&(k.Site.OtherDescription=a.RemoveNonStandardChars(k.Site.OtherDescription)),k},isValidDate:function(n){var t=yt(n);return t&&pt(t.day,t.month,t.year)?t:null},isValidRequestDate:function(n){var f=!1,i=this.isValidDate(n),t,r,u;return i&&(t=new Date,t.setHours(0,0,0,0),r=null,r=t.month===2&&t.day===29?new Date(t.getFullYear()+1,2,1):new Date(t.getFullYear()+1,t.getMonth(),t.getDate()),u=new Date(i.year,i.month-1,i.day),u>=t&&u<=r&&(f=!0)),f},isValidUrgentDate:function(n){var t=this.isValidDate(n),i,r;return t?(i=new Date,i.setHours(0,0,0,0),r=new Date(t.year,t.month-1,t.day),ut(i,r)>7)?!1:ut(i,r)<0?!1:!0:!1},SetGeneralDetails:function(n){v.Urgent=n.urgent;v.UrgentByDateTime=n.urgentbytime;v.PhoneTo=n.phoneto;v.FaxTo=n.faxto;v.Confidential=n.confidential;v.Phonefax=n.phonefax},SetRequestDate:function(n){n&&(rt=o("date")(n,"dd/MM/yyyy"))},GetRequestDate:function(){return rt},IsDirty:function(){return this.GetRequestedTests().length>0?!0:this.GetClinicalNotes()&&this.GetClinicalNotes().length>0?!0:!1},ValidateOrder:function(){return u.host!==app.enums.hostType.BlackSwan&&this.GetBillingOptions().length<1?(e.$broadcast("BillingValidationFail"),!1):!0},Submit:function(){return g=new ot,n({url:et+"/eorder/create",method:"POST",cache:!1,data:g}).then(function(n){return g.EOrderNumber=n.data.Data.EOrderNumber,g.OrderId=n.data.Data.Id,st(g),u.host==app.enums.hostType.BlackSwan&&window.parent.childLocalData&&window.parent.childLocalData.eOrderReceived(y),n.data})},Print:function(n,t){r.printEOrder(y,n,t)}};return p}]);appServices.factory("favouriteService",["$http","$rootScope","eOrdersSettings","localDataService","testService",function(n,t,i,r){function f(n,t,i){var o=r.getCurrentPatient(),s=r.getLoggedInUser(),h=r.getPractice(),c=r.getProductName(),l=h.PracticeID,a=s.PrescriberNo,e=null,u,f;return t=="patient"&&(e=o.PatientId),u=n,f=null,i==app.enums.favouriteType.Condition&&(u=null,f=n),{BuCode:r.getLabCode(),ApplicationId:c,SiteId:l,DoctorId:a,PatientId:e,TestId:u,ConditionId:f}}var u=i.apiUri,e;return{AddToFavourites:function(t,i,r){var e=u+"/favourite/AddToFavourites",o=f(t,i,r);return n({url:e,method:"POST",cache:!1,data:o}).then(function(n){return n.data.Success})},GetFavourites:function(t){var i=f(null,t);return n({url:u+"/favourite/GetFavourites",method:"POST",cache:!1,data:i}).then(function(n){return n.data.Data})},favouriteTypeSelected:function(){return e},setFavouriteTypeSelected:function(n){e=n;t.$broadcast("SelectedFavouriteChanged",n)},remove:function(t,i,r){var e=f(t,i,r),o=u+"/favourite/RemoveFavourites";return n({url:o,method:"POST",cache:!1,data:e}).then(function(n){return n.data.Success})}}}]);appServices.factory("focusFactory",["$timeout",function(n){return function(t){n(function(){var n=document.getElementById(t);n&&n.focus()},100)}}]);appServices.factory("histologyService",["toolsService",function(n){function r(n){for(var u=!1,r=0;r<t.length;r++)if(t[r].SequenceNo===n.SequenceNo){u=!0;break}u?i.updateSelected(n):n.Site.length>0&&(n.Code="HIS-Spec "+n.SequenceNo,t.push(n))}function u(t){var i="Specimen "+t.SequenceNo+":";return t.Site&&(i+=" "+t.Site),t.BiopsyType&&(i+=", "+t.BiopsyType),t.ProvisionalDiagnosis&&(i+=", ?"+t.ProvisionalDiagnosis),t.PastResult&&(i+=", "+t.PastResult),t.Description&&(i+=", "+t.Description),n.RemoveNonStandardChars(i)}var t=[],i={addToSelected:function(n){r(n)},removeFromSelected:function(n){for(var i=0;i<t.length;i++)t[i].SequenceNo===n&&t.splice(i,1)},updateSelected:function(n){(this.removeFromSelected(n.SequenceNo),n.Site.length!==0)&&(t.push(n),t.sort(function(n,t){return n[0]-t[0]}))},getSelected:function(){for(var r=[],i=0;i<t.length;i++)t[i].Site.length>0&&(t[i].PrintString=u(t[i]),t[i].Site&&(t[i].Site=n.RemoveNonStandardChars(t[i].Site)),t[i].BiopsyType&&(t[i].BiopsyType=n.RemoveNonStandardChars(t[i].BiopsyType)),t[i].ProvisionalDiagnosis&&(t[i].ProvisionalDiagnosis=n.RemoveNonStandardChars(t[i].ProvisionalDiagnosis)),t[i].PastResult&&(t[i].PastResult=n.RemoveNonStandardChars(t[i].PastResult)),t[i].Description&&(t[i].Description=n.RemoveNonStandardChars(t[i].Description)),r.push(t[i]));return r},clearSelected:function(){t=[]}};return i}]);appServices.factory("localDataService",["$http","eOrdersSettings","$q","$rootScope",function(n,t,i,r){function s(n){return/^\d{4}\d{1,2}\d{1,2}$/.test(n)?n.slice(6)+"/"+n.slice(4,6)+"/"+n.slice(0,4):""}function a(n){if(n.length>10){var t=n.split(" ")[0],i=n.split(" ")[1];return"/Date("+Date.parse(new Date(t.split("/")[2],t.split("/")[1]-1,t.split("/")[0],i.split(":")[0],i.split(":")[1]))+")/"}return"/Date("+Date.parse(new Date(n.split("/")[2],n.split("/")[1]-1,n.split("/")[0]))+")/"}function e(n){return JSON.parse(n)}var h=0,o=app.enums.hostType.MD3,c={getAuthenticationDetails:function(){var n=e(window.localData.GetAuthenticationDetails());return{ReferringApplication:n.ProductName,ReferringApplicationVersion:n.ProductVersion,LabCode:n.LabCode,PrescriberNo:n.PrescriberNo,SiteId:n.SiteId}},getProductName:function(){return this.getAuthenticationDetails().ReferringApplication},getSiteId:function(){return this.getAuthenticationDetails().SiteId},getLabCode:function(){return window.localData.GetLabCode().toUpperCase()},getCurrentPatient:function(){return e(window.localData.GetCurrentPatient())},getLoggedInUser:function(){return e(window.localData.GetLoggedInUser())},getPractice:function(){return e(window.localData.GetPractice())},getCurrentRx:function(){return e(window.localData.GetCurrentRx()).CurrentRx},getCurrentProgressNote:function(){var n="",t;try{t=window.localData.GetCurrentProgressNotes();n=JSON.parse(t)}catch(i){n={NotesHtml:"!!Something went wrong trying to get the progress note!!"}}return n},getPregnancy:function(){var n=e(window.localData.GetPregnancy());return{Pregnant:n.Pregnant,LMP:s(n.Lmp),EDC:s(n.Edc)}},getLocalAddressBookDoctors:function(n){var r=n||"",u=accent_fold.fold(r).toUpperCase(),i=u.split(/[\s-]+/),f=e(window.localData.GetAddressBookEntries("")).AddressBookEntries,t=[];return $.each(f,function(n,r){var u=[],f;$.each(i,function(n,t){var i=accent_fold.fold(r.Surname||"").toUpperCase(),f=accent_fold.fold(r.FirstName||"").toUpperCase(),e=i.split(/[\s-]+/),o=f.split(/[\s-]+/),s=e.filter(function(n){return n.indexOf(t)==0}),h=o.filter(function(n){return n.indexOf(t)==0});(s.length>0||h.length>0)&&u.push(t)});f=t.filter(function(n){return n.AddressBookId==r.AddressBookId});u.length==i.length&&f.length==0&&t.push(r)}),t},getEncryptedAuthenticationDetails:function(){var n=window.localData.GetEncryptedAuthenticationDetails();return encodeURIComponent(n)},printEOrder:function(n,t,i){var r,u,f;window.orderItem=n;r=n;u=r.RequestDate;u==null||u.trim()==""?r.RequestDate="/Date("+Date.parse(new Date)+")/":r.RequestDate.indexOf("/Date")==-1&&(r.RequestDate=a(r.RequestDate));f=r.CytologyData.LatestAbnormality;(f==null||f.trim()=="")&&(r.CytologyData.LatestAbnormality="");window.localData.SavePrintEOrder(JSON.stringify(r),t,i);h++},priorEOrders:function(){window.localData.ShowPriorOrders()},getShowPrinterPaperSetting:function(){return window.localData.ShowPrintPaperPrompt()},refreshEOrdersData:function(){console.log("%c localDataService function 'refreshEOrdersData()' is not supported!","color:firebrick;background-color:grape");throw"localDataService function 'refreshEOrdersData()' is not supported!";},setButtonEnabled:function(){}},l={getAuthenticationDetails:function(){var n=window.localData.User.authenticationDetails;return{ReferringApplication:n.ProductName,ReferringApplicationVersion:n.ProductVersion,LabCode:n.LabCode,PrescriberNo:n.PrescriberNo,ProviderNo:n.ProviderNo,SiteId:n.SiteId}},getProductName:function(){return window.localData.User.authenticationDetails.ProductName.toString()},getLabCode:function(){return window.localData.User.authenticationDetails.LabCode},getCurrentPatient:function(){var n=jQuery.extend({},window.localData.Patient.currentPatient);return n.DateOfBirth.indexOf("T")>=0&&(n.DateOfBirth=n.DateOfBirth.substring(0,4)+n.DateOfBirth.substring(5,7)+n.DateOfBirth.substring(8,10)),n},getLoggedInUser:function(){return jQuery.extend({},window.localData.User.userDetails)},getPractice:function(){return window.localData.User.practiceDetails},getCurrentRx:function(){return angular.copy(window.localData.Patient.currentRx.CurrentRx)},getCurrentProgressNote:function(){return{NotesHtml:window.localData.Patient.currentProgressNotes.NotesHtml.replace(/\n/g,"<br>")}},getPregnancy:function(){var n=window.localData.Patient.pregnancy;return{Pregnant:n.Pregnant,LMP:s(n.Lmp),EDC:s(n.Edc)}},getLocalAddressBookDoctors:function(i){var r=t.blackSwanApi;return n({url:r+"/addressbook/clinical?query="+i,method:"GET",cache:!1,headers:{"Access-Control-Allow-Origin":"*"}}).then(function(n){return n.data},function(){return console.log("Error getting blackswan address book"),[]})},getEncryptedAuthenticationDetails:function(){return window.localData.Token},printEOrder:function(){},priorEOrders:function(){console.log("%c localDataService function is 'priorEOrders()' not supported!","color:firebrick;background-color:grape");throw"localDataService function is 'priorEOrders()' not supported!";},getShowPrinterPaperSetting:function(){console.log("getShowPrinterPaperSetting()")},refreshEOrdersData:function(){var n=window.parent.childLocalData.CurrentPathologyRequest,s=JSON.stringify(n.Patient.currentRx.CurrentRx),h=JSON.stringify(window.localData.Patient.currentRx.CurrentRx),i=s!=h,c=JSON.stringify(n.Patient.currentProgressNotes.NotesHtml),l=JSON.stringify(window.localData.Patient.currentProgressNotes.NotesHtml),u=c!=l,a=JSON.stringify(n.Patient.pregnancy),v=JSON.stringify(window.localData.Patient.pregnancy),t=a!=v,e,o;f.watchData.hasCurrentRxChanged=i||f.watchData.hasCurrentRxChanged;f.watchData.hasProgressNotesChanged=u||f.watchData.hasProgressNotesChanged;f.watchData.hasPregnancyChanged=t||f.watchData.hasPregnancyChanged;t&&r.$broadcast("PregnantChanged",n.Patient.pregnancy.Pregnant);e=i||u||t;o=e?"background-color:#5191cd;color:#ff9;font-size:14px":"background-color:#5191cd;color:#fff;font-size:14px";console.log("%ceOrders refreshed localData",o,f.watchData);angular.copy(n,window.localData)},setButtonEnabled:function(n,t){window.parent.childLocalData.enableButton(t)},isDirtyCheck:function(){return eOrderService.IsDirty()}},u=null,f={getHost:function(){return o},setHost:function(n){o=n;o==app.enums.hostType.MD3?u=c:o==app.enums.hostType.BlackSwan?u=l:console.log("%c UNSUPPORTED HOST TYPE!! Check localDataService!","background-color:#DF2F00;color:#FFF;font-size:25px;padding:10px")},getAuthenticationDetails:function(){return u.getAuthenticationDetails()},getProductName:function(){return u.getProductName()},getLabCode:function(){return u.getLabCode()},getCurrentPatient:function(){return u.getCurrentPatient()},getLoggedInUser:function(){return u.getLoggedInUser()},getPractice:function(){return u.getPractice()},getCurrentRx:function(){return u.getCurrentRx()},getCurrentProgressNote:function(){return f.watchData.hasProgressNotesChanged=!1,u.getCurrentProgressNote()},getPregnancy:function(){return u.getPregnancy()},getLocalAddressBookDoctors:function(n){return u.getLocalAddressBookDoctors(n)},getEncryptedAuthenticationDetails:function(){return u.getEncryptedAuthenticationDetails()},printEOrder:function(n,t,i){u.printEOrder(n,t,i)},priorEOrders:function(){u.priorEOrders()},getShowPrinterPaperSetting:function(){return u.getShowPrinterPaperSetting()},setupHostSaveFunction:function(n){window.localDataService.sendEOrder=n},setupHostIsDirtyFunction:function(n){window.localDataService.isDirtyCheck=n},setupHostComplete:function(){window.parent.childLocalData&&(window.parent.childLocalData.isChildLoaded=!0,window.localDataService.refreshEOrdersData=u.refreshEOrdersData)},watchData:{hasCurrentRxChanged:!1,hasProgressNotesChanged:!1,hasPregnancyChanged:!1},setButtonEnabled:function(n,t){u.setButtonEnabled(n,t)}};return f.setHost(t.host),f}]);appServices.factory("patientService",["$http","eOrdersSettings","localDataService","$q",function(n,t,i){function r(n){return $.grep(n,function(n){return n})}function u(n){var t=[n.FirstName,n.LastName.toUpperCase()];return r(t).join(" ")}function f(n){var i=n.FullName,u=n.GenderText,t=n.DateOfBirth,f=t?t.getDate()+" "+["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()]+" "+t.getFullYear():null,e=t?"DOB: "+f+", "+n.Age:null,o=[i,u,e],s=r(o);return s.join(", ")}function e(n){var r=new Date,u="year",t=0,f=r.getFullYear()-n.getFullYear(),i=r.getMonth()-n.getMonth();if((i<0||i===0&&r.getDate()<n.getDate())&&f--,i<0&&(i+=12),i==1&&r.getDate()<n.getDate()&&i--,f==1)t=f,u="year";else if(f<1){var e=i,o=~~((r.getTime()-n.getTime())/864e5),s=~~(o/7);e<1?(t=o,u="day"):e<3?(t=s,u="week"):(t=e,u="month")}else t=f;return t+" "+u+(t==1?"":"s")}function o(n){if(!n||n.length!=8)return console.log&&console.log("Invalid DOB passed to patientService.patientAge()"),null;var t=Number(n.substring(0,4)),i=Number(n.substring(4,6))-1,r=Number(n.substring(6,8));return new Date(Date.UTC(t,i,r,0,0,0,0))}function s(n){switch(n){case"M":return"Male";case"F":return"Female";default:return""}}return{getPatientData:function(){var n=i.getCurrentPatient();return n.FullName=u(n),n.DateOfBirth=o(n.DateOfBirth),n.Age=e(n.DateOfBirth),n.GenderText=s(n.GenderCode),n.Description=f(n),n}}}]);appServices.factory("pregnancyService",["$http","searchService","eOrdersSettings","localDataService",function(n,t,i,r){var f=i.apiUri,u=[],e=[],o=r.getLabCode();return{getPregnancyScreenDetails:function(){return n({url:f+"/test/GetPregnancyScreenDetails?buCode="+o,method:"GET",cache:!1}).then(function(n){u=n.data.Data})},pregnancyDetailsList:function(){return u!=""&&(e=t.AddTestDisplayStringToConditionsList(u.Conditions)),u}}}]);appServices.factory("searchService",["$http","eOrdersSettings","localDataService",function(n,t,i){function s(n){for(var t,i=0;i<n.length;i++)t="",$.each(n[i].Tests,function(n,i){t=i.AlwaysPrivateBilling?t+i.TestName+" <span class='badge'>$<\/span>; ":t+i.TestName+"; "}),t=t.substring(0,t.length-2),n[i].TestsDisplayString=t;return n}function h(n){this.BuCode=c;this.SearchTerms=n;this.ApplicationId=i.getProductName();this.SiteId=v.PracticeID;this.DoctorId=a.PrescriberNo;this.PatientId=l.PatientId}var o=t.apiUri,f=[],e=[],r,u=!1,c=i.getLabCode(),l=i.getCurrentPatient(),a=i.getLoggedInUser(),v=i.getPractice();return{searchConditions:function(){return u=!0,n({url:o+"/condition/search",method:"GET",cache:!1,params:r}).then(function(n){var t=n.data.Data;f=s(t);u=!1})},conditionResults:function(){return f},clearConditionResults:function(){f=[]},setConditionSearchParams:function(n){r=new h(n)},AddTestDisplayStringToConditionsList:function(n){return s(n)},searchTests:function(){return u=!0,n({url:o+"/test/search",method:"GET",cache:!1,params:r}).then(function(n){var t=n.data.Data;e=t;u=!1})},testResults:function(){return e},clearTestResults:function(){e=[]},setTestSearchParams:function(n){r=new h(n)},SearchParams:function(){return r?r.SearchTerms:null},gettingResults:function(){return u},setFocusOnFirstTest:function(){e[0].hasfocus=!0},setFocusOnFirstCondition:function(){f[0].hasfocus=!0}}}]);appServices.factory("specialityService",["$http","eOrdersSettings","localDataService","$q",function(n,t,i,r){var f=t.apiUri,e=[],o=i.getLabCode(),s,u;return{getSpecialities:function(){return n({url:f+"/speciality/list?bu="+o,method:"GET",cache:!1}).then(function(n){return n.data})},getSubSpecialities:function(t,i){return u&&(u.resolve(),u=null),u=r.defer(),s=i,n({url:f+"/speciality/get?specialityId="+t+"&bu="+o,method:"GET",cache:!1,timeout:u.promise}).success(function(n){u=null;e=n.Data})},GetSelectedSpecialityName:function(){return s},subList:function(){return e}}}]);appServices.factory("testService",["$http","$rootScope","clinicalNotesService","eOrdersSettings","$timeout",function(n,t,i,r,u){function it(n){var t,i;if(n!==undefined&&n!=null)for(n.selected=!1,t=0;t<n.BillingRuleIds.length;t++)i=vt(n,n.BillingRuleIds[t].Id),i>=0&&l(f[i]),n.BillingRuleIds[t].selected=!1}function d(n){n.selected=!0;n.Urgent&&t.$broadcast("seturgent");s||(s=0);var i=p(n);n.conditions?n.conditions.indexOf(s)<0&&n.conditions.push(s):(n.conditions=[],n.conditions.push(s));n.conditions.length<2&&f.push(n);v++;w()}function b(){c<h.length?y.Add(h[c]):(v===0&&a(s),s=0,t.$broadcast("LoopingTestsComplete"))}function rt(n){for(var t=0;t<e.length;t++)if(e[t].Id===n.Id)return!0;return!1}function ut(n,t){for(var r,i=0;i<f.length;i++)if(r=f[i],r.Id===n){r.ExtraDetails=t;break}}function ft(n){var u,f,i,t,r;if(!n||!n.length)return[];for(u=et(),f=ot(),i=0;i<n.length;i++)t=n[i],t.disabled=u.indexOf(t.Code)>-1,r=f.findTestById(t.Id),r&&(t.ExtraDetails=r.ExtraDetails,t.selected=!0);return n}function et(){for(var t=[],i,n=0;n<f.length;n++)i=f[n],i.ExclusiveWith&&(t=t.concat(i.ExclusiveWith.split(",")));return t}function ot(){for(var t=[],i,n=0;n<f.length;n++)i=f[n],t["Id:"+i.Id]=i;return{data:t,findTestById:function(n){var i=t["Id:"+n];return i===undefined?null:i}}}function l(n){var o=p(n),i,r,e,u;if(o>-1){if(f.splice(o,1),n.selectedBillingRuleId=null,n.ExtraDetails=null,n.selected=!1,n.conditions=[],i=lt(),i.length>0)for(r=0;r<i.length;r++)a(i[r]);t.$broadcast("TestItemRemoved",n);w();n.Tags&&n.Tags.toLowerCase().indexOf("gynae cytology")>-1&&nt(!0)}if(t.customisedUrgent===undefined||!t.customisedUrgent){for(e=!1,u=0;u<f.length;u++)if(f[u].Urgent){e=!0;break}e||t.$broadcast("removeurgent")}}function st(n){return n.BillingRuleIds&&n.BillingRuleIds.length>0&&!n.selectedBillingRuleId?(typeof n.BillingRuleIds[0]!="object"&&y.UpdateBillingRulesForTest(n),!0):!1}function ht(n){return n.Tags&&n.Tags.toLowerCase().indexOf("rule3")>-1?!0:!1}function k(n){return n.BillingRuleIds&&n.BillingRuleIds.length>0&&!n.selectedBillingRuleId?(typeof n.BillingRuleIds[0]!="object"&&y.UpdateBillingRulesForTest(n),n.MicroSiteEnabled):!1}function a(n){var u=at(n),i,r;if(u>-1){if(e[u].selected=!1,e.splice(u,1),i=ct(n),i.length>0)for(r=0;r<i.length;r++)l(i[r]);t.$broadcast("ConditionItemRemoved",n);wt();n=0}}function ct(n){for(var r=[],i,u,e,t=0;t<f.length;t++)if(f[t].conditions)for(i=0;i<f[t].conditions.length;i++)u=f[t].conditions[i],u===n&&(e=f[t].conditions.indexOf(n),f[t].conditions.splice(e,1),f[t].conditions.length===0&&r.push(f[t]));return r}function lt(){for(var o=[],r,n,u,i,t=0;t<f.length;t++)o.push(f[t].Id);for(r=[],n=0;n<e.length;n++){for(u=0,i=0;i<e[n].Tests.length;i++)if(o.indexOf(e[n].Tests[i].Id)>-1){u++;break}u===0&&r.push(e[n].Id)}return r}function at(n){for(var i=-1,t=0;t<e.length;t++)if(e[t].Id===n){i=t;break}return i}function p(n){for(var i=-1,t=0;t<f.length;t++)if(f[t].Id===n.Id&&f[t].SiteId===n.SiteId){i=t;break}return i}function vt(n,t){for(var r=-1,i=0;i<f.length;i++)if(f[i].Id===n.Id&&f[i].SiteId===t){r=i;break}return r}function yt(n){for(var i,t=0;t<f.length;t++)i=f[t].conditions,i.indexOf(n)>-1&&(f[t].highlighted=!0)}function pt(n){for(var i,t=0;t<f.length;t++)i=f[t].conditions,i.indexOf(n)>-1&&(f[t].highlighted=!1)}function wt(){for(var n=0;n<f.length;n++)f[n].highlighted=!1}function w(){t.$broadcast("SelectedTestsChanged",f.length)}function bt(n){t.$broadcast("SelectSpeciality",n)}function g(){for(var t=!1,n=0;n<f.length;n++)if(f[0].Tags&&f[0].Tags.toLowerCase().indexOf("gynae cytology")>-1){t=f[0].selected===!0?!0:!1;break}return t}function nt(n){var i=g();n&&i||t.$broadcast("CytologyTestSelected",i)}var f=[],e=[],o=[],h=[],c=0,v=0,s=0,tt=r.apiUri,y={CheckManuallyEnteredTests:function(n){for(var t=0;t<f.length;t++)if(angular.lowercase(f[t].TestName)===angular.lowercase(n.TestName))return!0;return!1},enablePrintForFreeTyping:function(){w()},Add:function(n,i){var r=p(n);return(r>-1&&!k(n)&&(n=f[r]),n.highlighted=!1,n.disabled)?!1:s===0&&i!="histology"&&this.checkIfTestSelected(n)?(k(n)?it(n):(n.selected=!1,l(n)),!1):(i!="cytology"&&n.Tags&&n.Tags.toLowerCase().indexOf("cytology")>-1&&bt("Cytology"),i=="histology"&&n.selected===!0)?!1:k(n)?(t.$broadcast("OpenMicroSiteDialog",n),!1):st(n)?(this.ClearSelectedFlagOnMbs(n.BillingRuleIds),t.$broadcast("OpenBillingDialog",n),!1):ht(n)&&i!="addRule3Test"?(t.$broadcast("OpenRule3Dialog",n),!1):(d(n,s),n.Tags&&n.Tags.toLowerCase().indexOf("gynae cytology")>-1&&nt(),c===h.length&&(v===0&&a(s),s=0),h.length>0&&(c++,u(function(){b()},400)),!0)},AddBillingSelection:function(n,t){for(var u,f,r=0;r<n.BillingRuleIds.length;r++)n.BillingRuleIds[r].Id===t&&(n.BillingRuleIds[r].selected=!0);n.selectedBillingRuleId=t;u=this.GetMbsRuleById(t);i.AppendToClinicalNotes(u.ClinicalNoteAddendum);f=angular.copy(n);u.RuleType===3&&(f.Code=u.AltTestcode);this.Add(f)},UpdateSelectedMicroSitesForTest:function(n){for(var r=!1,i,t=0;t<n.BillingRuleIds.length;t++)i=angular.copy(n),i.SiteId=n.BillingRuleIds[t].Id,i.TestName+=" - "+n.BillingRuleIds[t].ClinicalNoteAddendum,n.BillingRuleIds[t].selected?(r=!0,n.BillingRuleIds[t].AltTestcode!==undefined&&(i.Code=n.BillingRuleIds[t].AltTestcode),p(i)<0&&d(i)):l(i);n.selected=r;w()},BillingSelectionCancelled:function(){u(function(){c++;b()},200)},AddCondition:function(n){return(v=0,h=[],s=n.Id,rt(n))?(a(n.Id),s=0,!1):(h=n.Tests,c=0,b(),n.selected=!0,e.unshift(n),!0)},checkIfTestSelected:function(n){for(var t=0;t<f.length;t++)if(f[t].Id===n.Id)return!0;return!1},removeTestFromSelected:function(n){l(n)},removeConditionFromSelected:function(n){a(n)},removeHistoTestFromSelected:function(n){l({Id:n})},removeMessage:"Are you sure you want to remove <strong>[testname]<\/strong> from the selected tests?",removeConditionMessage:"Are you sure you want to remove all the tests for the condition <strong>[conditionname]<\/strong>?",SelectedTests:f,GetSelectedTests:function(){return f},GetSelectedConditions:function(){return e},SelectedConditions:e,highlightTests:yt,removeHighlightOnTests:pt,ProcessSelectedTests:ft,CheckAConditionListForSelected:function(n){for(var r=[],t,i=0;i<e.length;i++)r.push(e[i].Id);for(t=0;t<n.length;t++)r.indexOf(n[t].Id)>-1&&(n[t].selected=!0);return n},UpdateTestExtraDetails:ut,SetMbsConditions:function(){n({url:tt+"/billingrule/get",method:"GET",cache:!0}).then(function(n){var i,t,r;for(o=n.data.Data,i=0;i<o.length;i++)t=o[i],t.RuleType===3&&(r=t.ExtraDetail?JSON.parse(t.ExtraDetail):null,t.AltTestcode=r&&r.TestCode?r.TestCode:null)})},UpdateBillingRulesForTest:function(n){for(var i=[],t,r=0;r<n.BillingRuleIds.length;r++)for(t=0;t<o.length;t++)if(n.BillingRuleIds[r]===o[t].Id){o[t].selected=!1;o[t].RuleType===2?(n.MicroSiteEnabled=!0,i.push(angular.copy(o[t]))):o[t].RuleType===3?(n.HistoryCodeEnabled=!0,i.push(angular.copy(o[t]))):i.push(o[t]);break}n.BillingRuleIds=i},GetMbsRuleById:function(n){for(var t=0;t<o.length;t++)if(o[t].Id===n)return o[t];return null},GetSelectedMbsConditionStatement:function(n){for(var i=null,t=0;t<o.length;t++)if(o[t].Id===n){i=o[t].ClinicalNoteAddendum;o[t].Name.toLowerCase()==="private bill"&&(i="");break}return i},ClearSelectedFlagOnMbs:function(n){if(n){for(var t=0;t<n.length;t++)n[t].selected=!1;return n}},CheckForOrphanedConditions:function(n){for(var u,i,r,t=0;t<e.length;t++)if(e[t].Id===n){for(u=0,i=0;i<e[t].Tests.length;i++)for(r=0;r<f.length;r++)f[r].Id===e[t].Tests[i].Id&&u++;u===0&&this.removeConditionFromSelected(e[t].Id)}},SelectRule3Test:function(n,t){if(t&&n.JSONTags&&n.JSONTags!=null){var r=JSON.parse(n.JSONTags),i=JSON.parse(JSON.stringify(n));i.Code=r.Code;i.TestName=r.Name;this.Add(i,"addRule3Test")}else this.Add(n,"addRule3Test")},IsGynaeTestSelected:g};return y}]);appServices.factory("tokenService",[function(){return{tokenData:null}}]);appServices.factory("toolsService",[function(){return{RemoveNonStandardChars:function(n){if(n){n=accent_fold.fold(n);return n=n.replace(/[^A-Za-z\d\u0020-\u0029\u002A\u002B\u002C\u002D\u002E\u002F\u0030-\u0039\u003A\u003B\u003C\u003D\u003E\u003F\u0040-\u0049\u004A\u004B\u004C\u004D\u004E\u004F\u0050-\u0059\u005A\u005B\u005C\u005D\u005E\u005F\u0060-\u0069\u006A\u006B\u006C\u006D\u006E\u006F\u0070-\u0079\u007A\u007B\u007C\u007D\u007E\u007F]/g,""),n=n.replace(/[\n\r]/g," "),n.trim()}},RemoveNonStandardCharsAndCarriageReturn:function(n){if(n){n=accent_fold.fold(n);return n=n.replace(/[^A-Za-z\d\u0020-\u0029\u002A\u002B\u002C\u002D\u002E\u002F\u0030-\u0039\u003A\u003B\u003C\u003D\u003E\u003F\u0040-\u0049\u004A\u004B\u004C\u004D\u004E\u004F\u0050-\u0059\u005A\u005B\u005C\u005D\u005E\u005F\u0060-\u0069\u006A\u006B\u006C\u006D\u006E\u006F\u0070-\u0079\u007A\u007B\u007C\u007D\u007E\u007F]\n\r/g,""),n=n.replace(/[\n\r]/g,", "),n.trim()}}}}]);appServices.factory("userService",["$http","$rootScope","localDataService",function(n,t,i){var r=i.GetLabCode();return{}}]);app=angular.module("app",["ngRoute","ngCookies","ngSanitize","app.services","mcAutocomplete"]);app.enums={favouriteType:{Test:1,Condition:2},hostType:{MD3:1,BlackSwan:2},postMessages:{ReadyForData:"READY_FOR_DATA",IsDirty:"IS_DIRTY",PrintSend:"PRINT_SEND"}};app.constants={pregnancyTabName:"Pregnancy",histologyTabName:"Histology",cytologyTabName:"Cytology"};app.config(["$routeProvider","$httpProvider",function(n,t){n.when("/",{templateUrl:"/app/views/default.html"}).when("/parent/:parentName",{templateUrl:"/app/views/default.html"}).otherwise({redirectTo:"/login"});t.defaults.withCredentials=!0;t.interceptors.push("authInterceptorService")}]);app.controller("adminfieldsController",["$scope","localDataService","eOrderService","$filter","$rootScope",function(n,t,i,r,u){function s(){n.phoneto="";n.faxto="";f()}function f(){var t=n.urgentDate+(n.selectedTime?" "+n.selectedTime:""),r={urgent:n.urgent,urgentbytime:t,phonefax:n.phoneEnabled||n.faxEnabled,phoneto:n.phoneto,faxto:n.faxto,confidential:n.confidential};i.SetGeneralDetails(r)}function c(){function e(i){for(var r=i;r<48;r++)if(parseInt(t)>0){if(parseInt(t)>30){i++;t=0;continue}if(n.time.push(h(i)+":30"),i+":30"=="23:30")break;i++;t=0}else n.time.push(h(i)+":00"),t=30}var i,u,f,t;if(n.time=[],i=new Date,u=n.urgentDate==r("date")(i,"dd/MM/yyyy")?!0:!1,!u){e(0);return}f=r("date")(i,"HH");t=r("date")(i,"mm");e(parseInt(f))}function h(n){return n=parseInt(n),n<10&&(n="0"+n),n}function o(){!e&&n.urgent&&n.urgentDate&&!n.isValidUrgentDate(n.urgentDate)?$("#urgentDate").tooltip("show"):$("#urgentDate").tooltip("destroy")}var l=t.getLoggedInUser(),e;n.selectedTime="";n.urgentDate="";n.confidential=!1;n.urgent=!1;n.phoneto="";n.faxto="";n.time=[];n.phoneEnabled=!1;n.faxEnabled=!1;$("#phoneInput").prop("disabled",!n.phoneEnabled);$("#faxInput").prop("disabled",!n.faxEnabled);n.toggleConfidential=function(){n.confidential=!n.confidential;f()};u.$on("seturgent",function(){n.urgent=!0;f()});u.$on("removeurgent",function(){n.urgent=!1;n.phonefax||s();f()});n.toggleUrgent=function(){u.customisedUrgent=!0;n.urgent?(n.urgent=!1,n.phonefax||s()):n.urgent=!0;f()};n.togglePhone=function(){n.phoneEnabled=!n.phoneEnabled;$("#phoneInput").prop("disabled",!n.phoneEnabled);f()};n.toggleFax=function(){n.faxEnabled=!n.faxEnabled;$("#faxInput").prop("disabled",!n.faxEnabled);f()};n.isValidUrgentDate=function(n){return i.isValidUrgentDate(n)};n.$watch("phoneto",function(n,t){n!==t;f()});n.$watch("faxto",function(n,t){n!==t;f()});n.$watch("urgentDate",function(n,t){n!==t&&(o(),c(),f())});n.$watch("urgent",function(n,t){n!==t&&o()});n.$watch("selectedTime",function(n,t){n!==t&&f()});e=!1;n.urgentDateFocused=function(n){e=n;o()}}]);app.controller("billingController",["$scope","eOrderService","patientService","clinicalNotesService","eOrdersSettings","localDataService","testService",function(n,t,i,r,u,f,e){var o;n.name="Billing";n.selectedBillingOptions=[];var s=i.getPatientData().MedicareNo,h=i.getPatientData().DVANo;n.billingOptions={options:[{id:"bulk",name:"Bulk Bill"},{id:"schedule",name:"Schedule"},{id:"private",name:"Private"},{id:"repat",name:"Repat"},{id:"inpatient",name:"Inpatient"},{id:"other",name:"Other"}]}.options;n.showBillingError=!1;n.toggle=function(i){var r=n.selectedBillingOptions.indexOf(i);r>-1?n.selectedBillingOptions.splice(r,1):n.selectedBillingOptions.push(i);t.BillingOptions(n.selectedBillingOptions);n.showBillingError=!1};n.isDisabled=function(t){var r=s==""||!s,i;return t=="bulk"&&r?(n.tooltipText="Medicare",r):(i=h==""||!h,t=="repat"&&i)?(n.tooltipText="DVA",i):n.selectedBillingOptions.length==0?!1:t==="bulk"&&(o(n.selectedBillingOptions,"schedule")||o(n.selectedBillingOptions,"private")||o(n.selectedBillingOptions,"repat")||o(n.selectedBillingOptions,"other"))?!0:t==="schedule"&&(o(n.selectedBillingOptions,"bulk")||o(n.selectedBillingOptions,"private")||o(n.selectedBillingOptions,"repat")||o(n.selectedBillingOptions,"other"))?!0:t==="private"&&(o(n.selectedBillingOptions,"bulk")||o(n.selectedBillingOptions,"schedule")||o(n.selectedBillingOptions,"repat")||o(n.selectedBillingOptions,"other"))?!0:t==="repat"&&(o(n.selectedBillingOptions,"bulk")||o(n.selectedBillingOptions,"schedule")||o(n.selectedBillingOptions,"private")||o(n.selectedBillingOptions,"other"))?!0:t==="inpatient"&&o(n.selectedBillingOptions,"other")?!0:t==="other"&&(o(n.selectedBillingOptions,"bulk")||o(n.selectedBillingOptions,"schedule")||o(n.selectedBillingOptions,"private")||o(n.selectedBillingOptions,"repat")||o(n.selectedBillingOptions,"inpatient"))?!0:!1};o=function(n,t){var i=$.grep(n,function(n){return n===t});return i.length==0?null:i.length==1?i[0]:null};n.$on("BillingValidationFail",function(){n.showBillingError=!0;f.setButtonEnabled("SendButton",!n.showBillingError)});n.$watch("showBillingError",function(n){n===!1&&u.host==app.enums.hostType.BlackSwan&&e.GetSelectedTests().length>0&&f.setButtonEnabled("SendButton",!0)})}]);app.controller("clinicaldetailsController",["$scope","clinicalNotesService","$timeout",function(n,t,i){function r(){n.limitExceeded=!0;i(function(){n.limitExceeded=!1},4e3)}n.name="Clinical Notes";n.limitExceeded=!1;n.notes="";n.exceedLimit=t.ExceedLimit;n.$on("ClinicalNotesUpdated",function(){n.notes=t.GetClinicalNotes();n.notes&&n.notes.length>n.exceedLimit-1&&r()});n.$watch("notes",function(i,u){i!=u&&(t.SetClinicalNotes(i),n.notes&&n.notes.length>n.exceedLimit-1?r():n.limitExceeded=!1)})}]);app.controller("clinicaldetailsPullOutController",["$scope","clinicalNotesService","localDataService","$timeout",function(n,t,i,r){function f(){window.getSelection?window.getSelection().removeAllRanges():document.selection&&document.selection.type!="Control"&&document.selection.empty()}function u(){return t.AvailableCharacters()}n.progressNoteText=i.getCurrentProgressNote().NotesHtml;n.service=t;n.$watch("service.HaveProgressNotesChanged()",function(t){t!=undefined&&t&&(n.progressNoteText=i.getCurrentProgressNote().NotesHtml)});n.copyEnabled=!1;n.selectedNotes="";var e=t.AvailableCharacters();n.availableCharacters=parseInt(e);n.selectNotes=function(){r(function(){window.getSelection?n.selectedNotes=window.getSelection().toString():document.selection&&document.selection.type!="Control"&&(n.selectedNotes=document.selection.createRange().text);n.selectedNotes.length>0?(n.copyEnabled=!0,n.availableCharacters=u()-n.selectedNotes.length):(n.copyEnabled=!1,t.AppendToClinicalNotes(n.selectedNotes),n.availableCharacters=u())},200)};n.pasteNotes=function(){n.selectedNotes.length>0&&(t.AppendToClinicalNotes(n.selectedNotes),n.toggleProgressNotes());f();n.copyEnabled=!1};n.clearNotesHighlight=function(){r(function(){f();n.availableCharacters=u();n.copyEnabled=!1},200)};n.$on("ClinicalNotesUpdated",function(){n.availableCharacters=t.AvailableCharacters();r(function(){parseInt(n.availableCharacters)==-1&&(n.availableCharacters=0)},500)})}]);app.controller("clinicalinformationController",["$scope","eOrderService","patientService","localDataService","$timeout",function(n,t,i,r,u){function f(){h||o||!n.LMP||n.isValidDate(n.LMP)||!n.Pregnant?$("#clinicalInformationLmp").tooltip("destroy"):$("#clinicalInformationLmp").tooltip("show")}function e(){c||s||!n.EDC||n.isValidDate(n.EDC)||!n.Pregnant?$("#clinicalInformationEdc").tooltip("destroy"):$("#clinicalInformationEdc").tooltip("show")}var o,s,h,c;n.Diabetic=!1;n.Fasting=!1;n.LMP=r.getPregnancy().LMP;i.getPatientData().GenderText==="Male"?(n.Pregnant=!1,n.EDC="",n.LMP=""):(n.Pregnant=r.getPregnancy().Pregnant,n.EDC=r.getPregnancy().EDC,n.LMP=r.getPregnancy().LMP);n.toggleDiabetic=function(){n.Diabetic=!n.Diabetic;t.SetDiabetic(n.Diabetic)};n.toggleFasting=function(){n.Fasting=!n.Fasting;t.SetFasting(n.Fasting)};n.togglePregnant=function(){n.Pregnant=!n.Pregnant;t.SetPregnant(n.Pregnant)};n.isPregnantDisabled=function(){return t.IsPregnantDisabled()};n.isLmpDisabled=function(){return t.isLmpDisabled()};n.isValidDate=function(n){return t.isValidDate(n)};n.$watch("Pregnant",function(i){t.SetPregnant(i);n.Pregnant||(n.EDC="",t.EDC=n.EDC);u(function(){e();f()},400)});n.$watch("LMP",function(){f();t.SetLmp(n.LMP)});n.$watch("EDC",function(){e();t.SetEdc(n.EDC)});n.$on("PregnantChanged",function(t,i){n.Pregnant=i});n.$on("LmpChanged",function(t,i){n.LMP=i});o=!1;n.$on("CytoLmpFocused",function(n,t){o=t;f()});n.$on("EdcChanged",function(t,i){n.EDC=i});s=!1;n.$on("CytoEdcFocused",function(n,t){s=t;e()});h=!1;n.lmpFocused=function(n){h=n;t.SetCiLmpFocused(n);f()};c=!1;n.edcFocused=function(n){c=n;t.SetCiEdcFocused(n);e()}}]);app.controller("conditionsController",["$scope","searchService","testService","favouriteService","$timeout","eOrdersSettings",function(n,t,i,r,u,f){function h(n){return i.CheckAConditionListForSelected(n)}function o(){for(var t=0;t<n.conditionsList.length;t++)n.conditionsList[t].selectFavouriteShow=!1}var e,s;n.showWarning=!1;n.conditionsList=[];e=!1;n.blackswanHost=!1;f.host===app.enums.hostType.BlackSwan&&(n.blackswanHost=!0);n.showDialog=function(){return e};n.service=t;n.selectedTests=i.SelectedTests;n.selectedConditions=i.SelectedConditions;n.$watch("service.conditionResults()",function(t){n.hasResults=t!=undefined&&t.length>0?!0:!1;n.conditionsList=h(t)});n.$watch("service.gettingResults()",function(t){n.gettingResults=t});n.$watch("service.SearchParams()",function(t){n.searchedFor=t});n.selectCondition=function(t){var r;r=typeof t!="object"?n.conditionsList[t]:t;n.testIndex=0;i.AddCondition(r);s=r};n.$on("ConditionItemRemoved",function(t,r){for(var f,u=0;u<n.conditionsList.length;u++)if(n.conditionsList[u].Id==r)for(n.conditionsList[u].selected=!1,f=0;f<n.conditionsList[u].Tests.length;f++)n.conditionsList[u].Tests[f].selectedBillingRuleId=null,i.ClearSelectedFlagOnMbs(n.conditionsList[u].Tests[f].BillingRuleIds)});n.showFavourite=function(n){n.favouriteShow=!0};n.hideFavourite=function(n){n.favouriteShow=!1};n.showSelectFavourite=function(n){o();n.selectFavouriteShow=!0};n.hideSelectFavourite=function(n){n.selectFavouriteShow=!1;o()};n.setFavourite=function(n,t){var i;n.DoctorFavourite||t!=="doctor"||(n.favourited=!0,n.DoctorFavourite=!0,i=r.AddToFavourites(n.Id,"doctor",app.enums.favouriteType.Condition),i.then(function(t){t||(n.DoctorFavourite=!1)}));n.PatientFavourite||t!=="patient"||(n.favourited=!0,n.PatientFavourite=!0,i=r.AddToFavourites(n.Id,"patient",app.enums.favouriteType.Condition),i.then(function(t){t||(n.PatientFavourite=!1)}))}}]);app.controller("copytodoctorsController",["$scope","copyToDoctorService",function(n,t){n.name="Copy To Doctors";n.selectedDoctors=t.SelectedDoctors;n.$on("SelectedDoctorsChanged",function(){n.selectedDoctors=t.SelectedDoctors});n.removeFromSelected=function(n){t.RemoveDoctorFromSelected(n)}}]);app.controller("copytodoctorsPullOutController",["$scope","copyToDoctorService","$timeout","localDataService","focusFactory","eOrdersSettings",function(n,t,i,r,u,f){function s(){i.cancel(e);e=i(function(){n.search()},500)}function h(){u("nameField")}function o(){n.newdoc={name:"",address:"",suburb:"",postcode:"",phone:"",fax:""};n.showModal=!1;n.submitted=!1}n.searchLocalAddressBook=!0;n.labCode=r.getLabCode();n.newcopytodoctorsenabled=!0;n.searchText="";n.searchResults=[];n.addressBookLabel=f.host==app.enums.hostType.MD3?"MD":"";n.displayMaxResultsMessage=!1;var e;n.toggleLocalSearch=function(t){n.searchLocalAddressBook=t==="local"?!0:!1;n.displayMaxResultsMessage=!1;n.searchResults=[];n.search()};n.newdoc={name:"",address:"",suburb:"",postcode:"",phone:"",fax:""};n.search=function(){var i,r,u;n.searching=!0;n.searchResults=[];n.displayMaxResultsMessage=!1;i=$.grep(n.searchText.split(" "),function(n){return n.length>=2});i.length>0?(t.setSearchParams(n.searchText),n.searchLocalAddressBook?(r=t.searchLocalAddressBook(n.searchText),r.then(function(i){n.searchResults=i;n.searching=!1;n.displayMaxResultsMessage=i.length>=t.MAX_SEARCH_RESULTS})):(u=t.searchUltraDoctors(),u.then(function(i){n.searchResults=i;n.searching=!1;n.displayMaxResultsMessage=i.length>=t.MAX_SEARCH_RESULTS}))):n.searching=!1};n.$watch("searchText",function(t){t.length==0&&(n.searchResults=[]);t&&s()});n.selectDoctor=function(i){i.selected=!0;var r=t.addDoctorToSelected(i);r||(t.RemoveDoctorFromSelected(i.Id),i.selected=!1);n.selectedDoctors=t.SelectedDoctors};n.$on("SelectedDoctorRemoved",function(t,i){for(var r=0;r<n.searchResults.length;r++)n.searchResults[r].Id==i&&(n.searchResults[r].selected=!1)});n.$on("SelectedDoctorsChanged",function(){n.newcopytodoctorsenabled=t.SelectedDoctors.length>=t.SelectedDoctorsLimit?!1:!0});n.$on("CopyToDoctorSearchInitialised",function(){n.searchLocalAddressBook=!0;n.searchText="";n.searchResults=[]});n.newDocValid=!1;n.toggleModal=function(){n.showModal=!n.showModal;n.submitted=!1;i(h,200);n.showModal&&$(".col3").css("z-index","2")};n.closeModal=function(){o();$(".col3").css("z-index","3")};n.submitNewDoctor=function(i){if(n.submitted=!0,i){var r=t.CreateNewDoctorObject(n.newdoc.name,n.newdoc.address,n.newdoc.suburb,n.newdoc.postcode,n.newdoc.phone,n.newdoc.fax);t.addDoctorToSelected(r);n.selectedDoctors=t.SelectedDoctors;o()}}}]);app.controller("currentRxController",["$scope","currentRxService",function(n,t){n.name="Current Rx";n.currentRxList=t.ImportCurrentRx();n.importEnabled=!1;n.removeEnabled=!1;n.service=t;n.currentRxList&&n.currentRxList.length>0&&(n.removeEnabled=!0);n.importRx=function(){n.currentRxList=t.ImportCurrentRx();n.importEnabled=!1;n.removeEnabled=!0};n.removeAll=function(){n.currentRxList=[];n.importEnabled=!0;n.removeEnabled=!1};n.removeSingle=function(i){n.importEnabled=!0;n.currentRxList.splice(i,1);n.currentRxList.length==0&&(n.removeEnabled=!1);t.SetCurrentRx=n.currentRxList};n.$watch("service.CanImportRx()",function(t){t!=undefined&&t&&(n.importEnabled=!0)})}]);app.controller("defaultController",["$scope","searchService","specialityService","patientService","$timeout","eOrderService","localDataService","testService","authService","favouriteService","$filter","focusFactory","copyToDoctorService","$rootScope","pregnancyService","eOrdersSettings",function(n,t,i,r,u,f,e,o,s,h,c,l,a,v,y,p){function tt(n){for(var i=!1,r=n.split(" "),t=0;t<r.length;t++)if(r[t].length>=2){i=!0;break}return i}function ft(){u.cancel(b);b=u(function(){if(t.setConditionSearchParams(n.conditionSearchText),n.conditionSearchText&&tt(n.conditionSearchText)){v.isLoading=!0;var i=t.searchConditions();i.then(function(){v.isLoading=!1;w("conditions")})}else t.clearConditionResults()},500)}function et(){u.cancel(b);b=u(function(){if(t.setTestSearchParams(n.testSearchText),n.testSearchText&&tt(n.testSearchText)){v.isLoading=!0;var i=t.searchTests();i.then(function(){v.isLoading=!1;w("tests")})}else t.clearTestResults()},500)}function w(t){n.displaySubSpecialities=!1;n.displayTestResults=!1;n.displayConditionResults=!1;n.displayDoctorFavourites=!1;n.displayPatientFavourites=!1;n.displayMostFrequent=!1;n.showHelp=!1;n.showCopytoDoctors=!1;n.showProgressNotes=!1;switch(t){case"tests":n.displayTestResults=!0;n.conditionSearchText="";n.specialityIndexSelected=-1;break;case"conditions":n.displayConditionResults=!0;n.testSearchText="";n.specialityIndexSelected=-1;break;case"specialities":n.displaySubSpecialities=!0;n.testSearchText="";n.conditionSearchText="";break;case"doctorfavourites":h.setFavouriteTypeSelected("doctor");n.testSearchText="";n.conditionSearchText="";n.displayDoctorFavourites=!0;n.specialityIndexSelected=-1;break;case"patientfavourites":h.setFavouriteTypeSelected("patient");n.testSearchText="";n.conditionSearchText="";n.displayPatientFavourites=!0;n.specialityIndexSelected=-1;break;case"mostfrequent":n.displaySubSpecialities=!0;n.testSearchText="";n.conditionSearchText="";n.specialityIndexSelected=-1;n.displayMostFrequent=!0}n.$broadcast("content_changed")}function ot(){n.submitted&&(n.displaySubSpecialities=!1,n.displayTestResults=!1,n.displayConditionResults=!1,n.specialityIndexSelected=-1,n.testSearchText="",n.enablePrintButton=!0,n.showCopytoDoctors=!1,n.showProgressNotes=!1,n.showHelp=!1,n.displayDoctorFavourites=!1,n.displayPatientFavourites=!1)}function st(){n.submitted=!1;n.printCount=0;n.displaySubmitSuccess=!1;n.enablePrintButton=!1;n.enableSendButton=!1;lt();var t=r.getPatientData();o.SetMbsConditions();n.patientData=t;n.clinicalInformationDialogShown=!1;n.Pregnant=!1;n.Fasting=!1;n.Diabetic=!1;n.labCode=e.getLabCode();n.$watch("enablePrintButton",function(n,t){n!=undefined&&n!=t&&e.setButtonEnabled("PrintButton",n)});n.$watch("enableSendButton",function(n,t){n!=undefined&&n!=t&&e.setButtonEnabled("SendButton",n)})}function ht(){var i=e.getEncryptedAuthenticationDetails(),r=e.getProductName(),t;if(r=="MedicalDir"){window.location.href="/unauthorised";return}t=s.Login(i);t.then(function(){ct()}).then(undefined,function(){n.showUnavailableDialog=!0})}function ct(){s.CheckUser().then(function(){st()}).then(undefined,function(){n.showUnavailableDialog=!0})}function lt(){var t=i.getSpecialities();t.then(function(t){t.Success?(n.showSpecialities=!0,n.specialityList=t.Data,window.location.href.toLowerCase().indexOf("cytology")>-1?it("cytology"):n.setDefaultView()):n.showSpecialities=!1})}function it(t){for(var r,i=0;i<n.specialityList.length;i++)if(r=n.specialityList[i],r.Name.toLowerCase()==t.toLowerCase()){n.specialityIndexSelected!=i&&n.getSubSpecialities(r.Id,i,t);break}}function at(){for(var n={},i,t=0;t<o.SelectedTests.length;t++)i=o.SelectedTests[t],d(i,"Pregnant")&&(n.Pregnant=!0),d(i,"Fasting")&&(n.Fasting=!0),d(i,"Diabetic")&&(n.Diabetic=!0);return n}function d(n,t){var i=(n.Tags?n.Tags:"").toLowerCase();return i.toLowerCase().indexOf(t.toLowerCase())>=0}function rt(){if(f.ValidateOrder()!==!1){f.SetRequestDate(n.requestDate);var t=f.Submit();t.then(function(t){t.Success?(n.submitted=!0,n.displaySubmitSuccess=!0,n.orderNo=t.Data.EOrderNumber,ot(),f.Print(!1,!1),e.getShowPrinterPaperSetting()?n.printerPrompt=!0:n.printEOrder(!n.printerPromptCancelled,!1)):console&&console.log&&console.log("Error trying to submit order: "+t)})}}function vt(){var t=at();if(r.getPatientData().GenderText==="Female"&&t.Pregnant&&!f.GetPregnant()||t.Fasting&&!f.GetFasting()||t.Diabetic&&!f.GetDiabetic()){n.showClinicalInformationModal=!0;return}rt()}function g(){var t=0;f.GetRequestedTests().length>0&&t++;n.enableSendButton=t===1&&k?!0:!1}function ut(){nt||!n.requestDate||n.isRequestDateValid(n.requestDate)?$("#requestDate").tooltip("destroy"):$("#requestDate").tooltip("show")}var b,k,nt;v.$watch("isLoading",function(n){v.showLoadingImg=!1;n===!0&&u(function(){v.showLoadingImg=!0},1e3)});n.isBlackSwan=p.host==app.enums.hostType.BlackSwan;n.bannerText=typeof p.showUATBanner!="undefined"&&p.showUATBanner===!0?"UAT eOrders Environment":"";ht();n.$root.$on("SelectSpeciality",function(n,t){it(t)});v.$watch("APIavailable",function(t){t===!1&&(n.showUnavailableDialog=!0)});n.$watch("testSearchText",function(i){i!=undefined&&(et(),i.length===0&&(t.setTestSearchParams(n.testSearchText),t.clearTestResults()))});n.$watch("conditionSearchText",function(i){i!=undefined&&(ft(),i.length===0&&(t.setConditionSearchParams(n.conditionSearchText),t.clearConditionResults()))});n.$watch("requestDate",function(){ut()});n.$on("SelectedTestsChanged",function(){g()});n.$on("BillingOptionsChanged",function(){g()});n.showDoctorFavourites=function(){v.isLoading=!0;w("doctorfavourites")};n.showPatientFavourites=function(){v.isLoading=!0;w("patientfavourites")};n.getSubSpecialities=function(t,r,u){n.submitted||(v.isLoading=!0,i.getSubSpecialities(t,u),n.specialityIndexSelected=r,w("specialities"),u&&u.toLowerCase()==app.constants.pregnancyTabName.toLowerCase()&&y.getPregnancyScreenDetails())};n.toggleProgressNotes=function(){n.showCopytoDoctors=!1;n.showHelp=!1;n.showProgressNotes=!n.showProgressNotes;n.$broadcast("content_changed")};n.toggleCopytoDoctors=function(){n.showProgressNotes=!1;n.showHelp=!1;n.showCopytoDoctors=!n.showCopytoDoctors;n.$broadcast("content_changed");n.showCopytoDoctors&&l("doctorSearch");a.SetShowCopyToDoctor(n.showCopytoDoctors)};n.toggleHelp=function(){n.showCopytoDoctors=!1;n.showProgressNotes=!1;n.showHelp=!n.showHelp;n.$broadcast("content_changed")};n.reprint=function(){if(n.submitted){if(e.getShowPrinterPaperSetting()){n.printerPrompt=!0;return}n.printEOrder(!0,!0)}};n.printEOrder=function(t,i){n.printCount++;f.Print(t,i)};n.cancelPrinterPrompt=function(){n.printerPrompt=!1;n.printerPromptCancelled=!0};n.continuePrinting=function(){n.printerPrompt=!1;n.printEOrder(!0,n.printCount>0)};n.saveEOrder=function(){n.submitted||vt()};n.isBlackSwan&&(n.isEOrdersDirty=function(){return f.IsDirty()},e.setupHostIsDirtyFunction(n.isEOrdersDirty),e.setupHostSaveFunction(n.saveEOrder),e.setupHostComplete());n.cancelSubmission=function(){n.showClinicalInformationModal=!1};n.continueSubmission=function(){n.showClinicalInformationModal=!1;rt()};n.dismissSubmitSuccess=function(){n.displaySubmitSuccess=!1};n.requestDate=c("date")(new Date,"dd/MM/yyyy");k=!0;n.isRequestDateValid=function(){var t=f.isValidRequestDate(n.requestDate);return t!=k&&(k=t,g()),t};n.closeServiceUnavailableMessage=function(){n.showUnavailableDialog=!1};nt=!1;n.requestDateFocused=function(n){nt=n;ut()};n.maxdays=function(){var t=null,n=new Date,i;return n.setHours(0,0,0,0),t=n.month===2&&n.day===29?new Date(n.getFullYear()+1,2,1):new Date(n.getFullYear()+1,n.getMonth(),n.getDate()),i=t.getTime()-n.getTime(),Math.ceil(i/864e5)};n.selectTestWithMbs=function(t,i){o.AddBillingSelection(t,i);u(function(){n.showMbsDialog=!1},200)};n.$on("OpenBillingDialog",function(t,i){n.selectedTest=i;u(function(){n.showMbsDialog=!0},200)});n.$on("OpenMicroSiteDialog",function(t,i){n.selectedTest=i;u(function(){n.showMicroSiteDialog=!0},200)});n.selectMicroSiteTest=function(t,i){for(var u,r=0;r<t.BillingRuleIds.length;r++)if(u=t.BillingRuleIds[r],u.Id===i){u.selected=!u.selected;break}n.selectedTest=t};n.updateMicroSites=function(){o.UpdateSelectedMicroSitesForTest(n.selectedTest);n.showMicroSiteDialog=!1};n.closeMicroSiteDialog=function(){n.showMicroSiteDialog=!1};n.closeMbsDialog=function(){o.BillingSelectionCancelled();n.showMbsDialog=!1};n.setDefaultView=function(){var t=n.specialityList[0];n.getSubSpecialities(t.Id,0,t.Name);w("mostfrequent")};n.priorEorders=function(){e.priorEOrders()}}]);app.controller("favouritesController",["$scope","favouriteService","testService","searchService","$timeout","$rootScope","eOrdersSettings",function(n,t,i,r,u,f,e){function c(){var u=t.GetFavourites("doctor");u.then(function(t){f.isLoading=!1;n.favouritesTests=t.Tests;i.ProcessSelectedTests(n.favouritesTests);o=Math.ceil(n.favouritesTests.length/2);n.chunkedData=s(n.favouritesTests,o);n.favouriteConditions=i.CheckAConditionListForSelected(r.AddTestDisplayStringToConditionsList(t.Conditions))})}function s(n,t){for(var r=[],i=0;i<n.length;i+=t)r.push(n.slice(i,i+t));return r}function l(){var u=t.GetFavourites("patient");u.then(function(t){f.isLoading=!1;n.favouritesTests=t.Tests;i.ProcessSelectedTests(n.favouritesTests);o=Math.ceil(n.favouritesTests.length/2);n.chunkedData=s(n.favouritesTests,o);n.favouriteConditions=i.CheckAConditionListForSelected(r.AddTestDisplayStringToConditionsList(t.Conditions))})}var o=0,h;n.favouriteType=null;n.showTests=!0;n.favouritesTests=[];n.favouriteConditions=[];n.blackswanHost=!1;e.host===app.enums.hostType.BlackSwan&&(n.blackswanHost=!0);n.$on("SelectedFavouriteChanged",function(t,i){n.showTests=!0;n.favouritesTests=[];n.favouriteType=i;i=="doctor"&&c();i=="patient"&&l()});n.toggleTestView=function(t){n.showTests=t=="tests"?!0:!1};n.selectTest=function(n){i.Add(n)};n.$on("TestItemRemoved",function(t,r){for(var u=0;u<n.favouritesTests.length;u++)n.favouritesTests[u].Id==r.Id&&(n.favouritesTests[u].selected=!1,n.favouritesTests[u].selectedBillingRuleId=null,i.ClearSelectedFlagOnMbs(n.favouritesTests[u].BillingRuleIds))});n.selectCondition=function(t){n.testIndex=0;var r=n.favouriteConditions[t];i.AddCondition(r);h=r};n.$on("ConditionItemRemoved",function(t,i){if(n.favouriteConditions)for(var r=0;r<n.favouriteConditions.length;r++)n.favouriteConditions[r].Id==i&&(n.favouriteConditions[r].selected=!1)});n.remove=function(i,r,u){var f=t.remove(i,r,u=="test"?app.enums.favouriteType.Test:app.enums.favouriteType.Condition);f.then(function(t){var r;if(t){if(u==="test"){for(r=0;r<n.favouritesTests.length;r++)n.favouritesTests[r].Id==i&&n.favouritesTests.splice(r,1);n.chunkedData=s(n.favouritesTests,Math.ceil(n.favouritesTests.length/2))}if(u==="condition")for(r=0;r<n.favouriteConditions.length;r++)n.favouriteConditions[r].Id==i&&n.favouriteConditions.splice(r,1)}})};n.$on("SelectedTestsChanged",function(){n.favouritesTests&&i.ProcessSelectedTests(n.favouritesTests)})}]);app.controller("helpController",["$scope","$http",function(n,t){t.get("/data/help.json").success(function(t){n.helpData=t;n.helpData[0].show=!0;n.helpData[0].Questions[0].show=!0});n.showAnswer=function(n){n.show=!n.show};n.showTopic=function(n){n.show=!n.show}}]);app.controller("histologyController",["$scope","$http","$timeout","testService","histologyService",function(n,t,i,r,u){function h(n){return this.SequenceNo=n,this.Site="",this.BiopsyType="",this.Description="",this.ProvisionalDiagnosis="",this.PastResult="",this}function c(n){return this.Id=f+n.SequenceNo,this.BuCode=null,this.Code=f+n.SequenceNo,this.TestName=f+n.SequenceNo,this.deleteData=!1,this}var e,o,f,s;for(n.name="Histology",n.jsonlistBiopsyData=[],n.selectedbiopsy="",n.jsonlistProvDiag=[],n.jsonlistPastDiag=[],n.specimens=[],t.get("/data/biopsy.json").success(function(t){n.jsonlistBiopsyData=t}),t.get("/data/provisional-diagnosis.json").success(function(t){n.jsonlistProvDiag=t;n.jsonlistPastDiag=t}),e=1;e<21;e++)n.specimens.push(new h(e));n.addTest=function(n){i.cancel(o);o=i(function(){if(n.Site.length===0){r.removeHistoTestFromSelected(f+n.SequenceNo);return}r.Add(new c(n),"histology");u.addToSelected(n)},400)};f="HIS-Spec ";n.$on("TestItemRemoved",function(t,i){for(var r=0;r<n.specimens.length;r++)f+n.specimens[r].SequenceNo==i.Id&&(n.specimens[r].Site="")});n.addToHisto=function(n){i.cancel(s);s=i(function(){u.addToSelected(n)},300)}}]);app.controller("pregnancyController",["$scope","searchService","$timeout","testService","pregnancyService","specialityService","eOrdersSettings",function(n,t,i,r,u,f,e){function s(n){return n!=undefined?r.CheckAConditionListForSelected(n):null}function o(t){var i,u,f,e;for(n.column1=[],n.column2=[],i=0,u=0,t[0]!=undefined&&(n.column1.push(t[0]),i+=1),t[1]!=undefined&&(n.column2.push(t[1]),u+=1),f=2;f<t.length;f++){e=Math.min(i,u);switch(e){case i:n.column1.push(t[f]);i+=1;break;case u:n.column2.push(t[f]);u+=1}r.ProcessSelectedTests(n.column1);r.ProcessSelectedTests(n.column2)}}n.service=u;n.pregnancyList=[];n.pregnancyConditionsList=[];n.pregnancyTestsList=[];e.host===app.enums.hostType.BlackSwan&&(n.blackswanHost=!0);n.$watch("service.pregnancyDetailsList()",function(t){n.pregnancyList=t;n.pregnancyTestsList=n.pregnancyList.Tests;n.pregnancyConditionsList=s(n.pregnancyList.Conditions);n.pregnancyTestsList&&o(n.pregnancyTestsList)});n.selectCondition=function(t){var i=n.pregnancyConditionsList[t];r.AddCondition(i)};n.$on("ConditionItemRemoved",function(t,i){var u,f;if(n.pregnancyConditionsList!=undefined)for(u=0;u<n.pregnancyConditionsList.length;u++)if(n.pregnancyConditionsList[u].Id==i)for(n.pregnancyConditionsList[u].selected=!1,f=0;f<n.pregnancyConditionsList[u].Tests.length;f++)n.pregnancyConditionsList[u].Tests[f].selectedBillingRuleId=null,r.ClearSelectedFlagOnMbs(n.pregnancyConditionsList[u].Tests[f].BillingRuleIds)});n.$on("TestItemRemoved",function(t,i){if(n.pregnancyTestsList!=undefined)for(var u=0;u<n.pregnancyTestsList.length;u++)n.pregnancyTestsList[u].Id==i.Id&&(n.pregnancyTestsList[u].selected=!1,n.pregnancyTestsList[u].selectedBillingRuleId=null,r.ClearSelectedFlagOnMbs(n.pregnancyTestsList[u].BillingRuleIds))});n.$on("SelectedTestsChanged",function(){n.pregnancyTestsList!=undefined&&o(n.pregnancyTestsList)});n.selectPregnancyTest=function(n){var t=f.GetSelectedSpecialityName()||"";t&&(t=t.toLowerCase());r.Add(n,t)}}]);app.controller("rule3Controller",["$scope","$timeout","testService","focusFactory","$filter","eOrderService","clinicalNotesService",function(n,t,i,r,u,f,e){function l(){s&&!f.isValidDate(n.inrDates.startDate)?$("#INRStartDate").tooltip("show"):$("#INRStartDate").tooltip("destroy")}function a(){h&&!f.isValidDate(n.inrDates.endDate)?$("#INREndDate").tooltip("show"):$("#INREndDate").tooltip("destroy")}function v(){switch(n.selectedFrequency){case 0:e.AppendToClinicalNotes("Warfarin monitoring.");break;case 1:e.AppendToClinicalNotes("Warfarin monitoring as required "+n.inrDates.startDate+" - "+n.inrDates.endDate+".");break;case 2:e.AppendToClinicalNotes("Warfarin monitoring weekly "+n.inrDates.startDate+" - "+n.inrDates.endDate+".");break;case 3:e.AppendToClinicalNotes("Warfarin monitoring fortnightly "+n.inrDates.startDate+" - "+n.inrDates.endDate+".");break;case 4:e.AppendToClinicalNotes("Warfarin monitoring monthly "+n.inrDates.startDate+" - "+n.inrDates.endDate+".")}if(n.warfarin.length>0)switch(n.warfarin){case"yes":e.AppendToClinicalNotes("Patient new to warfarin.");break;case"no":e.AppendToClinicalNotes("Patient not new to warfarin.");break;case"recommencing":e.AppendToClinicalNotes("Patient recommencing warfarin.")}}function y(){var t="";switch(n.selectedFrequency){case 0:t=t.concat("Warfarin monitoring");break;case 1:t=t.concat("Warfarin monitoring weekly "+n.inrDates.startDate+" - "+n.inrDates.endDate);break;case 2:t=t.concat("Warfarin monitoring fortnightly "+n.inrDates.startDate+" - "+n.inrDates.endDate);break;case 3:t=t.concat("Warfarin monitoring monthly "+n.inrDates.startDate+" - "+n.inrDates.endDate);break;case 4:t=t.concat("Warfarin monitoring as required "+n.inrDates.startDate+" - "+n.inrDates.endDate)}if(n.warfarin.length>0){t&&(t=t.concat(", "));switch(n.warfarin){case"yes":t=t.concat("Patient new to warfarin");break;case"no":t=t.concat("Patient not new to warfarin");break;case"recommencing":t=t.concat("Patient recommencing warfarin")}}return t}var o,c,s,h;n.inrDates={};o=function(){n.selectedFrequency=0;n.enableOrderButton=!1;n.oneoff=!1;n.inrDates={startDate:"",endDate:""};n.warfarin=""};c=function(){n.oneOffTestChecked=!1;n.repeatTestChecked=!1;o();n.showRule3Dialog=!0};n.checkOneOffTest=function(){n.oneOffTestChecked=!n.oneOffTestChecked;n.oneOffTestChecked&&(n.repeatTestChecked=!1,o())};n.checkRepeatTest=function(){n.repeatTestChecked=!n.repeatTestChecked;n.repeatTestChecked&&(n.oneOffTestChecked=!1)};n.$on("OpenRule3Dialog",function(i,r){t(function(){n.selectedTest=r;c()},200)});n.closeRule3Dialog=function(){n.showRule3Dialog=!1};n.selectRuleTest=function(r,u){i.SelectRule3Test(r,u);t(function(){n.showRule3Dialog=!1},200)};n.calculateEndDate=function(){var t=new Date(n.inrDates.yyyymmdd),i=t.addMonths(6);n.inrDates.endDate=u("date")(i,"dd/MM/yyyy")};n.$watch("inrDates.startDate",function(t){if(t){var i=f.isValidDate(t);l();typeof i=="object"&&i!=null&&(n.inrDates.yyyymmdd=i.year+"/"+i.month+"/"+i.day,n.calculateEndDate())}});n.$watch("inrDates.endDate",function(n){n&&a()});n.selectFrequency=function(t){n.selectedFrequency=n.selectedFrequency==t?0:t;n.selectedFrequency>0?(n.inrDates.yyyymmdd=u("date")(new Date,"yyyy/MM/dd"),n.inrDates.startDate=u("date")(new Date,"dd/MM/yyyy"),n.calculateEndDate(),n.enableOrderButton=!0):n.enableOrderButton=!1};n.selectWarfarin=function(t){n.warfarin=t==n.warfarin?"":t};n.orderInr=function(){var t=n.oneOffTestChecked;n.repeatTestChecked||(t=!0);t||(v(),n.selectedTest.R3eStatement=y());n.selectRuleTest(n.selectedTest,t)};n.isValidDate=function(n){return f.isValidDate(n)};s=!1;n.startDateFocused=function(n){s=n;l()};h=!1;n.endDateFocused=function(n){h=n;a()}}]);app.controller("searchController",["$scope",function(n){n.name="Search";n.searchType="freetext";n.setSearchType=function(t){n.searchType=t};var t=!1;n.diag1=function(){return t};n.testMessage="This is a sample message from the controller";n.closeDiag1=function(n){t=!1;n===!0};n.showDiag=function(){t=!0}}]);app.controller("subSpecialititesController",["$scope","specialityService","testService","eOrderService","$timeout","focusFactory","toolsService","$rootScope","eOrdersSettings",function(n,t,i,r,u,f,e,o,s){function k(){n.Pregnant=r.GetPregnant();n.LMP=r.GetLmp();n.EDC=r.GetEdc()}function nt(n){$("#"+n).attr("placeholder","Please enter")}function g(n){$("#"+n).val("");$("#"+n).attr("placeholder","")}function tt(n){if(n==undefined)return[];for(var t=0;t<n.length;t++)i.ProcessSelectedTests(n[t].Tests);return n}function y(t){var i,e;n.col1=[];n.col2=[];n.col3=[];var r=0,u=0,f=0;for(t[0]!=undefined&&(n.col1.push(t[0]),r+=t[0].Tests.length),t[1]!=undefined&&(n.col2.push(t[1]),u+=t[1].Tests.length),t[2]!=undefined&&(n.col3.push(t[2]),f+=t[2].Tests.length),i=3;i<t.length;i++){e=Math.min(r,u,f);switch(e){case r:n.col1.push(t[i]);r+=t[i].Tests.length;break;case u:n.col2.push(t[i]);u+=t[i].Tests.length;break;case f:n.col3.push(t[i]);f+=t[i].Tests.length}}}function h(){p||a||!n.LMP||n.isValidDate(n.LMP)?$("#cytoLmp").tooltip("destroy"):$("#cytoLmp").tooltip("show")}function c(){w||v||!n.EDC||n.isValidDate(n.EDC)?$("#cytoEdc").tooltip("destroy"):$("#cytoEdc").tooltip("show")}function l(){var t=n.cytoInfo.PreviousAbnormal;(t.High||t.Low||t.Inconclusive)&&!b&&n.cytoInfo.LatestAbnormality&&!n.isValidDate(n.cytoInfo.LatestAbnormality)?$("#latestAbnormality").tooltip("show"):$("#latestAbnormality").tooltip("destroy")}var d,a,v,p,w,b;n.currentActiveItem=null;n.subList=[];n.service=t;n.cytoInfo=r.GetCytologyInfo();n.blackswanHost=!1;s.host===app.enums.hostType.BlackSwan&&(n.blackswanHost=!0);k();n.$watch("service.subList()",function(i){n.selectedName=i.Name;n.subList=tt(i);o.isLoading=!1;var r=t.GetSelectedSpecialityName()||"";switch(r.toLowerCase()){case app.constants.cytologyTabName.toLowerCase():n.showCyto=!0;n.showHisto=!1;n.showPregnancy=!1;n.horizontalSpeciality=!1;$("#cytoLmp").tooltip("destroy");$("#cytoEdc").tooltip("destroy");u(function(){h();c()},400);k();y(n.subList);break;case app.constants.histologyTabName.toLowerCase():n.showCyto=!1;n.showHisto=!0;n.showPregnancy=!1;n.horizontalSpeciality=!1;u(function(){$(".histo-wrapper  input:first").focus()},500);break;case app.constants.pregnancyTabName.toLowerCase():n.showPregnancy=!0;n.showCyto=!1;n.showHisto=!1;n.horizontalSpeciality=!1;break;default:n.showCyto=!1;n.showHisto=!1;n.showPregnancy=!1;n.horizontalSpeciality=!1;y(n.subList)}});d=!1;n.showRemoveSpecialityTestDialog=function(){return d};n.selectedTests=i.SelectedTests;n.selectTest=function(n){var r=t.GetSelectedSpecialityName()||"";r&&(r=r.toLowerCase());i.Add(n,r)};n.toggleOption=function(n,t,i){if(i!=undefined)return n[t]=i,i;var r=!n[t];return n[t]=r,r};n.pholder="";n.toggleSiteOther=function(){n.cytoInfo.Site.Other=!n.cytoInfo.Site.Other;n.pholder="Please enter";n.cytoInfo.Site.Other||(n.cytoInfo.Site.OtherDescription="",n.pholder="");f("otherField")};n.toggleAppearance=function(t){var i=n.cytoInfo.Appearance;switch(t.toLowerCase()){case"benign":i.Benign=!i.Benign;i.Suspicious=!1;break;case"suspicious":i.Suspicious=!i.Suspicious;i.Benign=!1;break;default:i.Suspicious=!1;i.Benign=!1}};n.formatId=function(n){return"testid"+n};n.toggleNongynaeTest=function(t){var i=n.formatId(t.Id);f(i);u(function(){t.selected?nt(i):g(i)},0)};n.toggleNonPregnancyOption=function(t){var i=n.toggleOption(n.cytoInfo,t);switch(t){case"PostNatal":i&&(r.SetPregnant(!1),n.cytoInfo.PostMenopausal=!1,n.cytoInfo.Hysterectomy=!1);break;case"PostMenopausal":i&&(n.LMP="",r.SetPregnant(!1),n.cytoInfo.PostNatal=!1);break;case"HormoneTherapy":i&&r.SetPregnant(!1);break;case"OralContraceptive":i&&r.SetPregnant(!1);break;case"Hysterectomy":i&&(n.LMP="",r.SetPregnant(!1),n.cytoInfo.PostNatal=!1)}};n.updateTestExtraDetails=function(n,t){var u=t.Id,r=e.RemoveNonStandardChars(n.target.value);t.ExtraDetails=r;i.UpdateTestExtraDetails(u,r)};n.$on("TestItemRemoved",function(t,r){for(var f,e,u=0;u<n.subList.length;u++)for(f=0;f<n.subList[u].Tests.length;f++)n.subList[u].Tests[f].Id==r.Id&&(n.subList[u].Tests[f].selected=!1,n.subList[u].Tests[f].selectedBillingRuleId=!1,e=n.formatId(n.subList[u].Tests[f].Id),g(e),i.ClearSelectedFlagOnMbs(n.subList[u].Tests[f].BillingRuleIds));y(n.subList)});n.$on("SelectedTestsChanged",function(){for(var t=0;t<n.subList.length;t++)i.ProcessSelectedTests(n.subList[t].Tests)});n.$on("CytologyTestSelected",function(t,i){n.toggleOption(n.cytoInfo,"RegisterPapTest",i)});n.togglePregnant=function(t){n.isPregnantDisabled()||(n.Pregnant=t!==undefined?t:!n.Pregnant,r.SetPregnant(n.Pregnant),n.Pregnant?f("pregnantDate"):(n.EDC="",r.EDC=n.EDC))};n.isPregnantDisabled=function(){return r.IsPregnantDisabled()};n.isLmpDisabled=function(){return r.isLmpDisabled()};n.$watch("Pregnant",function(t){c();h();r.SetPregnant(t);n.Pregnant?(n.cytoInfo.PostNatal=!1,n.cytoInfo.PostMenopausal=!1,n.cytoInfo.HormoneTherapy=!1,n.cytoInfo.OralContraceptive=!1,n.cytoInfo.Hysterectomy=!1):(n.EDC="",r.EDC=n.EDC)});n.$watch("LMP",function(t){h();t&&(n.cytoInfo.PostMenopausal=!1,n.cytoInfo.Hysterectomy=!1);r.SetLmp(n.LMP)});n.$watch("EDC",function(){c();r.SetEdc(n.EDC)});n.$on("PregnantChanged",function(t,i){n.Pregnant=i});n.$on("LmpChanged",function(t,i){n.LMP=i});a=!1;n.$on("CiLmpFocused",function(n,t){a=t;h()});n.$on("EdcChanged",function(t,i){n.EDC=i});v=!1;n.$on("CiEdcFocused",function(n,t){v=t;c()});n.$watch("cytoInfo.PreviousAbnormal.High",function(){l()});n.$watch("cytoInfo.PreviousAbnormal.Low",function(){l()});n.$watch("cytoInfo.PreviousAbnormal.Inconclusive",function(){l()});n.$watch("cytoInfo.LatestAbnormality",function(){l()});n.isValidDate=function(n){return r.isValidDate(n)};n.togglePreviousAbnormalOption=function(t){var i=n.cytoInfo.PreviousAbnormal;n.toggleOption(i,t);!n.cytoInfo.LatestAbnormality||i.High||i.Low||i.Inconclusive||(n.cytoInfo.LatestAbnormality="");f("LatestAbnormality")};p=!1;n.lmpFocused=function(n){p=n;r.SetCytoLmpFocused(n);h()};w=!1;n.edcFocused=function(n){w=n;r.SetCytoEdcFocused(n);c()};b=!1;n.latestAbnormalityFocused=function(n){b=n;l()}}]);app.controller("testresultsController",["$scope","searchService","testService","favouriteService","$timeout","eOrdersSettings",function(n,t,i,r,u,f){function e(){for(var t=0;t<n.testResultsList.length;t++)n.testResultsList[t].selectFavouriteShow=!1}function s(t){for(var r=0;r<n.testResultsList.length;r++)if(angular.lowercase(n.testResultsList[r].TestName)===angular.lowercase(t.TestName))return n.testResultsList[r].selected=!0,i.ProcessSelectedTests(n.testResultsList),i.CheckManuallyEnteredTests(t)||(i.SelectedTests.push(n.testResultsList[r]),i.enablePrintForFreeTyping()),!0;return!1}n.name="Test Search: Remove this";n.showWarning=!1;n.testResultsList=[];n.BlackSwanHost=!1;n.service=t;n.countFreeTypingText=1e4;n.$watch("service.testResults()",function(t){n.hasResults=t!=undefined&&t.length>0?!0:!1;n.testResultsList=t;i.ProcessSelectedTests(n.testResultsList)});n.$watch("service.gettingResults()",function(t){n.gettingResults=t});n.$watch("service.SearchParams()",function(t){n.searchedFor=t;f.host===app.enums.hostType.BlackSwan&&(n.BlackSwanHost=!0)});var o=!1;n.showDialog=function(){return o};n.selectedTests=i.SelectedTests;n.addtest=function(n){i.Add(n)};n.$on("TestItemRemoved",function(t,r){for(var u=0;u<n.testResultsList.length;u++)n.testResultsList[u].Id==r.Id&&(n.testResultsList[u].selected=!1,n.testResultsList[u].selectedBillingRuleId=null,i.ClearSelectedFlagOnMbs(n.testResultsList[u].BillingRuleIds))});n.$on("SelectedTestsChanged",function(){i.ProcessSelectedTests(n.testResultsList)});n.showFavourite=function(n){n.favouriteShow=!0};n.hideFavourite=function(n){n.favouriteShow=!1};n.showSelectFavourite=function(n){e();n.selectFavouriteShow=!0};n.hideSelectFavourite=function(n){n.selectFavouriteShow=!1;e()};n.setFavourite=function(n,t){var i;n.DoctorFavourite||t!=="doctor"||(n.favourited=!0,n.DoctorFavourite=!0,i=r.AddToFavourites(n.Id,"doctor",app.enums.favouriteType.Test),i.then(function(t){t||(n.DoctorFavourite=!1)}));n.PatientFavourite||t!=="patient"||(n.favourited=!0,n.PatientFavourite=!0,i=r.AddToFavourites(n.Id,"patient",app.enums.favouriteType.Test),i.then(function(t){t||(n.PatientFavourite=!1)}))};n.orderFreeTypingTest=function(t){var r={};r.TestName=t;r.Code="free typing test";r.Urgent=!1;r.AdditionalSiteInfo=null;r.R3eStatement=null;r.IsCytologyTest=!1;r.JSONTags=null;r.freeTypingTest=!0;r.conditions=[];i.CheckManuallyEnteredTests(r)||s(r)||(n.countFreeTypingText+=1,r.Id=n.countFreeTypingText,i.SelectedTests.push(r),i.enablePrintForFreeTyping())}}]);app.controller("testsrequestedController",["$scope","testService",function(n,t){n.name="Tests Requested";n.requestedTests=t.SelectedTests;n.requestedConditions=t.SelectedConditions;n.service=t;n.$watch("service.SelectedTests",function(t){n.requestedTests=t});n.$watch("service.SelectedConditions",function(t){n.requestedConditions=t});n.conditionMouseEnter=function(n){t.highlightTests(n)};n.conditionMouseLeave=function(n){t.removeHighlightOnTests(n)};var i=!1;n.showDialog=function(){return i};n.removeTest=function(n){t.removeTestFromSelected(n)};n.removeCondition=function(n){t.removeConditionFromSelected(n)}}]);appDirectives=angular.module("app.directives",[]);app.directive("datepicker",["$parse",function(n){return{link:function(t,i,r){var f=r.maxdays,u;f=f!=undefined?"+"+f+"D":null;u=r.mindays;u=u==undefined?null:-u;var l=function(n){var i={},t=n.match(/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/);return t?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt("20"+t[3],10),i):(t=n.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/),t)?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt(t[3],10),i):(t=n.match(/^(\d{2})(\d{2})(\d{4})$/),t)?(i.day=parseInt(t[1],10),i.month=parseInt(t[2],10),i.year=parseInt(t[3],10),i):null},s=function(n,t){var i=t.getTime()-n.getTime();return Math.ceil(i/864e5)},h=r.maxdays,c=r.mindays,a=function(n,t,i){var u,r,f;return i<1900||i>3e3||t==0||t>12?!1:(u=[31,28,31,30,31,30,31,31,30,31,30,31],(i%400==0||i%100!=0&&i%4==0)&&(u[1]=29),!(n>0&&n<=u[t-1]))?!1:(r=new Date,r.setHours(0,0,0,0),f=new Date(i,t-1,n),h!=undefined&&s(r,f)>parseInt(h,10))?!1:c!=undefined&&s(r,f)<parseInt(c,10)*-1?!1:!0},e=function(n,t,i){var u=typeof i!="undefined"?i:"0",r=new Array(1+t).join(u);return(r+n).slice(-r.length)},o=!1;$(i).on("keydown",function(n){n.which===13&&(o=!0)}).on("keyup",function(i){var o=this.value,u=l(o),f;u&&a(u.day,u.month,u.year)&&i.which===13&&(f=e(u.day,2)+"/"+e(u.month,2)+"/"+e(u.year,4),t.$apply(function(){var i=n(r.ngModel);i.assign(t,f)}))}).datepicker({dateFormat:"dd/mm/yy",yearRange:"1900:3000",onSelect:function(i){if(o){o=!1;return}t.$apply(function(){var u=n(r.ngModel);u.assign(t,i)})},maxDate:f,minDate:u})}}}]);app.directive("mlcdialog",["$timeout",function(n){return{restrict:"E",templateUrl:"/app/directives/dialog.html",transclude:!0,scope:{okonly:"@",dismiss:"&",show:"=",message:"=",enableok:"=",dynamicTitle:"=",error:"@",title:"@"},link:function(t,i,r){var u=r.title,f=r.yestxt,e=r.notxt;t.title=u;t.yestxt=f;t.notxt=e;t.$watch("show",function(){t.show&&n(function(){$(".dialogbox").focus()})})}}}]);app.directive("ngcFocus",["$parse",function(n){return function(t,i,r){var u=n(r.ngcFocus);i.bind("focus",function(n){t.$apply(function(){u(t,{$event:n})})})}}]);app.directive("ngcBlur",["$parse",function(n){return function(t,i,r){var u=n(r.ngcBlur);i.bind("blur",function(n){t.$apply(function(){u(t,{$event:n})})})}}]);app.directive("focusOnShow",function(n){return{restrict:"A",link:function(t,i,r){r.ngShow&&t.$watch(r.ngShow,function(t){t&&n(function(){i.focus()},0)});r.ngHide&&t.$watch(r.ngHide,function(t){t||n(function(){i.focus()},0)})}}});app.directive("phcfullheight",["$window",function(n){return{restrict:"A",scope:{},link:function(t,i,r){function e(){u=document.documentElement.clientHeight;var n=i[0].getBoundingClientRect().top;return i[0].style.height=u-n+"px",u}function s(){u=document.documentElement.clientHeight;var n=i[0].getBoundingClientRect().top;return u>668&&(i[0].style.height=u-n+"px"),u}var o=angular.element(n),f=!1,u;r.blackswan&&(f=r.blackswan);u=0;e();o.bind("resize",function(){f=="true"?s():e();t.$apply()})}}}]);app.directive("navigatelist",["$timeout",function(n){return{restrict:"A",scope:{items:"=",enterselection:"&",scrollelement:"@"},controller:function(){this.setFocusOnFirst=function(){}},link:function(t,i){function a(){h=$(t.scrollelement).height();o=$(t.scrollelement)[0].getBoundingClientRect().top;c=h+o}function v(){for(var n=0;n<t.items.length;n++)t.items[n].hasfocus=!1}function s(r){if(t.items.length>0){v();t.items[r].hasfocus=!0;f=i.find("li")[r];l=$(f).outerHeight();var e=$(f).outerHeight(),s=f.getBoundingClientRect().bottom,h=f.getBoundingClientRect().top;s>c&&(u=u+e,$(t.scrollelement).scrollTop(u));h<o&&(u=u-e*2,$(t.scrollelement).scrollTop(u));n(function(){t.$apply()})}}var r=0,e=t.items.length,h,o,c,l,f,u;i.bind("keydown keypress",function(n){var i=n.which||n.keyCode;switch(i){case 13:t.enterselection({item:t.items[r]});n.preventDefault();break;case 38:r>0&&(r=r-1);s(r);n.preventDefault();break;case 40:r<e-1&&(r=r+1);s(r);n.preventDefault()}});i.bind("click",function(){r=$(document.activeElement).index();s(r)});t.$watch("items",function(){e=t.items.length;r=0;e>0&&n(function(){a()})});l=0;u=0}}}]);app.directive("navigatesearch",["searchService",function(n){return{restrict:"A",scope:{searchtype:"@",ngModel:"="},link:function(t,i){function r(t){var i;if(t==="test"){i=$(".testResults").find("li")[0];i.focus();n.setFocusOnFirstTest();return}i=$(".conditions").find("li")[0];i.focus();n.setFocusOnFirstCondition();return}i.bind("keydown keypress",function(n){var i=n.which||n.keyCode;switch(i){case 9:t.ngModel.length>0&&(n.preventDefault(),r(t.searchtype))}})}}}]);angular.module("ngDraggable",[]).service("ngDraggable",[function(){var n=this;n.inputEvent=function(n){return angular.isDefined(n.touches)?n.touches[0]:angular.isDefined(n.originalEvent)&&angular.isDefined(n.originalEvent.touches)?n.originalEvent.touches[0]:n}}]).directive("ngDrag",["$rootScope","$parse","$document","$window","ngDraggable",function(n,t,i,r,u){return{restrict:"A",link:function(f,e,o){f.value=o.ngDrag;var w,d=!1,s,h,c,l,g,nt,ut="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,ft="touchstart mousedown",b="touchmove mousemove",k="touchend mouseup",tt,et=f.$id,y=null,a=null,p=!1,ot=null,st=t(o.ngDragSuccess)||null,it=angular.isDefined(o.allowTransform)?f.$eval(o.allowTransform):!0,yt=t(o.ngDragData),ht=angular.noop,pt=function(){var n;e.attr("draggable","false");n=e[0].querySelectorAll?angular.element(e[0].querySelectorAll("[ng-drag-handle]")):e.find("[ng-drag-handle]");n.length&&(tt=n);ct(!0)},ct=function(n){if(n){if(f.$on("$destroy",wt),f.$watch(o.ngDrag,bt),f.$watch(o.ngCenterAnchor,kt),tt)tt.on(ft,lt);else e.on(ft,lt);if(!ut&&e[0].nodeName.toLowerCase()=="img")e.on("mousedown",function(){return!1})}},wt=function(){ct(!1)},bt=function(n){p=n},kt=function(n){angular.isDefined(n)&&(d=n||"true")},dt=function(n){return angular.isDefined(angular.element(n.target).attr("ng-cancel-drag"))},lt=function(n){if(p&&!dt(n)&&(n.type!="mousedown"||n.button==0))if(ut){v();ot=setTimeout(function(){v();at(n)},100);i.on(b,v);i.on(k,v)}else at(n)},v=function(){clearTimeout(ot);i.off(b,v);i.off(k,v)},at=function(t){if(p){t.preventDefault();w=e[0].getBoundingClientRect();a=it?w:{left:document.body.scrollLeft,top:document.body.scrollTop};e.centerX=e[0].offsetWidth/2;e.centerY=e[0].offsetHeight/2;s=u.inputEvent(t).pageX;h=u.inputEvent(t).pageY;g=s-w.left;nt=h-w.top;d?(c=s-e.centerX-r.pageXOffset,l=h-e.centerY-r.pageYOffset):(c=s-g-r.pageXOffset,l=h-nt-r.pageYOffset);i.on(b,rt);i.on(k,vt);ht=n.$on("draggable:_triggerHandlerMove",function(n,t){rt(t)})}},rt=function(t){p&&(t.preventDefault(),e.hasClass("dragging")||(y=yt(f),e.addClass("dragging"),n.$broadcast("draggable:start",{x:s,y:h,tx:c,ty:l,event:t,element:e,data:y})),s=u.inputEvent(t).pageX,h=u.inputEvent(t).pageY,d?(c=s-e.centerX-a.left,l=h-e.centerY-a.top):(c=s-g-a.left,l=h-nt-a.top),ti(c,l),n.$broadcast("draggable:move",{x:s,y:h,tx:c,ty:l,event:t,element:e,data:y,uid:et}))},vt=function(t){p&&(t.preventDefault(),n.$broadcast("draggable:end",{x:s,y:h,tx:c,ty:l,event:t,element:e,data:y,callback:gt,uid:et}),e.removeClass("dragging"),e.parent().find(".drag-enter").removeClass("drag-enter"),ni(),i.off(b,rt),i.off(k,vt),ht())},gt=function(n){st&&f.$apply(function(){st(f,{$data:y,$event:n})})},ni=function(){it?e.css({transform:"","z-index":"","-webkit-transform":"","-ms-transform":""}):e.css({position:"",top:"",left:""})},ti=function(n,t){it?e.css({transform:"matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, "+n+", "+t+", 0, 1)","z-index":99999,"-webkit-transform":"matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, "+n+", "+t+", 0, 1)","-ms-transform":"matrix(1, 0, 0, 1, "+n+", "+t+")"}):e.css({left:n+"px",top:t+"px",position:"fixed"})};pt()}}}]).directive("ngDrop",["$parse","$timeout","$window","$document","ngDraggable",function(n,t,i,r){return{restrict:"A",link:function(i,u,f){i.value=f.ngDrop;i.isTouching=!1;var o=null,l=i.$id,e=!1,a=n(f.ngDropSuccess),v=n(f.ngDragStart),y=n(f.ngDragStop),p=n(f.ngDragMove),w=function(){c(!0)},c=function(n){n&&(i.$watch(f.ngDrop,k),i.$on("$destroy",b),i.$on("draggable:start",d),i.$on("draggable:move",g),i.$on("draggable:end",nt))},b=function(){c(!1)},k=function(n){e=n},d=function(n,r){e&&(s(r.x,r.y,r.element),f.ngDragStart&&t(function(){v(i,{$data:r.data,$event:r})}))},g=function(n,r){e&&(s(r.x,r.y,r.element),f.ngDragMove&&t(function(){p(i,{$data:r.data,$event:r})}))},nt=function(n,r){if(!e||l===r.uid){h(!1,r.element);return}s(r.x,r.y,r.element)&&(r.callback&&r.callback(r),f.ngDropSuccess&&t(function(){a(i,{$data:r.data,$event:r,$target:i.$eval(i.value)})}));f.ngDragStop&&t(function(){y(i,{$data:r.data,$event:r})});h(!1,r.element)},s=function(n,t,r){var f=tt(n,t);return i.isTouching=f,f&&(o=u),h(f,r),f},h=function(n,t){n?(u.addClass("drag-enter"),t.addClass("drag-over")):o==u&&(o=null,u.removeClass("drag-enter"),t.removeClass("drag-over"))},tt=function(n,t){var i=u[0].getBoundingClientRect();return n-=r[0].body.scrollLeft+r[0].documentElement.scrollLeft,t-=r[0].body.scrollTop+r[0].documentElement.scrollTop,n>=i.left&&n<=i.right&&t<=i.bottom&&t>=i.top};w()}}}]).directive("ngDragClone",["$parse","$timeout","ngDraggable",function(){return{restrict:"A",link:function(n,t){var r,i=!0,u=null;n.clonedData={};var s=function(){r=t.find("img");t.attr("draggable","false");r.attr("draggable","false");f();h(!0)},h=function(t){t&&(n.$on("draggable:start",l),n.$on("draggable:move",a),n.$on("draggable:end",v),c())},c=function(){r.off("mousedown touchstart touchmove touchend touchcancel",o);r.on("mousedown touchstart touchmove touchend touchcancel",o)},l=function(r,f){i=!0;angular.isDefined(f.data.allowClone)&&(i=f.data.allowClone);i&&(n.$apply(function(){n.clonedData=f.data}),t.css("width",f.element[0].offsetWidth),t.css("height",f.element[0].offsetHeight),e(f.tx,f.ty));u=t[0].getBoundingClientRect()},a=function(n,t){i&&(_tx=t.tx+u.left,_ty=t.ty+u.top,e(_tx,_ty))},v=function(){i&&f()},f=function(){t.css({left:0,top:0,position:"fixed","z-index":-1,visibility:"hidden"})},e=function(n,i){t.css({transform:"matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, "+n+", "+i+", 0, 1)","z-index":99999,visibility:"visible","-webkit-transform":"matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, "+n+", "+i+", 0, 1)","-ms-transform":"matrix(1, 0, 0, 1, "+n+", "+i+")"})},o=function(n){var t=n;return t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0,t.returnValue=!1,!1};s()}}}]).directive("ngPreventDrag",["$parse","$timeout",function(){return{restrict:"A",link:function(n,t){var i=function(){t.attr("draggable","false");r(!0)},r=function(n){if(n)t.on("mousedown touchstart touchmove touchend touchcancel",u)},u=function(n){var t=n.originalEvent;return t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0,t.returnValue=!1,!1};i()}}}]).directive("ngCancelDrag",[function(){return{restrict:"A",link:function(n,t){t.find("*").attr("ng-cancel-drag","ng-cancel-drag")}}}]).directive("ngDragScroll",["$window","$interval","$timeout","$document","$rootScope",function(n,t,i,r,u){return{restrict:"A",link:function(t,i,f){var o=null,e={verticalScroll:f.verticalScroll||!0,horizontalScroll:f.horizontalScroll||!0,activationDistance:f.activationDistance||75,scrollDistance:f.scrollDistance||15},h=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(n){window.setTimeout(n,1e3/60)}}(),s=!1,c=function(){function t(n){var i=Array.prototype.slice.call(arguments);s&&h(function(){u.$apply(function(){n.apply(null,i);t(n)})})}s=!0;t(function(){var s,h;if(o){var c=Math.max(document.documentElement.clientWidth,window.innerWidth||0),l=Math.max(document.documentElement.clientHeight,window.innerHeight||0),t=0,f=0;if(e.horizontalScroll&&(o.clientX<e.activationDistance?t=-e.scrollDistance:o.clientX>c-e.activationDistance&&(t=e.scrollDistance)),e.verticalScroll&&(o.clientY<e.activationDistance?f=-e.scrollDistance:o.clientY>l-e.activationDistance&&(f=e.scrollDistance)),t!==0||f!==0){var a=n.pageXOffset||r[0].documentElement.scrollLeft,v=n.pageYOffset||r[0].documentElement.scrollTop,y=i.css("transform");i.css("transform","initial");n.scrollBy(t,f);s=(n.pageXOffset||r[0].documentElement.scrollLeft)-a;h=(n.pageYOffset||r[0].documentElement.scrollTop)-v;i.css("transform",y);o.pageX+=s;o.pageY+=h;u.$emit("draggable:_triggerHandlerMove",o)}}})},l=function(){s=!1};t.$on("draggable:start",function(n,t){t.element[0]===i[0]&&(s||c())});t.$on("draggable:end",function(n,t){t.element[0]===i[0]&&s&&l()});t.$on("draggable:move",function(n,t){t.element[0]===i[0]&&(o=t.event)})}}}]);app.directive("onlyDigits",function(){return{restrict:"A",require:"?ngModel",scope:{maxLength:"@"},link:function(n,t,i,r){r&&r.$parsers.push(function(n){if(n==undefined)return"";var t=n.replace(/[^0-9]/g,"");return t.length>i.maxLength&&(t=t.substr(0,i.maxLength)),t!=n&&(r.$setViewValue(t),r.$render()),t})}}});app.directive("parentheight",["$window",function(n){return{restrict:"A",link:function(t,i){function u(){return r=$(i).parent().height(),i[0].style.height=r-50+"px",r}var f=angular.element(n),r=0;u();f.bind("resize",function(){u();t.$apply()})}}}]);app.directive("mcPlaceholder",[function(){return{restrict:"A",scope:{placeholder:"=mcPlaceholder"},link:function(n,t){n.$watch("placeholder",function(){t[0].placeholder=n.placeholder})}}}]);app.directive("phcresizecol",[function(){return{restrict:"E",replace:!0,template:"<div class='colSplitter' ng-mousedown='beginresize()'><\/div>",scope:{},link:function(n,t,i){function v(n){n.preventDefault()}function y(){h=!0}function p(){h=!1}function w(){}function b(n){var v,t,y,i,a,p;n=n||window.event;h&&(c={x:n.clientX,y:n.clientY},v=r[0].getBoundingClientRect().left,t=c.x-v,u&&(y=r[0].getBoundingClientRect().right,t=y-c.x),t>o&&(t=o),t<s&&(t=s),i=f[0].offsetWidth,u?(a=0,t>e?(a=t-e,i=l-a):t<e&&(a=e-t,i=l+a)):(p=f[0].getBoundingClientRect().right,i=p-t),r.css("width",t+"px"),f.css("width",i+"px"))}var o=i.maxwidth,s=i.minwidth,a=window.innerWidth,u,e,l;o=a/100*o;s=a/100*s;u=!1;i.nextelement=="previous"&&(u=!0);var h=!1,c,r=t.parent(),f=r.next();u?(f=r.prev(),t.css("left",0)):t.css("right",0);t.css("height",r.offsetHeight);e=r[0].offsetWidth;l=f[0].offsetWidth;n.beginresize=function(){y();window.onmousedown=v;window.onmouseup=p;window.onmousemove=b;window.onclick=w}}}}]);app.directive("scrollToTopWhen",[function(){return{restrict:"A",link:function(n,t,i){n.$on(i.scrollToTopWhen,function(){angular.element(t)[0].scrollTop=0})}}}]);app.directive("slidedownup",[function(){return{restrict:"A",scope:{"switch":"="},link:function(n,t,i){var r=$(t),u,f;r.hide();u=400;f=400;i.transin&&(u=parseInt(i.transin));i.transout&&(f=parseInt(i.transout));n.$watch("switch",function(n){n===!0?r.slideDown(u):r.slideUp(f)})}}}]);app.directive("mcTooltip",[function(){return{restrict:"A",scope:{tooltip:"@"},link:function(n,t){function u(){i[0].innerHTML.length!=0&&i.css("display","block")}function r(){i.css("display","none")}t.after("<div class='mctooltip'>"+n.tooltip+"<\/div>");var i=t.next();r();t.on("mouseenter",function(){u()});t.on("mouseleave",function(){r()})}}}]);app.filter("mlctruncate",function(){return function(n,t){if(n)return n.length>t?n.substring(0,t).trim()+"...":n}});mcAutocomplete=angular.module("mcAutocomplete",[]);mcAutocomplete.directive("mcautocomplete",["$timeout",function(n){return{restrict:"EA",template:'<input type="text" maxlength="{{maxlen}}" ng-model="searchText" ng-change="search()" ng-blur="hideList()"><ul class="list-group mclist"><li class="list-group-item" ng-class="{\'focused\' : item.focused}" ng-repeat="item in results" ng-click="selectItem(item.name)">{{item.name}}<\/li><\/ul>',scope:{jsonlist:"=",selectedItem:"=",searchText:"=ngModel",onupdate:"="},link:function(t,i,r){function e(){if(t.results){var i=t.results.length,n=u();n>-1&&n<i-1?(t.results[n].focused=!1,t.results[n+1].focused=!0):n===i-1||(t.results[0].focused=!0);t.$apply()}}function o(){if(t.results){var i=t.results.length,n=u();n===0||n>-1&&n<=i-1&&(t.results[n].focused=!1,t.results[n-1].focused=!0);t.$apply()}}function s(){if(t.results){var n=u(),i=t.results[n];t.selectItem(i.name);t.$apply()}}function u(){for(var n=0;n<t.results.length;n++)if(t.results[n].focused===!0)return n;return-1}function h(){var i,n;if(t.results)for(i=t.results.length,n=0;n<i;++n)t.results[n].focused=!1}function c(n){if(n){var i=t.jsonlist;return i.filter(function(t){return t.name.toLowerCase().indexOf(n.toLowerCase())>-1})}}t.maxlen=r.maxLength?r.maxLength:1e3;var f;t.search=function(){n.cancel(f);f=n(function(){t.results=[];t.results=c(t.searchText);h();e()},500)};t.selectItem=function(n){t.results=[];t.selectedItem=n;t.searchText=n};i.bind("keydown keypress",function(n){switch(n.which){case 13:t.results&&t.results.length>0&&(s(),n.preventDefault());break;case 27:t.results=[];t.$apply();break;case 38:o();break;case 40:e()}});t.hideList=function(){n(function(){t.results=[]},500)}}}}]);accent_map={"ẚ":"a","Á":"a","á":"a","À":"a","à":"a","Ă":"a","ă":"a","Ắ":"a","ắ":"a","Ằ":"a","ằ":"a","Ẵ":"a","ẵ":"a","Ẳ":"a","ẳ":"a","Â":"a","â":"a","Ấ":"a","ấ":"a","Ầ":"a","ầ":"a","Ẫ":"a","ẫ":"a","Ẩ":"a","ẩ":"a","Ǎ":"a","ǎ":"a","Å":"a","å":"a","Ǻ":"a","ǻ":"a","Ä":"a","ä":"a","Ǟ":"a","ǟ":"a","Ã":"a","ã":"a","Ȧ":"a","ȧ":"a","Ǡ":"a","ǡ":"a","Ą":"a","ą":"a","Ā":"a","ā":"a","Ả":"a","ả":"a","Ȁ":"a","ȁ":"a","Ȃ":"a","ȃ":"a","Ạ":"a","ạ":"a","Ặ":"a","ặ":"a","Ậ":"a","ậ":"a","Ḁ":"a","ḁ":"a","Ⱥ":"a","ⱥ":"a","Ǽ":"a","ǽ":"a","Ǣ":"a","ǣ":"a","Ḃ":"b","ḃ":"b","Ḅ":"b","ḅ":"b","Ḇ":"b","ḇ":"b","Ƀ":"b","ƀ":"b","ᵬ":"b","Ɓ":"b","ɓ":"b","Ƃ":"b","ƃ":"b","Ć":"c","ć":"c","Ĉ":"c","ĉ":"c","Č":"c","č":"c","Ċ":"c","ċ":"c","Ç":"c","ç":"c","Ḉ":"c","ḉ":"c","Ȼ":"c","ȼ":"c","Ƈ":"c","ƈ":"c","ɕ":"c","Ď":"d","ď":"d","Ḋ":"d","ḋ":"d","Ḑ":"d","ḑ":"d","Ḍ":"d","ḍ":"d","Ḓ":"d","ḓ":"d","Ḏ":"d","ḏ":"d","Đ":"d","đ":"d","ᵭ":"d","Ɖ":"d","ɖ":"d","Ɗ":"d","ɗ":"d","Ƌ":"d","ƌ":"d","ȡ":"d","ð":"d","É":"e","Ə":"e","Ǝ":"e","ǝ":"e","é":"e","È":"e","è":"e","Ĕ":"e","ĕ":"e","Ê":"e","ê":"e","Ế":"e","ế":"e","Ề":"e","ề":"e","Ễ":"e","ễ":"e","Ể":"e","ể":"e","Ě":"e","ě":"e","Ë":"e","ë":"e","Ẽ":"e","ẽ":"e","Ė":"e","ė":"e","Ȩ":"e","ȩ":"e","Ḝ":"e","ḝ":"e","Ę":"e","ę":"e","Ē":"e","ē":"e","Ḗ":"e","ḗ":"e","Ḕ":"e","ḕ":"e","Ẻ":"e","ẻ":"e","Ȅ":"e","ȅ":"e","Ȇ":"e","ȇ":"e","Ẹ":"e","ẹ":"e","Ệ":"e","ệ":"e","Ḙ":"e","ḙ":"e","Ḛ":"e","ḛ":"e","Ɇ":"e","ɇ":"e","ɚ":"e","ɝ":"e","Ḟ":"f","ḟ":"f","ᵮ":"f","Ƒ":"f","ƒ":"f","Ǵ":"g","ǵ":"g","Ğ":"g","ğ":"g","Ĝ":"g","ĝ":"g","Ǧ":"g","ǧ":"g","Ġ":"g","ġ":"g","Ģ":"g","ģ":"g","Ḡ":"g","ḡ":"g","Ǥ":"g","ǥ":"g","Ɠ":"g","ɠ":"g","Ĥ":"h","ĥ":"h","Ȟ":"h","ȟ":"h","Ḧ":"h","ḧ":"h","Ḣ":"h","ḣ":"h","Ḩ":"h","ḩ":"h","Ḥ":"h","ḥ":"h","Ḫ":"h","ḫ":"h","̱":"h","ẖ":"h","Ħ":"h","ħ":"h","Ⱨ":"h","ⱨ":"h","Í":"i","í":"i","Ì":"i","ì":"i","Ĭ":"i","ĭ":"i","Î":"i","î":"i","Ǐ":"i","ǐ":"i","Ï":"i","ï":"i","Ḯ":"i","ḯ":"i","Ĩ":"i","ĩ":"i","İ":"i",i:"i","Į":"i","į":"i","Ī":"i","ī":"i","Ỉ":"i","ỉ":"i","Ȉ":"i","ȉ":"i","Ȋ":"i","ȋ":"i","Ị":"i","ị":"i","Ḭ":"i","ḭ":"i","ı":"i","Ɨ":"i","ɨ":"i","Ĵ":"j","ĵ":"j","̌":"j","ǰ":"j","ȷ":"j","Ɉ":"j","ɉ":"j","ʝ":"j","ɟ":"j","ʄ":"j","Ḱ":"k","ḱ":"k","Ǩ":"k","ǩ":"k","Ķ":"k","ķ":"k","Ḳ":"k","ḳ":"k","Ḵ":"k","ḵ":"k","Ƙ":"k","ƙ":"k","Ⱪ":"k","ⱪ":"k","Ĺ":"a","ĺ":"l","Ľ":"l","ľ":"l","Ļ":"l","ļ":"l","Ḷ":"l","ḷ":"l","Ḹ":"l","ḹ":"l","Ḽ":"l","ḽ":"l","Ḻ":"l","ḻ":"l","Ł":"l","ł":"l","Ł":"l","̣":"l","ł":"l","̣":"l","Ŀ":"l","ŀ":"l","Ƚ":"l","ƚ":"l","Ⱡ":"l","ⱡ":"l","Ɫ":"l","ɫ":"l","ɬ":"l","ɭ":"l","ȴ":"l","Ḿ":"m","ḿ":"m","Ṁ":"m","ṁ":"m","Ṃ":"m","ṃ":"m","ɱ":"m","Ń":"n","ń":"n","Ǹ":"n","ǹ":"n","Ň":"n","ň":"n","Ñ":"n","ñ":"n","Ṅ":"n","ṅ":"n","Ņ":"n","ņ":"n","Ṇ":"n","ṇ":"n","Ṋ":"n","ṋ":"n","Ṉ":"n","ṉ":"n","Ɲ":"n","ɲ":"n","Ƞ":"n","ƞ":"n","ɳ":"n","ȵ":"n","̈":"n",n:"n","̈":"n","Ó":"o","ó":"o","Ò":"o","ò":"o","Ŏ":"o","ŏ":"o","Ô":"o","ô":"o","Ố":"o","ố":"o","Ồ":"o","ồ":"o","Ỗ":"o","ỗ":"o","Ổ":"o","ổ":"o","Ǒ":"o","ǒ":"o","Ö":"o","ö":"o","Ȫ":"o","ȫ":"o","Ő":"o","ő":"o","Õ":"o","õ":"o","Ṍ":"o","ṍ":"o","Ṏ":"o","ṏ":"o","Ȭ":"o","ȭ":"o","Ȯ":"o","ȯ":"o","Ȱ":"o","ȱ":"o","Ø":"o","ø":"o","Ǿ":"o","ǿ":"o","Ǫ":"o","ǫ":"o","Ǭ":"o","ǭ":"o","Ō":"o","ō":"o","Ṓ":"o","ṓ":"o","Ṑ":"o","ṑ":"o","Ỏ":"o","ỏ":"o","Ȍ":"o","ȍ":"o","Ȏ":"o","ȏ":"o","Ơ":"o","ơ":"o","Ớ":"o","ớ":"o","Ờ":"o","ờ":"o","Ỡ":"o","ỡ":"o","Ở":"o","ở":"o","Ợ":"o","ợ":"o","Ọ":"o","ọ":"o","Ộ":"o","ộ":"o","Ɵ":"o","ɵ":"o","Ṕ":"p","ṕ":"p","Ṗ":"p","ṗ":"p","Ᵽ":"p","Ƥ":"p","ƥ":"p","̃":"p",p:"p","̃":"p","ʠ":"q","Ɋ":"q","ɋ":"q","Ŕ":"r","ŕ":"r","Ř":"r","ř":"r","Ṙ":"r","ṙ":"r","Ŗ":"r","ŗ":"r","Ȑ":"r","ȑ":"r","Ȓ":"r","ȓ":"r","Ṛ":"r","ṛ":"r","Ṝ":"r","ṝ":"r","Ṟ":"r","ṟ":"r","Ɍ":"r","ɍ":"r","ᵲ":"r","ɼ":"r","Ɽ":"r","ɽ":"r","ɾ":"r","ᵳ":"r","ß":"s","Ś":"s","ś":"s","Ṥ":"s","ṥ":"s","Ŝ":"s","ŝ":"s","Š":"s","š":"s","Ṧ":"s","ṧ":"s","Ṡ":"s","ṡ":"s","ẛ":"s","Ş":"s","ş":"s","Ṣ":"s","ṣ":"s","Ṩ":"s","ṩ":"s","Ș":"s","ș":"s","ʂ":"s","̩":"s",s:"s","̩":"s","Þ":"t","þ":"t","Ť":"t","ť":"t","̈":"t","ẗ":"t","Ṫ":"t","ṫ":"t","Ţ":"t","ţ":"t","Ṭ":"t","ṭ":"t","Ț":"t","ț":"t","Ṱ":"t","ṱ":"t","Ṯ":"t","ṯ":"t","Ŧ":"t","ŧ":"t","Ⱦ":"t","ⱦ":"t","ᵵ":"t","ƫ":"t","Ƭ":"t","ƭ":"t","Ʈ":"t","ʈ":"t","ȶ":"t","Ú":"u","ú":"u","Ù":"u","ù":"u","Ŭ":"u","ŭ":"u","Û":"u","û":"u","Ǔ":"u","ǔ":"u","Ů":"u","ů":"u","Ü":"u","ü":"u","Ǘ":"u","ǘ":"u","Ǜ":"u","ǜ":"u","Ǚ":"u","ǚ":"u","Ǖ":"u","ǖ":"u","Ű":"u","ű":"u","Ũ":"u","ũ":"u","Ṹ":"u","ṹ":"u","Ų":"u","ų":"u","Ū":"u","ū":"u","Ṻ":"u","ṻ":"u","Ủ":"u","ủ":"u","Ȕ":"u","ȕ":"u","Ȗ":"u","ȗ":"u","Ư":"u","ư":"u","Ứ":"u","ứ":"u","Ừ":"u","ừ":"u","Ữ":"u","ữ":"u","Ử":"u","ử":"u","Ự":"u","ự":"u","Ụ":"u","ụ":"u","Ṳ":"u","ṳ":"u","Ṷ":"u","ṷ":"u","Ṵ":"u","ṵ":"u","Ʉ":"u","ʉ":"u","Ṽ":"v","ṽ":"v","Ṿ":"v","ṿ":"v","Ʋ":"v","ʋ":"v","Ẃ":"w","ẃ":"w","Ẁ":"w","ẁ":"w","Ŵ":"w","ŵ":"w","̊":"w","ẘ":"w","Ẅ":"w","ẅ":"w","Ẇ":"w","ẇ":"w","Ẉ":"w","ẉ":"w","Ẍ":"x","ẍ":"x","Ẋ":"x","ẋ":"x","Ý":"y","ý":"y","Ỳ":"y","ỳ":"y","Ŷ":"y","ŷ":"y","̊":"y","ẙ":"y","Ÿ":"y","ÿ":"y","Ỹ":"y","ỹ":"y","Ẏ":"y","ẏ":"y","Ȳ":"y","ȳ":"y","Ỷ":"y","ỷ":"y","Ỵ":"y","ỵ":"y","ʏ":"y","Ɏ":"y","ɏ":"y","Ƴ":"y","ƴ":"y","Ź":"z","ź":"z","Ẑ":"z","ẑ":"z","Ž":"z","ž":"z","Ż":"z","ż":"z","Ẓ":"z","ẓ":"z","Ẕ":"z","ẕ":"z","Ƶ":"z","ƶ":"z","Ȥ":"z","ȥ":"z","ʐ":"z","ʑ":"z","Ⱬ":"z","ⱬ":"z","Ǯ":"z","ǯ":"z","ƺ":"z","２":"2","６":"6","Ｂ":"B","Ｆ":"F","Ｊ":"J","Ｎ":"N","Ｒ":"R","Ｖ":"V","Ｚ":"Z","ｂ":"b","ｆ":"f","ｊ":"j","ｎ":"n","ｒ":"r","ｖ":"v","ｚ":"z","１":"1","５":"5","９":"9","Ａ":"A","Ｅ":"E","Ｉ":"I","Ｍ":"M","Ｑ":"Q","Ｕ":"U","Ｙ":"Y","ａ":"a","ｅ":"e","ｉ":"i","ｍ":"m","ｑ":"q","ｕ":"u","ｙ":"y","０":"0","４":"4","８":"8","Ｄ":"D","Ｈ":"H","Ｌ":"L","Ｐ":"P","Ｔ":"T","Ｘ":"X","ｄ":"d","ｈ":"h","ｌ":"l","ｐ":"p","ｔ":"t","ｘ":"x","３":"3","７":"7","Ｃ":"C","Ｇ":"G","Ｋ":"K","Ｏ":"O","Ｓ":"S","Ｗ":"W","ｃ":"c","ｇ":"g","ｋ":"k","ｏ":"o","ｓ":"s","ｗ":"w"};accent_fold=function(){function n(n){var i,t;if(!n)return"";for(i="",t=0;t<n.length;t++)i+=accent_map[n.charAt(t)]||n.charAt(t);return i}return{fold:n}}()