コード例 #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 input
            int patId = PatId.Get(context);
            int sitId = SitId.Get(context);

            var pm = ImpacPersistenceManagerFactory.CreatePersistenceManager();

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

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

            if (site.Count != 1)
            {
                sitSetId = -1;
            }
            else
            {
                sitSetId = (int)site[0].SIT_SET_ID;
            }

            // Build the query
            pQuery.AddClause(Field.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId);
            pQuery.AddClause(Field.SIT_Set_IDEntityColumn, EntityQueryOp.EQ, sitSetId);
            pQuery.AddClause(Field.VersionEntityColumn, EntityQueryOp.EQ, 0);
            pQuery.AddOrderBy(Field.DisplaySequenceEntityColumn);
        }
コード例 #2
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 input
            int patId = PatId.Get(context);
            int pcpId = PcpId.Get(context);

            // In case startDate/endDate has input specified (Null/Nothing) it defaults to
            // DateTime.MinValue (0001-01-01 01:01:01).
            DateTime startDate = CheckDateTime(StartDate.Get(context));
            DateTime endDate   = CheckDateTime(EndDate.Get(context));

            // Build the query
            pQuery.AddClause(PatCItem.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId);
            pQuery.AddClause(PatCItem.PCP_IDEntityColumn, EntityQueryOp.EQ, pcpId);

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

            // Filter on EndDate if supplied
            if (endDate > SqlDateTime.MinValue.Value)
            {
                pQuery.AddClause(PatCItem.Due_DtTmEntityColumn, EntityQueryOp.LE, endDate);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
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 input
            int patId = PatId.Get(context);
            int pciId = PciId.Get(context);

            // Build the query
            pQuery.AddClause(PatTxCal.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId);
            pQuery.AddClause(PatTxCal.PCI_IDEntityColumn, EntityQueryOp.EQ, pciId);
        }
コード例 #5
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 patId = PatId.Get(context);
            int pcpId = PcpId.Get(context);

            pQuery.AddClause(PrescriptionSite.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId);
            pQuery.AddClause(PrescriptionSite.PCP_IDEntityColumn, EntityQueryOp.EQ, pcpId);
            pQuery.AddClause(PrescriptionSite.VersionEntityColumn, EntityQueryOp.EQ, 0);
            pQuery.AddOrderBy(PrescriptionSite.DisplaySequenceEntityColumn);
        }
コード例 #6
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);
            }
        }
コード例 #7
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);
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        protected override void DoWork(CodeActivityContext context)
        {
            var patId1  = PatId.Get(context);
            var patient = Patient.GetEntityByID(patId1, PM);

            if (patient.IsNullEntity)
            {
                return;
            }

            short?docType     = null;
            var   docTypeTemp = DocType.Get(context);

            if (docTypeTemp.HasValue)
            {
                docType = (short)docTypeTemp.Value;
            }

            var dictId = DictatedBy.Get(context);

            if (dictId == 0)
            {
                return;
            }

            int?reviewId = null;
            int temp     = ReviewRequiredBy.Get(context);

            if (temp > 0)
            {
                reviewId = temp;
            }

            int?cosignId = null;

            temp = CoSignRequiredBy.Get(context);
            if (temp > 0)
            {
                cosignId = temp;
            }

            int?transId = null;

            temp = TranscribedBy.Get(context);
            if (temp > 0)
            {
                transId = temp;
            }

            var encounterTemp = EncounterDate.Get(context);

            if (!encounterTemp.HasValue)
            {
                return;
            }
            var encounterDate = encounterTemp.Value;

            var transcribedDate = TranscribedDate.Get(context);

            var instId    = Department.Get(context);
            var accountId = Account.Get(context);

            var template = Template.Get(context);

            var openAfterCreation = OpenAfterCreation.Get(context).Key == (int)OpenAfterCreationOptions.Yes;
            var status            = (byte)Status.Get(context);

            if (CreateIfDuplicateExists.Get(context).Key == (int)CreateIfDuplicateExistsOptions.No)
            {
                // Check for a duplicate encounter
                var query = new ImpacRdbQuery(typeof(ObjectTable));
                query.AddClause(ObjectTableDataRow.Pat_ID1EntityColumn, EntityQueryOp.EQ, patId1);
                query.AddClause(ObjectTableDataRow.DocTypeEntityColumn, EntityQueryOp.EQ, docType);

                query.AddClause(ObjectTableDataRow.Dict_IDEntityColumn, EntityQueryOp.EQ, dictId);
                query.AddClause(ObjectTableDataRow.Review_IDEntityColumn, EntityQueryOp.EQ, reviewId);
                query.AddClause(ObjectTableDataRow.CoSig_IDEntityColumn, EntityQueryOp.EQ, cosignId);
                query.AddClause(ObjectTableDataRow.Trans_IDEntityColumn, EntityQueryOp.EQ, transId);

                // Defect 11605, the Encounter_DtTm and Trans_DtTm store date time rather than the previous date part
                // so we should check items if it exists within the day of datetime
                query.AddClause(ObjectTableDataRow.Encounter_DtTmEntityColumn, EntityQueryOp.Between, encounterDate.Date, encounterDate.Date.AddDays(1));

                if (transcribedDate.HasValue)
                {
                    query.AddClause(ObjectTableDataRow.Trans_DtTmEntityColumn, EntityQueryOp.Between, transcribedDate.Value.Date, transcribedDate.Value.Date.AddDays(1));
                }

                query.AddClause(ObjectTableDataRow.Inst_IDEntityColumn, EntityQueryOp.EQ, instId);
                query.AddClause(ObjectTableDataRow.Account_IDEntityColumn, EntityQueryOp.EQ, accountId);
                query.AddClause(ObjectTableDataRow.DocumentTemplateEntityColumn, EntityQueryOp.EQ, template);

                var objectEntity = PM.GetEntity(query);
                if (objectEntity != null && !objectEntity.IsNullEntity)
                {
                    return;
                }
            }

            EscribeOperations.CreateDocument(patId1, docType,
                                             dictId, reviewId, cosignId, transId,
                                             encounterDate, transcribedDate,
                                             instId, accountId, template,
                                             status, openAfterCreation);
        }
コード例 #9
0
        /// <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);
            }
        }