Пример #1
0
    protected void btnSumbit_click(object sender, EventArgs e)
    {
        try
        {
            #region Unable to decode referral id, try finding original referral based on email address
            if (badReferralId)
            {
                try
                {
                    Referral badRef = new Referral(email_address.Text);
                    if (badRef.id > 0)
                    {
                        referralid = badRef.id;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    logService.LogAppEvent("", @"HarperNET", "Referral", "Unable to link email to referral id (id could not be decoded and email not on file). Using default referrer. Referral id in url: " + Request["ReferralId"] + ", email address entered: " + email_address.Text, ex.Message, ex.StackTrace, "", "Page_Load");

                    Referral defaultReferral = new Referral();
                    defaultReferral.keycode = "POTRIAL";
                    defaultReferral.pubcode = "PO";
                    ReferralOffer offer = new ReferralOffer(defaultReferral.keycode, defaultReferral.pubcode);

                    defaultReferral.ccmember    = false;
                    defaultReferral.datecreated = DateTime.Now;
                    defaultReferral.dateexpires = defaultReferral.datecreated.AddMonths(offer.offerexpiresmonths);
                    defaultReferral.friendemail = email_address.Text;
                    defaultReferral.friendname  = first_name.Text + " " + last_name.Text;

                    HarperLINQ.tbl_Customer defaultReferrer = new tbl_Customer(ConfigurationManager.AppSettings["default_referrer_username"], true);
                    defaultReferral.memberid           = defaultReferrer.cusID;
                    defaultReferral.subscriptionlength = offer.triallengthinmonths;

                    defaultReferral.Save();
                    referralid = defaultReferral.id;
                }
            }
            #endregion

            HarperMembershipService.BaseResponse      response   = new HarperMembershipService.BaseResponse();
            HarperMembershipService.MembershipService webservice = new HarperMembershipService.MembershipService();

            #region Get selected region
            country = ddlCountries.SelectedValue;
            ISO3166 iso            = new ISO3166(country, IdentifierType.Country_Code_Alpha2);
            string  sfgcountrycode = iso.SFGCode;

            if (txtRegion.Text != "" && txtRegion.Text != null)
            {
                region = txtRegion.Text;
            }
            else if (txtRegionNotListed.Text != "" && txtRegionNotListed.Text != null)
            {
                region = txtRegionNotListed.Text;
            }
            else
            {
                region = ddlRegion.SelectedValue;
            }
            #endregion

            string erefid = Cryptography.EncryptData(referralid.ToString());
            string epwd   = Cryptography.EncryptData(txtPassword.Text);

            #region Redeem the referral
            response = webservice.RedeemReferral(erefid, first_name.Text, last_name.Text, email_address.Text,
                                                 sfgcountrycode, address_line_1.Text, address_line_2.Text, city.Text, region, postal.Text, true,
                                                 txtUserName.Text, epwd);
            #endregion

            #region Check for errors
            if (response == null)
            {
                throw new Exception(string.Format("Error redeeming referral id {0}, response from SFG was null.", referralid));
            }
            if (response.Messages != null && response.Messages.Count() > 0)
            {
                throw new Exception(response.Messages[0].AhMessage);
            }
            #endregion

            Response.Redirect("~/Referral/RedemptionConfirmation.aspx", false);
        }
        catch (Exception ex)
        {
            logService.LogAppEvent("", @"HarperNET", "Referral", "Error in btnSumbit_click", ex.Message, ex.StackTrace, "", "btnSubmit_click");
            LiteralControl err = new LiteralControl();
            err.Text = "<p class=\"error-message\">An error has occurred.  Please contact the membership department at <a href=\"mailto:[email protected]\">[email protected]</a></p>";
            lblErrorMessage.Controls.Add(err);
            lblErrorMessage.Visible = true;
        }
    }
Пример #2
0
        public BaseResponse CreateReferral(string cusid, string membername, string memberemail, string keycode,
                                           string pubcode, string friendname, string friendemailaddress, bool ccmember)
        {
            methodName = "CreateReferral";

            List <Message> errors   = new List <Message>();
            Referral       referral = new Referral();

            try
            {
                tbl_Customer member = new tbl_Customer(int.Parse(cusid), false);

                #region validate input
                if (member == null)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.memberDoesNotExistError, cusid, "", null));
                }
                if (member.SfgId == null)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.invalidMemberIdError, "", "", null));
                }
                if (string.IsNullOrEmpty(membername))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingMemberNameError, "", "", null));
                }
                if (ccmember && string.IsNullOrEmpty(memberemail))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingMemberEmailError, "", "", null));
                }
                if (string.IsNullOrEmpty(keycode))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingKeycodeError, "", "", null));
                }
                if (string.IsNullOrEmpty(pubcode))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingPubcodeError, "", "", null));
                }
                if (string.IsNullOrEmpty(friendname))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingFriendNameError, "", "", null));
                }
                if (string.IsNullOrEmpty(friendemailaddress))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingFriendEmailError, "", "", null));
                }
                #endregion

                #region enforce business rules
                tbl_Customer friend = new tbl_Customer(friendemailaddress, false);
                try
                {
                    Referral existing_referral = new Referral(friendemailaddress);

                    if (memberemail == friendemailaddress)
                    {
                        errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.cannotReferSelfError, "", "", null));
                    }
                    else if (friend.cusID > 0)
                    {
                        errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.existingMemberError, "", "", null));
                    }
                    else if (existing_referral.dateredeemed == null)
                    {
                        if (existing_referral.id > 0 && existing_referral.dateexpires.CompareTo(DateTime.Now) >= 0)
                        {
                            errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.existingReferralError, "", "", null));
                        }
                    }
                    if (errors.Count <= 0)
                    {
                        GetMemberResponse checkFriend = (GetMemberByUserName(friendemailaddress).TypedResponse as GetMemberResponse);
                        if (checkFriend != null && (checkFriend.MemberFound || checkFriend.WebAccountFound))
                        {
                            errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.freindEmailInUseSFGError, "", "", null));
                        }
                    }
                }
                catch (HarperLINQ.DataLoadException dle)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.freindEmailInUseAHError, "", "", null));
                }
                if (errors.Count() > 0)
                {
                    string errstring = string.Empty;
                    foreach (Message msg in errors)
                    {
                        string sfgmessages = string.Empty;
                        if (msg.SfgMessages != null)
                        {
                            foreach (string sfgmsg in msg.SfgMessages)
                            {
                                sfgmessages += string.Format("SFGMessage: {0}", sfgmsg);
                            }
                        }
                        errstring += string.Format("AhMessage: {0}|| {1}", new object[] { msg.AhMessage, sfgmessages });
                    }
                    throw new Exception(string.Format("Error creating referral: [{0}]", errstring));
                }
                #endregion

                ReferralOffer offer = new ReferralOffer(keycode, pubcode);


                #region save referral
                referral = new Referral(int.Parse(cusid), membername, memberemail, keycode, pubcode, friendname, friendemailaddress, ccmember, offer.triallengthinmonths, offer.offerexpiresmonths);
                referral.Save();
                #endregion

                #region send email
                //create mailer and sent mail
                Mailer mailer = new Mailer();

                string ccEmail = memberemail;

                if (!ccmember)
                {
                    ccEmail = string.Empty;
                }

                mailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                                 ConfigurationManager.AppSettings["mailservicepwd"],
                                 string.Format("Membership Invitation from {0}", membername),
                                 ConfigurationManager.AppSettings["referemailfrom"],
                                 friendemailaddress,
                                 ccEmail,
                                 string.Empty,
                                 referral.GetReferralEmailBody(),
                                 true,
                                 ConfigurationManager.AppSettings["smtpserver"]);
                #endregion
            }
            catch (Exception ex)
            {
                LogMethodError(methodName, ex);
            }
            if (baseResponse != null && baseResponse.Messages != null)
            {
                foreach (Message error in errors)
                {
                    baseResponse.Messages.Add(error);
                }
            }
            if (baseResponse.Messages.Count() <= 0 && referral != null && referral.id >= 0)
            {
                #region create typed response
                baseResponse.TypedResponse         = new ReferralResponse();
                baseResponse.TypedResponse.Success = true;
                (baseResponse.TypedResponse as ReferralResponse).referralid = referral.id;
                #endregion
            }
            else
            {
                baseResponse.TypedResponse         = new ReferralResponse();
                baseResponse.TypedResponse.Success = false;
            }

            return(baseResponse);
        }
        public IActionResult RegisterVisit()
        {
            Users user = new Users {
                Id = Int64.Parse(HttpContext.User.FindFirst(ClaimTypes.Actor).Value)
            };
            Patient patient = VisitModel.Visit.Patient;

            patient.Status = new PatientStatus
            {
                Id = Constants.STATUS_ACTIVE
            };
            patient.UpdateStatus();

            Encounter encounter = new Encounter
            {
                Type = new EncounterType {
                    Id = Constants.ENCOUNTER_VISIT
                },
                Patient   = patient,
                CreatedBy = user
            };

            encounter.Create(IPatientService);

            Visit visit = VisitModel.Visit;

            visit.Type = new VisitType {
                Id = Constants.VISIT_FACILITY
            };
            visit.CreatedBy = user;
            visit.CreatedOn = DateTime.Now;
            visit.Save();

            Referral referral = VisitModel.Referral;

            if (!referral.Type.Id.Equals(0))
            {
                referral.Visit     = visit;
                referral.CreatedBy = user;
                referral.Save();

                var      seps    = new string[] { "," };
                string[] doctors = VisitModel.DoctorString.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                foreach (string doc in doctors)
                {
                    new ReferralDoctors
                    {
                        Referral = referral,
                        Doctor   = new Doctor {
                            Id = Convert.ToInt64(doc)
                        }
                    }.Save();
                }
            }

            Bills bill = VisitModel.Bill;

            bill.Visit     = visit;
            bill.CreatedBy = user;
            bill.Save();

            if (VisitModel.Waiver)
            {
                bill.Waiver       = bill.Amount;
                bill.WaiverReason = VisitModel.WaiverReason;
                bill.WaivedBy     = user;
                bill.UpdateWaiver();

                bill.Flag = new BillsFlag {
                    Id = 1
                };
                bill.ProcessedBy = user;
                bill.UpdateProcess();
            }

            BillsItem item = VisitModel.Item;

            item.Bill      = bill;
            item.CreatedBy = user;
            item.Save();

            Queues queue = VisitModel.Queue;

            queue.Bill      = bill;
            queue.CreatedBy = user;
            queue.Save();

            return(LocalRedirect("/registration/search"));
        }
Пример #4
0
        public IActionResult RegisterVisit()
        {
            Users user = new Users {
                Id = Int64.Parse(HttpContext.User.FindFirst(ClaimTypes.Actor).Value)
            };
            Patient patient = VisitModel.Visit.Patient;

            patient.Status = new PatientStatus
            {
                Id = Constants.STATUS_ACTIVE
            };
            patient.UpdateStatus();

            Encounter encounter = new Encounter
            {
                Type = new EncounterType {
                    Id = Constants.ENCOUNTER_VISIT
                },
                Patient   = patient,
                CreatedBy = user
            };

            encounter.Create(IPatientService);

            Visit visit = VisitModel.Visit;

            visit.Type = new VisitType {
                Id = Constants.VISIT_FACILITY
            };
            visit.CreatedBy = user;
            visit.CreatedOn = DateTime.Now;
            visit.Save();

            Referral referral = VisitModel.Referral;

            if (!referral.Type.Id.Equals(0))
            {
                referral.Visit     = visit;
                referral.CreatedBy = user;
                referral.Save();

                var      seps    = new string[] { "," };
                string[] doctors = VisitModel.DoctorString.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                foreach (string doc in doctors)
                {
                    new ReferralDoctors
                    {
                        Referral = referral,
                        Doctor   = new Doctor {
                            Id = Convert.ToInt64(doc)
                        }
                    }.Save();
                }
            }

            Bills bill = VisitModel.Bill;

            bill.Visit      = visit;
            bill.Department = new Department {
                Id = Constants.DEPT_REGISTRATION
            };
            bill.CreatedBy = user;
            bill.Save();

            if (VisitModel.Waiver)
            {
                bill.Waiver       = bill.Amount;
                bill.WaiverReason = VisitModel.WaiverReason;
                bill.WaivedBy     = user;
                bill.UpdateWaiver();

                bill.Flag = new BillingFlag {
                    Id = Constants.FLAG_CLEARED
                };
                bill.ProcessedBy = user;
                bill.UpdateProcess();
            }

            BillsItem item = VisitModel.Item;

            item.Bill      = bill;
            item.CreatedBy = user;
            item.Save();

            //INVOICE/FLAG/CLEAR
            if (VisitModel.Waiver)
            {
                Invoice invoice = new Invoice {
                    Patient = patient,
                    Flag    = new BillingFlag {
                        Id = Constants.FLAG_CLEARED
                    },
                    CreatedBy = user,
                    Notes     = "Waivered Bill"
                };
                invoice.Save();

                InvoiceDetails details = new InvoiceDetails {
                    Invoice   = invoice,
                    Item      = item,
                    CreatedBy = user,
                    Notes     = "Waivered Item"
                };
                details.Save();

                InvoicePayment payment = new InvoicePayment {
                    Invoice   = invoice,
                    CreatedBy = user,
                    Notes     = "Waiver Payment"
                };
                payment.Save();

                InvoicePaymentDetails pd = new InvoicePaymentDetails {
                    Mode = new BillingMode {
                        Id = Constants.MODE_WAIVER
                    },
                    Reference = "CASHIER-00",
                    Amount    = bill.Amount,
                    Notes     = "Waiver Payment"
                };
                pd.Save();
            }

            Queues queue = VisitModel.Queue;

            queue.Visit     = visit;
            queue.Item      = item;
            queue.CreatedBy = user;
            queue.Save();

            return(LocalRedirect("/registration/search"));
        }