Beispiel #1
0
        /// <summary>
        /// Activity heavy lifting.
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            // Activity inputs
            int patId = PatId.Get(context);
            int pciId = PciId.Get(context);
            ImpacPersistenceManager pm = PersistenceManager.Expression != null
                                             ? PersistenceManager.Get(context)
                                             : PM;

            // Activity output
            FieldsDeleted.Set(context, 0); // Initialize the Activity output to 0

            // Get the available session fields for given PCI_ID
            var query = new ImpacRdbQuery(typeof(PatTxCal));

            query.AddClause(PatTxCal.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId);
            query.AddClause(PatTxCal.PCI_IDEntityColumn, EntityQueryOp.EQ, pciId);
            var sessionItems = pm.GetEntities <PatTxCal>(query);

            // Delete fields in the given session
            int fieldsDeleted = 0;

            try
            {
                // Store PatCItem record
                PatCItem patCItem       = null;
                byte     patCItemStatus = 0;

                if (sessionItems.Count > 0)
                {
                    // The Delete() member of PatTxField sets PatCItem.Status to "Pending" if the Status is "Approved"
                    // Save state of PatCItem record
                    patCItem       = sessionItems[0].PatCItemEntity;
                    patCItemStatus = patCItem.Status_Enum;
                }
                while (sessionItems.Count > 0)
                {
                    sessionItems[sessionItems.Count - 1].Delete();
                    pm.SaveChanges();
                    fieldsDeleted++;
                }
                if (patCItem != null)
                {
                    patCItem.Status_Enum = patCItemStatus;
                    pm.SaveChanges();
                }
            }
            catch
            {
                fieldsDeleted = -1;
            }
            finally
            {
                // Update Activity output
                FieldsDeleted.Set(context, fieldsDeleted);
            }
        }
        /// <summary>
        /// Writes to the PharmCalcAccept table indicating that the calculation factor passed in has
        /// been accepted.
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            ImpacPersistenceManager pm = ImpacPersistenceManagerFactory.CreatePersistenceManager();
            int    rxoSetId            = RxoSetId.Get(context);
            double calcFactor          = AcceptedCalcFactor.Get(context);

            //Get PharmOrd Object
            BOM.Entities.PharmOrd pharmOrd = BOM.Entities.PharmOrd.GetEntityByRxoSetIdAndVersion0(rxoSetId);

            if (pharmOrd.IsNullEntity)
            {
                throw new InvalidOperationException("Cannot find PharmOrd record with Version = 0 and Rxo_Set_Id = " + rxoSetId);
            }

            //Only write to the table if a BSA is found.
            if (pharmOrd.BSA != 0)
            {
                PharmCalcAccept obj = PharmCalcAccept.Create(pm);
                obj.RXO_Set_ID = rxoSetId;

                //If the BSA on the order is equal to the value passed in, reject the change since there's no reason to save the record.
                if (calcFactor == pharmOrd.BSA)
                {
                    pm.RejectChanges();
                    return;
                }

                //Otherwise, if the acepted calc factor is greater than the order BSA, set the high value.  If it's less than the order
                //BSA, set the low value.
                if (calcFactor > pharmOrd.BSA)
                {
                    obj.Accepted_High = calcFactor;
                }
                else
                {
                    obj.Accepted_Low = calcFactor;
                }

                pm.SaveChanges();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Activity heavy lifting.
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            // This processing is intended for the Plan-of-the-Day feature and does not necessarily support any other usage
            // The passed Site.SIT_ID must be for a version zero prescription record (aka the 'tip' or 'current' version)
            // Prescribed fraction dose must not be zero and must be uniform
            // If fractionation details records exist for the prescription (Site_FractionDetails) then the passed deltaFraction must be negative
            // For Plan-of-the-Day the deltaFraction value is -1
            // The valid range of prescribed fractions after the adjustment is 0 to 100 inclusive

            // Activity inputs
            int patId                  = PatId.Get(context);
            int sitId                  = Sitid.Get(context);
            int deltaFraction          = DeltaFraction.Get(context);
            ImpacPersistenceManager pm = PersistenceManager.Expression != null
                                             ? PersistenceManager.Get(context)
                                             : PM;

            // Activity output
            FractionsChanged.Set(context, false); // Initialize the Activity output to False

            // Don't do anything if deltaFraction is zero i.e., no adjustment requested
            if (deltaFraction == 0)
            {
                return;
            }

            // Get the Rad Rx to be updated
            PrescriptionSite site = PrescriptionSite.GetEntityByID(sitId, pm);

            // Determine whether the request is valid for this prescription

            // If the Site record no longer exists or the record's version is no longer zero (because a version roll has occurred)
            // then do not proceed with updates to this prescription
            if (site.IsNullEntity || site.Version != 0)
            {
                return;
            }

            // If the prescribed fraction dose is zero or non-uniform then do not proceed with updates to this prescription
            // (Dose_Tx is zero when fraction dose is non-uniform; check for negative dose is excessive but doesn't hurt)
            if (site.Dose_Tx <= 0)
            {
                return;
            }

            // If the adjusted number of fractions won't be valid (must be between 0 and 100 inclusive)
            // then do not proceed with updates to this prescription
            int newFractions = site.Fractions + deltaFraction;

            if ((newFractions < 0) || (newFractions > 100))
            {
                return;
            }

            // Get the fraction and wave detail records (if any) for this prescription
            if (site.FxType == 2)
            {
                // When there are fraction detail records, FxType is 2
                EntityList <SiteFractionDetails> siteFractionDetails = SiteFractionDetails.GetSiteFractionDetailsEntitiesBySitId(sitId, pm, QueryStrategy.DataSourceOnly);

                // There can be wave detail records only when there are fraction detail records
                if (siteFractionDetails.Count > 0)
                {
                    EntityList <SiteWaveDetails> siteWaveDetails = SiteWaveDetails.GetSiteWaveDetailsEntitiesBySitId(sitId, pm, QueryStrategy.DataSourceOnly);
                }

                // If there are fraction and/or wave detail records and deltaFraction > 0
                // then do NOT proceed because inserting fraction and/or wave detail records is NOT supported here
                if (deltaFraction > 0 && siteFractionDetails.Count > 0)
                {
                    return;
                }
            }

            // The request is valid for this prescription so make the adjustments

            // Prepare for edit, including version roll if necessary
            var revisionedSite = (PrescriptionSite)site.PrepareEntityForEdit("PlanOfTheDay", true);

            // Adjust prescribed total dose and prescribed number of fractions
            revisionedSite.Dose_Ttl  = revisionedSite.Dose_Tx * newFractions;
            revisionedSite.Fractions = (short)newFractions;

            // If the prescription is approved, maintain the approval status and approving staff
            // but set the approval date/time stamp to now
            if (revisionedSite.Sanct_Id.HasValue)
            {
                revisionedSite.Sanct_DtTm = DateTime.Now;
            }

            if (revisionedSite.FxType == 2)
            {
                // Manage the fraction details, fraction specific Notes and wave details records (if any)
                RemoveExcessSiteFractionDetailsAndNotes(pm, revisionedSite);
                RemoveUnreferencedSiteWaveDetails(pm, revisionedSite);

                // If fractions were reduced to zero
                // then there will be no details records when the update is complete so change FxType to 0 (no details records)
                if (revisionedSite.Fractions == 0)
                {
                    revisionedSite.FxType = 0;
                }
            }

            try
            {
                pm.SaveChanges();
            }
            catch
            {
                return;
            }

            FractionsChanged.Set(context, true);
        }
Beispiel #4
0
        /// <summary>
        /// Activity heavy lifting.
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            // Activity inputs
            int patId      = PatId.Get(context);
            int sitId      = SitId.Get(context);
            int pciId      = PciId.Get(context);
            int statusEnum = StatusEnum.Expression != null?StatusEnum.Get(context) : 5;

            if ((statusEnum != 5) && (statusEnum != 7))
            {
                statusEnum = 7;
            }
            bool useAfs = UseAfs.Expression != null?UseAfs.Get(context) : false;

            bool useMfs = UseMfs.Expression != null?UseMfs.Get(context) : false;

            ImpacPersistenceManager pm = PersistenceManager.Expression != null
                                             ? PersistenceManager.Get(context)
                                             : PM;

            // Activity output
            FieldsInserted.Set(context, -1); // Initialize the Activity output to -1 (indication of error)

            // Do not continue if both AFS and MFS are set to true (there is no way to resolve this at run time)
            if (useAfs && useMfs)
            {
                return;
            }

            // Get the Sit_Set_Id of the Site (Sit_Id) given
            var query = new ImpacRdbQuery(typeof(PrescriptionSite));

            query.AddClause(PrescriptionSiteDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId);
            query.AddClause(PrescriptionSiteDataRow.SIT_IDEntityColumn, EntityQueryOp.EQ, sitId);
            var site = pm.GetEntities <PrescriptionSite>(query);

            if (site.Count != 1)
            {
                return;
            }

            int sitSetId = (int)site[0].SIT_SET_ID.GetValueOrDefault(0);

            // Get the list of treatment fields from the given Rad Rx to insert
            query = new ImpacRdbQuery(typeof(Field));
            query.AddClause(FieldDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId);
            query.AddClause(FieldDataRow.SIT_Set_IDEntityColumn, EntityQueryOp.EQ, sitSetId);
            query.AddClause(FieldDataRow.VersionEntityColumn, EntityQueryOp.EQ, 0);
            query.AddOrderBy(FieldDataRow.DisplaySequenceEntityColumn);
            var txField = pm.GetEntities <Field>(query);

            if (txField.Count == 0)
            {
                return;
            }

            // Make sure we have a (1) session to insert the fields in to
            query = new ImpacRdbQuery(typeof(PatCItem));
            query.AddClause(PatCItemDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId);
            query.AddClause(PatCItemDataRow.PCI_IDEntityColumn, EntityQueryOp.EQ, pciId);
            var calendarSession = pm.GetEntities <PatCItem>(query);

            if (calendarSession.Count != 1)
            {
                return;
            }

            // Add new entry to PatTxCal for each treatment field
            int fieldsInserted = 0;

            try
            {
                for (int f = 0; f < txField.Count; f++)
                {
                    PatTxCal sessionItem = PatTxCal.Create(pm);
                    sessionItem.PCI_ID      = calendarSession[0].PCI_ID;
                    sessionItem.Status_enum = (byte)statusEnum;
                    sessionItem.Pat_ID1     = patId;
                    sessionItem.FLD_Set_ID  = txField[f].FLD_SET_ID;
                    sessionItem.TxSequence  = (short)(f + 1);
                    sessionItem.ProFormaPF  = 0;
                    if (useAfs)
                    {
                        if (f == 0)
                        {
                            sessionItem.AFS_Begin = true;
                        }
                        else
                        {
                            sessionItem.AFS = true;
                        }
                    }
                    if (useMfs)
                    {
                        if (f == 0)
                        {
                            sessionItem.MFS_Begin = true;
                        }
                        else
                        {
                            sessionItem.MFS = true;
                        }
                    }
                    sessionItem.PF_Only = txField[f].Type_Enum == 3 || txField[f].Type_Enum == 4 ||
                                          txField[f].Type_Enum == 5 || txField[f].Type_Enum == 9; //FLD.Type_Enum: 3=Setup, 4=kV Setup, 5=CT, 9=MVCT

                    pm.SaveChanges();
                    fieldsInserted++;
                }
            }
            catch
            {
                fieldsInserted = -1;
            }
            finally
            {
                FieldsInserted.Set(context, fieldsInserted);
            }
        }
        /// <summary>
        /// Activity heavy lifting.
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            // Activity inputs
            int patId1 = PatId.Get(context);
            EntityList <PrescriptionSite> rxSite = RxSite.Get(context);
            string regionName = RegionName.Get(context);
            double doseCoeff  = DoseCoeff.Expression != null?DoseCoeff.Get(context) : 1.000;

            ImpacPersistenceManager pm = PersistenceManager.Expression != null
                                             ? PersistenceManager.Get(context)
                                             : PM;


            // Activity output
            DoseSiteCreated.Set(context, false); // Initialize the Activity output to False

            // Make sure rxSite is not supplied as a null (e.g. Nothing)
            if (rxSite == null)
            {
                return;
            }

            // Make sure none of the given Sites is Null
            if (rxSite.Count == 0)
            {
                return;
            }

            for (int i = 0; i < rxSite.Count; i++)
            {
                if (rxSite[i] == null)
                {
                    return;
                }
            }

            // Only continue if doseCoeff given is within valid range
            if ((doseCoeff < 0.0) || (doseCoeff > 9.9990))
            {
                return;
            }

            // Name for the Region cannot be empty or null
            if (string.IsNullOrEmpty(regionName))
            {
                return;
            }

            // Trim regionName to max allowed chars
            const int maxSiteNameLength = 20;

            if (regionName.Length > maxSiteNameLength)
            {
                regionName = regionName.Substring(0, maxSiteNameLength);
            }

            // First check if supplied siteName exists already in the database
            var query = new ImpacRdbQuery(typeof(Region));

            query.AddClause(Region.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1);
            query.AddClause(Region.Region_NameEntityColumn, EntityQueryOp.EQ, regionName);
            EntityList <Region> queryRegion = pm.GetEntities <Region>(query);

            if (queryRegion.Count > 0)
            {
                return;
            }

            // Check if any of the tip revision or historic Rx sites are already using the name
            var rxSitesQuery = new ImpacRdbQuery(typeof(PrescriptionSite));

            rxSitesQuery.AddClause(PrescriptionSiteDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1);
            rxSitesQuery.AddClause(PrescriptionSiteDataRow.SiteNameEntityColumn, EntityQueryOp.EQ, regionName);
            if (pm.GetEntities <PrescriptionSite>(rxSitesQuery).Count > 0)
            {
                return;
            }

            // Create an entry in the Region table (new REG_ID will be used later)
            Region region = Region.Create(pm);

            region.Pat_ID1     = patId1;
            region.Region_Name = regionName;
            try
            {
                pm.SaveChanges();
            }
            catch
            {
                return;
            }

            // Go through each Rx Site given and collect the treatment field properties
            var txField = new EntityList <Field>();

            foreach (var t in rxSite)
            {
                query = new ImpacRdbQuery(typeof(PrescriptionSite));
                query.AddClause(PrescriptionSite.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1);
                query.AddClause(PrescriptionSite.SIT_IDEntityColumn, EntityQueryOp.EQ, t.SIT_ID);
                query.AddClause(PrescriptionSite.VersionEntityColumn, EntityQueryOp.EQ, 0);
                EntityList <PrescriptionSite> site = pm.GetEntities <PrescriptionSite>(query);

                if (site.Count == 1)
                {
                    query = new ImpacRdbQuery(typeof(Field));
                    query.AddClause(Field.SIT_Set_IDEntityColumn, EntityQueryOp.EQ, site[0].SIT_SET_ID);
                    query.AddClause(Field.VersionEntityColumn, EntityQueryOp.EQ, 0);
                    txField.AddRange(pm.GetEntities <Field>(query));
                }
            }

            // Now add for each field an entry in the Coeff table with a link to the Region entry earlier
            int fieldsInserted = 0;

            try
            {
                foreach (var t in txField)
                {
                    Coeff coeff = Coeff.Create(pm);
                    coeff.Pat_ID1                   = patId1;
                    coeff.FLD_SET_ID                = t.FLD_SET_ID;
                    coeff.REG_ID                    = region.REG_ID;
                    coeff.Reg_Coeff                 = doseCoeff;
                    coeff.IsFromDataImport          = false;
                    coeff.IsModifiedAfterDataImport = false;
                    pm.SaveChanges();
                    fieldsInserted++;
                }
            }
            finally
            {
                DoseSiteCreated.Set(context, fieldsInserted == txField.Count);
            }
        }