Exemplo n.º 1
0
 /// <summary>
 /// Map term to code
 /// </summary>
 private static AuditCode MapTermToCode(AuditTerm r)
 {
     return(new AuditCode(r.Mnemonic, r.Domain)
     {
         DisplayName = r.DisplayName
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Map code
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="code"></param>
        /// <returns></returns>
        private static AuditTerm MapOrCreateCode <T>(CodeValue <T> code)
        {
            if (code == null)
            {
                return(null);
            }

            var auditTermService = ApplicationServiceContext.Current.GetService <IAuditTermLookupService>();
            var retVal           = auditTermService?.GetTerm(code.Code, code.CodeSystem, typeof(T).Name);

            if (retVal == null)
            {
                retVal = auditTermService?.Register(code.Code, code.CodeSystem ?? typeof(T).Name, code.DisplayName);
            }
            if (retVal == null)
            {
                retVal = new AuditTerm()
                {
                    Domain      = code.CodeSystem,
                    DisplayName = code.DisplayName,
                    LoadState   = SanteDB.Core.Model.LoadState.New,
                    Mnemonic    = code.Code
                }
            }
            ;
            return(retVal);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Map code
        /// </summary>
        private static CodeValue <T> MapTerm <T>(AuditTerm term)
        {
            if (term == null)
            {
                return(null);
            }

            return(new CodeValue <T>()
            {
                Code = term.Mnemonic,
                CodeSystem = term.Domain,
                DisplayName = term.DisplayName
            });
        }
Exemplo n.º 4
0
        public void TestCanInsertAudit()
        {
            var termService = ApplicationServiceContext.Current.GetService <IDataPersistenceService <AuditTerm> >();

            Assert.IsNotNull(termService);

            AuditTerm actionCode      = termService.Query(o => o.Mnemonic == "E" && o.Domain == "ActionType", AuthenticationContext.SystemPrincipal).First(),
                      outcomeCode     = termService.Query(o => o.Mnemonic == "0" && o.Domain == "OutcomeIndicator", AuthenticationContext.SystemPrincipal).First(),
                      eventCode       = termService.Query(o => o.Mnemonic == "110100", AuthenticationContext.SystemPrincipal).First(),
                      objectType      = termService.Query(o => o.Mnemonic == "1" && o.Domain == "AuditableObjectType", AuthenticationContext.SystemPrincipal).First(),
                      objectRole      = termService.Query(o => o.Mnemonic == "1" && o.Domain == "AuditableObjectRole", AuthenticationContext.SystemPrincipal).First(),
                      objectLifecycle = termService.Query(o => o.Mnemonic == "1" && o.Domain == "AuditableObjectLifecycle", AuthenticationContext.SystemPrincipal).First(),
                      objectIdType    = termService.Query(o => o.Mnemonic == "1" && o.Domain == "AuditableObjectIdType", AuthenticationContext.SystemPrincipal).First();
            var auditUnderTest        = new Audit()
            {
                ActionCode  = actionCode,
                EventIdCode = eventCode,
                OutcomeCode = outcomeCode,
                AuditSource = new AuditSource()
                {
                    EnterpriseSiteId = "TEST",
                    AuditSourceId    = "TEST"
                },
                EventTypeCodes = new System.Collections.Generic.List <AuditTerm>()
                {
                    new AuditTerm()
                    {
                        Mnemonic = "FOO", DisplayName = "BAR", Domain = "FOO CODES"
                    }
                },
                CorrelationToken = Guid.Empty,
                EventTimestamp   = DateTimeOffset.Now,
                Objects          = new System.Collections.Generic.List <AuditObject>()
                {
                    new AuditObject()
                    {
                        ExternalIdentifier = "blahblahtest",
                        IdTypeCode         = objectIdType,
                        LifecycleCode      = objectLifecycle,
                        RoleCode           = objectRole,
                        TypeCode           = objectType,
                        Specification      = new System.Collections.Generic.List <AuditObjectSpecification>()
                        {
                            new AuditObjectSpecification()
                            {
                                Specification     = "FOOFOO",
                                SpecificationType = "N"
                            }
                        },
                        Details = new System.Collections.Generic.List <AuditObjectDetail>()
                        {
                            new AuditObjectDetail()
                            {
                                Value     = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
                                DetailKey = "random"
                            }
                        }
                    }
                },
                Participants = new System.Collections.Generic.List <AuditParticipation>()
                {
                    new AuditParticipation()
                    {
                        IsRequestor = true,
                        Roles       = new System.Collections.Generic.List <AuditTerm>()
                        {
                            new AuditTerm()
                            {
                                DisplayName = "Tester User Group", Domain = "GroupType", Mnemonic = "TESTERS"
                            }
                        },
                        Actor = new AuditActor()
                        {
                            NetworkAccessPoint     = "http://google.com",
                            NetworkAccessPointType = NetworkAccessPointType.Uri,
                            UserIdentifier         = AuthenticationContext.SystemUserSid,
                            UserName = "******"
                        }
                    }
                },
                ProcessId   = "2039",
                ProcessName = "TestProcess.exe"
            };

            // Insert
            var audService = ApplicationServiceContext.Current.GetService <IDataPersistenceService <Audit> >();

            Assert.IsNotNull(audService);
            var inserted = audService.Insert(auditUnderTest, TransactionMode.Commit, AuthenticationContext.SystemPrincipal);

            Assert.IsTrue(inserted.Key.HasValue);
            Assert.AreEqual(Guid.Empty, inserted.CorrelationToken);
        }