protected static FR_MD_GAIwPID_1629 Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_MD_GAIwPID_1629();
            returnValue.Result = new MD_GAIwPID_1629();
            returnValue.Result.AccountInformation = new MD_GAI_1617();

            var data = cls_Get_Account_Information.Invoke(Connection, Transaction, securityTicket).Result;
            returnValue.Result.AccountInformation = data;

            if (data.group_id == "mm.docconect.doc.app.group")
            {
                var is_doctor = !data.role.Contains("practice");


                if (is_doctor)
                {
                    var medical_practice = cls_Get_PracticeID_for_Doctor_BusinessParticipantID.Invoke(Connection, Transaction, new P_CAS_GPIDfDBPTID_1205()
                    {
                        BusinessParticipantID = data.CMN_BPT_BusinessParticipantID
                    }, securityTicket).Result;
                    var hec_doctorQuery = new ORM_HEC_Doctor.Query();
                    hec_doctorQuery.IsDeleted    = false;
                    hec_doctorQuery.Tenant_RefID = securityTicket.TenantID;
                    hec_doctorQuery.BusinessParticipant_RefID = data.CMN_BPT_BusinessParticipantID;

                    var hec_doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, hec_doctorQuery).Single();

                    returnValue.Result.DoctorID = hec_doctor.HEC_DoctorID;

                    returnValue.Result.PracticeID   = medical_practice.practice_id;
                    returnValue.Result.PracticeName = medical_practice.practice_name;
                }
                else
                {
                    var medical_practice = cls_Get_Case_PracticeData_for_PracticeBptID.Invoke(Connection, Transaction, new P_CAS_GCPDfPBptID_1248()
                    {
                        PracticeBptID = data.CMN_BPT_BusinessParticipantID
                    }, securityTicket).Result;

                    returnValue.Result.PracticeID   = medical_practice.id;
                    returnValue.Result.PracticeName = medical_practice.name;
                }
            }
            return(returnValue);

            #endregion UserCode
        }
示例#2
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
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, PL5DO_SD_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            if (Parameter.isDeleted == true)
            {
                P_L3MD_DDbID_1031 param1 = new P_L3MD_DDbID_1031();
                param1.DoctorID = Parameter.DoctorID;

                var deleteQuery = new ORM_HEC_Patient_Treatment.Query();
                deleteQuery.IsTreatmentPerformed = true;
                deleteQuery.IfTreatmentPerformed_ByDoctor_RefID = Parameter.DoctorID;

                var treatmentsList = ORM_HEC_Patient_Treatment.Query.Search(Connection, Transaction, deleteQuery).ToList();

                foreach (var treatment in treatmentsList)
                {
                    treatment.IsTreatmentPerformed = false;
                    treatment.Save(Connection, Transaction);
                }


                cls_Delete_Doctor_byID.Invoke(Connection, Transaction, param1, securityTicket);
            }

            else
            {
                P_L3MD_SDBI_1349 param = new P_L3MD_SDBI_1349();

                param.Account_RefID         = Parameter.Account_RefID;
                param.DoctorID              = Parameter.DoctorID;
                param.Title                 = Parameter.Title;
                param.FirstName             = Parameter.FirstName;
                param.LastName              = Parameter.LastName;
                param.ifLucentis_LoginEmail = Parameter.LoginEmail;
                param.isLucentisSave        = true;
                param.ifLucentis_LANR       = Parameter.ifLucentis_LANR;

                List <P_L3MD_SDBI_1349_Practice> practiceNewList = new List <P_L3MD_SDBI_1349_Practice>();

                foreach (var practice in Parameter.Practices)
                {
                    P_L3MD_SDBI_1349_Practice practiceNew = new P_L3MD_SDBI_1349_Practice();
                    practiceNew.AssociatedParticipant_FunctionName = practice.AssociatedParticipant_FunctionName;
                    practiceNew.isDeleted  = practice.isDeleted;
                    practiceNew.PracticeID = practice.PracticeID;
                    practiceNewList.Add(practiceNew);
                }



                param.Practices = practiceNewList.ToArray();



                List <P_L3MD_SDBI_1349_Contacts> contactsNewList = new List <P_L3MD_SDBI_1349_Contacts>();

                foreach (var contact in Parameter.Contacts)
                {
                    P_L3MD_SDBI_1349_Contacts contactNew = new P_L3MD_SDBI_1349_Contacts();
                    contactNew.CMN_PER_CommunicationContact_TypeID = contact.CMN_PER_CommunicationContact_TypeID;
                    contactNew.Content = contact.Content;
                    contactsNewList.Add(contactNew);
                }


                param.Contacts = contactsNewList.ToArray();


                Guid Hec_Doctor_ID = cls_Save_Doctor_BaseInfo.Invoke(Connection, Transaction, param, securityTicket).Result;


                if (Parameter.DoctorID != Guid.Empty)
                {
                    #region Edit

                    var doctorQuery = new ORM_HEC_Doctor.Query();

                    doctorQuery.IsDeleted    = false;
                    doctorQuery.HEC_DoctorID = Hec_Doctor_ID;

                    var doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).FirstOrDefault();

                    if (doctor != null)
                    {
                        var bussiness_2_BankaAccountQuery = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query();
                        bussiness_2_BankaAccountQuery.IsDeleted = false;
                        bussiness_2_BankaAccountQuery.CMN_BPT_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID;

                        var bussiness_2_BankaAccount = ORM_CMN_BPT_BusinessParticipant_2_BankAccount.Query.Search(Connection, Transaction, bussiness_2_BankaAccountQuery).FirstOrDefault();

                        if (bussiness_2_BankaAccount != null)
                        {
                            var bankAccountQuery = new ORM_ACC_BNK_BankAccount.Query();
                            bankAccountQuery.IsDeleted             = false;
                            bankAccountQuery.ACC_BNK_BankAccountID = bussiness_2_BankaAccount.ACC_BNK_BankAccount_RefID;

                            var bankAccount = ORM_ACC_BNK_BankAccount.Query.Search(Connection, Transaction, bankAccountQuery).FirstOrDefault();


                            bankAccount.OwnerText     = Parameter.AccountHolder;
                            bankAccount.AccountNumber = Parameter.AccountNumber;
                            bankAccount.IBAN          = Parameter.IBAN;
                            bankAccount.Save(Connection, Transaction);


                            var bankQuery = new ORM_ACC_BNK_Bank.Query();
                            bankQuery.IsDeleted      = false;
                            bankQuery.ACC_BNK_BankID = bankAccount.Bank_RefID;

                            var bank = ORM_ACC_BNK_Bank.Query.Search(Connection, Transaction, bankQuery).FirstOrDefault();


                            bank.BankName   = Parameter.BankName;
                            bank.BICCode    = Parameter.BIC;
                            bank.BankNumber = Parameter.BankNumber;
                            bank.Save(Connection, Transaction);
                        }
                        else
                        {
                            ORM_CMN_BPT_BusinessParticipant_2_BankAccount bussiness_2_BankaAccount1 = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                            bussiness_2_BankaAccount1.AssignmentID = Guid.NewGuid();
                            bussiness_2_BankaAccount1.CMN_BPT_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID;
                            bussiness_2_BankaAccount1.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                            bussiness_2_BankaAccount1.Creation_Timestamp = DateTime.Now;
                            bussiness_2_BankaAccount1.Tenant_RefID       = securityTicket.TenantID;
                            bussiness_2_BankaAccount1.IsDeleted          = false;

                            bussiness_2_BankaAccount1.Save(Connection, Transaction);

                            ORM_ACC_BNK_BankAccount bankAccount = new ORM_ACC_BNK_BankAccount();

                            bankAccount.ACC_BNK_BankAccountID = bussiness_2_BankaAccount1.ACC_BNK_BankAccount_RefID;
                            bankAccount.Creation_Timestamp    = DateTime.Now;
                            bankAccount.Tenant_RefID          = securityTicket.TenantID;
                            bankAccount.OwnerText             = Parameter.AccountHolder;
                            bankAccount.AccountNumber         = Parameter.AccountNumber;
                            bankAccount.IBAN       = Parameter.IBAN;
                            bankAccount.Bank_RefID = Guid.NewGuid();
                            bankAccount.IsDeleted  = false;

                            bankAccount.Save(Connection, Transaction);

                            ORM_ACC_BNK_Bank bank = new ORM_ACC_BNK_Bank();
                            bank.ACC_BNK_BankID     = bankAccount.Bank_RefID;
                            bank.Tenant_RefID       = securityTicket.TenantID;
                            bank.IsDeleted          = false;
                            bank.Creation_Timestamp = DateTime.Now;
                            bank.BankName           = Parameter.BankName;
                            bank.BICCode            = Parameter.BIC;
                            bank.BankNumber         = Parameter.BankNumber;

                            bank.Save(Connection, Transaction);
                        }
                    }


                    #endregion
                }
                else
                {
                    #region Save

                    var doctorQuery = new ORM_HEC_Doctor.Query();

                    doctorQuery.IsDeleted    = false;
                    doctorQuery.HEC_DoctorID = Hec_Doctor_ID;

                    var doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).FirstOrDefault();

                    if (doctor != null)
                    {
                        ORM_CMN_BPT_BusinessParticipant_2_BankAccount bussiness_2_BankaAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount();
                        bussiness_2_BankaAccount.AssignmentID = Guid.NewGuid();
                        bussiness_2_BankaAccount.CMN_BPT_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID;
                        bussiness_2_BankaAccount.ACC_BNK_BankAccount_RefID         = Guid.NewGuid();
                        bussiness_2_BankaAccount.Creation_Timestamp = DateTime.Now;
                        bussiness_2_BankaAccount.Tenant_RefID       = securityTicket.TenantID;
                        bussiness_2_BankaAccount.IsDeleted          = false;

                        bussiness_2_BankaAccount.Save(Connection, Transaction);

                        ORM_ACC_BNK_BankAccount bankAccount = new ORM_ACC_BNK_BankAccount();

                        bankAccount.ACC_BNK_BankAccountID = bussiness_2_BankaAccount.ACC_BNK_BankAccount_RefID;
                        bankAccount.Creation_Timestamp    = DateTime.Now;
                        bankAccount.Tenant_RefID          = securityTicket.TenantID;
                        bankAccount.OwnerText             = Parameter.AccountHolder;
                        bankAccount.AccountNumber         = Parameter.AccountNumber;
                        bankAccount.IBAN       = Parameter.IBAN;
                        bankAccount.Bank_RefID = Guid.NewGuid();
                        bankAccount.IsDeleted  = false;

                        bankAccount.Save(Connection, Transaction);

                        ORM_ACC_BNK_Bank bank = new ORM_ACC_BNK_Bank();
                        bank.ACC_BNK_BankID     = bankAccount.Bank_RefID;
                        bank.Tenant_RefID       = securityTicket.TenantID;
                        bank.IsDeleted          = false;
                        bank.Creation_Timestamp = DateTime.Now;
                        bank.BankName           = Parameter.BankName;
                        bank.BICCode            = Parameter.BIC;
                        bank.BankNumber         = Parameter.BankNumber;

                        bank.Save(Connection, Transaction);
                    }

                    #endregion
                }

                returnValue.Result = Hec_Doctor_ID;
            }
            return(returnValue);

            #endregion UserCode
        }
示例#4
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OM_SM_0951 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            var doctorQuery = new ORM_HEC_Doctor.Query();
            doctorQuery.HEC_DoctorID = Parameter.Doctor_ID;
            var doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First();

            var practicesQuery = new ORM_HEC_MedicalPractis.Query();
            practicesQuery.HEC_MedicalPractiseID = Parameter.Practice_ID;
            var practices = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practicesQuery).First();

            var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
            companyInfoQuery.CMN_COM_CompanyInfoID = practices.Ext_CompanyInfo_RefID;
            var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First();

            var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            bParticipantQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID;
            var practice_bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).FirstOrDefault();

            ORM_CMN_BPT_Memo memo = new ORM_CMN_BPT_Memo();
            if (Parameter.CMN_BPT_MemoID != Guid.Empty)
            {
                var result = memo.Load(Connection, Transaction, Parameter.CMN_BPT_MemoID);
                if (result.Status != FR_Status.Success || memo.CMN_BPT_MemoID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
                memo.UpdatedBy_Account_RefID = securityTicket.AccountID;
                memo.UpdatedOn = Parameter.Creation_Timestamp;
            }
            else
            {
                ORM_DOC_Structure_Header docHeader = new ORM_DOC_Structure_Header();
                docHeader.Label        = Parameter.Memo_Abbreviation + "_Header_Label";
                docHeader.Tenant_RefID = securityTicket.TenantID;
                docHeader.Save(Connection, Transaction);

                ORM_DOC_Structure docStructure = new ORM_DOC_Structure();
                docStructure.Label                  = Parameter.Memo_Abbreviation + "_Structure";
                docStructure.Tenant_RefID           = securityTicket.TenantID;
                docStructure.Structure_Header_RefID = docHeader.DOC_Structure_HeaderID;
                docStructure.Save(Connection, Transaction);

                memo.DocumentStructureHeader_RefID = docHeader.DOC_Structure_HeaderID;
                memo.CreatedBy_Account_RefID       = securityTicket.AccountID;
                memo.Creation_Timestamp            = Parameter.Creation_Timestamp;
                memo.UpdatedOn = memo.Creation_Timestamp;
            }

            memo.Memo_Text         = Parameter.Memo_Text;
            memo.Memo_Title        = Parameter.Memo_Title;
            memo.Memo_Abbreviation = Parameter.Memo_Abbreviation;
            memo.Tenant_RefID      = securityTicket.TenantID;
            memo.Save(Connection, Transaction);

            if (Parameter.AdditionalFields != null)
            {
                foreach (var AdditionalField in Parameter.AdditionalFields)
                {
                    ORM_CMN_BPT_Memo_AdditionalField addFieldItem = new ORM_CMN_BPT_Memo_AdditionalField();
                    if (AdditionalField.CMN_BPT_Memo_AdditionalFieldID != Guid.Empty)
                    {
                        var result = addFieldItem.Load(Connection, Transaction, AdditionalField.CMN_BPT_Memo_AdditionalFieldID);
                        if (result.Status != FR_Status.Success || addFieldItem.CMN_BPT_Memo_AdditionalFieldID == Guid.Empty)
                        {
                            var error = new FR_Guid();
                            error.ErrorMessage = "No Such ID";
                            error.Status       = FR_Status.Error_Internal;
                            return(error);
                        }
                    }
                    addFieldItem.Memo_RefID   = memo.CMN_BPT_MemoID;
                    addFieldItem.Field_Key    = AdditionalField.Field_Key;
                    addFieldItem.Field_Value  = AdditionalField.Field_Value;
                    addFieldItem.Tenant_RefID = securityTicket.TenantID;
                    addFieldItem.Save(Connection, Transaction);
                }
            }
            var memo2DocQuery = new ORM_CMN_BPT_Memo_RelatedParticipant.Query();
            memo2DocQuery.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
            memo2DocQuery.CMN_BPT_Memo_RelatedParticipantID = doctor.BusinessParticipant_RefID;
            var memo2DocQueryRes = ORM_CMN_BPT_Memo_RelatedParticipant.Query.Search(Connection, Transaction, memo2DocQuery).FirstOrDefault();
            ORM_CMN_BPT_Memo_RelatedParticipant memo2Doc;
            if (memo2DocQueryRes != null)
            {
                memo2Doc = memo2DocQueryRes;
            }
            else
            {
                memo2Doc = new ORM_CMN_BPT_Memo_RelatedParticipant();
                memo2Doc.CMN_BPT_Memo_RelatedParticipantID = Guid.NewGuid();
            }
            memo2Doc.Tenant_RefID       = securityTicket.TenantID;
            memo2Doc.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
            memo2Doc.CMN_BPT_BusinessParticipant_RefID = doctor.BusinessParticipant_RefID;
            memo2Doc.Save(Connection, Transaction);



            var memo2PracticeQuery = new ORM_CMN_BPT_Memo_RelatedParticipant.Query();
            memo2DocQuery.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
            memo2DocQuery.CMN_BPT_Memo_RelatedParticipantID = practice_bParticipant.CMN_BPT_BusinessParticipantID;
            var memo2PracticeQueryRes = ORM_CMN_BPT_Memo_RelatedParticipant.Query.Search(Connection, Transaction, memo2DocQuery).FirstOrDefault();
            ORM_CMN_BPT_Memo_RelatedParticipant memo2Practice;
            if (memo2DocQueryRes != null)
            {
                memo2Practice = memo2DocQueryRes;
            }
            else
            {
                memo2Practice = new ORM_CMN_BPT_Memo_RelatedParticipant();
                memo2Practice.CMN_BPT_Memo_RelatedParticipantID = Guid.NewGuid();
            }
            memo2Practice.Tenant_RefID       = securityTicket.TenantID;
            memo2Practice.CMN_BPT_Memo_RefID = memo.CMN_BPT_MemoID;
            memo2Practice.CMN_BPT_BusinessParticipant_RefID = practice_bParticipant.CMN_BPT_BusinessParticipantID;
            memo2Practice.Save(Connection, Transaction);


            returnValue.Result = memo.CMN_BPT_MemoID;

            return(returnValue);

            #endregion UserCode
        }
示例#5
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OD_SD_1130 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            Guid           accounrRefID = Guid.Empty;
            var            doctorQuery  = new ORM_HEC_Doctor.Query();
            ORM_HEC_Doctor doctor;
            if (Parameter.HEC_DoctorID != Guid.Empty)
            {
                doctorQuery.HEC_DoctorID = Parameter.HEC_DoctorID;
                doctor       = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First();
                accounrRefID = doctor.Account_RefID;
            }

            P_L3MD_SDBI_1349 sbdParam = new P_L3MD_SDBI_1349();
            sbdParam.DoctorID      = Parameter.HEC_DoctorID;
            sbdParam.Account_RefID = accounrRefID;
            sbdParam.FirstName     = Parameter.FirstName;
            sbdParam.LastName      = Parameter.LastName;
            sbdParam.isOphthalSave = true;
            sbdParam.ifOphthal_Salutation_General = Parameter.Salutation_General;
            sbdParam.ifOphthal_Salutation_Letter  = Parameter.Salutation_Letter;
            sbdParam.Title = Parameter.Title;

            List <P_L3MD_SDBI_1349_Contacts> contactsParams = new List <P_L3MD_SDBI_1349_Contacts>();
            if (Parameter.Contacts != null)
            {
                foreach (var item in Parameter.Contacts)
                {
                    var c = new P_L3MD_SDBI_1349_Contacts();
                    c.CMN_PER_CommunicationContact_TypeID = item.CMN_PER_CommunicationContact_TypeID;
                    c.Content = item.Content;
                    contactsParams.Add(c);
                }
            }
            sbdParam.Contacts = contactsParams.ToArray();

            List <P_L3MD_SDBI_1349_Practice> practicesParams = new List <P_L3MD_SDBI_1349_Practice>();
            if (Parameter.Practices != null)
            {
                foreach (var item in Parameter.Practices)
                {
                    var p = new P_L3MD_SDBI_1349_Practice();
                    p.PracticeID = item.PracticeID;
                    p.isDeleted  = item.isDeleted;
                    p.AssociatedParticipant_FunctionName = item.AssociatedParticipant_FunctionName;
                    practicesParams.Add(p);
                }
            }
            sbdParam.Practices = practicesParams.ToArray();

            var docID = cls_Save_Doctor_BaseInfo.Invoke(Connection, Transaction, sbdParam, securityTicket).Result;

            doctorQuery = new ORM_HEC_Doctor.Query();
            doctorQuery.HEC_DoctorID = docID;

            doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First();
            var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            bParticipantQuery.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID;
            var bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).First();

            ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative SalesRepresentative;
            var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query();
            customerQuery.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).FirstOrDefault();
            if (customer == null)
            {
                customer = new ORM_CMN_BPT_CTM_Customer();
                customer.CMN_BPT_CTM_CustomerID        = Guid.NewGuid();
                customer.Tenant_RefID                  = securityTicket.TenantID;
                SalesRepresentative                    = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative();
                SalesRepresentative.AssignmentID       = Guid.NewGuid();
                SalesRepresentative.Customer_RefID     = customer.CMN_BPT_CTM_CustomerID;
                SalesRepresentative.Tenant_RefID       = securityTicket.TenantID;
                customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            }
            else
            {
                customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First();
                var SalesRepresentativeQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query();
                SalesRepresentativeQuery.Customer_RefID = customer.CMN_BPT_CTM_CustomerID;
                SalesRepresentative = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, SalesRepresentativeQuery).First();
            }
            SalesRepresentative.SalesRepresentative_RefID = Parameter.CMN_BPT_SalesRepresentativeID;

            var sRepresentativeQuery = new ORM_CMN_BPT_SalesRepresentative.Query();
            sRepresentativeQuery.CMN_BPT_SalesRepresentativeID = Parameter.CMN_BPT_SalesRepresentativeID;
            sRepresentativeQuery.IsDeleted = false;
            var sRepresentative = ORM_CMN_BPT_SalesRepresentative.Query.Search(Connection, Transaction, sRepresentativeQuery).FirstOrDefault();
            if (sRepresentative == null)
            {
                sRepresentative = new ORM_CMN_BPT_SalesRepresentative();
                sRepresentative.CMN_BPT_SalesRepresentativeID = Parameter.CMN_BPT_SalesRepresentativeID;
                sRepresentative.Save(Connection, Transaction);
            }

            customer.Save(Connection, Transaction);
            SalesRepresentative.Save(Connection, Transaction);

            ORM_USR_Account            account;
            ORM_USR_Device_AccountCode code;
            ORM_USR_Device_AccountCode_StatusHistory codeStatus;
            var accountQuery = new ORM_USR_Account.Query();
            accountQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
            accountQuery.AccountType = 3;
            var accountQueryRes = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery);
            if (accountQueryRes.Count == 0)
            {
                account = new ORM_USR_Account();
                account.USR_AccountID             = Guid.NewGuid();
                account.Tenant_RefID              = securityTicket.TenantID;
                account.AccountType               = 3;
                account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID;
                account.Save(Connection, Transaction);

                code = new ORM_USR_Device_AccountCode();
                code.Tenant_RefID             = securityTicket.TenantID;
                code.USR_Device_AccountCodeID = Guid.NewGuid();
                code.Account_RefID            = account.USR_AccountID;
                code.AccountCode_ValidFrom    = DateTime.Now;

                codeStatus = new ORM_USR_Device_AccountCode_StatusHistory();
                codeStatus.USR_Device_AccountCode_StatusHistoryID = Guid.NewGuid();
                codeStatus.Device_AccountCode_RefID = code.USR_Device_AccountCodeID;
                codeStatus.Tenant_RefID             = securityTicket.TenantID;
                codeStatus.IsAccountCode_Active     = true;
                codeStatus.Save(Connection, Transaction);

                code.AccountCode_CurrentStatus_RefID = codeStatus.USR_Device_AccountCode_StatusHistoryID;

                L3DAC_GDACFTCV_1616   checkCodeValue;
                P_L3DAC_GDACFTCV_1616 codeParam = new P_L3DAC_GDACFTCV_1616();
                string codeValue;
                do
                {
                    codeValue           = RandomString.Generate(8);
                    codeParam.CodeValue = codeValue;
                    checkCodeValue      = cls_GetDeviceAccountCodeForTenantAndCodeValue.Invoke(Connection, Transaction, codeParam, securityTicket).Result;
                } while (checkCodeValue != null);

                code.AccountCode_Value = codeValue;
                code.Save(Connection, Transaction);
            }

            returnValue.Result = docID;
            return(returnValue);

            #endregion UserCode
        }