protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_CAS_SCP_1308 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            var caseProperty = ORM_HEC_CAS_Case_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_CAS_Case_UniversalProperty.Query()
            {
                GlobalPropertyMatchingID = Parameter.property_gpm_id,
                PropertyName             = Parameter.property_name,
                Tenant_RefID             = securityTicket.TenantID,
                IsValue_Boolean          = Parameter.property_boolean_value.HasValue,
                IsValue_Number           = Parameter.property_numeric_value.HasValue,
                IsValue_String           = !String.IsNullOrEmpty(Parameter.property_string_value),
                IsDeleted = false
            }).SingleOrDefault();

            if (caseProperty == null)
            {
                caseProperty = new ORM_HEC_CAS_Case_UniversalProperty()
                {
                    IsValue_Boolean          = Parameter.property_boolean_value.HasValue,
                    IsValue_Number           = Parameter.property_numeric_value.HasValue,
                    IsValue_String           = !String.IsNullOrEmpty(Parameter.property_string_value),
                    GlobalPropertyMatchingID = Parameter.property_gpm_id,
                    Modification_Timestamp   = DateTime.Now,
                    Tenant_RefID             = securityTicket.TenantID,
                    PropertyName             = Parameter.property_name
                };

                caseProperty.Save(Connection, Transaction);
            }

            var casePropertyValue = 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 = caseProperty.HEC_CAS_Case_UniversalPropertyID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (casePropertyValue == null)
            {
                casePropertyValue = new ORM_HEC_CAS_Case_UniversalPropertyValue();
                casePropertyValue.HEC_CAS_Case_RefID = Parameter.case_id;
                casePropertyValue.HEC_CAS_Case_UniversalProperty_RefID = caseProperty.HEC_CAS_Case_UniversalPropertyID;
                casePropertyValue.Tenant_RefID = securityTicket.TenantID;
            }

            casePropertyValue.Modification_Timestamp = DateTime.Now;
            casePropertyValue.Value_Boolean          = Parameter.property_boolean_value.HasValue ? Parameter.property_boolean_value.Value : false;
            casePropertyValue.Value_Number           = Parameter.property_numeric_value.HasValue ? Parameter.property_numeric_value.Value : 0;
            casePropertyValue.Value_String           = !String.IsNullOrEmpty(Parameter.property_string_value) ? Parameter.property_string_value : null;

            casePropertyValue.Save(Connection, Transaction);
            return(returnValue);

            #endregion UserCode
        }
Example #2
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_ARCH_UCPD_0950 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here
            if (Parameter.PlannedActionID == Guid.Empty)
            {
                return(returnValue);
            }

            var documentUpload = ORM_DOC_Document.Query.Search(Connection, Transaction, new ORM_DOC_Document.Query()
            {
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false,
                Alias        = Parameter.PlannedActionID.ToString()
            }).SingleOrDefault();

            var documentUploadRevision = new ORM_DOC_DocumentRevision();
            documentUploadRevision.Revision = 0;

            if (documentUpload == null)
            {
                documentUpload = new ORM_DOC_Document();
                documentUpload.Tenant_RefID             = securityTicket.TenantID;
                documentUpload.Alias                    = Parameter.PlannedActionID.ToString();
                documentUpload.GlobalPropertyMatchingID = "case pdf";

                documentUpload.Save(Connection, Transaction);
            }
            else
            {
                var previousDocumentUploadRevision = ORM_DOC_DocumentRevision.Query.Search(Connection, Transaction, new ORM_DOC_DocumentRevision.Query()
                {
                    IsLastRevision = true,
                    Tenant_RefID   = securityTicket.TenantID,
                    IsDeleted      = false,
                    Document_RefID = documentUpload.DOC_DocumentID
                }).SingleOrDefault();

                previousDocumentUploadRevision.IsLastRevision         = false;
                previousDocumentUploadRevision.Modification_Timestamp = DateTime.Now;

                previousDocumentUploadRevision.Save(Connection, Transaction);

                documentUploadRevision.Revision = previousDocumentUploadRevision.Revision + 1;
            }

            documentUploadRevision.File_MIMEType       = Parameter.Mime;
            documentUploadRevision.Tenant_RefID        = securityTicket.TenantID;
            documentUploadRevision.Document_RefID      = documentUpload.DOC_DocumentID;
            documentUploadRevision.UploadedByAccount   = securityTicket.AccountID;
            documentUploadRevision.File_ServerLocation = Parameter.DocumentID.ToString();
            documentUploadRevision.File_Name           = Parameter.DocumentName;
            documentUploadRevision.File_Description    = Parameter.CaseID.ToString();
            documentUploadRevision.IsLastRevision      = true;

            documentUploadRevision.Save(Connection, Transaction);

            var docStructure = ORM_DOC_Structure.Query.Search(Connection, Transaction, new ORM_DOC_Structure.Query()
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID,
                Label        = Parameter.CaseID.ToString()
            }).FirstOrDefault();

            if (docStructure == null)
            {
                docStructure = new ORM_DOC_Structure();
                docStructure.Tenant_RefID = securityTicket.TenantID;
                docStructure.Label        = Parameter.CaseID.ToString();

                docStructure.Save(Connection, Transaction);
            }

            var doc2docStructure = new ORM_DOC_Document_2_Structure();
            doc2docStructure.Tenant_RefID    = securityTicket.TenantID;
            doc2docStructure.Document_RefID  = documentUpload.DOC_DocumentID;
            doc2docStructure.Structure_RefID = docStructure.DOC_StructureID;

            doc2docStructure.Save(Connection, Transaction);

            #region Case property
            var caseProperty = ORM_HEC_CAS_Case_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_CAS_Case_UniversalProperty.Query()
            {
                GlobalPropertyMatchingID = ECaseProperty.ReportDownloaded.Value(),
                Tenant_RefID             = securityTicket.TenantID,
                IsValue_String           = true,
                IsDeleted    = false,
                PropertyName = "Case Report Downloaded"
            }).SingleOrDefault();

            if (caseProperty == null)
            {
                caseProperty = new ORM_HEC_CAS_Case_UniversalProperty();
                caseProperty.GlobalPropertyMatchingID = ECaseProperty.ReportDownloaded.Value();
                caseProperty.IsValue_String           = true;
                caseProperty.Modification_Timestamp   = DateTime.Now;
                caseProperty.PropertyName             = "Case Report Downloaded";
                caseProperty.Tenant_RefID             = securityTicket.TenantID;

                caseProperty.Save(Connection, Transaction);
            }

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

            if (casePropertyValue == null)
            {
                casePropertyValue = new ORM_HEC_CAS_Case_UniversalPropertyValue();
                casePropertyValue.HEC_CAS_Case_RefID = Parameter.CaseID;
                casePropertyValue.HEC_CAS_Case_UniversalProperty_RefID = caseProperty.HEC_CAS_Case_UniversalPropertyID;
                casePropertyValue.Tenant_RefID = securityTicket.TenantID;
            }

            casePropertyValue.Modification_Timestamp = DateTime.Now;
            if (casePropertyValue.Value_String == null)
            {
                casePropertyValue.Value_String = Parameter.PlannedActionID.ToString();
            }
            else
            {
                if (!casePropertyValue.Value_String.Contains(Parameter.PlannedActionID.ToString()))
                {
                    casePropertyValue.Value_String += ";" + Parameter.PlannedActionID.ToString();
                }
            }

            casePropertyValue.Save(Connection, Transaction);
            #endregion

            if (!Parameter.IsBackgroundTask)
            {
                #region Update elastic
                try
                {
                    var settlement = Get_Settlement.GetSettlementForID(Parameter.PlannedActionID.ToString(), securityTicket);
                    settlement.is_report_downloaded = true;

                    Add_new_Settlement.Import_Settlement_to_ElasticDB(new List <Settlement_Model>()
                    {
                        settlement
                    }, securityTicket.TenantID.ToString());

                    var patientDetails = Retrieve_Patients.Get_PatientDetaiForID(Parameter.PlannedActionID.ToString(), securityTicket);
                    patientDetails.if_settlement_is_report_downloaded = true;

                    Add_New_Patient.ImportPatientDetailsToElastic(new List <PatientDetailViewModel>()
                    {
                        patientDetails
                    }, securityTicket.TenantID.ToString());
                }
                catch { }
            }

            #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
        }
        protected static FR_String Execute(DbConnection Connection, DbTransaction Transaction, P_CAS_SCONfOID_1442 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_String();
            //Put your code here
            var caseOrderNumber     = 00001;
            var lastCaseOrderNumber = cls_Get_Last_Case_Order_Number_for_PracticeBSNR.Invoke(Connection, Transaction, new P_CAS_GLCONfPBSNR_1534
            {
                PracticeBSNR = String.Format("%{0}-%", Parameter.practice_bsnr)
            }, securityTicket).Result;
            if (lastCaseOrderNumber != null)
            {
                caseOrderNumber = lastCaseOrderNumber.CaseOrderNumber + 1;
            }

            var newCaseNumber = String.Format("{0}-{1}", Parameter.practice_bsnr, caseOrderNumber.ToString("D5"));

            var cases = cls_Get_CaseIDs_for_OrderIDs.Invoke(Connection, Transaction, new P_CAS_GCIDsfOIDs_1508
            {
                OrderIDs = Parameter.order_ids
            }, securityTicket).Result;

            foreach (var cas in cases)
            {
                var case_universal_property = ORM_HEC_CAS_Case_UniversalProperty.Query.Search(Connection, Transaction, new ORM_HEC_CAS_Case_UniversalProperty.Query()
                {
                    GlobalPropertyMatchingID = ECaseProperty.CaseOrderNumber.Value(),
                    Tenant_RefID             = securityTicket.TenantID,
                    IsDeleted = false
                }).SingleOrDefault();

                if (case_universal_property == null)
                {
                    case_universal_property = new ORM_HEC_CAS_Case_UniversalProperty();
                    case_universal_property.Tenant_RefID             = securityTicket.TenantID;
                    case_universal_property.PropertyName             = "Case order number";
                    case_universal_property.IsValue_Boolean          = true;
                    case_universal_property.GlobalPropertyMatchingID = ECaseProperty.CaseOrderNumber.Value();
                    case_universal_property.Modification_Timestamp   = DateTime.Now;

                    case_universal_property.Save(Connection, Transaction);
                }

                #region parameter value
                var case_universal_property_value = ORM_HEC_CAS_Case_UniversalPropertyValue.Query.Search(Connection, Transaction, new ORM_HEC_CAS_Case_UniversalPropertyValue.Query()
                {
                    HEC_CAS_Case_RefID = cas.CaseID,
                    HEC_CAS_Case_UniversalProperty_RefID = case_universal_property.HEC_CAS_Case_UniversalPropertyID,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                }).SingleOrDefault();

                if (case_universal_property_value == null)
                {
                    case_universal_property_value = new ORM_HEC_CAS_Case_UniversalPropertyValue();
                    case_universal_property_value.Tenant_RefID       = securityTicket.TenantID;
                    case_universal_property_value.HEC_CAS_Case_RefID = cas.CaseID;
                    case_universal_property_value.HEC_CAS_Case_UniversalProperty_RefID = case_universal_property.HEC_CAS_Case_UniversalPropertyID;
                }
                case_universal_property_value.Modification_Timestamp = DateTime.Now;
                case_universal_property_value.Value_String           = newCaseNumber;

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

            returnValue.Result = newCaseNumber;
            return(returnValue);

            #endregion UserCode
        }