Beispiel #1
0
        /// <summary>
        /// Send specified audit
        /// </summary>
        public static void SendAudit(AuditData audit)
        {
            traceSource.TraceVerbose("Sending Audit - {0}", audit.CorrelationToken);

            ApplicationContext.Current.GetService <IThreadPoolService>().QueueUserWorkItem(o =>
            {
                AuthenticationContext.Current = new AuthenticationContext(AuthenticationContext.SystemPrincipal);
                // Translate codes to DICOM
                if (audit.EventTypeCode != null)
                {
                    IConceptRepositoryService icpcr = ApplicationContext.Current.GetService <IConceptRepositoryService>();
                    var concept = icpcr.GetConcept(audit.EventTypeCode.Code);
                    if (concept != null)
                    {
                        var refTerm = icpcr.GetConceptReferenceTerm(concept.Key.Value, "DCM");
                        if (refTerm != null)
                        {
                            audit.EventTypeCode = new AuditCode(refTerm.Mnemonic, "DCM")
                            {
                                DisplayName = refTerm.LoadCollection <ReferenceTermName>("DisplayNames")?.FirstOrDefault()?.Name
                            }
                        }
                        ;
                        else
                        {
                            audit.EventTypeCode.DisplayName = concept.LoadCollection <ConceptName>("ConceptNames").FirstOrDefault()?.Name;
                        }
                    }
                    traceSource.TraceVerbose("Mapped Audit Type Code - {0}-{1}-{2}", audit.EventTypeCode.CodeSystem, audit.EventTypeCode.Code, audit.EventTypeCode.DisplayName);
                }

                ApplicationContext.Current.GetService <IAuditorService>()?.SendAudit(audit);
            });
        }
Beispiel #2
0
        /// <summary>
        /// Queue the sending of an audit
        /// </summary>
        /// <param name="state"></param>
        private void SendAuditAsync(object state)
        {
            using (AuthenticationContext.EnterSystemContext())
            {
                try
                {
                    var ad = state as SdbAudit.AuditData;

                    // Translate codes to DICOM
                    if (ad.EventTypeCode != null)
                    {
                        IConceptRepositoryService icpcr = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>();
                        var concept = icpcr?.GetConcept(ad.EventTypeCode.Code);
                        if (concept != null)
                        {
                            var refTerm = icpcr.GetConceptReferenceTerm(concept.Key.Value, "DCM");
                            if (refTerm != null)
                            {
                                ad.EventTypeCode = new AuditCode(refTerm.Mnemonic, "DCM")
                                {
                                    DisplayName = refTerm.LoadCollection <ReferenceTermName>("DisplayNames")?.FirstOrDefault()?.Name
                                }
                            }
                            ;
                            else
                            {
                                ad.EventTypeCode.DisplayName = concept.LoadCollection <ConceptName>("ConceptNames").FirstOrDefault()?.Name;
                            }
                        }
                        this.m_tracer.TraceVerbose("Mapped Audit Type Code - {0}-{1}-{2}", ad.EventTypeCode.CodeSystem, ad.EventTypeCode.Code, ad.EventTypeCode.DisplayName);
                    }

                    // Create the audit basic
                    AuditMessage am = new AuditMessage(
                        ad.Timestamp.DateTime, (AtnaApi.Model.ActionType)Enum.Parse(typeof(AtnaApi.Model.ActionType), ad.ActionCode.ToString()),
                        (AtnaApi.Model.OutcomeIndicator)Enum.Parse(typeof(AtnaApi.Model.OutcomeIndicator), ad.Outcome.ToString()),
                        (AtnaApi.Model.EventIdentifierType)Enum.Parse(typeof(AtnaApi.Model.EventIdentifierType), ad.EventIdentifier.ToString()),
                        null
                        );
                    if (ad.EventTypeCode != null)
                    {
                        am.EventIdentification.EventType.Add(new CodeValue <String>(ad.EventTypeCode.Code, ad.EventTypeCode.CodeSystem)
                        {
                            DisplayName = ad.EventTypeCode.DisplayName
                        });
                    }

                    am.SourceIdentification.Add(new AuditSourceIdentificationType()
                    {
                        AuditEnterpriseSiteID = ad.Metadata.FirstOrDefault(o => o.Key == SdbAudit.AuditMetadataKey.EnterpriseSiteID)?.Value ?? this.m_configuration.EnterpriseSiteId,
                        AuditSourceID         = ad.Metadata.FirstOrDefault(o => o.Key == SdbAudit.AuditMetadataKey.AuditSourceID)?.Value ?? Dns.GetHostName(),
                        AuditSourceTypeCode   = new List <CodeValue <AtnaApi.Model.AuditSourceType> >()
                        {
                            new CodeValue <AtnaApi.Model.AuditSourceType>(
                                (AtnaApi.Model.AuditSourceType)Enum.Parse(typeof(AtnaApi.Model.AuditSourceType), ad.Metadata.FirstOrDefault(o => o.Key == SdbAudit.AuditMetadataKey.AuditSourceType)?.Value ?? "ApplicationServerProcess"))
                        }
                    });

                    // Add additional data like the participant
                    bool   thisFound = false;
                    string dnsName   = Dns.GetHostName();
                    foreach (var adActor in ad.Actors)
                    {
                        thisFound |= (adActor.NetworkAccessPointId == Environment.MachineName || adActor.NetworkAccessPointId == dnsName) &&
                                     adActor.NetworkAccessPointType == SdbAudit.NetworkAccessPointType.MachineName;
                        var act = new AtnaApi.Model.AuditActorData()
                        {
                            NetworkAccessPointId            = adActor.NetworkAccessPointId,
                            NetworkAccessPointType          = (AtnaApi.Model.NetworkAccessPointType)Enum.Parse(typeof(AtnaApi.Model.NetworkAccessPointType), adActor.NetworkAccessPointType.ToString()),
                            NetworkAccessPointTypeSpecified = adActor.NetworkAccessPointType != 0,
                            UserIdentifier    = adActor.UserIdentifier,
                            UserIsRequestor   = adActor.UserIsRequestor,
                            UserName          = adActor.UserName,
                            AlternativeUserId = adActor.AlternativeUserId
                        };

                        if (adActor.ActorRoleCode != null)
                        {
                            foreach (var rol in adActor.ActorRoleCode)
                            {
                                act.ActorRoleCode.Add(new CodeValue <string>(rol.Code, rol.CodeSystem)
                                {
                                    DisplayName = rol.DisplayName
                                });
                            }
                        }
                        am.Actors.Add(act);
                    }

                    foreach (var aoPtctpt in ad.AuditableObjects)
                    {
                        var atnaAo = new AtnaApi.Model.AuditableObject()
                        {
                            IDTypeCode = aoPtctpt.IDTypeCode.HasValue && aoPtctpt.IDTypeCode != SdbAudit.AuditableObjectIdType.NotSpecified ?
                                         aoPtctpt.IDTypeCode.Value != SdbAudit.AuditableObjectIdType.Custom ?
                                         new CodeValue <AtnaApi.Model.AuditableObjectIdType>((AtnaApi.Model.AuditableObjectIdType)Enum.Parse(typeof(AtnaApi.Model.AuditableObjectIdType), aoPtctpt?.IDTypeCode?.ToString())) :
                                         (aoPtctpt.CustomIdTypeCode != null ?
                                          new CodeValue <AtnaApi.Model.AuditableObjectIdType>()
                            {
                                Code = aoPtctpt.CustomIdTypeCode?.Code,
                                CodeSystem = aoPtctpt.CustomIdTypeCode?.CodeSystem,
                                DisplayName = aoPtctpt.CustomIdTypeCode?.DisplayName
                            } : null) :
                                         null,
                            LifecycleType          = aoPtctpt.LifecycleType != SdbAudit.AuditableObjectLifecycle.NotSet && aoPtctpt.LifecycleType.HasValue ? (AtnaApi.Model.AuditableObjectLifecycle)Enum.Parse(typeof(AtnaApi.Model.AuditableObjectLifecycle), aoPtctpt.LifecycleType.ToString()) : 0,
                            LifecycleTypeSpecified = aoPtctpt.LifecycleType != SdbAudit.AuditableObjectLifecycle.NotSet && aoPtctpt.LifecycleType.HasValue,
                            ObjectId         = aoPtctpt.ObjectId,
                            Role             = aoPtctpt.Role.HasValue ? (AtnaApi.Model.AuditableObjectRole)Enum.Parse(typeof(AtnaApi.Model.AuditableObjectRole), aoPtctpt.Role.ToString()) : 0,
                            RoleSpecified    = aoPtctpt.Role != 0,
                            Type             = aoPtctpt.Type == SdbAudit.AuditableObjectType.NotSpecified ? AtnaApi.Model.AuditableObjectType.Other : (AtnaApi.Model.AuditableObjectType)Enum.Parse(typeof(AtnaApi.Model.AuditableObjectType), aoPtctpt.Type.ToString()),
                            TypeSpecified    = aoPtctpt.Type != SdbAudit.AuditableObjectType.NotSpecified,
                            ObjectSpec       = aoPtctpt.QueryData ?? aoPtctpt.NameData,
                            ObjectSpecChoice = aoPtctpt.QueryData == null ? ObjectDataChoiceType.ParticipantObjectName : ObjectDataChoiceType.ParticipantObjectQuery
                        };
                        // TODO: Object Data
                        foreach (var kv in aoPtctpt.ObjectData)
                        {
                            if (!String.IsNullOrEmpty(kv.Key))
                            {
                                atnaAo.ObjectDetail.Add(new ObjectDetailType()
                                {
                                    Type  = kv.Key,
                                    Value = kv.Value
                                });
                            }
                        }
                        am.AuditableObjects.Add(atnaAo);
                    }

                    // Send the message
                    this.m_tracer.TraceVerbose("Dispatching audit {0} via SYSLOG", ad.Key);
                    this.m_transporter.SendMessage(am);
                }
                catch (Exception e)
                {
                    this.m_tracer.TraceError(e.ToString());
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Create a care plan
        /// </summary>
        public Object Create(Object data, bool updateIfExists)
        {
            (data as Bundle)?.Reconstitute();
            data = (data as CarePlan)?.Target ?? data as Patient;
            if (data == null)
            {
                this.m_tracer.TraceError("Careplan requires a patient or bundle containing a patient entry");
                throw new InvalidOperationException(this.m_localizationService.GetString("error.rest.hdsi.careplanRequiresPatient"));
            }

            // Get care plan service
            var carePlanner = ApplicationServiceContext.Current.GetService <ICarePlanService>();
            var plan        = carePlanner.CreateCarePlan(data as Patient,
                                                         RestOperationContext.Current.IncomingRequest.QueryString["_asEncounters"] == "true",
                                                         RestOperationContext.Current.IncomingRequest.QueryString.ToQuery().ToDictionary(o => o.Key, o => (Object)o.Value));

            // Expand the participation roles form the care planner
            IConceptRepositoryService conceptService = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>();

            foreach (var p in plan.Action)
            {
                p.Participations.ForEach(o => o.ParticipationRoleKey = o.ParticipationRoleKey ?? conceptService.GetConcept(o.ParticipationRole?.Mnemonic).Key);
            }
            return(Bundle.CreateBundle(plan));
        }
Beispiel #4
0
        /// <summary>
        /// Query for care plan objects... Constructs a care plan for all patients matching the specified query parameters
        /// </summary>
        /// TODO: Change this to actually query care plans
        public IEnumerable <Object> Query(NameValueCollection queryParameters, int offset, int count, out int totalCount)
        {
            var repositoryService = ApplicationServiceContext.Current.GetService <IRepositoryService <Patient> >();

            if (repositoryService == null)
            {
                this.m_tracer.TraceError("Could not find patient repository service");
                throw new InvalidOperationException(this.m_localizationService.GetString("error.type.InvalidOperation.missingPatientRepo"));
            }


            // Query
            var carePlanner = ApplicationServiceContext.Current.GetService <ICarePlanService>();

            Expression <Func <Patient, bool> > queryExpr = QueryExpressionParser.BuildLinqExpression <Patient>(queryParameters);
            List <String>         queryId  = null;
            IEnumerable <Patient> patients = null;

            if (queryParameters.TryGetValue("_queryId", out queryId) && repositoryService is IPersistableQueryRepositoryService <Patient> )
            {
                patients = (repositoryService as IPersistableQueryRepositoryService <Patient>).Find(queryExpr, offset, count, out totalCount, new Guid(queryId[0]));
            }
            else
            {
                patients = repositoryService.Find(queryExpr, offset, count, out totalCount);
            }

            // Create care plan for the patients
            IConceptRepositoryService conceptService = ApplicationServiceContext.Current.GetService <IConceptRepositoryService>();

            return(patients.Select(o =>
            {
                var plan = carePlanner.CreateCarePlan(o);
                foreach (var p in plan.Action)
                {
                    p.Participations.ForEach(x => x.ParticipationRoleKey = x.ParticipationRoleKey ?? conceptService.GetConcept(x.ParticipationRole?.Mnemonic).Key);
                }
                return plan;
            }));
        }
        /// <summary>
        /// Gets a careplan by identifier
        /// </summary>
        public IdentifiedData Get(Guid id, Guid versionId)
        {
            Patient target      = ApplicationContext.Current.GetService <IRepositoryService <Patient> >().Get(id);
            var     carePlanner = ApplicationContext.Current.GetService <ICarePlanService>();
            var     plan        = carePlanner.CreateCarePlan(target,
                                                             WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["_asEncounters"] == "true",
                                                             WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters.ToQuery().ToDictionary(o => o.Key, o => (Object)o.Value));
            IConceptRepositoryService conceptService = ApplicationContext.Current.GetService <IConceptRepositoryService>();

            foreach (var p in plan.Action)
            {
                p.Participations.ForEach(o => o.ParticipationRoleKey = o.ParticipationRoleKey ?? conceptService.GetConcept(o.ParticipationRole?.Mnemonic).Key);
            }
            return(plan);
        }
        /// <summary>
        /// Create a care plan
        /// </summary>
        public IdentifiedData Create(IdentifiedData data, bool updateIfExists)
        {
            (data as Bundle)?.Reconstitute();
            data = (data as CarePlan)?.Target ?? data as Patient;
            if (data == null)
            {
                throw new InvalidOperationException("Careplan requires a patient or bundle containing a patient entry");
            }

            // Get care plan service
            var carePlanner = ApplicationContext.Current.GetService <ICarePlanService>();
            var plan        = carePlanner.CreateCarePlan(data as Patient,
                                                         WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["_asEncounters"] == "true",
                                                         WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters.ToQuery().ToDictionary(o => o.Key, o => (Object)o.Value));

            // Expand the participation roles form the care planner
            IConceptRepositoryService conceptService = ApplicationContext.Current.GetService <IConceptRepositoryService>();

            foreach (var p in plan.Action)
            {
                p.Participations.ForEach(o => o.ParticipationRoleKey = o.ParticipationRoleKey ?? conceptService.GetConcept(o.ParticipationRole?.Mnemonic).Key);
            }
            return(Bundle.CreateBundle(plan));
        }