Esempio n. 1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5CO_CBH_1606 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_BIL_BillHeader billHeader = null;
            ORM_BIL_BillHeader_2_BillStatus billHeader2BillStatus  = null;
            ORM_CMN_UniversalContactDetail  universalContactDetail = null;

            var BillParam = Parameter.Bill_Parameter.BillHeaderData;

            #region Preloading data

            ORM_USR_Account account = new ORM_USR_Account();
            account.Load(Connection, Transaction, securityTicket.AccountID);
            var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction,
                                                                 new ORM_CMN_BPT_CTM_Customer.Query()
            {
                CMN_BPT_CTM_CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID
            }).SingleOrDefault();

            List <L3ACAAD_GCAfT_1612> customerAddresses = cls_Get_CustomerAddresses_for_CustomerID.Invoke(Connection, Transaction, new P_L3ACAAD_GCAfCID_1612 {
                CustomerID = BillParam.BillingReceiverCustomer.CMN_BPT_CTM_CustomerID
            }, securityTicket).Result.ToList();
            L3ACAAD_GCAfT_1612 customerAddress = customerAddresses.Where(x => x.AddressID == BillParam.BillingAddressID).SingleOrDefault();

            var incrNumberParam = new P_L2NR_GaIINfUA_1454()
            {
                GlobalStaticMatchingID = EnumUtils.GetEnumDescription(ENumberRangeUsageAreaType.BillNumber)
            };
            var billNumber = cls_Get_and_Increase_IncreasingNumber_for_UsageArea.Invoke(Connection, Transaction, incrNumberParam, securityTicket).Result.Current_IncreasingNumber;

            #endregion

            #region Universal Contact Detail

            universalContactDetail = new ORM_CMN_UniversalContactDetail()
            {
                CMN_UniversalContactDetailID = Guid.NewGuid(),
                Country_639_1_ISOCode        = customerAddress.Country_639_1_ISOCode,
                Country_Name      = customerAddress.Country_Name,
                Street_Name       = customerAddress.Street_Name,
                Street_Number     = customerAddress.Street_Number,
                Town              = customerAddress.Town,
                ZIP               = customerAddress.ZIP,
                Tenant_RefID      = account.Tenant_RefID,
                CompanyName_Line1 = BillParam.BillingReceiverCustomer.DisplayName,
                First_Name        = BillParam.BillingReceiverCustomer.FirstName,
                Last_Name         = BillParam.BillingReceiverCustomer.LastName,
                IsCompany         = BillParam.BillingReceiverCustomer.IsCompany
            };
            universalContactDetail.Save(Connection, Transaction);
            #endregion

            #region Bill Header

            billHeader = new ORM_BIL_BillHeader
            {
                BIL_BillHeaderID = Guid.NewGuid(),
                BillNumber       = billNumber,
                CreatedBy_BusinessParticipant_RefID     = account.BusinessParticipant_RefID,
                BillRecipient_BuisnessParticipant_RefID = customer.Ext_BusinessParticipant_RefID,
                TotalValue_BeforeTax     = 0,
                TotalValue_IncludingTax  = 0,
                BillingAddress_UCD_RefID = universalContactDetail.CMN_UniversalContactDetailID,
                DateOnBill     = BillParam.BillingDate,
                BillComment    = BillParam.Comment,
                Currency_RefID = cls_Get_DefaultCurrency_for_Tenant.Invoke(Connection, Transaction, securityTicket).Result.CMN_CurrencyID,
                BillHeader_PaymentCondition_RefID = Parameter.Bill_Parameter.BillHeaderData.PaymentTargetID,
                Tenant_RefID = securityTicket.TenantID
            };

            billHeader.Save(Connection, Transaction);

            #endregion

            #region Method of Payment

            var methodOfPayment = new CL1_BIL.ORM_BIL_BillHeader_MethodOfPayment
            {
                BIL_BillHeader_MethodOfPaymentID = Guid.NewGuid(),
                ACC_PAY_Type_RefID         = Parameter.Bill_Parameter.BillHeaderData.PaymentTypeID,
                BIL_BillHeader_RefID       = billHeader.BIL_BillHeaderID,
                IsPreferredMethodOfPayment = true,
                SequenceNumber             = 0,
                Tenant_RefID = securityTicket.TenantID
            };
            methodOfPayment.Save(Connection, Transaction);

            #endregion

            #region Bill Status - Created

            var statusCreated = ORM_BIL_BillStatus.Query.Search(Connection, Transaction,
                                                                new ORM_BIL_BillStatus.Query()
            {
                GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EBillStatus.Created),
                Tenant_RefID             = account.Tenant_RefID,
                IsDeleted = false
            }).Single();

            billHeader2BillStatus = new ORM_BIL_BillHeader_2_BillStatus
            {
                AssignmentID         = Guid.NewGuid(),
                BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID,
                BIL_BillStatus_RefID = statusCreated.BIL_BillStatusID,
                Tenant_RefID         = account.Tenant_RefID,
                IsCurrentStatus      = true
            };
            billHeader2BillStatus.Save(Connection, Transaction);

            #endregion

            returnValue.Result = billHeader.BIL_BillHeaderID;
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 2
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5BL_DBH_1332 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            #region Retreve Bill Header

            var billHeader = new ORM_BIL_BillHeader();
            billHeader.Load(Connection, Transaction, Parameter.BillHeaderID);

            #endregion

            returnValue.Result = billHeader.BIL_BillHeaderID;

            #region Delete Bill Positions for Bill Header

            // Retrieve bill positions for bill header.
            var billPositions = ORM_BIL_BillPosition.Query.Search(Connection, Transaction,
                                                                  new ORM_BIL_BillPosition.Query
            {
                BIL_BilHeader_RefID = billHeader.BIL_BillHeaderID,
                Tenant_RefID        = securityTicket.TenantID,
                IsDeleted           = false
            });

            foreach (var billPosition in billPositions)
            {
                // Delete relationship between BillPositions and CustomerOrderPositions in Assignment table.
                var billPos2CusPoss = ORM_BIL_BillPosition_2_ShipmentPosition.Query.SoftDelete(Connection, Transaction,
                                                                                               new ORM_BIL_BillPosition_2_ShipmentPosition.Query
                {
                    BIL_BillPosition_RefID = billPosition.BIL_BillPositionID,
                    Tenant_RefID           = securityTicket.TenantID,
                    IsDeleted = false
                });

                CL1_BIL.ORM_BIL_BillPosition_2_CustomerOrderReturnPosition.Query.SoftDelete(Connection, Transaction,
                                                                                            new CL1_BIL.ORM_BIL_BillPosition_2_CustomerOrderReturnPosition.Query
                {
                    BIL_BillPosition_RefID = billPosition.BIL_BillPositionID,
                    Tenant_RefID           = securityTicket.TenantID,
                    IsDeleted = false
                });

                billPosition.IsDeleted = true;
                billPosition.Save(Connection, Transaction);
            }

            #endregion

            #region Delete Bill Header's statuses

            // Delete all statuses for Bill header
            var billHeader2Statuses = ORM_BIL_BillHeader_2_BillStatus.Query.SoftDelete(Connection, Transaction,
                                                                                       new ORM_BIL_BillHeader_2_BillStatus.Query
            {
                BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID,
                Tenant_RefID         = securityTicket.TenantID,
                IsDeleted            = false
            });

            #endregion

            #region Delete Bill Header

            billHeader.IsDeleted = true;
            billHeader.Save(Connection, Transaction);

            #endregion

            return(returnValue);

            #endregion UserCode
        }
Esempio n. 3
0
        protected static FR_CAS_SPE_1805 Execute(DbConnection Connection, DbTransaction Transaction, P_CAS_SPE_1805 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_CAS_SPE_1805();
            returnValue.Result = new CAS_SPE_1805();
            //Put your code here
            var case_id = Parameter.case_id;

            #region DATA
            var patient_details = cls_Get_Patient_Details_for_PatientID.Invoke(Connection, Transaction, new P_P_PA_GPDfPID_1124()
            {
                PatientID = Parameter.patient_id
            }, securityTicket).Result;
            if (patient_details == null)
            {
                throw new Exception("Patient details not found for ID: " + Parameter.patient_id);
            }

            var doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, new ORM_HEC_Doctor.Query()
            {
                Tenant_RefID = securityTicket.TenantID, HEC_DoctorID = Parameter.doctor_id, IsDeleted = false
            }).SingleOrDefault();
            if (doctor == null)
            {
                throw new Exception("Doctor not found for ID: " + Parameter.doctor_id);
            }


            var doctor_details = cls_Get_Doctor_Details_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDDfDID_0823()
            {
                DoctorID = Parameter.doctor_id
            }, securityTicket).Result.FirstOrDefault();

            if (doctor_details == null)
            {
                throw new Exception("Doctor details not found for ID: " + Parameter.doctor_id);
            }

            var practice_details = cls_Get_Practice_Details_for_PracticeID.Invoke(Connection, Transaction, new P_DO_GPDfPID_1432()
            {
                PracticeID = doctor_details.practice_id
            }, securityTicket).Result.FirstOrDefault();
            if (practice_details == null)
            {
                throw new Exception("Practice details not found for ID: " + doctor_details.practice_id);
            }

            var shouldDownloadReportProperty = cls_Get_Practice_PropertyValue_for_PropertyName_and_PracticeID.Invoke(Connection, Transaction, new P_DO_GPPVfPNaPID_0916()
            {
                PracticeID = doctor_details.practice_id, PropertyName = "Download Report Upon Submission"
            }, securityTicket).Result;
            var shouldDownloadReport = shouldDownloadReportProperty == null ? false : shouldDownloadReportProperty.BooleanValue;

            ORM_USR_Account.Query trigger_accQ = new ORM_USR_Account.Query();
            trigger_accQ.Tenant_RefID  = securityTicket.TenantID;
            trigger_accQ.USR_AccountID = securityTicket.AccountID;
            trigger_accQ.IsDeleted     = false;

            ORM_USR_Account trigger_acc = ORM_USR_Account.Query.Search(Connection, Transaction, trigger_accQ).Single();

            ORM_CMN_Language.Query all_languagesQ = new ORM_CMN_Language.Query();
            all_languagesQ.Tenant_RefID = securityTicket.TenantID;
            all_languagesQ.IsDeleted    = false;

            var all_languagesL           = ORM_CMN_Language.Query.Search(Connection, Transaction, all_languagesQ).ToArray();
            var intraocular_procedure_id = Guid.Empty;
            #endregion

            if (!Parameter.isResubmit)
            {
                #region NEW CASE
                ORM_HEC_CAS_Case new_case = new ORM_HEC_CAS_Case();
                new_case.HEC_CAS_CaseID     = Guid.NewGuid();
                new_case.Creation_Timestamp = DateTime.Now;
                new_case.CreatedBy_BusinessParticipant_RefID = trigger_acc.BusinessParticipant_RefID;
                new_case.Patient_RefID          = Parameter.patient_id;
                new_case.Patient_FirstName      = patient_details.patient_first_name;
                new_case.Patient_LastName       = patient_details.patient_last_name;
                new_case.Patient_Gender         = patient_details.gender;
                new_case.Patient_BirthDate      = patient_details.birthday;
                new_case.CaseNumber             = cls_Get_Next_Case_Number.Invoke(Connection, Transaction, securityTicket).Result.case_number;
                new_case.Modification_Timestamp = DateTime.Now;

                DateTime today = DateTime.Today;
                int      age   = today.Year - patient_details.birthday.Year;
                if (patient_details.birthday > today.AddYears(-age))
                {
                    age--;
                }

                new_case.Patient_Age  = age;
                new_case.Tenant_RefID = securityTicket.TenantID;

                new_case.Save(Connection, Transaction);
                case_id = new_case.HEC_CAS_CaseID;
                #endregion NEW CASE

                #region INITIAL PERFORMED ACTION
                var initial_performed_action_id = cls_Create_Initial_Performed_Action.Invoke(Connection, Transaction, new P_CAS_CIPA_1140()
                {
                    all_languagesL    = all_languagesL,
                    case_id           = new_case.HEC_CAS_CaseID,
                    created_by_bpt    = trigger_acc.BusinessParticipant_RefID,
                    patient_id        = Parameter.patient_id,
                    practice_id       = doctor_details.practice_id,
                    action_type_gpmid = "mm.docconect.doc.app.performed.action.preexamination"
                }, securityTicket).Result;
                #endregion INITIAL PERFORMED ACTION

                #region LOCALIZATION
                ORM_HEC_DIA_Diagnosis_Localization diagnosis_localization = new ORM_HEC_DIA_Diagnosis_Localization();
                diagnosis_localization.Modification_Timestamp = DateTime.Now;
                diagnosis_localization.Tenant_RefID           = securityTicket.TenantID;
                diagnosis_localization.LocalizationCode       = Parameter.localization;

                diagnosis_localization.Save(Connection, Transaction);

                ORM_HEC_ACT_PerformedAction_DiagnosisUpdate initial_performed_action_diagnose = new ORM_HEC_ACT_PerformedAction_DiagnosisUpdate();
                initial_performed_action_diagnose.HEC_ACT_PerformedAction_RefID = initial_performed_action_id;
                initial_performed_action_diagnose.Modification_Timestamp        = DateTime.Now;
                initial_performed_action_diagnose.Tenant_RefID = securityTicket.TenantID;

                initial_performed_action_diagnose.Save(Connection, Transaction);

                ORM_HEC_ACT_PerformedAction_DiagnosisUpdate_Localization initial_performed_action_diagnose_localization = new ORM_HEC_ACT_PerformedAction_DiagnosisUpdate_Localization();
                initial_performed_action_diagnose_localization.HEX_EXC_Action_DiagnosisUpdate_RefID = initial_performed_action_diagnose.HEC_ACT_PerformedAction_DiagnosisUpdateID;
                initial_performed_action_diagnose_localization.HEC_DIA_Diagnosis_Localization_RefID = diagnosis_localization.HEC_DIA_Diagnosis_LocalizationID;
                initial_performed_action_diagnose_localization.Modification_Timestamp = DateTime.Now;
                initial_performed_action_diagnose_localization.Tenant_RefID           = securityTicket.TenantID;
                initial_performed_action_diagnose_localization.IM_PotentialDiagnosisLocalization_Code = Parameter.localization;

                initial_performed_action_diagnose_localization.Save(Connection, Transaction);
                #endregion

                #region PLANNED ACTION
                var action_gpmid = "mm.docconect.doc.app.planned.action.preexamination";

                var planned_action_type = ORM_HEC_ACT_ActionType.Query.Search(Connection, Transaction, new ORM_HEC_ACT_ActionType.Query()
                {
                    GlobalPropertyMatchingID = action_gpmid,
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted = false
                }).SingleOrDefault();

                if (planned_action_type == null)
                {
                    planned_action_type = new ORM_HEC_ACT_ActionType();
                    planned_action_type.GlobalPropertyMatchingID = action_gpmid;
                    planned_action_type.Modification_Timestamp   = DateTime.Now;
                    planned_action_type.Tenant_RefID             = securityTicket.TenantID;

                    planned_action_type.Save(Connection, Transaction);
                }

                // circular reference to same performed action in order to be compatible with treatment planned actions,
                // so that it can be accessed in the same way
                var preexamination_planned_action = new ORM_HEC_ACT_PlannedAction();
                preexamination_planned_action.IfPlannedFollowup_PreviousAction_RefID = initial_performed_action_id;
                preexamination_planned_action.IsPerformed = true;
                preexamination_planned_action.IfPerformed_PerformedAction_RefID = initial_performed_action_id;
                preexamination_planned_action.MedicalPractice_RefID             = doctor_details.practice_id;
                preexamination_planned_action.Modification_Timestamp            = DateTime.Now;
                preexamination_planned_action.Patient_RefID   = Parameter.patient_id;
                preexamination_planned_action.PlannedFor_Date = Parameter.date;
                preexamination_planned_action.ToBePerformedBy_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID;
                preexamination_planned_action.Tenant_RefID = securityTicket.TenantID;

                preexamination_planned_action.Save(Connection, Transaction);

                var action_to_type = new ORM_HEC_ACT_PlannedAction_2_ActionType();
                action_to_type.HEC_ACT_ActionType_RefID    = planned_action_type.HEC_ACT_ActionTypeID;
                action_to_type.HEC_ACT_PlannedAction_RefID = preexamination_planned_action.HEC_ACT_PlannedActionID;
                action_to_type.Modification_Timestamp      = DateTime.Now;
                action_to_type.Tenant_RefID = securityTicket.TenantID;

                action_to_type.Save(Connection, Transaction);
                #endregion

                #region GPOS
                var patient_consent = ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient.Query.Search(Connection, Transaction, new ORM_HEC_CRT_InsuranceToBrokerContract_ParticipatingPatient.Query()
                {
                    Patient_RefID = Parameter.patient_id,
                    IsDeleted     = false,
                    Tenant_RefID  = securityTicket.TenantID
                }).Where(t =>
                {
                    var ctrParameter = cls_Get_Contract_Parameter_Value_for_InsuranceToBrokerContractID.Invoke(Connection, Transaction, new P_MD_GCPVfITBCID_1647()
                    {
                        ParameterName = "Duration of participation consent – Month",
                        InsuranceToBrokerContractID = t.InsuranceToBrokerContract_RefID
                    }, securityTicket).Result;

                    var validThrough = ctrParameter == null || ctrParameter.ConsentValidForMonths == double.MaxValue ? DateTime.MaxValue : t.ValidFrom.AddMonths(Convert.ToInt32(ctrParameter.ConsentValidForMonths));
                    return(t.ValidFrom <= Parameter.date && validThrough >= Parameter.date);
                }).OrderBy(t => t.ValidFrom).FirstOrDefault();

                if (patient_consent == null)
                {
                    throw new Exception("No patients consents found for selected date: " + Parameter.date.ToString("dd.MM.yyyy") + " and  patient id: " + Parameter.patient_id);
                }


                var gpos_gpmid = "mm.docconnect.gpos.catalog.voruntersuchung";
                var preexamination_gpos_catalog = ORM_HEC_BIL_PotentialCode_Catalog.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode_Catalog.Query()
                {
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted                = false,
                    GlobalPropertyMatchingID = gpos_gpmid
                }).SingleOrDefault();

                if (preexamination_gpos_catalog == null)
                {
                    throw new Exception("Preexamination catalog not found.");
                }

                var gpos_connections_to_drugs = ORM_HEC_BIL_PotentialCode_2_HealthcareProduct.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode_2_HealthcareProduct.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).GroupBy(t => t.HEC_BIL_PotentialCode_RefID);

                var gpos_connections_to_diagnoses = ORM_HEC_BIL_PotentialCode_2_PotentialDiagnosis.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode_2_PotentialDiagnosis.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).GroupBy(t => t.HEC_BIL_PotentialCode_RefID);

                var preexamination_gposes = ORM_HEC_BIL_PotentialCode.Query.Search(Connection, Transaction, new ORM_HEC_BIL_PotentialCode.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    PotentialCode_Catalog_RefID = preexamination_gpos_catalog.HEC_BIL_PotentialCode_CatalogID
                });

                var covered_gposes = ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCode.Query.Search(Connection, Transaction, new ORM_HEC_CTR_InsuranceToBrokerContracts_CoveredPotentialBillCode.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false,
                    InsuranceToBrokerContract_RefID = patient_consent.InsuranceToBrokerContract_RefID
                });

                preexamination_gposes = preexamination_gposes.Where(t => covered_gposes.Any(c => c.PotentialBillCode_RefID == t.HEC_BIL_PotentialCodeID)).ToList();

                var bill_header = new ORM_BIL_BillHeader();
                bill_header.Modification_Timestamp = DateTime.Now;
                bill_header.Tenant_RefID           = securityTicket.TenantID;

                foreach (var gpos in preexamination_gposes)
                {
                    if (!gpos_connections_to_diagnoses.Any(t => t.Key == gpos.HEC_BIL_PotentialCodeID) && !gpos_connections_to_drugs.Any(t => t.Key == gpos.HEC_BIL_PotentialCodeID))
                    {
                        var price_value = ORM_CMN_Price_Value.Query.Search(Connection, Transaction, new ORM_CMN_Price_Value.Query()
                        {
                            Price_RefID = gpos.Price_RefID, IsDeleted = false, Tenant_RefID = securityTicket.TenantID
                        }).SingleOrDefault();
                        if (price_value == null)
                        {
                            throw new Exception("Price value not found for GPOS: " + gpos.BillingCode);
                        }

                        ORM_BIL_BillPosition gpos_position = new ORM_BIL_BillPosition();
                        gpos_position.BIL_BilHeader_RefID        = bill_header.BIL_BillHeaderID;
                        gpos_position.Modification_Timestamp     = DateTime.Now;
                        gpos_position.Tenant_RefID               = securityTicket.TenantID;
                        gpos_position.PositionValue_IncludingTax = Convert.ToDecimal(price_value.PriceValue_Amount);
                        gpos_position.PositionNumber             = cls_Get_Next_Bill_Position_Number.Invoke(Connection, Transaction, securityTicket).Result.bill_position_number;

                        gpos_position.Save(Connection, Transaction);

                        ORM_BIL_BillPosition_TransmitionStatus fs_status = new ORM_BIL_BillPosition_TransmitionStatus();
                        fs_status.BillPosition_RefID     = gpos_position.BIL_BillPositionID;
                        fs_status.IsActive               = true;
                        fs_status.Modification_Timestamp = DateTime.Now;
                        fs_status.Tenant_RefID           = securityTicket.TenantID;
                        fs_status.TransmitionCode        = 1;
                        fs_status.TransmitionStatusKey   = "preexamination";
                        fs_status.TransmittedOnDate      = DateTime.Now;

                        fs_status.Save(Connection, Transaction);

                        ORM_HEC_BIL_BillPosition hec_gpos_position = new ORM_HEC_BIL_BillPosition();
                        hec_gpos_position.Ext_BIL_BillPosition_RefID = gpos_position.BIL_BillPositionID;
                        hec_gpos_position.Modification_Timestamp     = DateTime.Now;
                        hec_gpos_position.Tenant_RefID = securityTicket.TenantID;
                        hec_gpos_position.PositionFor_Patient_RefID = Parameter.patient_id;

                        hec_gpos_position.Save(Connection, Transaction);

                        ORM_HEC_BIL_BillPosition_BillCode hec_gpos_position_code = new ORM_HEC_BIL_BillPosition_BillCode();
                        hec_gpos_position_code.BillPosition_RefID     = hec_gpos_position.HEC_BIL_BillPositionID;
                        hec_gpos_position_code.IM_BillingCode         = gpos.BillingCode;
                        hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                        hec_gpos_position_code.PotentialCode_RefID    = gpos.HEC_BIL_PotentialCodeID;
                        hec_gpos_position_code.Tenant_RefID           = securityTicket.TenantID;

                        hec_gpos_position_code.Save(Connection, Transaction);

                        ORM_HEC_CAS_Case_BillCode hec_gpos_case_code = new ORM_HEC_CAS_Case_BillCode();
                        hec_gpos_case_code.HEC_BIL_BillPosition_BillCode_RefID = hec_gpos_position_code.HEC_BIL_BillPosition_BillCodeID;
                        hec_gpos_case_code.HEC_CAS_Case_RefID     = new_case.HEC_CAS_CaseID;
                        hec_gpos_case_code.Modification_Timestamp = DateTime.Now;
                        hec_gpos_case_code.Tenant_RefID           = securityTicket.TenantID;

                        hec_gpos_case_code.Save(Connection, Transaction);

                        ORM_BIL_BillPosition_PropertyValue gpos_management_fee_property_value = new ORM_BIL_BillPosition_PropertyValue();
                        gpos_management_fee_property_value.BIL_BillPosition_RefID           = gpos_position.BIL_BillPositionID;
                        gpos_management_fee_property_value.BIL_BillPosition_PropertyValueID = Guid.NewGuid();
                        gpos_management_fee_property_value.Creation_Timestamp     = DateTime.Now;
                        gpos_management_fee_property_value.Modification_Timestamp = DateTime.Now;
                        gpos_management_fee_property_value.PropertyKey            = "mm.doc.connect.management.fee";
                        gpos_management_fee_property_value.PropertyValue          = "waived";
                        gpos_management_fee_property_value.Tenant_RefID           = securityTicket.TenantID;

                        gpos_management_fee_property_value.Save(Connection, Transaction);

                        bill_header.TotalValue_IncludingTax += Convert.ToDecimal(price_value.PriceValue_Amount);
                    }
                }

                bill_header.Save(Connection, Transaction);
                #endregion
            }

            return(returnValue);

            #endregion UserCode
        }
Esempio n. 4
0
        protected static FR_L6TR_BT_2204 Execute(DbConnection Connection, DbTransaction Transaction, P_L6TR_BT_2204 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L6TR_BT_2204();
            returnValue.Result = new L6TR_BT_2204();
            ORM_BIL_BillHeader header     = new ORM_BIL_BillHeader();
            long previousMaxPositionIndex = Parameter.previousMaxPositionIndex;

            #region persistHeader

            if (Parameter.isNewBilling)
            {
                header.Tenant_RefID     = securityTicket.TenantID;
                header.BIL_BillHeaderID = Guid.NewGuid();

                var tenantHeaders = ORM_BIL_BillHeader.Query.Search(Connection, Transaction, new ORM_BIL_BillHeader.Query()
                {
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).ToArray();
                tenantHeaders = tenantHeaders.OrderBy(t => t.Creation_Timestamp).ToArray();
                var headersForThisYear = tenantHeaders.Where(h => h.Creation_Timestamp.Year == DateTime.Now.Year).ToArray();

                int prevMaxHeaderNumber = 0;
                if (headersForThisYear.Length > 0)
                {
                    ORM_BIL_BillHeader prevHeader = null;
                    foreach (var headerTY in headersForThisYear)
                    {
                        int hn = 0;
                        if (int.TryParse(headerTY.BillNumber, out hn) && prevMaxHeaderNumber <= hn)
                        {
                            prevMaxHeaderNumber = hn;
                            prevHeader          = headerTY;
                        }
                    }

                    if (prevHeader != null)
                    {
                        var positionQuery = new ORM_BIL_BillPosition.Query();
                        positionQuery.Tenant_RefID        = securityTicket.TenantID;
                        positionQuery.BIL_BilHeader_RefID = prevHeader.BIL_BillHeaderID;
                        var prevPositions = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, positionQuery).ToArray();
                        if (prevPositions != null && prevPositions.Length > 0)
                        {
                            foreach (var prevPosition in prevPositions)
                            {
                                long number = 0;
                                if (long.TryParse(prevPosition.External_PositionReferenceField, out number) && previousMaxPositionIndex < number)
                                {
                                    previousMaxPositionIndex = number;
                                }
                            }
                        }
                    }
                }
                header.BillNumber = prevMaxHeaderNumber + 1 + "";
                if (Parameter.billTreatments)
                {
                    header.Save(Connection, Transaction);
                }
            }
            else
            {
                header.Tenant_RefID     = securityTicket.TenantID;
                header.BIL_BillHeaderID = Parameter.ifOldBillingHeaderID;
                header.BillNumber       = Parameter.ifOldBillingHeaderNumber;
            }

            //new edifact entry
            ORM_BIL_BillHeaderExtension_EDIFACT.Query edifactQuery = new ORM_BIL_BillHeaderExtension_EDIFACT.Query();
            edifactQuery.Tenant_RefID = securityTicket.TenantID;
            var edifactRes = ORM_BIL_BillHeaderExtension_EDIFACT.Query.Search(Connection, Transaction, edifactQuery);
            edifactRes = edifactRes.Where(e => e.Creation_Timestamp.Year == DateTime.Now.Year).ToList();
            ORM_BIL_BillHeaderExtension_EDIFACT edifact = new ORM_BIL_BillHeaderExtension_EDIFACT();
            edifact.BIL_BillHeader_RefID = header.BIL_BillHeaderID;
            edifact.BIL_BillHeaderExtension_EDIFACTID = Guid.NewGuid();
            edifact.EDIFACTCounter = edifactRes.Count + 1;
            edifact.Tenant_RefID   = securityTicket.TenantID;
            if (Parameter.billTreatments)
            {
                edifact.Save(Connection, Transaction);
            }
            #endregion

            //positions
            List <L6TR_BT_2204_Position> positions          = new List <L6TR_BT_2204_Position>();
            List <Guid>             patientsIDlist          = new List <Guid>();
            Dictionary <Guid, Guid> treatment2patient       = new Dictionary <Guid, Guid>();
            Dictionary <Guid, int>  positionCountPerPatient = new Dictionary <Guid, int>();

            foreach (var id in Parameter.TreatmentID_List)
            {
                var item = new ORM_HEC_Patient_Treatment();
                item.Load(Connection, Transaction, id);
                if (item.IsTreatmentFollowup)
                {
                    throw new Exception("This treatment, ID: " + id + ", is followup!");
                }
                var patient2treatmentQuery = new ORM_HEC_Patient_2_PatientTreatment.Query();
                patient2treatmentQuery.Tenant_RefID = securityTicket.TenantID;
                patient2treatmentQuery.HEC_Patient_Treatment_RefID = id;
                var patient2treatmentRes = ORM_HEC_Patient_2_PatientTreatment.Query.Search(Connection, Transaction, patient2treatmentQuery).First();
                if (!patientsIDlist.Contains(patient2treatmentRes.HEC_Patient_RefID))
                {
                    patientsIDlist.Add(patient2treatmentRes.HEC_Patient_RefID);
                }
                treatment2patient.Add(id, patient2treatmentRes.HEC_Patient_RefID);

                if (!positionCountPerPatient.ContainsKey(patient2treatmentRes.HEC_Patient_RefID))
                {
                    positionCountPerPatient.Add(patient2treatmentRes.HEC_Patient_RefID, 0);
                }
            }

            //log.Debug("first loop finished after: " + sw.ElapsedMilliseconds);

            P_L6PA_GPBIfPID_1155 patParam = new P_L6PA_GPBIfPID_1155();
            patParam.PatientID = patientsIDlist.ToArray();
            var patients = cls_Get_PatientBillInfo_for_PatientID.Invoke(Connection, Transaction, patParam, securityTicket).Result;

            P_L6TR_GTaRDfBIbT_1204 tretParam = new P_L6TR_GTaRDfBIbT_1204();
            tretParam.TreatmentID = Parameter.TreatmentID_List;
            var treatments = cls_Get_Treatment_and_RelevantDiagnosis_for_BillInfo_by_TreatmentID.Invoke(Connection, Transaction, tretParam, securityTicket).Result;

            List <Guid> followTretIDs = new List <Guid>();
            if (treatments != null)
            {
                foreach (var t in treatments)
                {
                    followTretIDs.Add(t.HEC_Patient_TreatmentID);
                }
            }
            P_L6TR_GFTfRbIDs_1646 followParam = new P_L6TR_GFTfRbIDs_1646();
            followParam.TreatmentIDs = followTretIDs.ToArray();
            var followups = cls_Get_Followups_for_Report_byIDs.Invoke(Connection, Transaction, followParam, securityTicket).Result;

            ///counter bill
            P_L5TR_GTCfPID_1152 tcParam = new P_L5TR_GTCfPID_1152();
            tcParam.PatientID = patientsIDlist.ToArray();
            var tretRes = cls_Get_TreatmentCount_for_PatientIDlist.Invoke(Connection, Transaction, tcParam, securityTicket).Result;

            int i = 1;
            foreach (var id in Parameter.TreatmentID_List)
            {
                #region collectPositionDataForReport

                var patient = patients.FirstOrDefault(p => p.HEC_PatientID == treatment2patient[id]);
                if (patient == null)
                {
                    //throw new Exception("No patient for ID: " + treatment2patient[id]);
                }
                var treatment = treatments.FirstOrDefault(t => t.HEC_Patient_TreatmentID == id);
                if (treatment == null)
                {
                    throw new Exception("No treatment for ID: " + id);
                }

                var followupsForThisThreatment = followups.Where(f => f.IfTreatmentFollowup_FromTreatment_RefID == treatment.HEC_Patient_TreatmentID).ToArray();

                #region changeFlag
                if (Parameter.billTreatments)
                {
                    var item = new ORM_HEC_Patient_Treatment();
                    item.Load(Connection, Transaction, id);
                    item.IsTreatmentBilled      = true;
                    item.IfTreatmentBilled_Date = DateTime.Now;
                    item.Save(Connection, Transaction);
                }
                #endregion

                #region persistPosition
                ORM_BIL_BillPosition position = new ORM_BIL_BillPosition();
                position.Tenant_RefID        = securityTicket.TenantID;
                position.PositionIndex       = i;
                position.BIL_BilHeader_RefID = header.BIL_BillHeaderID;
                position.BIL_BillPositionID  = Guid.NewGuid();
                if (Parameter.billTreatments)
                {
                    position.Save(Connection, Transaction);
                }

                ORM_BIL_BillPosition_2_PatientTreatment p2t = new ORM_BIL_BillPosition_2_PatientTreatment();
                p2t.AssignmentID                = Guid.NewGuid();
                p2t.Tenant_RefID                = securityTicket.TenantID;
                p2t.BIL_BillPosition_RefID      = position.BIL_BillPositionID;
                p2t.HEC_Patient_Treatment_RefID = treatment.HEC_Patient_TreatmentID;
                if (Parameter.billTreatments)
                {
                    p2t.Save(Connection, Transaction);
                }
                #endregion

                ORM_HEC_Doctor doctor = new ORM_HEC_Doctor();
                if (treatment.IfTreatmentPerformed_ByDoctor_RefID != Guid.Empty)
                {
                    var doctorQuery = new ORM_HEC_Doctor.Query();
                    doctorQuery.HEC_DoctorID = treatment.IfTreatmentPerformed_ByDoctor_RefID;
                    doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).FirstOrDefault();
                }

                var practiceQuery = new ORM_HEC_MedicalPractis.Query();
                practiceQuery.HEC_MedicalPractiseID = treatment.TreatmentPractice_RefID;
                practiceQuery.Tenant_RefID          = securityTicket.TenantID;
                var    practice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practiceQuery).FirstOrDefault();
                string BSNR     = "x";
                if (practice != null)
                {
                    var practiceInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
                    practiceInfoQuery.CMN_COM_CompanyInfoID = practice.Ext_CompanyInfo_RefID;
                    practiceInfoQuery.Tenant_RefID          = securityTicket.TenantID;
                    var practiceInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, practiceInfoQuery).First();
                    BSNR = practiceInfo.CompanyInfo_EstablishmentNumber;
                }

                L6TR_BT_2204_Position pos = new L6TR_BT_2204_Position();
                pos.ORM_BIL_BillPositionID = position.BIL_BillPositionID;
                pos.strDoctorLANR          = (doctor != null) ? doctor.DoctorIDNumber : "HEC_Doctor is null!!!!";
                pos.TreatmentID            = treatment.HEC_Patient_TreatmentID;
                pos.bTreatmentIsFollowup   = treatment.IsTreatmentFollowup;
                pos.strPracticeBSNR        = BSNR;
                pos.dtTreatment            = treatment.IfTreatmentPerformed_Date;

                if (patient != null)
                {
                    pos.iTreatmentNumber       = tretRes.FirstOrDefault(t => t.HEC_PatientID == patient.HEC_PatientID).treatmentCount + positionCountPerPatient[treatment2patient[id]];
                    pos.iPatientSex            = patient.Gender;
                    pos.iPatientInsuranceState = (patient.InsuranceStateCode != null) ? patient.InsuranceStateCode : String.Empty;
                    pos.dtPatientBirthDate     = patient.Birthdate;
                    pos.PatientFirstName       = patient.FirstName;
                    pos.PatientLastName        = patient.LastName;
                    pos.PatientInsuranceNumber = (patient.HealthInsurance_Number != null) ? patient.HealthInsurance_Number : String.Empty;
                }
                else
                {
                    pos.iTreatmentNumber       = -1;
                    pos.iPatientSex            = 0;
                    pos.iPatientInsuranceState = "xxxxx";
                    pos.dtPatientBirthDate     = DateTime.MinValue;
                    pos.PatientFirstName       = "x";
                    pos.PatientLastName        = "x";
                    pos.PatientInsuranceNumber = "x";
                }

                pos.cTreatmentLocalization = (treatment.IsTreatmentOfLeftEye) ? "L" : "R";
                pos.strFollowupPractice    = "-";
                pos.strFollowupDoctor      = "-";
                pos.strFollowupStatus      = "Keine Nachuntersuchung geplant.";
                if (followupsForThisThreatment != null && followupsForThisThreatment.Length > 0)
                {
                    var performedF = followupsForThisThreatment.Where(f => f.IsTreatmentPerformed == true).ToArray();
                    if (performedF != null && performedF.Length > 0)
                    {
                        performedF = performedF.OrderBy(f => f.IfTreatmentPerformed_Date).ToArray();
                        var firstPF = performedF.First();
                        pos.strFollowupDoctor   = firstPF.DoctorFirstName + " " + firstPF.DoctorLastname;
                        pos.dtFollowup          = firstPF.IfTreatmentPerformed_Date;
                        pos.strFollowupPractice = firstPF.DisplayName;
                        pos.strFollowupStatus   = (firstPF.IsTreatmentPerformed) ? "durchgeführt" : "geplant";
                    }
                    else
                    {
                        var scheduledF = followupsForThisThreatment.Where(f => f.IsScheduled == true).ToArray();
                        if (scheduledF != null && scheduledF.Length > 0)
                        {
                            scheduledF = scheduledF.OrderBy(f => f.IfSheduled_Date).ToArray();
                            var firstSF = scheduledF.First();
                            pos.strFollowupDoctor   = firstSF.DoctorFirstName + " " + firstSF.DoctorLastname;
                            pos.dtFollowup          = firstSF.IfTreatmentPerformed_Date;
                            pos.strFollowupPractice = firstSF.DisplayName;
                            pos.strFollowupStatus   = (firstSF.IsTreatmentPerformed) ? "durchgeführt" : "geplant";
                        }
                    }
                }

                var articles = new List <L6TR_BT_2204_ArticleInfo>();
                foreach (var art in treatment.Article)
                {
                    var article = new L6TR_BT_2204_ArticleInfo();
                    article.ArticleID = art.CMN_PRO_ProductID;
                    article.Name      = art.Product_Name;
                    article.PZN       = art.Product_Number;
                    article.Quantity  = art.Quantity;
                    articles.Add(article);
                }
                pos.ArticleInfo = articles.ToArray();

                var diagnosies = new List <L6TR_BT_2204_DiagnosisInfo>();
                foreach (var diag in treatment.RelevantDiagnosis)
                {
                    var diagnose = new L6TR_BT_2204_DiagnosisInfo();
                    diagnose.cDiagnosisState       = diag.DiagnosisState_Abbreviation;
                    diagnose.DiagnosisID           = diag.HEC_Patient_Treatment_RelevantDiagnosisID;
                    diagnose.strDiagnosisICD10     = diag.ICD10_Code;
                    diagnose.PatientInsuranceState = diag.DiagnosisState_Name;
                    diagnosies.Add(diagnose);
                }
                pos.DiagnosisInfo = diagnosies.ToArray();
                positions.Add(pos);
                #endregion

                positionCountPerPatient[treatment2patient[id]] = positionCountPerPatient[treatment2patient[id]] + 1;
                i++;
            }

            returnValue.Result.Positions                = positions.ToArray();
            returnValue.Result.EDIFACTCounter           = edifact.EDIFACTCounter;
            returnValue.Result.HeaderNumber             = header.BillNumber;
            returnValue.Result.HeaderID                 = header.BIL_BillHeaderID;
            returnValue.Result.previousMaxPositionIndex = previousMaxPositionIndex;
            return(returnValue);

            #endregion UserCode
        }
Esempio n. 5
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L6TR_MRDfTre_1300 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode

            FR_Base returnValue = new FR_Base();
            returnValue.Status = FR_Status.Error_Internal;

            List <Converter> listOfConvertesForEdifactFiles = new List <Converter>();

            string excelFileName = string.Empty;
            Guid   headerID      = Guid.Empty;

            List <ExcelOutput> allExcelData = new List <ExcelOutput>();

            L6TR_GTBDpHICfID_1130 collectedData = null;
            if (Parameter.IsTreatment)
            {
                collectedData = cls_Get_TreatmentBillingData_per_HICompany_byIDs.Invoke(Connection, Transaction, new P_L6TR_GTBDpHICfID_1130()
                {
                    TreatmentID_List = Parameter.TreatmentID_List
                }, securityTicket).Result;
            }
            else
            {
                collectedData = cls_Get_FollowupBillingData_per_HICompany_byIDs.Invoke(Connection, Transaction, new P_L6TR_GFBDpHICfID_1412()
                {
                    TreatmentID_List = Parameter.TreatmentID_List
                }, securityTicket).Result.Data;
            }

            #region HeaderNum
            var tenantHeaders = ORM_BIL_BillHeader.Query.Search(Connection, Transaction, new ORM_BIL_BillHeader.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).ToArray();
            tenantHeaders = tenantHeaders.OrderBy(t => t.Creation_Timestamp).ToArray();
            //var headersForThisYear = tenantHeaders.Where(h => h.Creation_Timestamp.Year == DateTime.Now.Year).ToArray(); // This was when we needed to restart the numbers at the end of each year
            var headersForThisYear = tenantHeaders;

            int  prevMaxHeaderNumber      = 0;
            long previousMaxPositionIndex = 0;
            if (headersForThisYear.Length > 0)
            {
                ORM_BIL_BillHeader prevHeader = null;
                foreach (var headerTY in headersForThisYear)
                {
                    int hn = 0;
                    if (int.TryParse(headerTY.BillNumber, out hn) && prevMaxHeaderNumber <= hn)
                    {
                        prevMaxHeaderNumber = hn;
                        prevHeader          = headerTY;
                    }
                }


                if (prevHeader != null)
                {
                    var positionQuery = new ORM_BIL_BillPosition.Query();
                    positionQuery.Tenant_RefID        = securityTicket.TenantID;
                    positionQuery.BIL_BilHeader_RefID = prevHeader.BIL_BillHeaderID;
                    var prevPositions = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, positionQuery).ToArray();
                    if (prevPositions != null && prevPositions.Length > 0)
                    {
                        foreach (var prevPosition in prevPositions)
                        {
                            long number = 0;
                            if (long.TryParse(prevPosition.External_PositionReferenceField, out number) && previousMaxPositionIndex < number)
                            {
                                previousMaxPositionIndex = number;
                            }
                        }
                    }
                }
            }
            var edifactRes = ORM_BIL_BillHeaderExtension_EDIFACT.Query.Search(Connection, Transaction, new ORM_BIL_BillHeaderExtension_EDIFACT.Query()
            {
                Tenant_RefID = securityTicket.TenantID
            });
            #endregion

            int  currentEdifatNumber      = edifactRes.Where(e => e.Creation_Timestamp.Year == DateTime.Now.Year).Count() + 1;
            int  currentHeaderNumber      = prevMaxHeaderNumber + 1;
            long currentMaxPositionNumber = previousMaxPositionIndex;

            if (Parameter.IsBilling)
            {
                ORM_BIL_BillHeader header = new ORM_BIL_BillHeader();
                header.Tenant_RefID     = securityTicket.TenantID;
                header.BIL_BillHeaderID = Guid.NewGuid();
                header.BillNumber       = currentHeaderNumber.ToString();
                header.Save(Connection, Transaction);
                headerID = header.BIL_BillHeaderID;
            }

            foreach (var dataPerCompany in collectedData.HICompanies)
            {
                List <BillingInfo> listBInfo = new List <BillingInfo>();
                foreach (var pos in dataPerCompany.Positions)
                {
                    List <ArticleInfo>   articleList   = new List <ArticleInfo>();
                    List <DiagnosisInfo> diagnosisList = new List <DiagnosisInfo>();

                    foreach (var art in pos.ArticleInfos)
                    {
                        articleList.Add(new ArticleInfo(art.ArticleID.ToString(), art.Name.GetContent(Parameter.LanguageID), art.PZN, Convert.ToInt32(art.Quantity)));
                    }

                    foreach (var diag in pos.DiagnosisInfos)
                    {
                        diagnosisList.Add(new DiagnosisInfo(diag.strDiagnosisICD10, diag.cDiagnosisState.ToCharArray()[0]));
                    }

                    listBInfo.Add(new BillingInfo(
                                      !pos.bTreatmentIsFollowup ? pos.TreatmentID.ToString() : pos.FollowupID.ToString(),
                                      pos.iPatientInsuranceState,
                                      pos.PatientInsuranceNumber,
                                      pos.iPatientSex,
                                      pos.PatientFirstName,
                                      pos.PatientLastName,
                                      pos.dtPatientBirthDate,
                                      pos.strDoctorLANR,
                                      pos.strPracticeBSNR,
                                      diagnosisList,
                                      pos.cTreatmentLocalization.ToCharArray()[0],
                                      pos.bTreatmentIsFollowup,
                                      pos.iTreatmentNumber,
                                      articleList,
                                      pos.dtTreatment,
                                      pos.strFollowupPractice,
                                      pos.strFollowupDoctor,
                                      pos.strFollowupStatus,
                                      pos.dtFollowup));
                }

                Converter converter = new Converter(currentEdifatNumber, currentHeaderNumber, currentMaxPositionNumber,
                                                    dataPerCompany.Positions.OrderBy(p => p.dtTreatment).First().dtTreatment, dataPerCompany.Positions.OrderBy(p => p.dtTreatment).Last().dtTreatment,
                                                    listBInfo, dataPerCompany.HealthInsurance_Number, false);

                listOfConvertesForEdifactFiles.Add(converter);
                var excelData = converter.getExcel();

                if (excelFileName == string.Empty)
                {
                    excelFileName = converter.getExcelFilename();
                }

                allExcelData.AddRange(excelData);

                #region  Save GPOS, charged value, Additional position compensation, Relevant article and article quantity (if is billing)
                if (Parameter.IsBilling)
                {
                    var persistParam = new P_L6TR_PBD_1706()
                    {
                        EdifactNumber = currentEdifatNumber,
                        HeaderID      = headerID,
                        OutputData    = excelData.ToArray()
                    };
                    cls_Persist_TreatmentsBillData.Invoke(Connection, Transaction, persistParam, securityTicket);
                }
                #endregion

                currentEdifatNumber++;
                currentMaxPositionNumber = excelData.Max(e => e.iProcessNumber);
            }

            List <String>       LANR = allExcelData.Select(x => x.strDoctorLANR).ToList();
            P_L5DO_GDDfLfR_1409 parameterDoctorData = new P_L5DO_GDDfLfR_1409();
            parameterDoctorData.LANR = LANR.ToArray();
            List <L5DO_GDDfLfR_1409> doctorData = cls_Get_DoctorData_for_LANR_for_Reports.Invoke(Connection, Transaction, parameterDoctorData, securityTicket).Result.ToList();

            List <Attachment> atts = new List <Attachment>();
            string            file = ReportUtils.generateBillTreatmentsXLS(allExcelData, doctorData);

            MemoryStream ms = new MemoryStream(File.ReadAllBytes(file));
            atts.Add(new System.Net.Mail.Attachment(ms, excelFileName));

            foreach (var converter in listOfConvertesForEdifactFiles)
            {
                var edifact = converter.getEdifact();

                var tempFilePath = Path.GetTempFileName();
                using (System.IO.StreamWriter tempFile = new System.IO.StreamWriter(tempFilePath, true))
                {
                    tempFile.Write(converter.getAuf(1));
                }
                long tempFileSize = 0;
                if (File.Exists(tempFilePath))
                {
                    FileInfo fi = new FileInfo(tempFilePath);
                    tempFileSize = fi.Length;
                    fi.Delete();
                }
                atts.Add(Attachment.CreateAttachmentFromString(edifact, converter.getEdifactFilename()));
                atts.Add(Attachment.CreateAttachmentFromString(converter.getAuf(tempFileSize), converter.getAufFilename()));
            }

            string[] toMails;
            string   mailRes = (String)HttpContext.GetGlobalResourceObject("Global", "ReportMails");
#if DEBUG
            mailRes = (String)HttpContext.GetGlobalResourceObject("Global", "ReportMailsDebug");
#endif
            toMails = mailRes.Split(';');
            string subjectRes = (String)HttpContext.GetGlobalResourceObject("Global", "ReportMailSubject");

            EmailUtils.SendMail(toMails, subjectRes, "", atts);



            // @Laci, ako budes se prebacivao na thread odkomentarisi ovaj kod ispod

            //Thread emailThread = new Thread(() =>
            //{
            //    IEmail acceptEmail = EmailFactory.BasicEmail();
            //    acceptEmail.sendMailNotifier(toMails.ToList(), subjectRes, "", atts);
            //});
            //emailThread.Start();

            returnValue.Status = FR_Status.Success;

            return(returnValue);

            #endregion UserCode
        }