Example #1
0
        /// <summary> Populates a query object created by the base class. </summary>
        /// <param name="context"></param>
        /// <param name="pQuery"></param>
        protected override void PopulateQuery(CodeActivityContext context, ImpacRdbQuery pQuery)
        {
            // Activity inputs
            int      patId1    = PatId1.Get(context);
            int      sitId     = (SitId.Expression != null) ? SitId.Get(context) : 0;
            DateTime startDate = CheckDateTime(StartDate.Get(context));
            DateTime endDate   = CheckDateTime(EndDate.Get(context));

            // Get the Dose_Hst entries for the given patient
            pQuery.AddClause(DoseHst.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1);

            // Filter on SIT_ID if supplied
            if (sitId != 0)
            {
                pQuery.AddClause(DoseHst.SIT_IDEntityColumn, EntityQueryOp.EQ, sitId);
            }

            // Filter on StartDate if supplied
            if (startDate > SqlDateTime.MinValue.Value)
            {
                pQuery.AddClause(DoseHst.Tx_DtTmEntityColumn, EntityQueryOp.GE, startDate);
            }

            // Filter on EndDate if supplied
            if (endDate > SqlDateTime.MinValue.Value)
            {
                pQuery.AddClause(DoseHst.Tx_DtTmEntityColumn, EntityQueryOp.LE, endDate);
            }
        }
Example #2
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);
            }
        }