示例#1
0
        protected override void TakeFormAction()
        {
            var currentActvity = CurrentActivity();

            if (currentActvity.CurrAction.FormDataProcessing.IsSaveRequestData)
            {
                if (WorkflowInstance.Treatment != null)
                {
                    var  treatment = WorkflowInstance.Treatment;
                    bool isUpdate  = false;

                    if (RequestHeader.Id > 0)
                    {
                        var currentTreatment = _treatmentRepository.GetByRequestHeader(RequestHeader.Id);
                        if (currentTreatment != null)
                        {
                            currentTreatment.RequestHeaderId  = treatment.RequestHeaderId;
                            currentTreatment.FitToWork        = treatment.FitToWork;
                            currentTreatment.TimeArrived      = treatment.TimeArrived;
                            currentTreatment.TimeDeparted     = treatment.TimeDeparted;
                            currentTreatment.CheckOutDateTime = treatment.TimeDeparted; // treatment.CheckOutDateTime;
                            currentTreatment.Days             = (treatment.FitToWork == 0) ? treatment.Days : null;
                            currentTreatment.Remark           = (treatment.FitToWork == 0) ? treatment.Remark : string.Empty;
                            currentTreatment.Symptom          = treatment.Symptom;
                            currentTreatment.Diagnosis        = treatment.Diagnosis;
                            currentTreatment.Hours            = (treatment.FitToWork == 1) ? treatment.Hours : null;
                            currentTreatment.Comment          = treatment.Comment;
                            currentTreatment.WorkShift        = treatment.WorkShift;

                            _treatmentRepository.Update(currentTreatment);
                            treatment.RequestHeaderId = RequestHeader.Id;
                            isUpdate = true;
                        }
                    }

                    if (!isUpdate)
                    {
                        WorkflowInstance.Treatment.RequestHeaderId = RequestHeader.Id;
                        _treatmentRepository.Add(treatment);
                    }

                    if (treatment.FitToWork == 0)
                    {
                        ProcessUnfitToWorkData(WorkflowInstance.AddUnfitToWorks, DataOP.AddNew, RequestHeader);
                        ProcessUnfitToWorkData(WorkflowInstance.EditUnfitToWorks, DataOP.EDIT, RequestHeader);
                        ProcessUnfitToWorkData(WorkflowInstance.DelUnfitToWorks, DataOP.DEL, RequestHeader);

                        if (RequestHeader != null && RequestHeader.Id > 0)
                        {
                            _treatmentRepository.UpdateDayLeave(RequestHeader.Id);
                        }
                    }
                    else if (treatment.FitToWork == 1)
                    {
                        if (RequestHeader != null && RequestHeader.Id > 0)
                        {
                            _treatmentRepository.DeleteUniftTW(RequestHeader.Id);
                        }
                    }
                    else if (treatment.FitToWork == 1)
                    {
                        if (RequestHeader != null && RequestHeader.Id > 0)
                        {
                            _treatmentRepository.DeleteUniftTW(RequestHeader.Id);
                        }
                    }

                    // Process transaction data for request items
                    ProcessPrescriptionData(WorkflowInstance.AddPrescriptions, DataOP.AddNew, treatment);
                    ProcessPrescriptionData(WorkflowInstance.EditPrescriptions, DataOP.EDIT, treatment);
                    ProcessPrescriptionData(WorkflowInstance.DelPrescriptions, DataOP.DEL, treatment);

                    if (FORM_SUBMISSION.IsCaseInsensitiveEqual(CurrentActivity().ActivityName))
                    {
                        WorkflowInstance.Message = string.Format("Your request number is @FOLIO. <br/>{0}", _treatmentRepository.GetPendingTreamentMessage());
                    }
                }
                else
                {
                    throw new Exception("Medical treatment form has no request instance");
                }
            }
        }