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

            var item = new ORM_HEC_Patient_Treatment();
            if (Parameter.HEC_Patient_TreatmentID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.HEC_Patient_TreatmentID);
                if (result.Status != FR_Status.Success || item.HEC_Patient_TreatmentID == Guid.Empty)
                {
                    //Item doesn't exist, create it
                    Parameter.HEC_Patient_TreatmentID = Guid.Empty;

                    if (Parameter.IsDeleted)
                    {
                        return(returnValue);
                    }
                }
            }

            if (Parameter.IsDeleted == true)
            {
                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_Patient_TreatmentID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.HEC_Patient_TreatmentID == Guid.Empty)
            {
                item.HEC_Patient_TreatmentID = Guid.NewGuid();
                item.Tenant_RefID            = securityTicket.TenantID;
            }

            item.TreatmentPractice_RefID             = Parameter.TreatmentPractice_RefID;
            item.IsTreatmentPerformed                = Parameter.IsTreatmentPerformed;
            item.IfTreatmentPerformed_ByDoctor_RefID = Parameter.IfTreatmentPerformed_ByDoctor_RefID;
            item.IfTreatmentPerformed_Date           = Parameter.IfTreatmentPerformed_Date;
            item.IsTreatmentFollowup = Parameter.IsTreatmentFollowup;
            item.IfTreatmentFollowup_FromTreatment_RefID = Parameter.IfTreatmentFollowup_FromTreatment_RefID;
            item.IsScheduled                = Parameter.IsScheduled;
            item.IfSheduled_Date            = Parameter.IfSheduled_Date;
            item.IfSheduled_ForDoctor_RefID = Parameter.IfSheduled_ForDoctor_RefID;
            item.IsTreatmentBilled          = Parameter.IsTreatmentBilled;
            item.IfTreatmentBilled_Date     = Parameter.IfTreatmentBilled_Date;
            item.Treatment_Comment          = Parameter.Treatment_Comment;

            return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_Patient_TreatmentID));

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

            var item = new ORM_HEC_Patient_Treatment();
            if (Parameter.HEC_Patient_TreatmentID != Guid.Empty)
            {
                var result = item.Load(Connection, Transaction, Parameter.HEC_Patient_TreatmentID);
                if (result.Status != FR_Status.Success || item.HEC_Patient_TreatmentID == Guid.Empty)
                {
                    var error = new FR_Guid();
                    error.ErrorMessage = "No Such ID";
                    error.Status       = FR_Status.Error_Internal;
                    return(error);
                }
            }

            if (Parameter.IsDeleted == true)
            {
                #region Delete Assignment

                var query = new ORM_HEC_Patient_2_PatientTreatment.Query();
                query.HEC_Patient_Treatment_RefID = Parameter.HEC_Patient_TreatmentID;
                query.IsDeleted = false;


                ORM_HEC_Patient_2_PatientTreatment.Query.SoftDelete(Connection, Transaction, query);

                #endregion

                item.IsDeleted = true;
                return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_Patient_TreatmentID));
            }

            //Creation specific parameters (Tenant, Account ... )
            if (Parameter.HEC_Patient_TreatmentID == Guid.Empty)
            {
                item.HEC_Patient_TreatmentID = Guid.NewGuid();
                item.Tenant_RefID            = securityTicket.TenantID;
                if (Parameter.IfTreatmentScheduled_ByDoctor_RefID != Guid.Empty)
                {
                    item.IfSheduled_ForDoctor_RefID = Parameter.IfTreatmentPerformed_ByDoctor_RefID;
                }
                #region Add Assignment

                var assignment = new ORM_HEC_Patient_2_PatientTreatment();
                assignment.AssignmentID                = Guid.NewGuid();
                assignment.HEC_Patient_RefID           = Parameter.Patient_RefID;
                assignment.HEC_Patient_Treatment_RefID = item.HEC_Patient_TreatmentID;
                assignment.Creation_Timestamp          = DateTime.Now;
                assignment.Modification_Timestamp      = DateTime.Now;
                assignment.Tenant_RefID                = securityTicket.TenantID;
                assignment.Save(Connection, Transaction);

                #endregion

                ORM_HEC_Patient_Treatment_OcularExtension ocularExtension = new ORM_HEC_Patient_Treatment_OcularExtension();
                ocularExtension.HEC_Patient_Treatment_OcularExtensionID = Guid.NewGuid();
                ocularExtension.HEC_Patient_Treatment_RefID             = item.HEC_Patient_TreatmentID;
                ocularExtension.IsTreatmentOfLeftEye  = Parameter.IsTreatmentOfLeftEye;
                ocularExtension.IsTreatmentOfRightEye = Parameter.IsTreatmentOfRightEye;
                ocularExtension.Creation_Timestamp    = DateTime.Now;
                ocularExtension.Tenant_RefID          = securityTicket.TenantID;
                ocularExtension.Save(Connection, Transaction);
            }
            else
            {
                var query = new ORM_HEC_Patient_Treatment_OcularExtension.Query();
                query.HEC_Patient_Treatment_RefID = item.HEC_Patient_TreatmentID;

                var ocularExtension = ORM_HEC_Patient_Treatment_OcularExtension.Query.Search(Connection, Transaction, query).FirstOrDefault();

                if (ocularExtension != null)
                {
                    ocularExtension.IsTreatmentOfLeftEye  = Parameter.IsTreatmentOfLeftEye;
                    ocularExtension.IsTreatmentOfRightEye = Parameter.IsTreatmentOfRightEye;
                    ocularExtension.Save(Connection, Transaction);
                }
                else
                {
                    ORM_HEC_Patient_Treatment_OcularExtension ocularExtension1 = new ORM_HEC_Patient_Treatment_OcularExtension();
                    ocularExtension1.HEC_Patient_Treatment_OcularExtensionID = Guid.NewGuid();
                    ocularExtension1.HEC_Patient_Treatment_RefID             = item.HEC_Patient_TreatmentID;
                    ocularExtension1.IsTreatmentOfLeftEye  = Parameter.IsTreatmentOfLeftEye;
                    ocularExtension1.IsTreatmentOfRightEye = Parameter.IsTreatmentOfRightEye;
                    ocularExtension1.Creation_Timestamp    = DateTime.Now;
                    ocularExtension1.Tenant_RefID          = securityTicket.TenantID;
                    ocularExtension1.Save(Connection, Transaction);
                }
            }

            item.TreatmentPractice_RefID = Parameter.TreatmentPractice_RefID;
            item.IsTreatmentPerformed    = Parameter.IsTreatmentPerformed;
            if (Parameter.IfTreatmentScheduled_ByDoctor_RefID != Guid.Empty)
            {
                item.IfSheduled_ForDoctor_RefID = Parameter.IfTreatmentScheduled_ByDoctor_RefID;
            }
            item.IfTreatmentPerformed_ByDoctor_RefID = Parameter.IfTreatmentPerformed_ByDoctor_RefID;
            item.IfTreatmentPerformed_Date           = Parameter.IfTreatmentPerformed_Date;
            item.IsTreatmentFollowup = Parameter.IsTreatmentFollowup;
            item.IfTreatmentFollowup_FromTreatment_RefID = Parameter.IfTreatmentFollowup_FromTreatment_RefID;
            item.IsScheduled            = Parameter.IsScheduled;
            item.IfSheduled_Date        = Parameter.IfSheduled_Date;
            item.IsTreatmentBilled      = Parameter.IsTreatmentBilled;
            item.IfTreatmentBilled_Date = Parameter.IfTreatmentBilled_Date;
            item.Treatment_Comment      = Parameter.Treatment_Comment;



            return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_Patient_TreatmentID));

            #endregion UserCode
        }