Example #1
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MP_DP_1145 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();

            ORM_CMN_PRO_Product item = new ORM_CMN_PRO_Product();

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


            /**********************Delete Hec_Product***********************************/
            var hecProductQuery = new ORM_HEC_Product.Query();
            hecProductQuery.Ext_PRO_Product_RefID = Parameter.CMN_PRO_ProductID;
            hecProductQuery.IsDeleted             = false;

            var medProduct = ORM_HEC_Product.Query.Search(Connection, Transaction, hecProductQuery).FirstOrDefault();

            if (medProduct != null)
            {
                medProduct.IsDeleted = true;
                medProduct.Save(Connection, Transaction);
            }

            /**********************Delete Surveys***************************************/

            var surveysQuery = new ORM_CMN_PRO_Product_Questionnaire_Assignment.Query();
            surveysQuery.CMN_PRO_Product_RefID = Parameter.CMN_PRO_ProductID;
            surveysQuery.IsDeleted             = false;

            var surveyes = ORM_CMN_PRO_Product_Questionnaire_Assignment.Query.Search(Connection, Transaction, surveysQuery).ToList();

            if (surveyes.Count != 0)
            {
                foreach (var survey in surveyes)
                {
                    survey.IsDeleted = true;
                    survey.Save(Connection, Transaction);
                }
            }

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


            return(returnValue);

            #endregion UserCode
        }
Example #2
0
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_CAS_UCGPOS_1516 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Base();
            //Put your code here

            String[] treatment_gpos = cls_Get_All_GPOS_Billing_Codes_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, new P_CAS_GAGPOSBCfGPMID_1516()
            {
                GlobalPropertyMatchingID = "mm.docconnect.gpos.catalog.operation"
            }, securityTicket).Result.Select(gpos => gpos.BillingCode).ToArray();
            String[] aftercare_gpos = cls_Get_All_GPOS_Billing_Codes_for_GlobalPropertyMatchingID.Invoke(Connection, Transaction, new P_CAS_GAGPOSBCfGPMID_1516()
            {
                GlobalPropertyMatchingID = "mm.docconnect.gpos.catalog.nachsorge"
            }, securityTicket).Result.Select(gpos => gpos.BillingCode).ToArray();

            #region CONSTANTS
            const decimal OZURDEX_TREATMENT_FEE = 230;
            const decimal OZURDEX_AFTERCARE_FEE = 150;
            const decimal TREATMENT_FEE         = 230;
            const decimal AFTERCARE_FEE         = 60;
            #endregion

            Guid treatment_performed_action_type_id = Guid.Empty;

            var treatment_performed_action_type = ORM_HEC_ACT_ActionType.Query.Search(Connection, Transaction, new ORM_HEC_ACT_ActionType.Query()
            {
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted                = false,
                GlobalPropertyMatchingID = "mm.docconect.doc.app.performed.action.treatment"
            }).SingleOrDefault();

            if (treatment_performed_action_type == null)
            {
                treatment_performed_action_type = new ORM_HEC_ACT_ActionType();
                treatment_performed_action_type.GlobalPropertyMatchingID = "mm.docconect.doc.app.performed.action.treatment";
                treatment_performed_action_type.Creation_Timestamp       = DateTime.Now;
                treatment_performed_action_type.Modification_Timestamp   = DateTime.Now;
                treatment_performed_action_type.Tenant_RefID             = securityTicket.TenantID;

                treatment_performed_action_type.Save(Connection, Transaction);

                treatment_performed_action_type_id = treatment_performed_action_type.HEC_ACT_ActionTypeID;
            }
            else
            {
                treatment_performed_action_type_id = treatment_performed_action_type.HEC_ACT_ActionTypeID;
            }

            ORM_HEC_BIL_PotentialCode.Query gpos_codeQ = new ORM_HEC_BIL_PotentialCode.Query();
            gpos_codeQ.Tenant_RefID = securityTicket.TenantID;
            gpos_codeQ.IsDeleted    = false;

            ORM_HEC_Product.Query hec_drug_detailsQ = new ORM_HEC_Product.Query();
            hec_drug_detailsQ.HEC_ProductID = Parameter.drug_id;
            hec_drug_detailsQ.Tenant_RefID  = securityTicket.TenantID;
            hec_drug_detailsQ.IsDeleted     = false;

            var hec_drug_details = ORM_HEC_Product.Query.Search(Connection, Transaction, hec_drug_detailsQ).SingleOrDefault();
            if (hec_drug_details != null)
            {
                ORM_CMN_PRO_Product.Query cmn_drug_detailsQ = new ORM_CMN_PRO_Product.Query();
                cmn_drug_detailsQ.Tenant_RefID      = securityTicket.TenantID;
                cmn_drug_detailsQ.CMN_PRO_ProductID = hec_drug_details.Ext_PRO_Product_RefID;
                cmn_drug_detailsQ.IsDeleted         = false;

                var cmn_drug_details = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, cmn_drug_detailsQ).SingleOrDefault();
                if (cmn_drug_details != null)
                {
                    var drug_name = cmn_drug_details.Product_Name.GetContent(Parameter.all_languagesL.FirstOrDefault().CMN_LanguageID);

                    var gpos_diagnose_details = cls_Get_Diagnose_Details_for_DiagnoseID.Invoke(Connection, Transaction, new P_CAS_GDDfDID_1357()
                    {
                        DiagnoseID = Parameter.diagnose_id
                    }, securityTicket).Result;
                    if (gpos_diagnose_details != null)
                    {
                        var treatment_count = cls_Get_Treatment_Count_for_PatientID_And_DiagnoseID_and_LocalizationCode.Invoke(Connection, Transaction, new P_CAS_GTCfPIDaDIDaLC_1008()
                        {
                            ActionTypeID = treatment_performed_action_type_id, DiagnoseID = Parameter.diagnose_id, PatientID = Parameter.patient_id, LocalizationCode = Parameter.localization, PerformedDate = DateTime.Now
                        }, securityTicket).Result;
                        if (treatment_count != null)
                        {
                            var bill_position_ids = cls_Get_BillPositionIDs_for_CaseID.Invoke(Connection, Transaction, new P_CAS_GBPIDsfCID_0928()
                            {
                                CaseID = Parameter.case_id
                            }, securityTicket).Result;

                            foreach (var id in bill_position_ids)
                            {
                                var billing_code = cls_Get_BillingCode_for_CaseBillCodeID.Invoke(Connection, Transaction, new P_CAS_GBCfCBCID_1334()
                                {
                                    CaseBillCodeID = id.hec_case_bill_code_id
                                }, securityTicket).Result;
                                if (billing_code != null)
                                {
                                    #region ICD H34.8
                                    if (gpos_diagnose_details.diagnose_icd_10.Equals("H34.8"))
                                    {
                                        #region Ozurdex position
                                        if (drug_name.Equals("Ozurdex"))
                                        {
                                            if (treatment_gpos.Contains(billing_code.BillingCode))
                                            {
                                                gpos_codeQ.BillingCode = treatment_count.treatment_count - 1 < 1 ? "36620055" : "36620056";

                                                var gpos_code = ORM_HEC_BIL_PotentialCode.Query.Search(Connection, Transaction, gpos_codeQ).SingleOrDefault();
                                                if (gpos_code != null)
                                                {
                                                    ORM_BIL_BillPosition.Query old_gpos_positionQ = new ORM_BIL_BillPosition.Query();
                                                    old_gpos_positionQ.BIL_BillPositionID = id.bill_position_id;
                                                    old_gpos_positionQ.Tenant_RefID       = securityTicket.TenantID;
                                                    old_gpos_positionQ.IsDeleted          = false;

                                                    var old_gpos_position = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, old_gpos_positionQ).SingleOrDefault();
                                                    if (old_gpos_position != null)
                                                    {
                                                        old_gpos_position.Modification_Timestamp     = DateTime.Now;
                                                        old_gpos_position.PositionValue_IncludingTax = OZURDEX_TREATMENT_FEE;

                                                        old_gpos_position.Save(Connection, Transaction);

                                                        ORM_HEC_BIL_BillPosition.Query old_hec_gpos_positionQ = new ORM_HEC_BIL_BillPosition.Query();
                                                        old_hec_gpos_positionQ.Ext_BIL_BillPosition_RefID = old_gpos_position.BIL_BillPositionID;
                                                        old_hec_gpos_positionQ.Tenant_RefID = securityTicket.TenantID;
                                                        old_hec_gpos_positionQ.PositionFor_Patient_RefID = Parameter.patient_id;
                                                        old_hec_gpos_positionQ.IsDeleted = false;

                                                        var old_hec_gpos_position = ORM_HEC_BIL_BillPosition.Query.Search(Connection, Transaction, old_hec_gpos_positionQ).SingleOrDefault();
                                                        if (old_hec_gpos_position != null)
                                                        {
                                                            ORM_HEC_BIL_BillPosition_BillCode.Query old_hec_gpos_position_codeQ = new ORM_HEC_BIL_BillPosition_BillCode.Query();
                                                            old_hec_gpos_position_codeQ.Tenant_RefID       = securityTicket.TenantID;
                                                            old_hec_gpos_position_codeQ.BillPosition_RefID = old_hec_gpos_position.HEC_BIL_BillPositionID;
                                                            old_hec_gpos_position_codeQ.IsDeleted          = false;

                                                            var old_hec_gpos_position_code = ORM_HEC_BIL_BillPosition_BillCode.Query.Search(Connection, Transaction, old_hec_gpos_position_codeQ).SingleOrDefault();
                                                            if (old_hec_gpos_position_code != null)
                                                            {
                                                                old_hec_gpos_position_code.IM_BillingCode         = gpos_code.BillingCode;
                                                                old_hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                                                                old_hec_gpos_position_code.PotentialCode_RefID    = gpos_code.HEC_BIL_PotentialCodeID;

                                                                old_hec_gpos_position_code.Save(Connection, Transaction);
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            if (aftercare_gpos.Contains(billing_code.BillingCode))
                                            {
                                                gpos_codeQ.BillingCode = treatment_count.treatment_count - 1 < 1 ? "36620063" : "36620064";

                                                var gpos_code = ORM_HEC_BIL_PotentialCode.Query.Search(Connection, Transaction, gpos_codeQ).SingleOrDefault();
                                                if (gpos_code != null)
                                                {
                                                    ORM_BIL_BillPosition.Query old_gpos_positionQ = new ORM_BIL_BillPosition.Query();
                                                    old_gpos_positionQ.BIL_BillPositionID = id.bill_position_id;
                                                    old_gpos_positionQ.Tenant_RefID       = securityTicket.TenantID;
                                                    old_gpos_positionQ.IsDeleted          = false;

                                                    var old_gpos_position = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, old_gpos_positionQ).SingleOrDefault();
                                                    if (old_gpos_position != null)
                                                    {
                                                        old_gpos_position.Modification_Timestamp     = DateTime.Now;
                                                        old_gpos_position.PositionValue_IncludingTax = OZURDEX_AFTERCARE_FEE;

                                                        old_gpos_position.Save(Connection, Transaction);

                                                        ORM_HEC_BIL_BillPosition.Query old_hec_gpos_positionQ = new ORM_HEC_BIL_BillPosition.Query();
                                                        old_hec_gpos_positionQ.Ext_BIL_BillPosition_RefID = old_gpos_position.BIL_BillPositionID;
                                                        old_hec_gpos_positionQ.Tenant_RefID = securityTicket.TenantID;
                                                        old_hec_gpos_positionQ.PositionFor_Patient_RefID = Parameter.patient_id;
                                                        old_hec_gpos_positionQ.IsDeleted = false;

                                                        var old_hec_gpos_position = ORM_HEC_BIL_BillPosition.Query.Search(Connection, Transaction, old_hec_gpos_positionQ).SingleOrDefault();
                                                        if (old_hec_gpos_position != null)
                                                        {
                                                            ORM_HEC_BIL_BillPosition_BillCode.Query old_hec_gpos_position_codeQ = new ORM_HEC_BIL_BillPosition_BillCode.Query();
                                                            old_hec_gpos_position_codeQ.Tenant_RefID       = securityTicket.TenantID;
                                                            old_hec_gpos_position_codeQ.BillPosition_RefID = old_hec_gpos_position.HEC_BIL_BillPositionID;
                                                            old_hec_gpos_position_codeQ.IsDeleted          = false;

                                                            var old_hec_gpos_position_code = ORM_HEC_BIL_BillPosition_BillCode.Query.Search(Connection, Transaction, old_hec_gpos_position_codeQ).SingleOrDefault();
                                                            if (old_hec_gpos_position_code != null)
                                                            {
                                                                old_hec_gpos_position_code.IM_BillingCode         = gpos_code.BillingCode;
                                                                old_hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                                                                old_hec_gpos_position_code.PotentialCode_RefID    = gpos_code.HEC_BIL_PotentialCodeID;

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

                                        #region Other drugs
                                        else
                                        {
                                            if (treatment_gpos.Contains(billing_code.BillingCode))
                                            {
                                                gpos_codeQ.BillingCode = treatment_count.treatment_count - 1 < 3 ? "36620053" : "36620054";

                                                var gpos_code = ORM_HEC_BIL_PotentialCode.Query.Search(Connection, Transaction, gpos_codeQ).SingleOrDefault();
                                                if (gpos_code != null)
                                                {
                                                    ORM_BIL_BillPosition.Query old_gpos_positionQ = new ORM_BIL_BillPosition.Query();
                                                    old_gpos_positionQ.BIL_BillPositionID = id.bill_position_id;
                                                    old_gpos_positionQ.Tenant_RefID       = securityTicket.TenantID;
                                                    old_gpos_positionQ.IsDeleted          = false;

                                                    var old_gpos_position = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, old_gpos_positionQ).SingleOrDefault();
                                                    if (old_gpos_position != null)
                                                    {
                                                        old_gpos_position.Modification_Timestamp     = DateTime.Now;
                                                        old_gpos_position.PositionValue_IncludingTax = TREATMENT_FEE;

                                                        old_gpos_position.Save(Connection, Transaction);

                                                        ORM_HEC_BIL_BillPosition.Query old_hec_gpos_positionQ = new ORM_HEC_BIL_BillPosition.Query();
                                                        old_hec_gpos_positionQ.Ext_BIL_BillPosition_RefID = old_gpos_position.BIL_BillPositionID;
                                                        old_hec_gpos_positionQ.Tenant_RefID = securityTicket.TenantID;
                                                        old_hec_gpos_positionQ.PositionFor_Patient_RefID = Parameter.patient_id;
                                                        old_hec_gpos_positionQ.IsDeleted = false;

                                                        var old_hec_gpos_position = ORM_HEC_BIL_BillPosition.Query.Search(Connection, Transaction, old_hec_gpos_positionQ).SingleOrDefault();
                                                        if (old_hec_gpos_position != null)
                                                        {
                                                            ORM_HEC_BIL_BillPosition_BillCode.Query old_hec_gpos_position_codeQ = new ORM_HEC_BIL_BillPosition_BillCode.Query();
                                                            old_hec_gpos_position_codeQ.Tenant_RefID       = securityTicket.TenantID;
                                                            old_hec_gpos_position_codeQ.BillPosition_RefID = old_hec_gpos_position.HEC_BIL_BillPositionID;
                                                            old_hec_gpos_position_codeQ.IsDeleted          = false;

                                                            var old_hec_gpos_position_code = ORM_HEC_BIL_BillPosition_BillCode.Query.Search(Connection, Transaction, old_hec_gpos_position_codeQ).SingleOrDefault();
                                                            if (old_hec_gpos_position_code != null)
                                                            {
                                                                old_hec_gpos_position_code.IM_BillingCode         = gpos_code.BillingCode;
                                                                old_hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                                                                old_hec_gpos_position_code.PotentialCode_RefID    = gpos_code.HEC_BIL_PotentialCodeID;

                                                                old_hec_gpos_position_code.Save(Connection, Transaction);
                                                            }
                                                        }
                                                    }
                                                }
                                            }


                                            if (aftercare_gpos.Contains(billing_code.BillingCode))
                                            {
                                                gpos_codeQ.BillingCode = treatment_count.treatment_count - 1 < 3 ? "36620061" : "36620062";

                                                var gpos_code = ORM_HEC_BIL_PotentialCode.Query.Search(Connection, Transaction, gpos_codeQ).SingleOrDefault();
                                                if (gpos_code != null)
                                                {
                                                    ORM_BIL_BillPosition.Query old_gpos_positionQ = new ORM_BIL_BillPosition.Query();
                                                    old_gpos_positionQ.BIL_BillPositionID = id.bill_position_id;
                                                    old_gpos_positionQ.Tenant_RefID       = securityTicket.TenantID;
                                                    old_gpos_positionQ.IsDeleted          = false;

                                                    var old_gpos_position = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, old_gpos_positionQ).SingleOrDefault();
                                                    if (old_gpos_position != null)
                                                    {
                                                        old_gpos_position.Modification_Timestamp     = DateTime.Now;
                                                        old_gpos_position.PositionValue_IncludingTax = AFTERCARE_FEE;

                                                        old_gpos_position.Save(Connection, Transaction);

                                                        ORM_HEC_BIL_BillPosition.Query old_hec_gpos_positionQ = new ORM_HEC_BIL_BillPosition.Query();
                                                        old_hec_gpos_positionQ.Ext_BIL_BillPosition_RefID = old_gpos_position.BIL_BillPositionID;
                                                        old_hec_gpos_positionQ.Tenant_RefID = securityTicket.TenantID;
                                                        old_hec_gpos_positionQ.PositionFor_Patient_RefID = Parameter.patient_id;
                                                        old_hec_gpos_positionQ.IsDeleted = false;

                                                        var old_hec_gpos_position = ORM_HEC_BIL_BillPosition.Query.Search(Connection, Transaction, old_hec_gpos_positionQ).SingleOrDefault();
                                                        if (old_hec_gpos_position != null)
                                                        {
                                                            ORM_HEC_BIL_BillPosition_BillCode.Query old_hec_gpos_position_codeQ = new ORM_HEC_BIL_BillPosition_BillCode.Query();
                                                            old_hec_gpos_position_codeQ.Tenant_RefID       = securityTicket.TenantID;
                                                            old_hec_gpos_position_codeQ.BillPosition_RefID = old_hec_gpos_position.HEC_BIL_BillPositionID;
                                                            old_hec_gpos_position_codeQ.IsDeleted          = false;

                                                            var old_hec_gpos_position_code = ORM_HEC_BIL_BillPosition_BillCode.Query.Search(Connection, Transaction, old_hec_gpos_position_codeQ).SingleOrDefault();
                                                            if (old_hec_gpos_position_code != null)
                                                            {
                                                                old_hec_gpos_position_code.IM_BillingCode         = gpos_code.BillingCode;
                                                                old_hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                                                                old_hec_gpos_position_code.PotentialCode_RefID    = gpos_code.HEC_BIL_PotentialCodeID;

                                                                old_hec_gpos_position_code.Save(Connection, Transaction);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                    #endregion ICD H34.8

                                    #region ICD H35.3 or H36.0
                                    else if (gpos_diagnose_details.diagnose_icd_10.Equals("H35.3") || gpos_diagnose_details.diagnose_icd_10.Equals("H36.0")) // H35.3 or H36.0
                                    {
                                        if (treatment_gpos.Contains(billing_code.BillingCode))
                                        {
                                            gpos_codeQ.BillingCode = treatment_count.treatment_count - 1 < 3 ? "36620050" : treatment_count.treatment_count - 1 < 6 ? "36620051" : "36620052";

                                            var gpos_code = ORM_HEC_BIL_PotentialCode.Query.Search(Connection, Transaction, gpos_codeQ).SingleOrDefault();
                                            if (gpos_code != null)
                                            {
                                                ORM_BIL_BillPosition.Query old_gpos_positionQ = new ORM_BIL_BillPosition.Query();
                                                old_gpos_positionQ.BIL_BillPositionID = id.bill_position_id;
                                                old_gpos_positionQ.Tenant_RefID       = securityTicket.TenantID;
                                                old_gpos_positionQ.IsDeleted          = false;

                                                var old_gpos_position = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, old_gpos_positionQ).SingleOrDefault();
                                                if (old_gpos_position != null)
                                                {
                                                    old_gpos_position.Modification_Timestamp     = DateTime.Now;
                                                    old_gpos_position.PositionValue_IncludingTax = TREATMENT_FEE;

                                                    old_gpos_position.Save(Connection, Transaction);

                                                    ORM_HEC_BIL_BillPosition.Query old_hec_gpos_positionQ = new ORM_HEC_BIL_BillPosition.Query();
                                                    old_hec_gpos_positionQ.Ext_BIL_BillPosition_RefID = old_gpos_position.BIL_BillPositionID;
                                                    old_hec_gpos_positionQ.Tenant_RefID = securityTicket.TenantID;
                                                    old_hec_gpos_positionQ.PositionFor_Patient_RefID = Parameter.patient_id;
                                                    old_hec_gpos_positionQ.IsDeleted = false;

                                                    var old_hec_gpos_position = ORM_HEC_BIL_BillPosition.Query.Search(Connection, Transaction, old_hec_gpos_positionQ).SingleOrDefault();
                                                    if (old_hec_gpos_position != null)
                                                    {
                                                        ORM_HEC_BIL_BillPosition_BillCode.Query old_hec_gpos_position_codeQ = new ORM_HEC_BIL_BillPosition_BillCode.Query();
                                                        old_hec_gpos_position_codeQ.Tenant_RefID       = securityTicket.TenantID;
                                                        old_hec_gpos_position_codeQ.BillPosition_RefID = old_hec_gpos_position.HEC_BIL_BillPositionID;
                                                        old_hec_gpos_position_codeQ.IsDeleted          = false;

                                                        var old_hec_gpos_position_code = ORM_HEC_BIL_BillPosition_BillCode.Query.Search(Connection, Transaction, old_hec_gpos_position_codeQ).SingleOrDefault();
                                                        if (old_hec_gpos_position_code != null)
                                                        {
                                                            old_hec_gpos_position_code.IM_BillingCode         = gpos_code.BillingCode;
                                                            old_hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                                                            old_hec_gpos_position_code.PotentialCode_RefID    = gpos_code.HEC_BIL_PotentialCodeID;

                                                            old_hec_gpos_position_code.Save(Connection, Transaction);
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        if (aftercare_gpos.Contains(billing_code.BillingCode))
                                        {
                                            gpos_codeQ.BillingCode = treatment_count.treatment_count - 1 < 3 ? "36620058" : treatment_count.treatment_count - 1 < 6 ? "36620059" : "36620060";

                                            var gpos_code = ORM_HEC_BIL_PotentialCode.Query.Search(Connection, Transaction, gpos_codeQ).SingleOrDefault();
                                            if (gpos_code != null)
                                            {
                                                ORM_BIL_BillPosition.Query old_gpos_positionQ = new ORM_BIL_BillPosition.Query();
                                                old_gpos_positionQ.BIL_BillPositionID = id.bill_position_id;
                                                old_gpos_positionQ.Tenant_RefID       = securityTicket.TenantID;
                                                old_gpos_positionQ.IsDeleted          = false;

                                                var old_gpos_position = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, old_gpos_positionQ).SingleOrDefault();
                                                if (old_gpos_position != null)
                                                {
                                                    old_gpos_position.Modification_Timestamp     = DateTime.Now;
                                                    old_gpos_position.PositionValue_IncludingTax = AFTERCARE_FEE;

                                                    old_gpos_position.Save(Connection, Transaction);

                                                    ORM_HEC_BIL_BillPosition.Query old_hec_gpos_positionQ = new ORM_HEC_BIL_BillPosition.Query();
                                                    old_hec_gpos_positionQ.Ext_BIL_BillPosition_RefID = old_gpos_position.BIL_BillPositionID;
                                                    old_hec_gpos_positionQ.Tenant_RefID = securityTicket.TenantID;
                                                    old_hec_gpos_positionQ.PositionFor_Patient_RefID = Parameter.patient_id;
                                                    old_hec_gpos_positionQ.IsDeleted = false;

                                                    var old_hec_gpos_position = ORM_HEC_BIL_BillPosition.Query.Search(Connection, Transaction, old_hec_gpos_positionQ).SingleOrDefault();
                                                    if (old_hec_gpos_position != null)
                                                    {
                                                        ORM_HEC_BIL_BillPosition_BillCode.Query old_hec_gpos_position_codeQ = new ORM_HEC_BIL_BillPosition_BillCode.Query();
                                                        old_hec_gpos_position_codeQ.Tenant_RefID       = securityTicket.TenantID;
                                                        old_hec_gpos_position_codeQ.BillPosition_RefID = old_hec_gpos_position.HEC_BIL_BillPositionID;
                                                        old_hec_gpos_position_codeQ.IsDeleted          = false;

                                                        var old_hec_gpos_position_code = ORM_HEC_BIL_BillPosition_BillCode.Query.Search(Connection, Transaction, old_hec_gpos_position_codeQ).SingleOrDefault();
                                                        if (old_hec_gpos_position_code != null)
                                                        {
                                                            old_hec_gpos_position_code.IM_BillingCode         = gpos_code.BillingCode;
                                                            old_hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                                                            old_hec_gpos_position_code.PotentialCode_RefID    = gpos_code.HEC_BIL_PotentialCodeID;

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

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_CAS_CCGPOS_1000 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var  returnValue = new FR_Base();
            Guid treatment_performed_action_type_id = Guid.Empty;

            var treatment_performed_action_type = ORM_HEC_ACT_ActionType.Query.Search(Connection, Transaction, new ORM_HEC_ACT_ActionType.Query()
            {
                Tenant_RefID             = securityTicket.TenantID,
                IsDeleted                = false,
                GlobalPropertyMatchingID = "mm.docconect.doc.app.performed.action.treatment"
            }).SingleOrDefault();

            if (treatment_performed_action_type == null)
            {
                treatment_performed_action_type = new ORM_HEC_ACT_ActionType();
                treatment_performed_action_type.GlobalPropertyMatchingID = "mm.docconect.doc.app.performed.action.treatment";
                treatment_performed_action_type.Creation_Timestamp       = DateTime.Now;
                treatment_performed_action_type.Modification_Timestamp   = DateTime.Now;
                treatment_performed_action_type.Tenant_RefID             = securityTicket.TenantID;

                treatment_performed_action_type.Save(Connection, Transaction);

                treatment_performed_action_type_id = treatment_performed_action_type.HEC_ACT_ActionTypeID;
            }
            else
            {
                treatment_performed_action_type_id = treatment_performed_action_type.HEC_ACT_ActionTypeID;
            }

            ORM_HEC_Product.Query hec_drug_detailsQ = new ORM_HEC_Product.Query();
            hec_drug_detailsQ.HEC_ProductID = Parameter.drug_id;
            hec_drug_detailsQ.Tenant_RefID  = securityTicket.TenantID;
            hec_drug_detailsQ.IsDeleted     = false;

            var hec_drug_details = ORM_HEC_Product.Query.Search(Connection, Transaction, hec_drug_detailsQ).SingleOrDefault();
            if (hec_drug_details != null)
            {
                ORM_CMN_PRO_Product.Query cmn_drug_detailsQ = new ORM_CMN_PRO_Product.Query();
                cmn_drug_detailsQ.Tenant_RefID      = securityTicket.TenantID;
                cmn_drug_detailsQ.CMN_PRO_ProductID = hec_drug_details.Ext_PRO_Product_RefID;
                cmn_drug_detailsQ.IsDeleted         = false;

                var cmn_drug_details = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, cmn_drug_detailsQ).SingleOrDefault();
                if (cmn_drug_details != null)
                {
                    var drug_name = cmn_drug_details.Product_Name.GetContent(Parameter.all_languagesL.FirstOrDefault().CMN_LanguageID);

                    var treatment_count = cls_Get_Treatment_Count_for_PatientID_And_DiagnoseID_and_LocalizationCode.Invoke(Connection, Transaction, new P_CAS_GTCfPIDaDIDaLC_1008()
                    {
                        ActionTypeID     = treatment_performed_action_type_id,
                        DiagnoseID       = Parameter.diagnose_id,
                        PatientID        = Parameter.patient_id,
                        LocalizationCode = Parameter.localization,
                        PerformedDate    = Parameter.treatment_date == DateTime.MinValue ? DateTime.Now : Parameter.treatment_date
                    }, securityTicket).Result;

                    if (treatment_count != null)
                    {
                        treatment_count.treatment_count++;

                        var contracts = cls_Get_InsuranceToBrokerContractID_for_DrugID_and_DiagnoseID.Invoke(Connection, Transaction, new P_CAS_GItBCIDfDIDaDID_1541()
                        {
                            DiagnoseID    = Parameter.diagnose_id,
                            DrugID        = Parameter.drug_id,
                            PatientID     = Parameter.patient_id,
                            TreatmentDate = Parameter.treatment_date
                        }, securityTicket).Result;

                        var contract_id = contracts.Where(ctr => ctr.patient_consent_valid_from.AddMonths(ctr.contract_consent_valid_for_months) >= Parameter.treatment_date).OrderBy(ctr => ctr.patient_consent_valid_from).FirstOrDefault();

                        if (contract_id != null)
                        {
                            var gpos_details = cls_Get_GPOS_Details_for_DiagnoseID_and_DrugID.Invoke(Connection, Transaction, new P_CAS_GGPOSDfDIDaDID_1033()
                            {
                                DiagnoseID = Parameter.diagnose_id,
                                DrugID     = Parameter.drug_id,
                                ContractID = contract_id.contract_id
                            }, securityTicket).Result;

                            if (gpos_details.Length != 0)
                            {
                                if (!Parameter.should_update)
                                {
                                    List <string> gpos_types = new List <string>();

                                    if (Parameter.treatment_doctor_id != Guid.Empty)
                                    {
                                        gpos_types.Add("mm.docconnect.gpos.catalog.operation");
                                    }

                                    if (Parameter.ac_doctor_id != Guid.Empty)
                                    {
                                        gpos_types.Add("mm.docconnect.gpos.catalog.nachsorge");
                                    }

                                    if (drug_name.Contains("Bevacizumab") && Parameter.treatment_doctor_id != Guid.Empty)
                                    {
                                        gpos_types.Add("mm.docconnect.gpos.catalog.zusatzposition.bevacizumab");
                                    }

                                    if (Parameter.treatment_doctor_id != Guid.Empty)
                                    {
                                        gpos_types.Add("mm.docconnect.gpos.catalog.wartezeitenmanagement");
                                    }

                                    foreach (var gpos_type in gpos_types)
                                    {
                                        foreach (var gpos_detail in gpos_details)
                                        {
                                            if (gpos_detail.gpos_type == gpos_type)
                                            {
                                                bool gpos_condition = gpos_type == "mm.docconnect.gpos.catalog.operation" || gpos_type == "mm.docconnect.gpos.catalog.nachsorge" ?
                                                                      treatment_count.treatment_count >= gpos_detail.injection_from &&
                                                                      !gpos_details.Any(gpos => treatment_count.treatment_count >= gpos.injection_from && gpos.injection_from > gpos_detail.injection_from && gpos.gpos_type == gpos_type) : true;

                                                if (gpos_condition)
                                                {
                                                    ORM_BIL_BillPosition gpos_position = new ORM_BIL_BillPosition();
                                                    gpos_position.BIL_BilHeader_RefID        = Guid.Empty;
                                                    gpos_position.BIL_BillPositionID         = Guid.NewGuid();
                                                    gpos_position.Creation_Timestamp         = DateTime.Now;
                                                    gpos_position.Modification_Timestamp     = DateTime.Now;
                                                    gpos_position.Tenant_RefID               = securityTicket.TenantID;
                                                    gpos_position.PositionValue_IncludingTax = Convert.ToDecimal(gpos_detail.gpos_price);

                                                    gpos_position.Save(Connection, Transaction);

                                                    ORM_HEC_BIL_BillPosition hec_gpos_position = new ORM_HEC_BIL_BillPosition();
                                                    hec_gpos_position.Creation_Timestamp         = DateTime.Now;
                                                    hec_gpos_position.Ext_BIL_BillPosition_RefID = gpos_position.BIL_BillPositionID;
                                                    hec_gpos_position.HEC_BIL_BillPositionID     = Guid.NewGuid();
                                                    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.Creation_Timestamp = DateTime.Now;
                                                    hec_gpos_position_code.HEC_BIL_BillPosition_BillCodeID = Guid.NewGuid();
                                                    hec_gpos_position_code.IM_BillingCode         = gpos_detail.gpos_code;
                                                    hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                                                    hec_gpos_position_code.PotentialCode_RefID    = gpos_detail.gpos_id;
                                                    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.Creation_Timestamp = DateTime.Now;
                                                    hec_gpos_case_code.HEC_BIL_BillPosition_BillCode_RefID = hec_gpos_position_code.HEC_BIL_BillPosition_BillCodeID;
                                                    hec_gpos_case_code.HEC_CAS_Case_BillCodeID             = Guid.NewGuid();
                                                    hec_gpos_case_code.HEC_CAS_Case_RefID     = Parameter.case_id;
                                                    hec_gpos_case_code.Modification_Timestamp = DateTime.Now;
                                                    hec_gpos_case_code.Tenant_RefID           = securityTicket.TenantID;

                                                    hec_gpos_case_code.Save(Connection, Transaction);
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    var bill_position_ids = cls_Get_BillPositionIDs_for_CaseID.Invoke(Connection, Transaction, new P_CAS_GBPIDsfCID_0928()
                                    {
                                        CaseID = Parameter.case_id
                                    }, securityTicket).Result;

                                    foreach (var id in bill_position_ids)
                                    {
                                        foreach (var gpos_detail in gpos_details)
                                        {
                                            if (id.gpos_type == "mm.docconnect.gpos.catalog.operation" || id.gpos_type == "mm.docconnect.gpos.catalog.nachsorge")
                                            {
                                                if (id.gpos_type == gpos_detail.gpos_type)
                                                {
                                                    if (treatment_count.treatment_count >= gpos_detail.injection_from &&
                                                        !gpos_details.Any(gpos => treatment_count.treatment_count >= gpos.injection_from && gpos.injection_from > gpos_detail.injection_from))
                                                    {
                                                        ORM_BIL_BillPosition.Query old_gpos_positionQ = new ORM_BIL_BillPosition.Query();
                                                        old_gpos_positionQ.BIL_BillPositionID = id.bill_position_id;
                                                        old_gpos_positionQ.Tenant_RefID       = securityTicket.TenantID;
                                                        old_gpos_positionQ.IsDeleted          = false;

                                                        var old_gpos_position = ORM_BIL_BillPosition.Query.Search(Connection, Transaction, old_gpos_positionQ).SingleOrDefault();
                                                        if (old_gpos_position != null)
                                                        {
                                                            old_gpos_position.Modification_Timestamp     = DateTime.Now;
                                                            old_gpos_position.PositionValue_IncludingTax = Convert.ToDecimal(gpos_detail.gpos_price);

                                                            old_gpos_position.Save(Connection, Transaction);

                                                            ORM_HEC_BIL_BillPosition.Query old_hec_gpos_positionQ = new ORM_HEC_BIL_BillPosition.Query();
                                                            old_hec_gpos_positionQ.Ext_BIL_BillPosition_RefID = old_gpos_position.BIL_BillPositionID;
                                                            old_hec_gpos_positionQ.Tenant_RefID = securityTicket.TenantID;
                                                            old_hec_gpos_positionQ.PositionFor_Patient_RefID = Parameter.patient_id;
                                                            old_hec_gpos_positionQ.IsDeleted = false;

                                                            var old_hec_gpos_position = ORM_HEC_BIL_BillPosition.Query.Search(Connection, Transaction, old_hec_gpos_positionQ).SingleOrDefault();
                                                            if (old_hec_gpos_position != null)
                                                            {
                                                                ORM_HEC_BIL_BillPosition_BillCode.Query old_hec_gpos_position_codeQ = new ORM_HEC_BIL_BillPosition_BillCode.Query();
                                                                old_hec_gpos_position_codeQ.Tenant_RefID       = securityTicket.TenantID;
                                                                old_hec_gpos_position_codeQ.BillPosition_RefID = old_hec_gpos_position.HEC_BIL_BillPositionID;
                                                                old_hec_gpos_position_codeQ.IsDeleted          = false;

                                                                var old_hec_gpos_position_code = ORM_HEC_BIL_BillPosition_BillCode.Query.Search(Connection, Transaction, old_hec_gpos_position_codeQ).SingleOrDefault();
                                                                if (old_hec_gpos_position_code != null)
                                                                {
                                                                    old_hec_gpos_position_code.IM_BillingCode         = gpos_detail.gpos_code;
                                                                    old_hec_gpos_position_code.Modification_Timestamp = DateTime.Now;
                                                                    old_hec_gpos_position_code.PotentialCode_RefID    = gpos_detail.gpos_id;

                                                                    old_hec_gpos_position_code.Save(Connection, Transaction);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(returnValue);

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


            if (Parameter.IsDeleted == true)
            {
                P_L3MP_DP_1145 param = new P_L3MP_DP_1145();
                param.CMN_PRO_ProductID = Parameter.CMN_PRO_ProductID;

                cls_Delete_Product.Invoke(Connection, Transaction, param, securityTicket);
            }

            else
            {
                P_L3MP_SP_1045 par = new P_L3MP_SP_1045();

                par.CMN_PRO_ProductID   = Parameter.CMN_PRO_ProductID;
                par.IsDeleted           = Parameter.IsDeleted;
                par.Product_Description = Parameter.Product_Description;
                par.Product_Name_DictID = Parameter.Product_Name_DictID;
                par.Product_Number      = Parameter.Product_Number;


                if (Parameter.CMN_PRO_ProductID != Guid.Empty && Parameter.CMN_PRO_ProductID != null)
                {
                    #region Edit


                    Guid Ext_PRO_Product_RefID = cls_Save_Product.Invoke(Connection, Transaction, par, securityTicket).Result;


                    var hecProductQuery2 = new ORM_HEC_Product.Query();
                    hecProductQuery2.Ext_PRO_Product_RefID = Parameter.CMN_PRO_ProductID;
                    hecProductQuery2.IsDeleted             = false;

                    var medProduct2 = ORM_HEC_Product.Query.Search(Connection, Transaction, hecProductQuery2).FirstOrDefault();

                    if (medProduct2 != null)
                    {
                        medProduct2.Recepie = Parameter.Recepie;
                        medProduct2.Save(Connection, Transaction);
                    }
                    else
                    {
                        ORM_HEC_Product hecProductNew = new ORM_HEC_Product();

                        hecProductNew.Creation_Timestamp    = DateTime.Now;
                        hecProductNew.HEC_ProductID         = Guid.NewGuid();
                        hecProductNew.IsDeleted             = false;
                        hecProductNew.Ext_PRO_Product_RefID = Ext_PRO_Product_RefID;
                        hecProductNew.Recepie      = Parameter.Recepie;
                        hecProductNew.Tenant_RefID = securityTicket.TenantID;

                        hecProductNew.Save(Connection, Transaction);
                    }

                    #endregion
                }
                else
                {
                    #region Save

                    Guid Ext_PRO_Product_RefID = cls_Save_Product.Invoke(Connection, Transaction, par, securityTicket).Result;

                    ORM_HEC_Product hec_Product = new ORM_HEC_Product();

                    hec_Product.Creation_Timestamp    = DateTime.Now;
                    hec_Product.HEC_ProductID         = Guid.NewGuid();
                    hec_Product.IsDeleted             = false;
                    hec_Product.Ext_PRO_Product_RefID = Ext_PRO_Product_RefID;
                    hec_Product.Recepie      = Parameter.Recepie;
                    hec_Product.Tenant_RefID = securityTicket.TenantID;

                    hec_Product.Save(Connection, Transaction);

                    returnValue.Result = Ext_PRO_Product_RefID;
                    #endregion
                }
            }



            return(returnValue);

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

            /*
             * @save product
             * */
            P_L3ICaCnP_1426 par = new P_L3ICaCnP_1426();
            par.CatalogCodeITL     = Parameter.CatalogCodeITL;
            par.CatalogDescription = Parameter.CatalogDescription;
            par.CatalogName        = Parameter.CatalogName;
            par.isDeleted          = Parameter.isDeleted;
            par.SubscribedBy_BusinessParticipant_RefID = Parameter.SubscribedBy_BusinessParticipant_RefID;
            par.ValidFrom_Date = Parameter.ValidFrom_Date;
            par.ValidTo_Date   = Parameter.ValidTo_Date;
            par.CatalogLanguage_ISO_639_1_codes = Parameter.CatalogLanguage_ISO_639_1_codes;
            par.CatalogCurrency_ISO_4217        = Parameter.CatalogCurrency_ISO_4217;
            par.CatalogVersion  = Parameter.CatalogVersion;
            par.IsCatalogPublic = Parameter.IsCatalogPublic;
            par.ClientName      = Parameter.ClientName;

            List <P_L3ICaCnP_1426_Products> productList = new List <P_L3ICaCnP_1426_Products>();

            if (Parameter.Products != null)
            {
                foreach (var item in Parameter.Products)
                {
                    P_L3ICaCnP_1426_Products product = new P_L3ICaCnP_1426_Products();
                    product.isDeleted           = item.isDeleted;
                    product.IsProduct_Article   = item.IsProduct_Article;
                    product.Product_Description = item.Product_Description;
                    product.Product_Name        = item.Product_Name;
                    product.Product_Number      = item.Product_Number;
                    product.ProductITL          = item.ProductITL;
                    product.Dosage = item.Dosage;
                    product.Price  = item.Price;
                    product.Amount = item.Amount;
                    product.MeasuredInUnit_ISO_um_ums = item.MeasuredInUnit_ISO_um_ums;
                    product.VAT = item.VAT;
                    productList.Add(product);
                }

                par.Products = productList.ToArray();
            }
            if (Parameter.SupplierData != null)
            {
                P_L3ICaCnP_1426_SupplierData supplier = new P_L3ICaCnP_1426_SupplierData();
                supplier.SupplierITL   = Parameter.SupplierData.SupplierITL;
                supplier.Supplier_Name = Parameter.SupplierData.Supplier_Name;
                supplier.CountryISO    = Parameter.SupplierData.CountryISO;
                supplier.Street_Name   = Parameter.SupplierData.Street_Name;
                supplier.Street_Number = Parameter.SupplierData.Street_Number;
                supplier.ZIP           = Parameter.SupplierData.ZIP;
                supplier.Town          = Parameter.SupplierData.ZIP;
                supplier.Region_Code   = Parameter.SupplierData.Region_Code;
                supplier.TenantITL     = Parameter.SupplierData.TenantITL;

                par.SupplierData = supplier;
            }
            List <L3ICaCnP_1426> products = cls_Import_Catalog_and_Create_new_PricelIst_with_Products.Invoke(Connection, Transaction, par, securityTicket).Result.ToList();


            /*
             * @save hec_product
             * */

            var DBLanguages = cls_Get_All_Languages.Invoke(Connection, Transaction, securityTicket).Result.ToList();

            foreach (var product in products)
            {
                #region edit hec_product

                if (product.isEdit == true)
                {
                    var hec_productQuery = new ORM_HEC_Product.Query();
                    hec_productQuery.Tenant_RefID          = securityTicket.TenantID;
                    hec_productQuery.Ext_PRO_Product_RefID = product.ProductID;
                    hec_productQuery.IsDeleted             = false;

                    var hec_product = ORM_HEC_Product.Query.Search(Connection, Transaction, hec_productQuery).First();

                    //try to find dosage if it exists
                    var dosageQuery = new ORM_HEC_Product_DosageForm.Query();
                    dosageQuery.Tenant_RefID             = securityTicket.TenantID;
                    dosageQuery.IsDeleted                = false;
                    dosageQuery.GlobalPropertyMatchingID = product.Dosage;

                    var dosage = ORM_HEC_Product_DosageForm.Query.Search(Connection, Transaction, dosageQuery).FirstOrDefault();

                    //if not create new
                    if (dosage == null)
                    {
                        dosage = new ORM_HEC_Product_DosageForm();
                        dosage.HEC_Product_DosageFormID = Guid.NewGuid();//hec_product.ProductDosageForm_RefID
                        dosage.Tenant_RefID             = securityTicket.TenantID;
                        dosage.Creation_Timestamp       = DateTime.Now;

                        dosage.GlobalPropertyMatchingID = product.Dosage;
                        dosage.Save(Connection, Transaction);
                    }

                    hec_product.ProductDosageForm_RefID = dosage.HEC_Product_DosageFormID;
                    hec_product.Save(Connection, Transaction);
                }
                #endregion

                #region save hec_product
                else
                {
                    ORM_HEC_Product hec_product = new ORM_HEC_Product();
                    hec_product.Ext_PRO_Product_RefID = product.ProductID;
                    hec_product.HEC_ProductID         = Guid.NewGuid();
                    hec_product.Creation_Timestamp    = DateTime.Now;
                    hec_product.Tenant_RefID          = securityTicket.TenantID;
                    hec_product.IsDeleted             = false;

                    //try to find dosage if it exists
                    var dosageQuery = new ORM_HEC_Product_DosageForm.Query();
                    dosageQuery.Tenant_RefID             = securityTicket.TenantID;
                    dosageQuery.IsDeleted                = false;
                    dosageQuery.GlobalPropertyMatchingID = product.Dosage;

                    var dosage = ORM_HEC_Product_DosageForm.Query.Search(Connection, Transaction, dosageQuery).FirstOrDefault();

                    //if not create new
                    if (dosage == null)
                    {
                        dosage = new ORM_HEC_Product_DosageForm();
                        dosage.HEC_Product_DosageFormID = Guid.NewGuid();//hec_product.ProductDosageForm_RefID
                        dosage.Tenant_RefID             = securityTicket.TenantID;
                        dosage.Creation_Timestamp       = DateTime.Now;

                        dosage.GlobalPropertyMatchingID = product.Dosage;
                        dosage.Save(Connection, Transaction);
                    }

                    hec_product.ProductDosageForm_RefID = dosage.HEC_Product_DosageFormID;
                    hec_product.Save(Connection, Transaction);
                }
                #endregion
            }

            return(returnValue);

            #endregion UserCode
        }
Example #6
0
        protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5PA_SPEM_1413 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Bool();

            var medPro_Credentials = cls_Get_TenantMemershipData.Invoke(Connection, Transaction, securityTicket).Result;

            P_L2LN_GALFTID_1530 langParam = new P_L2LN_GALFTID_1530();
            langParam.Tenant_RefID = securityTicket.TenantID;
            var DBLanguages = cls_Get_All_Languages_ForTenantID.Invoke(Connection, Transaction, langParam, securityTicket).Result;

            var examination = ORM_HEC_ACT_PerformedAction.Query.Search(Connection, Transaction, new ORM_HEC_ACT_PerformedAction.Query()
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID,
                HEC_ACT_PerformedActionID = Parameter.ExaminationID
            }).Single();
            #region Save

            foreach (var item in Parameter.new_medication)
            {
                //check if dosage exists

                var dosageQuery = new ORM_HEC_Dosage.Query();
                dosageQuery.IsDeleted    = false;
                dosageQuery.Tenant_RefID = securityTicket.TenantID;
                dosageQuery.DosageText   = item.dosage_text;

                var dosage_table = ORM_HEC_Dosage.Query.Search(Connection, Transaction, dosageQuery).SingleOrDefault();

                if (dosage_table == null)
                {
                    dosage_table = new ORM_HEC_Dosage();
                    dosage_table.HEC_DosageID           = Guid.NewGuid();
                    dosage_table.Tenant_RefID           = securityTicket.TenantID;
                    dosage_table.Creation_Timestamp     = DateTime.Now;
                    dosage_table.Modification_Timestamp = DateTime.Now;
                    dosage_table.DosageText             = item.dosage_text;
                    dosage_table.Save(Connection, Transaction);
                }

                ORM_HEC_ACT_PerformedAction_MedicationUpdate medicationUpdate = new ORM_HEC_ACT_PerformedAction_MedicationUpdate();
                medicationUpdate.HEC_ACT_PerformedAction_MedicationUpdateID = Guid.NewGuid();
                medicationUpdate.Tenant_RefID           = securityTicket.TenantID;
                medicationUpdate.Creation_Timestamp     = DateTime.Now;
                medicationUpdate.Modification_Timestamp = DateTime.Now;
                medicationUpdate.IsSubstance            = !item.is_product;
                medicationUpdate.IsHealthcareProduct    = item.is_product;
                medicationUpdate.IntendedApplicationDuration_in_days = item.days_valid;
                medicationUpdate.HEC_ACT_PerformedAction_RefID       = Parameter.ExaminationID;
                medicationUpdate.HEC_Patient_Medication_RefID        = Guid.NewGuid();

                ORM_HEC_Patient_Medication patient_medications = new ORM_HEC_Patient_Medication();
                patient_medications.HEC_Patient_MedicationID = medicationUpdate.HEC_Patient_Medication_RefID;
                patient_medications.Patient_RefID            = Parameter.PatientID;
                patient_medications.Creation_Timestamp       = DateTime.Now;
                patient_medications.Tenant_RefID             = securityTicket.TenantID;
                patient_medications.Modification_Timestamp   = DateTime.Now;
                patient_medications.R_IsActive            = true;
                patient_medications.R_DateOfAdding        = examination.IfPerfomed_DateOfAction;
                patient_medications.R_IsHealthcareProduct = item.is_product;
                patient_medications.R_IsSubstance         = !item.is_product;
                patient_medications.R_ActiveUntill        = patient_medications.R_DateOfAdding.AddDays(item.days_valid);


                if (item.is_product)//medication is a product
                {
                    Guid Hec_ProductID = Guid.Empty;

                    //check if product exists
                    var productQuery = new ORM_CMN_PRO_Product.Query();
                    productQuery.Tenant_RefID = securityTicket.TenantID;
                    productQuery.IsDeleted    = false;
                    productQuery.ProductITL   = item.product_itl;

                    var product = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, productQuery).SingleOrDefault();

                    //if product does not exist create it
                    if (product == null)
                    {
                        ORM_CMN_PRO_Product cmn_pro_product = new ORM_CMN_PRO_Product();
                        cmn_pro_product.CMN_PRO_ProductID      = Guid.NewGuid();
                        cmn_pro_product.Tenant_RefID           = securityTicket.TenantID;
                        cmn_pro_product.Creation_Timestamp     = DateTime.Now;
                        cmn_pro_product.Modification_Timestamp = DateTime.Now;

                        Dict product_name = new Dict("cmn_pro_products");
                        for (int i = 0; i < DBLanguages.Length; i++)
                        {
                            product_name.AddEntry(DBLanguages[i].CMN_LanguageID, item.product_name);
                        }

                        cmn_pro_product.Product_Name = product_name;
                        cmn_pro_product.ProductITL   = item.product_itl;
                        cmn_pro_product.ProducingBusinessParticipant_RefID = Guid.NewGuid(); //manufacturer
                        cmn_pro_product.PackageInfo_RefID = Guid.NewGuid();                  // package info
                        cmn_pro_product.Save(Connection, Transaction);

                        ORM_CMN_BPT_BusinessParticipant manufacturer = new ORM_CMN_BPT_BusinessParticipant();
                        manufacturer.CMN_BPT_BusinessParticipantID = cmn_pro_product.ProducingBusinessParticipant_RefID;
                        manufacturer.DisplayName            = item.product_manufacturer;
                        manufacturer.IsCompany              = true;
                        manufacturer.IsNaturalPerson        = false;
                        manufacturer.Tenant_RefID           = securityTicket.TenantID;
                        manufacturer.Creation_Timestamp     = DateTime.Now;
                        manufacturer.Modification_Timestamp = DateTime.Now;
                        manufacturer.Save(Connection, Transaction);

                        ORM_CMN_PRO_PAC_PackageInfo package_info = new ORM_CMN_PRO_PAC_PackageInfo();
                        package_info.CMN_PRO_PAC_PackageInfoID = cmn_pro_product.PackageInfo_RefID;
                        package_info.Tenant_RefID           = securityTicket.TenantID;
                        package_info.Creation_Timestamp     = DateTime.Now;
                        package_info.Modification_Timestamp = DateTime.Now;

                        string amount = String.Empty;
                        string unit   = String.Empty;
                        foreach (char c in item.product_strength)
                        {
                            // Do not use IsDigit as it will include more than the characters 0 through to 9
                            if (c >= '0' && c <= '9')
                            {
                                amount += c;
                            }
                            else
                            {
                                unit += c;
                            }
                        }
                        package_info.PackageContent_Amount       = Int32.Parse(amount);
                        package_info.PackageContent_DisplayLabel = amount;


                        var unitQuery = new ORM_CMN_Unit.Query();
                        unitQuery.IsDeleted    = false;
                        unitQuery.Tenant_RefID = securityTicket.TenantID;
                        unitQuery.ISOCode      = unit;

                        var cmn_unit = ORM_CMN_Unit.Query.Search(Connection, Transaction, unitQuery).FirstOrDefault();

                        if (cmn_unit == null)
                        {
                            cmn_unit                        = new ORM_CMN_Unit();
                            cmn_unit.CMN_UnitID             = Guid.NewGuid();
                            cmn_unit.Tenant_RefID           = securityTicket.TenantID;
                            cmn_unit.Creation_Timestamp     = DateTime.Now;
                            cmn_unit.Modification_Timestamp = DateTime.Now;
                            cmn_unit.ISOCode                = unit;
                            cmn_unit.Save(Connection, Transaction);
                        }

                        package_info.PackageContent_MeasuredInUnit_RefID = cmn_unit.CMN_UnitID;
                        package_info.Save(Connection, Transaction);


                        //hec_products
                        ORM_HEC_Product hec_product = new ORM_HEC_Product();
                        hec_product.HEC_ProductID          = Guid.NewGuid();
                        hec_product.Ext_PRO_Product_RefID  = cmn_pro_product.CMN_PRO_ProductID;
                        hec_product.Tenant_RefID           = securityTicket.TenantID;
                        hec_product.Creation_Timestamp     = DateTime.Now;
                        hec_product.Modification_Timestamp = DateTime.Now;

                        Hec_ProductID = hec_product.HEC_ProductID;

                        var dosage_formQuery = new ORM_HEC_Product_DosageForm.Query();
                        dosage_formQuery.Tenant_RefID             = securityTicket.TenantID;
                        dosage_formQuery.IsDeleted                = false;
                        dosage_formQuery.GlobalPropertyMatchingID = item.product_form;

                        var dosage_form = ORM_HEC_Product_DosageForm.Query.Search(Connection, Transaction, dosage_formQuery).SingleOrDefault();

                        if (dosage_form == null)
                        {
                            dosage_form = new ORM_HEC_Product_DosageForm();
                            dosage_form.HEC_Product_DosageFormID = Guid.NewGuid();
                            dosage_form.GlobalPropertyMatchingID = item.product_form;
                            dosage_form.Tenant_RefID             = securityTicket.TenantID;
                            dosage_form.Creation_Timestamp       = DateTime.Now;
                            dosage_form.Modification_Timestamp   = DateTime.Now;

                            Dict form_name = new Dict("hec_product_dosageforms");
                            for (int i = 0; i < DBLanguages.Length; i++)
                            {
                                form_name.AddEntry(DBLanguages[i].CMN_LanguageID, item.product_form);
                            }
                            dosage_form.DosageForm_Name = form_name;
                            dosage_form.Save(Connection, Transaction);
                        }

                        hec_product.ProductDosageForm_RefID = dosage_form.HEC_Product_DosageFormID;  //dosage form
                        hec_product.Save(Connection, Transaction);


                        //product component

                        ORM_HEC_PRO_Product_Component product_component = new ORM_HEC_PRO_Product_Component();
                        product_component.HEC_PRO_Product_ComponentID = Guid.NewGuid();
                        product_component.HEC_PRO_Component_RefID     = Guid.NewGuid();//pro_component
                        product_component.HEC_PRO_Product_RefID       = hec_product.HEC_ProductID;
                        product_component.Tenant_RefID           = securityTicket.TenantID;
                        product_component.Creation_Timestamp     = DateTime.Now;
                        product_component.Modification_Timestamp = DateTime.Now;
                        product_component.Save(Connection, Transaction);

                        ORM_HEC_PRO_Component pro_component = new ORM_HEC_PRO_Component();
                        pro_component.HEC_PRO_ComponentID    = product_component.HEC_PRO_Component_RefID;
                        pro_component.Tenant_RefID           = securityTicket.TenantID;
                        pro_component.Creation_Timestamp     = DateTime.Now;
                        pro_component.Modification_Timestamp = DateTime.Now;
                        pro_component.Save(Connection, Transaction);

                        ORM_HEC_PRO_Component_SubstanceIngredient component_SubstanceIngredient = new ORM_HEC_PRO_Component_SubstanceIngredient();
                        component_SubstanceIngredient.HEC_PRO_Component_SubstanceIngredientID = Guid.NewGuid();
                        component_SubstanceIngredient.Component_RefID        = pro_component.HEC_PRO_ComponentID;
                        component_SubstanceIngredient.Tenant_RefID           = securityTicket.TenantID;
                        component_SubstanceIngredient.Creation_Timestamp     = DateTime.Now;
                        component_SubstanceIngredient.Modification_Timestamp = DateTime.Now;


                        var substanceQuery = new ORM_HEC_SUB_Substance.Query();
                        substanceQuery.IsDeleted              = false;
                        substanceQuery.Tenant_RefID           = securityTicket.TenantID;
                        substanceQuery.HealthcareSubstanceITL = item.substance_itl;

                        var substance = ORM_HEC_SUB_Substance.Query.Search(Connection, Transaction, substanceQuery).SingleOrDefault();

                        if (substance == null)
                        {
                            substance = new ORM_HEC_SUB_Substance();
                            substance.HealthcareSubstanceITL   = item.substance_itl;
                            substance.HEC_SUB_SubstanceID      = Guid.NewGuid();
                            substance.GlobalPropertyMatchingID = item.substance_name;
                            substance.Tenant_RefID             = securityTicket.TenantID;
                            substance.Creation_Timestamp       = DateTime.Now;
                            substance.Modification_Timestamp   = DateTime.Now;
                            substance.Save(Connection, Transaction);

                            ORM_HEC_SUB_Substance_Name substance_name = new ORM_HEC_SUB_Substance_Name();
                            substance_name.HEC_SUB_Substance_NameID = Guid.NewGuid();
                            substance_name.HEC_SUB_Substance_RefID  = substance.HEC_SUB_SubstanceID;

                            Dict substance_name_ = new Dict("hec_sub_substance_names");
                            for (int i = 0; i < DBLanguages.Length; i++)
                            {
                                substance_name_.AddEntry(DBLanguages[i].CMN_LanguageID, item.substance_name);
                            }
                            substance_name.SubstanceName_Label    = substance_name_;
                            substance_name.Tenant_RefID           = securityTicket.TenantID;
                            substance_name.Creation_Timestamp     = DateTime.Now;
                            substance_name.Modification_Timestamp = DateTime.Now;
                            substance_name.Save(Connection, Transaction);
                        }

                        component_SubstanceIngredient.Substance_RefID = substance.HEC_SUB_SubstanceID;
                        component_SubstanceIngredient.Save(Connection, Transaction);
                    }
                    else
                    {
                        var hec_productQuery = new ORM_HEC_Product.Query();
                        hec_productQuery.IsDeleted             = false;
                        hec_productQuery.Tenant_RefID          = securityTicket.TenantID;
                        hec_productQuery.Ext_PRO_Product_RefID = product.CMN_PRO_ProductID;

                        var hec_product = ORM_HEC_Product.Query.Search(Connection, Transaction, hec_productQuery).Single();

                        Hec_ProductID = hec_product.HEC_ProductID;
                    }


                    medicationUpdate.HEC_Product_RefID      = Hec_ProductID;
                    patient_medications.R_HEC_Product_RefID = Hec_ProductID;
                    patient_medications.R_DosageText        = item.dosage_text;
                    medicationUpdate.DosageText             = item.dosage_text;
                }
                else// medication is a substance
                {
                    medicationUpdate.IfSubstance_Strength        = item.substance_strength;
                    patient_medications.R_IfSubstance_Strength   = item.substance_strength;
                    medicationUpdate.IfSubstance_Unit_RefID      = item.substance_unit;
                    patient_medications.R_IfSubstance_Unit_RefID = item.substance_unit;
                    patient_medications.R_DosageText             = item.dosage_text;
                    medicationUpdate.DosageText = item.dosage_text;

                    var substanceQuery = new ORM_HEC_SUB_Substance.Query();
                    substanceQuery.IsDeleted              = false;
                    substanceQuery.Tenant_RefID           = securityTicket.TenantID;
                    substanceQuery.HealthcareSubstanceITL = item.substance_itl;

                    var substance = ORM_HEC_SUB_Substance.Query.Search(Connection, Transaction, substanceQuery).SingleOrDefault();

                    if (substance == null)
                    {
                        substance = new ORM_HEC_SUB_Substance();
                        substance.HealthcareSubstanceITL   = item.substance_itl;
                        substance.HEC_SUB_SubstanceID      = Guid.NewGuid();
                        substance.GlobalPropertyMatchingID = item.substance_name;
                        substance.Tenant_RefID             = securityTicket.TenantID;
                        substance.Creation_Timestamp       = DateTime.Now;
                        substance.Modification_Timestamp   = DateTime.Now;
                        substance.Save(Connection, Transaction);

                        ORM_HEC_SUB_Substance_Name substance_name = new ORM_HEC_SUB_Substance_Name();
                        substance_name.HEC_SUB_Substance_NameID = Guid.NewGuid();
                        substance_name.HEC_SUB_Substance_RefID  = substance.HEC_SUB_SubstanceID;

                        Dict substance_name_ = new Dict("hec_sub_substance_names");
                        for (int i = 0; i < DBLanguages.Length; i++)
                        {
                            substance_name_.AddEntry(DBLanguages[i].CMN_LanguageID, item.substance_name);
                        }
                        substance_name.SubstanceName_Label    = substance_name_;
                        substance_name.Tenant_RefID           = securityTicket.TenantID;
                        substance_name.Creation_Timestamp     = DateTime.Now;
                        substance_name.Modification_Timestamp = DateTime.Now;
                        substance_name.Save(Connection, Transaction);
                    }

                    medicationUpdate.IfSubstance_Substance_RefiD      = substance.HEC_SUB_SubstanceID;
                    patient_medications.R_IfSubstance_Substance_RefiD = substance.HEC_SUB_SubstanceID;
                }

                patient_medications.Save(Connection, Transaction);
                medicationUpdate.Save(Connection, Transaction);
                returnValue.Result = true;
            }

            #endregion

            #region Delete
            foreach (var item in Parameter.deleted_medications)
            {
                var medicationUpdateQuery = new ORM_HEC_ACT_PerformedAction_MedicationUpdate.Query();
                medicationUpdateQuery.IsDeleted = false;
                medicationUpdateQuery.IsMedicationDeactivated = false;
                medicationUpdateQuery.Tenant_RefID            = securityTicket.TenantID;
                medicationUpdateQuery.HEC_ACT_PerformedAction_MedicationUpdateID = item.performedAction_medicationUpdate_id;

                var medicationUpdate = ORM_HEC_ACT_PerformedAction_MedicationUpdate.Query.Search(Connection, Transaction, medicationUpdateQuery).Single();
                medicationUpdate.IsMedicationDeactivated = true;
                medicationUpdate.Save(Connection, Transaction);
            }

            #endregion
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_CAS_CDO_1202 Execute(DbConnection Connection, DbTransaction Transaction, P_CAS_CDO_1202 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_CAS_CDO_1202();
            returnValue.Result = new CAS_CDO_1202();
            //Put your code here
            var statusCodePrefix = "MO";
            var statusCode       = 0;

            var drugOrderStatus = String.Format("{0}{1}", statusCodePrefix, statusCode);

            var hec_drugQ = new ORM_HEC_Product.Query();
            hec_drugQ.Tenant_RefID  = securityTicket.TenantID;
            hec_drugQ.IsDeleted     = false;
            hec_drugQ.HEC_ProductID = Parameter.drug_id;

            var hec_drug = ORM_HEC_Product.Query.Search(Connection, Transaction, hec_drugQ).SingleOrDefault();
            if (hec_drug != null)
            {
                var ord_drug_order_header = new ORM_ORD_PRC_ProcurementOrder_Header();
                ord_drug_order_header.CreatedBy_BusinessParticipant_RefID = Parameter.created_by_bpt;
                ord_drug_order_header.ProcurementOrder_Date   = DateTime.Now;
                ord_drug_order_header.Tenant_RefID            = securityTicket.TenantID;
                ord_drug_order_header.ProcurementOrder_Number = cls_Get_Next_Order_Number.Invoke(Connection, Transaction, securityTicket).Result.order_number;

                returnValue.Result.procurement_order_header_id = ord_drug_order_header.ORD_PRC_ProcurementOrder_HeaderID;

                var drug_order_status = new ORM_ORD_PRC_ProcurementOrder_Status();
                drug_order_status.GlobalPropertyMatchingID = String.Format("mm.doc.connect.drug.order.status.{0}", drugOrderStatus.ToLower());
                drug_order_status.Status_Code  = statusCode;
                drug_order_status.Tenant_RefID = securityTicket.TenantID;
                drug_order_status.Status_Name  = new Dict(ORM_ORD_PRC_ProcurementOrder_Status.TableName);
                foreach (var lang in Parameter.all_languagesL)
                {
                    drug_order_status.Status_Name.AddEntry(lang.CMN_LanguageID, drugOrderStatus);
                }

                drug_order_status.Save(Connection, Transaction);

                ord_drug_order_header.Current_ProcurementOrderStatus_RefID = drug_order_status.ORD_PRC_ProcurementOrder_StatusID;
                ord_drug_order_header.Save(Connection, Transaction);

                var drug_order_status_history = new ORM_ORD_PRC_ProcurementOrder_StatusHistory();
                drug_order_status_history.ProcurementOrder_Header_RefID = ord_drug_order_header.ORD_PRC_ProcurementOrder_HeaderID;
                drug_order_status_history.ProcurementOrder_Status_RefID = drug_order_status.ORD_PRC_ProcurementOrder_StatusID;
                drug_order_status_history.Tenant_RefID     = securityTicket.TenantID;
                drug_order_status_history.IsStatus_Created = true;
                drug_order_status_history.TriggeredAt_Date = DateTime.Now;
                drug_order_status_history.TriggeredBy_BusinessParticipant_RefID = Parameter.created_by_bpt;

                drug_order_status_history.Save(Connection, Transaction);

                var ord_drug_order_position = new ORM_ORD_PRC_ProcurementOrder_Position();
                ord_drug_order_position.CMN_PRO_Product_RefID            = hec_drug.Ext_PRO_Product_RefID;
                ord_drug_order_position.Position_RequestedDateOfDelivery = Parameter.delivery_date;
                ord_drug_order_position.ProcurementOrder_Header_RefID    = ord_drug_order_header.ORD_PRC_ProcurementOrder_HeaderID;
                ord_drug_order_position.Tenant_RefID = securityTicket.TenantID;
                ord_drug_order_position.RequestedDateOfDelivery_TimeFrame_From = Parameter.is_alternative_delivery_date ? Parameter.alternative_delivery_date_from : Parameter.treatment_date.AddHours(08).AddMinutes(00).AddSeconds(00);
                ord_drug_order_position.RequestedDateOfDelivery_TimeFrame_To   = Parameter.is_alternative_delivery_date ? Parameter.alternative_delivery_date_to : Parameter.treatment_date.AddHours(17).AddMinutes(59).AddSeconds(59);
                ord_drug_order_position.IsProFormaOrderPosition = Parameter.is_label_only;
                ord_drug_order_position.Position_Comment        = Parameter.order_comment;

                if (Parameter.is_send_invoice_to_practice)
                {
                    var id = Guid.Empty;
                    var practice_account = cls_Get_Practice_AccountID_for_PracticeID.Invoke(Connection, Transaction, new P_DO_GPAIDfPID_1351()
                    {
                        PracticeID = Parameter.practice_id
                    }, securityTicket).Result;
                    if (practice_account != null)
                    {
                        id = practice_account.accountID;
                    }

                    var invoice_practice_accountQ = new ORM_USR_Account.Query();
                    invoice_practice_accountQ.USR_AccountID = id;
                    invoice_practice_accountQ.Tenant_RefID  = securityTicket.TenantID;
                    invoice_practice_accountQ.IsDeleted     = false;

                    var invoice_practice_account = ORM_USR_Account.Query.Search(Connection, Transaction, invoice_practice_accountQ).SingleOrDefault();
                    if (invoice_practice_account != null)
                    {
                        ord_drug_order_position.BillTo_BusinessParticipant_RefID = invoice_practice_account.BusinessParticipant_RefID;
                    }
                }

                ord_drug_order_position.Save(Connection, Transaction);

                var ord_drug_order_history = new ORM_ORD_PRC_ProcurementOrder_Position_History();
                ord_drug_order_history.Creation_Timestamp     = DateTime.Now;
                ord_drug_order_history.IsCreated              = true;
                ord_drug_order_history.Modification_Timestamp = DateTime.Now;
                ord_drug_order_history.Tenant_RefID           = securityTicket.TenantID;
                ord_drug_order_history.TriggeredBy_BusinessParticipant_RefID = Parameter.created_by_bpt;
                ord_drug_order_history.ProcurementOrder_Position_RefID       = ord_drug_order_position.ORD_PRC_ProcurementOrder_PositionID;

                ord_drug_order_history.Save(Connection, Transaction);

                var hec_drug_order_position = new ORM_HEC_PRC_ProcurementOrder_Position();
                hec_drug_order_position.Creation_Timestamp = DateTime.Now;
                hec_drug_order_position.Ext_ORD_PRC_ProcurementOrder_Position_RefID = ord_drug_order_position.ORD_PRC_ProcurementOrder_PositionID;
                hec_drug_order_position.Modification_Timestamp   = DateTime.Now;
                hec_drug_order_position.OrderedFor_Patient_RefID = Parameter.patient_id;
                hec_drug_order_position.Tenant_RefID             = securityTicket.TenantID;
                hec_drug_order_position.IfProFormaOrderPosition_PrintLabelOnly = Parameter.is_label_only;
                hec_drug_order_position.IsOrderForPatient_PatientFeeWaived     = Parameter.is_patient_fee_waived;

                if (Parameter.treatment_doctor_id != Guid.Empty)
                {
                    hec_drug_order_position.OrderedFor_Doctor_RefID      = Parameter.treatment_doctor_id;
                    hec_drug_order_position.OrderedForDoctor_DisplayName = GenericUtils.GetDoctorName(Parameter.treatment_doctor_details);
                }
                else
                {
                    var doctor_id = cls_Get_DoctorID_for_AccountID.Invoke(Connection, Transaction, securityTicket).Result;
                    if (doctor_id != null)
                    {
                        var doctor = cls_Get_Doctor_Details_for_DoctorID.Invoke(Connection, Transaction, new P_DO_GDDfDID_0823()
                        {
                            DoctorID = doctor_id.DoctorID
                        }, securityTicket).Result.SingleOrDefault();
                        if (doctor != null)
                        {
                            hec_drug_order_position.OrderedFor_Doctor_RefID      = doctor.id;
                            hec_drug_order_position.OrderedForDoctor_DisplayName = GenericUtils.GetDoctorName(doctor);
                        }
                    }
                }

                hec_drug_order_position.OrderedForPatient_DisplayName = Parameter.patient_details.patient_last_name + " " + Parameter.patient_details.patient_first_name;

                hec_drug_order_position.Save(Connection, Transaction);

                returnValue.Result.procurement_order_position_id = hec_drug_order_position.HEC_PRC_ProcurementOrder_PositionID;

                var practice_invoice_universal_property = ORM_HEC_CAS_Case_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_CAS_Case_UniversalProperty.Query()
                {
                    GlobalPropertyMatchingID = "mm.doc.connect.case.practice.invoice",
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted = false
                }).SingleOrDefault();

                if (practice_invoice_universal_property == null)
                {
                    practice_invoice_universal_property = new ORM_HEC_CAS_Case_UniversalProperty();
                    practice_invoice_universal_property.Tenant_RefID             = securityTicket.TenantID;
                    practice_invoice_universal_property.PropertyName             = "Send Invoice to Practice";
                    practice_invoice_universal_property.IsValue_Boolean          = true;
                    practice_invoice_universal_property.GlobalPropertyMatchingID = "mm.doc.connect.case.practice.invoice";
                    practice_invoice_universal_property.Modification_Timestamp   = DateTime.Now;

                    practice_invoice_universal_property.Save(Connection, Transaction);
                }

                var practice_invoice_universal_property_value = ORM_HEC_CAS_Case_UniversalPropertyValue.Query.Search(Connection, Transaction, new ORM_HEC_CAS_Case_UniversalPropertyValue.Query()
                {
                    HEC_CAS_Case_RefID = Parameter.case_id,
                    HEC_CAS_Case_UniversalProperty_RefID = practice_invoice_universal_property.HEC_CAS_Case_UniversalPropertyID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (practice_invoice_universal_property_value == null)
                {
                    practice_invoice_universal_property_value = new ORM_HEC_CAS_Case_UniversalPropertyValue();
                    practice_invoice_universal_property_value.Tenant_RefID       = securityTicket.TenantID;
                    practice_invoice_universal_property_value.HEC_CAS_Case_RefID = Parameter.case_id;
                    practice_invoice_universal_property_value.HEC_CAS_Case_UniversalProperty_RefID = practice_invoice_universal_property.HEC_CAS_Case_UniversalPropertyID;
                }
                practice_invoice_universal_property_value.Modification_Timestamp = DateTime.Now;
                practice_invoice_universal_property_value.Value_Boolean          = Parameter.is_send_invoice_to_practice;

                practice_invoice_universal_property_value.Save(Connection, Transaction);
            }

            return(returnValue);

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

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

            var languages = ORM_CMN_Language.Query.Search(Connection, Transaction, languageQuery);

            var product = new ORM_CMN_PRO_Product();

            if (Parameter.ArticleID == Guid.Empty)
            {
                #region ORM_CMN_PRO_Product

                product = new ORM_CMN_PRO_Product();
                product.CMN_PRO_ProductID = Guid.NewGuid();
                product.ProductITL        = Guid.NewGuid().ToString();

                product.IsProduct_Article             = true;
                product.IsProductAvailableForOrdering = true;
                product.IsImportedFromExternalCatalog = false;

                product.Product_Name        = new Dict(ORM_CMN_PRO_Product.TableName);
                product.Product_Description = new Dict(ORM_CMN_PRO_Product.TableName);

                product.PackageInfo_RefID = Guid.NewGuid();

                product.Creation_Timestamp = DateTime.Now;
                product.Tenant_RefID       = securityTicket.TenantID;

                product.Save(Connection, Transaction);

                #endregion

                #region CustomArticles Group

                var customerArticlesGroupID = Guid.Empty;

                var customArticlesGlobalMatching = EnumUtils.GetEnumDescription(EProductGroup.CustomArticles);

                var customerArticlesGroup = ORM_CMN_PRO_ProductGroup.Query.Search(Connection, Transaction, new ORM_CMN_PRO_ProductGroup.Query()
                {
                    GlobalPropertyMatchingID = customArticlesGlobalMatching,
                    IsDeleted    = false,
                    Tenant_RefID = securityTicket.TenantID
                });

                if (customerArticlesGroup == null || customerArticlesGroup.Count() == 0)
                {
                    var group = new ORM_CMN_PRO_ProductGroup();
                    group.CMN_PRO_ProductGroupID   = Guid.NewGuid();
                    group.GlobalPropertyMatchingID = customArticlesGlobalMatching;
                    group.ProductGroup_Name        = new Dict(ORM_CMN_PRO_ProductGroup.TableName);
                    foreach (var language in languages)
                    {
                        group.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "Custom Articles");
                    }
                    group.ProductGroup_Description = new Dict(ORM_CMN_PRO_ProductGroup.TableName);
                    group.IsDeleted          = false;
                    group.Creation_Timestamp = DateTime.Now;
                    group.Tenant_RefID       = securityTicket.TenantID;
                    group.Save(Connection, Transaction);

                    customerArticlesGroupID = group.CMN_PRO_ProductGroupID;
                }
                else
                {
                    customerArticlesGroupID = customerArticlesGroup.Single().CMN_PRO_ProductGroupID;
                }

                var product2Group = new ORM_CMN_PRO_Product_2_ProductGroup();
                product2Group.AssignmentID               = Guid.NewGuid();
                product2Group.CMN_PRO_Product_RefID      = product.CMN_PRO_ProductID;
                product2Group.CMN_PRO_ProductGroup_RefID = customerArticlesGroupID;
                product2Group.Creation_Timestamp         = DateTime.Now;
                product2Group.Tenant_RefID               = securityTicket.TenantID;
                product2Group.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                product.Load(Connection, Transaction, Parameter.ArticleID);
            }

            #region ORM_CMN_PRO_Product

            product.Product_Number = Parameter.PZN;

            foreach (var language in languages)
            {
                product.Product_Name.UpdateEntry(language.CMN_LanguageID, Parameter.ArticleName);
            }

            foreach (var language in languages)
            {
                product.Product_Description.UpdateEntry(language.CMN_LanguageID, Parameter.Notice);
            }

            product.DefaultStorageTemperature_min_in_kelvin = Parameter.StorageTemperatureFrom_in_kelvin;
            product.DefaultStorageTemperature_max_in_kelvin = Parameter.StorageTemperatureTo_in_kelvin;
            product.DefaultExpirationPeriod_in_sec          = Parameter.Expiring_in_seconds;

            product.ProductType_RefID = Parameter.ArticleType_RefID;

            product.IsPlaceholderArticle = Parameter.IsDummy;

            product.IsStorage_CoolingRequired      = Parameter.IsStorage_CoolingRequired;
            product.IsStorage_BatchNumberMandatory = Parameter.IsStorage_BatchNumberMandatory;
            product.IsStorage_ExpiryDateMandatory  = Parameter.IsStorage_ExpiryDateMandatory;
            product.IsProductPartOfDefaultStock    = Parameter.IsProduct_PartOfDefaultStock;

            var xml = new ProductAdditionalInfoXML()
            {
                IsPharmacyOnlyDistribution = Parameter.IsProduct_PharmacyOnlyDistribution
            };
            product.ProductAdditionalInfoXML = xml.ToPayload();

            product.ProductSuccessor_RefID = Parameter.ProductSuccessor_RefID;

            product.Save(Connection, Transaction);

            #endregion

            #region ORM_HEC_Product

            var query = new ORM_HEC_Product.Query();
            query.Ext_PRO_Product_RefID = product.CMN_PRO_ProductID;
            query.IsDeleted             = false;
            query.Tenant_RefID          = securityTicket.TenantID;

            var hecProduct = ORM_HEC_Product.Query.Search(Connection, Transaction, query).SingleOrDefault();
            if (hecProduct == null)
            {
                hecProduct = new ORM_HEC_Product();
                hecProduct.HEC_ProductID         = Guid.NewGuid();
                hecProduct.Ext_PRO_Product_RefID = product.CMN_PRO_ProductID;
                hecProduct.Creation_Timestamp    = DateTime.Now;
                hecProduct.Tenant_RefID          = securityTicket.TenantID;
            }
            hecProduct.ProductDosageForm_RefID = Parameter.DosageForm_RefID;
            hecProduct.IsProduct_AddictiveDrug = Parameter.IsProduct_AddictiveDrug;
            hecProduct.Save(Connection, Transaction);

            #endregion

            #region ORM_CMN_PRO_Product_2_ProductGroup

            var groupQuery = new ORM_CMN_PRO_Product_2_ProductGroup.Query();
            groupQuery.CMN_PRO_Product_RefID = product.CMN_PRO_ProductID;
            groupQuery.IsDeleted             = false;
            groupQuery.Tenant_RefID          = securityTicket.TenantID;

            var alreadyPersistedGroups = ORM_CMN_PRO_Product_2_ProductGroup.Query.Search(Connection, Transaction, groupQuery);

            //delete removed groups
            foreach (var item in alreadyPersistedGroups)
            {
                var globalGroup = new ORM_CMN_PRO_ProductGroup();
                globalGroup.Load(Connection, Transaction, item.CMN_PRO_ProductGroup_RefID);

                if (!Parameter.ArticleGroup_RefIDs.Contains(item.CMN_PRO_ProductGroup_RefID) && String.IsNullOrEmpty(globalGroup.GlobalPropertyMatchingID))
                {
                    item.IsDeleted = true;
                    item.Save(Connection, Transaction);
                }
            }

            //add new groups
            foreach (var groupID in Parameter.ArticleGroup_RefIDs)
            {
                if (!alreadyPersistedGroups.Select(i => i.CMN_PRO_ProductGroup_RefID).Contains(groupID))
                {
                    var group = new ORM_CMN_PRO_Product_2_ProductGroup();
                    group.AssignmentID               = Guid.NewGuid();
                    group.CMN_PRO_Product_RefID      = product.CMN_PRO_ProductID;
                    group.CMN_PRO_ProductGroup_RefID = groupID;
                    group.Creation_Timestamp         = DateTime.Now;
                    group.Tenant_RefID               = securityTicket.TenantID;
                    group.Save(Connection, Transaction);
                }
            }

            #endregion

            #region ORM_CMN_PRO_Product_SalesTaxAssignmnet

            var salesTaxQuery = new ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query();
            salesTaxQuery.Product_RefID = product.CMN_PRO_ProductID;
            salesTaxQuery.IsDeleted     = false;
            salesTaxQuery.Tenant_RefID  = securityTicket.TenantID;

            var salesTax = ORM_CMN_PRO_Product_SalesTaxAssignmnet.Query.Search(Connection, Transaction, salesTaxQuery).SingleOrDefault();
            if (salesTax == null)
            {
                salesTax = new ORM_CMN_PRO_Product_SalesTaxAssignmnet();
                salesTax.CMN_PRO_Product_SalesTaxAssignmnetID = Guid.NewGuid();
                salesTax.Product_RefID      = product.CMN_PRO_ProductID;
                salesTax.Creation_Timestamp = DateTime.Now;
                salesTax.Tenant_RefID       = securityTicket.TenantID;
            }
            salesTax.ApplicableSalesTax_RefID = Parameter.VAT_RefID;
            salesTax.Save(Connection, Transaction);

            #endregion

            #region ORM_CMN_PRO_Product_2_ProductCode

            var product2CodeQuery = new ORM_CMN_PRO_Product_2_ProductCode.Query();
            product2CodeQuery.CMN_PRO_Product_RefID = product.CMN_PRO_ProductID;
            product2CodeQuery.Tenant_RefID          = securityTicket.TenantID;
            product2CodeQuery.IsDeleted             = false;

            var productCodeAssignment = ORM_CMN_PRO_Product_2_ProductCode.Query.Search(Connection, Transaction, product2CodeQuery).SingleOrDefault();

            if (productCodeAssignment == null)
            {
                #region ORM_CMN_PRO_ProductCode

                //Get Product Code Type or create it if not exist
                var eanID = DMProductCodeTypes.Get_ProductCodeType_ByGlobalMatchingID(Connection, Transaction, EProductCodeType.EAN, securityTicket);

                var productCode = new ORM_CMN_PRO_ProductCode();
                productCode.CMN_PRO_ProductCodeID  = Guid.NewGuid();
                productCode.ProductCode_Type_RefID = eanID;
                productCode.ProductCode_Value      = Parameter.EAN;
                productCode.Creation_Timestamp     = DateTime.Now;
                productCode.Tenant_RefID           = securityTicket.TenantID;
                productCode.Save(Connection, Transaction);

                #endregion

                #region ORM_CMN_PRO_Product_2_ProductCode

                var product2Code = new ORM_CMN_PRO_Product_2_ProductCode();
                product2Code.AssignmentID              = Guid.NewGuid();
                product2Code.CMN_PRO_Product_RefID     = product.CMN_PRO_ProductID;
                product2Code.CMN_PRO_ProductCode_RefID = productCode.CMN_PRO_ProductCodeID;
                product2Code.Creation_Timestamp        = DateTime.Now;
                product2Code.Tenant_RefID              = securityTicket.TenantID;
                product2Code.Save(Connection, Transaction);

                #endregion
            }
            else
            {
                #region ORM_CMN_PRO_ProductCode

                var productCode = new ORM_CMN_PRO_ProductCode();
                productCode.Load(Connection, Transaction, productCodeAssignment.CMN_PRO_ProductCode_RefID);
                productCode.ProductCode_Value = Parameter.EAN;
                productCode.Save(Connection, Transaction);

                #endregion
            }

            #endregion

            #region ORM_CMN_PRO_PackageInfo

            var packageInfo = new ORM_CMN_PRO_PAC_PackageInfo();
            packageInfo.Load(Connection, Transaction, product.PackageInfo_RefID);
            if (packageInfo.CMN_PRO_PAC_PackageInfoID == Guid.Empty)
            {
                packageInfo = new ORM_CMN_PRO_PAC_PackageInfo();
                packageInfo.CMN_PRO_PAC_PackageInfoID = product.PackageInfo_RefID;
                packageInfo.Creation_Timestamp        = DateTime.Now;
                packageInfo.Tenant_RefID = securityTicket.TenantID;
            }
            packageInfo.PackageContent_Amount               = PackageAmountUtils.GetPackageAmount(Parameter.UnitAmount);
            packageInfo.PackageContent_DisplayLabel         = Parameter.UnitAmount;
            packageInfo.PackageContent_MeasuredInUnit_RefID = Parameter.Unit_RefID;
            packageInfo.Save(Connection, Transaction);

            #endregion

            #region Producer

            var producer = new ORM_CMN_BPT_BusinessParticipant();
            producer.Load(Connection, Transaction, product.ProducingBusinessParticipant_RefID);
            if (producer.CMN_BPT_BusinessParticipantID == Guid.Empty)
            {
                producer.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                producer.IsCompany          = true;
                producer.Tenant_RefID       = securityTicket.TenantID;
                producer.Creation_Timestamp = DateTime.Now;

                product.ProducingBusinessParticipant_RefID = producer.CMN_BPT_BusinessParticipantID;
                product.Save(Connection, Transaction);
            }
            producer.DisplayName = Parameter.Producer;
            producer.Save(Connection, Transaction);

            #endregion

            returnValue.Result = product.CMN_PRO_ProductID;
            return(returnValue);

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

            List <L2PD_GAPfTI_1541> allProducts = cls_Get_Product_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result.ToList();

            List <L3MP_GPfTID_1602> sortedData = new List <L3MP_GPfTID_1602>();

            for (int i = 0; i < allProducts.Count; i++)
            {
                //Ovo ce se brisati#################################

                var cmn_pro_product_2_productGroupQuery = new ORM_CMN_PRO_Product_2_ProductGroup.Query();
                cmn_pro_product_2_productGroupQuery.Tenant_RefID          = securityTicket.TenantID;
                cmn_pro_product_2_productGroupQuery.CMN_PRO_Product_RefID = allProducts[i].CMN_PRO_ProductID;
                cmn_pro_product_2_productGroupQuery.IsDeleted             = false;

                var cmn_pro_product_2_productGroup = ORM_CMN_PRO_Product_2_ProductGroup.Query.Search(Connection, Transaction, cmn_pro_product_2_productGroupQuery).FirstOrDefault();
                //#################################

                if (cmn_pro_product_2_productGroup == null)
                {
                    L3MP_GPfTID_1602 product = new L3MP_GPfTID_1602();

                    product.CMN_PRO_ProductID   = allProducts[i].CMN_PRO_ProductID;
                    product.Creation_Timestamp  = allProducts[i].Creation_Timestamp;
                    product.Product_Description = allProducts[i].Product_Description;
                    product.Product_Name_DictID = allProducts[i].Product_Name_DictID;
                    product.Product_Number      = allProducts[i].Product_Number;
                    product.Tenant_RefID        = allProducts[i].Tenant_RefID;

                    #region Surveys

                    var surveysQuery = new ORM_CMN_PRO_Product_Questionnaire_Assignment.Query();
                    surveysQuery.CMN_PRO_Product_RefID = allProducts[i].CMN_PRO_ProductID;
                    surveysQuery.IsDeleted             = false;

                    var surveyes = ORM_CMN_PRO_Product_Questionnaire_Assignment.Query.Search(Connection, Transaction, surveysQuery).ToList();

                    if (surveyes.Count != 0)
                    {
                        List <L3MP_GPfTID_1602_Surveys> listOfSurveys = new List <L3MP_GPfTID_1602_Surveys>();

                        foreach (var survey in surveyes)
                        {
                            L3MP_GPfTID_1602_Surveys surveyData = new L3MP_GPfTID_1602_Surveys();
                            surveyData.CMN_PRO_Product_Questionnaire_AssignmentID = survey.CMN_PRO_Product_Questionnaire_AssignmentID;
                            listOfSurveys.Add(surveyData);
                        }

                        product.Surveys = listOfSurveys.ToArray();
                    }

                    #endregion

                    #region Medical_ProductData

                    var medicalProductDataQuery = new ORM_HEC_Product.Query();
                    medicalProductDataQuery.Ext_PRO_Product_RefID = allProducts[i].CMN_PRO_ProductID;
                    medicalProductDataQuery.IsDeleted             = false;

                    var medicalProductData = ORM_HEC_Product.Query.Search(Connection, Transaction, medicalProductDataQuery).FirstOrDefault();

                    if (medicalProductData != null)
                    {
                        L3MP_GPfTID_1602_Medical_ProductData productData = new L3MP_GPfTID_1602_Medical_ProductData();
                        productData.HEC_ProductID = medicalProductData.HEC_ProductID;
                        productData.Recepie       = medicalProductData.Recepie;

                        product.Medical_ProductData = productData;
                    }

                    #endregion

                    sortedData.Add(product);
                }
                else
                {
                    continue;
                }
            }

            returnValue.Result = sortedData.ToArray();

            return(returnValue);

            #endregion UserCode
        }