Ejemplo n.º 1
0
 /// <summary>
 /// Find an extension
 /// </summary>
 public static ExtendedAttribute FindExtension(this HealthServiceRecordContainer me, Predicate<ExtendedAttribute> match)
 {
     foreach (var cmp in me.Components)
         if (cmp is ExtendedAttribute && match.Invoke(cmp as ExtendedAttribute))
             return cmp as ExtendedAttribute;
     return null;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Find an extension
 /// </summary>
 public static IEnumerable<ExtendedAttribute> FindAllExtensions(this HealthServiceRecordContainer me, Predicate<ExtendedAttribute> match)
 {
     List<ExtendedAttribute> retr = new List<ExtendedAttribute>();
     foreach (var cmp in me.Components)
         if (cmp is ExtendedAttribute && match.Invoke(cmp as ExtendedAttribute))
             retr.Add(cmp as ExtendedAttribute);
     return retr;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Link this HSR record to another
        /// </summary>
        private void LinkHSRRecord(IDbConnection conn, IDbTransaction tx, HealthServiceRecordComponentRef hsr)
        {
            // TODO: Check to ensure that we don't double replace or double succeed a record
            // An HSR can only be linked to another HSR, so ...
            // first we need to find the HSR container to link to
            IContainer hsrContainer = hsr.Site.Container;

            while (!(hsrContainer is RegistrationEvent) && hsrContainer != null)
            {
                hsrContainer = (hsrContainer as IComponent).Site.Container;
            }
            RegistrationEvent parentHsr = hsrContainer as RegistrationEvent;

            // Get the root container
            HealthServiceRecordContainer parentContainer = hsr.Site.Container as HealthServiceRecordContainer;

            while (parentContainer.Site != null)
            {
                parentContainer = parentContainer.Site.Container as HealthServiceRecordContainer;
            }

            // Now we want to link
            if (parentHsr == null)
            {
                throw new InvalidOperationException("Can only link a Health Service Record event to a Registration Event");
            }
            else if (parentContainer.Id.Equals(hsr.Id))
            {
                throw new InvalidOperationException("Can't link a record to itself");
            }

            // Insert link
            IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx);

            try
            {
                cmd.CommandText = "add_hsr_lnk";
                cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "cmp_hsr_id_in", DbType.Decimal, hsr.Id));
                cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "cbc_hsr_id_in", DbType.Decimal, parentHsr.Id));
                cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "lnk_cls_in", DbType.Decimal, (decimal)(hsr.Site as HealthServiceRecordSite).SiteRoleType));
                cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "conduction_in", DbType.Boolean, (hsr.Site as HealthServiceRecordSite).ContextConduction));
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw new ConstraintException(String.Format("Cannot locate referenced record for '{0}' relationship", (hsr.Site as HealthServiceRecordSite).SiteRoleType));
            }
            finally
            {
                cmd.Dispose();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Link this HSR record to another
        /// </summary>
        internal void LinkHSRRecord(IDbConnection conn, IDbTransaction tx, HealthServiceRecordContainer hsr)
        {
            // An HSR can only be linked to another HSR, so ...
            // first we need to find the HSR container to link to
            IContainer hsrContainer = hsr.Site.Container;

            while (!(hsrContainer is RegistrationEvent) && hsrContainer != null)
            {
                hsrContainer = (hsrContainer as IComponent).Site.Container;
            }
            RegistrationEvent parentHsr = hsrContainer as RegistrationEvent;

            // Now we want to link
            if (parentHsr == null)
            {
                throw new InvalidOperationException("Can only link an Health Service Record event to another Health Service Record Event");
            }

            // Insert link
            IDbCommand cmd = DbUtil.CreateCommandStoredProc(conn, tx);

            try
            {
                cmd.CommandText = "add_hsr_lnk";
                cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "cmp_hsr_id_in", DbType.Decimal, hsr.Id));
                cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "cbc_hsr_id_in", DbType.Decimal, parentHsr.Id));
                cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "lnk_cls_in", DbType.Decimal, (decimal)(hsr.Site as HealthServiceRecordSite).SiteRoleType));
                cmd.Parameters.Add(DbUtil.CreateParameterIn(cmd, "conduction_in", DbType.Boolean, (hsr.Site as HealthServiceRecordSite).ContextConduction));

                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (DbException e)
                {
                    throw new InvalidOperationException(string.Format("Cannot insert link between {0} and {1}. {2}",
                                                                      hsr.Id, parentHsr.Id, e.Message));
                }
            }
            finally
            {
                cmd.Dispose();
            }
        }
        /// <summary>
        /// Get records asynchronously
        /// </summary>
        private List <HealthServiceRecordContainer> GetRecordsAsync(VersionedDomainIdentifier[] recordIds, List <VersionedDomainIdentifier> retRecordId, RegistryQueryRequest qd, List <IResultDetail> dtls)
        {
            // Decision Support service
            HealthServiceRecordContainer[] retVal = new HealthServiceRecordContainer[qd.Limit < recordIds.Length ? qd.Limit : recordIds.Length];
            retRecordId.AddRange(recordIds);

            List <VersionedDomainIdentifier> recordFetch = new List <VersionedDomainIdentifier>(retVal.Length);

            // Get the number of records to include
            for (int i = 0; i < retVal.Length; i++)
            {
                recordFetch.Add(recordIds[i]);
            }

            int maxWorkerBees = recordFetch.Count < Environment.ProcessorCount * 2 ? recordFetch.Count : Environment.ProcessorCount * 2;

            //List<Thread> workerBees = new List<Thread>(maxWorkerBees);  // Worker bees
            var wtp = new MARC.Everest.Threading.WaitThreadPool(maxWorkerBees);

            try
            {
                //// Get components
                foreach (var id in recordFetch)
                {
                    wtp.QueueUserWorkItem((WaitCallback) delegate(object parm)
                    {
                        List <IResultDetail> mDtls = new List <IResultDetail>(10);

                        // DSS Service
                        if (this.m_decisionSupportService != null)
                        {
                            foreach (var itm in this.m_decisionSupportService.RetrievingRecord(id))
                            {
                                dtls.Add(new DetectedIssueResultDetail(
                                             itm.Priority == SVC.Core.Issues.IssuePriorityType.Error ? ResultDetailType.Error : itm.Priority == SVC.Core.Issues.IssuePriorityType.Warning ? ResultDetailType.Warning : ResultDetailType.Information,
                                             itm.Text,
                                             (string)null,
                                             itm));
                            }
                        }

                        var result = this.GetRecord(parm as VersionedDomainIdentifier, mDtls, qd);


                        // Process result
                        if (result != null)
                        {
                            // DSS Service
                            if (this.m_decisionSupportService != null)
                            {
                                foreach (var itm in this.m_decisionSupportService.RetrievedRecord(result))
                                {
                                    dtls.Add(new DetectedIssueResultDetail(
                                                 itm.Priority == SVC.Core.Issues.IssuePriorityType.Error ? ResultDetailType.Error : itm.Priority == SVC.Core.Issues.IssuePriorityType.Warning ? ResultDetailType.Warning : ResultDetailType.Information,
                                                 itm.Text,
                                                 (String)null,
                                                 itm));
                                }
                            }

                            // Add to the results
                            lock (this.m_syncLock)
                            {
                                // Add return value
                                if (retRecordId.IndexOf(parm as VersionedDomainIdentifier) < retVal.Length)
                                {
                                    retVal[retRecordId.IndexOf(parm as VersionedDomainIdentifier)] = result;
                                }
                            }
                        }
                        else
                        {
                            dtls.Add(new DetectedIssueResultDetail(
                                         ResultDetailType.Warning,
                                         String.Format("Record '{1}^^^&{0}&ISO' will not be retrieved", id.Domain, (parm as VersionedDomainIdentifier).Identifier),
                                         (string)null,
                                         new DetectedIssue()
                            {
                                Priority = IssuePriorityType.Warning,
                                Severity = IssueSeverityType.Moderate,
                                Text     = String.Format("Record '{1}^^^&{0}&ISO' will not be retrieved", id.Domain, (parm as VersionedDomainIdentifier).Identifier),
                                Type     = IssueType.DetectedIssue
                            }));
                        }

                        // Are we disclosing this record?
                        if (result == null || result.IsMasked)
                        {
                            lock (m_syncLock)
                                retRecordId.Remove(parm as VersionedDomainIdentifier);
                        }

                        // Add issues and details
                        lock (m_syncLock)
                        {
                            dtls.AddRange(mDtls);
                        }
                    }, id
                                          );
                }

                // Wait for return
                // TODO: Move this to a configuration parameter
                bool didReturn = wtp.WaitOne(50000, true);

                if (!didReturn)
                {
                    throw new TimeoutException("The query could not complete in the specified amount of time");
                }
            }
            finally
            {
                wtp.Dispose();
            }

            return(new List <HealthServiceRecordContainer>(retVal));
        }