Пример #1
0
        /// <summary>
        /// Initialize the patient
        /// </summary>
        public void Initialize(Patient p, IDictionary <String, Object> parameters)
        {
            if (parameters.ContainsKey("xml.initialized"))
            {
                return;
            }

            // Merge the view models
            NullViewModelSerializer serializer = new NullViewModelSerializer();

            if (parameters["runProtocols"] == null)
            {
                serializer.ViewModel = this.Definition.Initialize;
                serializer.ViewModel?.Initialize();
            }
            else
            {
                serializer.ViewModel = ViewModelDescription.Merge((parameters["runProtocols"] as IEnumerable <IClinicalProtocol>).OfType <XmlClinicalProtocol>().Select(o => o.Definition.Initialize));
                serializer.ViewModel?.Initialize();
            }

            // serialize - This will load data
            serializer.Serialize(p);

            parameters.Add("xml.initialized", true);
        }
Пример #2
0
        /// <summary>
        /// Create the specified serializer
        /// </summary>
        private JsonViewModelSerializer CreateSerializer(ViewModelDescription viewModelDescription)
        {
            var retVal = new JsonViewModelSerializer();

            retVal.ViewModel = viewModelDescription ?? this.m_defaultViewModel;
            retVal.LoadSerializerAssembly(typeof(OpenIZ.Core.Model.Json.Formatter.ActExtensionViewModelSerializer).Assembly);
            return(retVal);
        }
Пример #3
0
        // Static ctor
        static AgsDispatchFormatter()
        {
            m_defaultViewModel = ViewModelDescription.Load(Assembly.Load("SanteDB.Rest.Common").GetManifestResourceStream("SanteDB.Rest.Common.Resources.ViewModel.xml"));
            var tracer = Tracer.GetTracer(typeof(AgsDispatchFormatter <TContract>));

            foreach (var t in s_knownTypes)
            {
                ModelSerializationBinder.RegisterModelType(t);
            }
            tracer.TraceInfo("Will generate serializer for {0}", typeof(TContract).FullName);
        }
Пример #4
0
        /// <summary>
        /// Gets the template definition
        /// </summary>
        public ViewModel.Description.ViewModelDescription GetViewModelDescription(String viewModelName)
        {
            ViewModelDescription retVal = null;

            viewModelName = viewModelName?.ToLowerInvariant();
            if (!s_viewModelCache.TryGetValue(viewModelName ?? "", out retVal))
            {
                lock (s_syncLock)
                {
                    var viewModelDefinition = this.m_appletManifest.SelectMany(o => o.ViewModel).
                                              FirstOrDefault(o => o.ViewModelId.ToLowerInvariant() == viewModelName);

                    if (viewModelDefinition != null)
                    {
                        viewModelDefinition.DefinitionContent = this.RenderAssetContent(this.ResolveAsset(viewModelDefinition.Definition));
                    }

                    // De-serialize
                    using (MemoryStream ms = new MemoryStream(viewModelDefinition.DefinitionContent))
                    {
                        retVal = ViewModelDescription.Load(ms);
                        foreach (var itm in retVal.Include)
                        {
                            retVal.Model.AddRange(this.GetViewModelDescription(itm).Model);
                        }

                        // caching
                        if (this.CachePages)
                        {
                            if (!s_viewModelCache.ContainsKey(viewModelName))
                            {
                                s_viewModelCache.Add(viewModelName, retVal);
                            }
                        }
                    }
                }
            }
            return(retVal);
        }
Пример #5
0
 /// <summary>
 /// Creates a json view model serializer
 /// </summary>
 public JsonViewModelSerializer()
 {
     this.ViewModel = ViewModelDescription.Load(typeof(JsonViewModelSerializer).GetTypeInfo().Assembly.GetManifestResourceStream("OpenIZ.Core.Applets.ViewModel.Default.xml"));
 }
Пример #6
0
        public bool Start()
        {
            try
            {
                this.Starting?.Invoke(this, EventArgs.Empty);

                this.m_tracer.TraceInfo("Starting internal IMS services...");
                this.m_threadPool = ApplicationContext.Current.GetService <IThreadPoolService>();

                XamarinApplicationContext.Current.SetProgress("IMS Service Bus", 0);

                this.m_bypassMagic      = XamarinApplicationContext.Current.GetType().Name == "MiniApplicationContext";
                this.m_listener         = new HttpListener();
                this.m_defaultViewModel = ViewModelDescription.Load(typeof(MiniImsServer).Assembly.GetManifestResourceStream("OpenIZ.Mobile.Core.Xamarin.Resources.ViewModel.xml"));

                // Scan for services
                try
                {
                    foreach (var t in typeof(MiniImsServer).Assembly.DefinedTypes.Where(o => o.GetCustomAttribute <RestServiceAttribute>() != null))
                    {
                        var    serviceAtt = t.GetCustomAttribute <RestServiceAttribute>();
                        object instance   = Activator.CreateInstance(t);
                        foreach (var mi in t.GetRuntimeMethods().Where(o => o.GetCustomAttribute <RestOperationAttribute>() != null))
                        {
                            var operationAtt = mi.GetCustomAttribute <RestOperationAttribute>();
                            var faultMethod  = operationAtt.FaultProvider != null?t.GetRuntimeMethod(operationAtt.FaultProvider, new Type[] { typeof(Exception) }) : null;

                            String pathMatch = String.Format("{0}:{1}{2}", operationAtt.Method, serviceAtt.BaseAddress, operationAtt.UriPath);
                            if (!this.m_services.ContainsKey(pathMatch))
                            {
                                lock (this.m_lockObject)
                                    this.m_services.Add(pathMatch, new InvokationInformation()
                                    {
                                        BindObject    = instance,
                                        Method        = mi,
                                        FaultProvider = faultMethod,
                                        Demand        = (mi.GetCustomAttributes <DemandAttribute>().Union(t.GetCustomAttributes <DemandAttribute>())).Select(o => o.PolicyId).ToList(),
                                        Anonymous     = (mi.GetCustomAttribute <AnonymousAttribute>() ?? t.GetCustomAttribute <AnonymousAttribute>()) != null,
                                        Parameters    = mi.GetParameters()
                                    });
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    this.m_tracer.TraceWarning("Could scan for handlers : {1}", e);
                }

                // Get loopback
                var loopback = GetLocalIpAddress();

                // Core always on 9200
                this.m_listener.Prefixes.Add(String.Format("http://{0}:9200/", loopback));

                this.m_acceptThread = new Thread(() =>
                {
                    // Process the request
                    while (this.m_listener != null)
                    {
                        try
                        {
                            //var iAsyncResult = this.m_listener.BeginGetContext(null, null);
                            //iAsyncResult.AsyncWaitHandle.WaitOne();
                            var context = this.m_listener.GetContext(); //this.m_listener.EndGetContext(iAsyncResult);
                            this.m_threadPool.QueueUserWorkItem(TimeSpan.MinValue, this.HandleRequest, context);
                        }
                        catch (Exception e)
                        {
                            this.m_tracer.TraceError("Listener Error: {0}", e);
                        }
                    }
                });

                this.m_listener.Start();
                this.m_acceptThread.IsBackground = true;
                this.m_acceptThread.Start();
                this.m_acceptThread.Name = "MiniIMS";
                this.m_tracer.TraceInfo("Started internal IMS services...");

                // We have to wait for the IAppletManager service to come up or else it is pretty useless
                this.Started?.Invoke(this, EventArgs.Empty);

                this.m_startFinished = true;
                return(true);
            }
            catch (Exception ex)
            {
                this.m_tracer.TraceError("Error starting IMS : {0}", ex);
                ApplicationContext.Current.Alert(Strings.err_moreThanOneApplication);
                return(false);
            }
        }
Пример #7
0
        public void TestSerializeActWithDeepNestDefinition()
        {
            var act = new Act
            {
                ClassConcept = new Concept
                {
                    Key = ActClassKeys.Encounter
                },
                CreationTime = DateTimeOffset.Now,
                Key          = Guid.NewGuid(),
                MoodConcept  = new Concept
                {
                    Key = ActMoodKeys.Eventoccurrence
                },
                Relationships = new List <ActRelationship>
                {
                    new ActRelationship
                    {
                        RelationshipType = new Concept
                        {
                            Key      = ActRelationshipTypeKeys.HasSubject,
                            Mnemonic = "HasSubject"
                        },
                        TargetAct = new Act
                        {
                            Participations = new List <ActParticipation>
                            {
                                new ActParticipation
                                {
                                    ParticipationRole = new Concept
                                    {
                                        Key      = ActParticipationKey.RecordTarget,
                                        Mnemonic = "RecordTarget"
                                    },
                                    PlayerEntity = this.m_patientUnderTest
                                },
                                new ActParticipation
                                {
                                    ParticipationRole = new Concept
                                    {
                                        Key      = ActParticipationKey.Location,
                                        Mnemonic = "Location"
                                    },
                                    PlayerEntity = new Place
                                    {
                                        Key = Guid.Parse("AE2795E7-C40A-41CF-B77D-855EE2C3BF47")
                                    }
                                }
                            }
                        }
                    }
                }
            };

            this.m_patientUnderTest.Names[0].Component[0].ComponentType = new Concept()
            {
                Key      = NameComponentKeys.Family,
                Mnemonic = "Family"
            };
            ViewModelDescription vmd = ViewModelDescription.Load(typeof(ViewModelSerializerTest).Assembly.GetManifestResourceStream("OpenIZ.Core.Applets.Test.DeepActModel.xml"));
            var serializer           = new JsonViewModelSerializer();

            serializer.ViewModel = vmd;
            var actual = serializer.Serialize(act);

            Assert.IsTrue(actual.Contains(ActMoodKeys.Eventoccurrence.ToString()));
            Assert.IsTrue(actual.Contains(ActRelationshipTypeKeys.HasSubject.ToString()));
        }
        public void TestSerializeActWithDefinition()
        {
            var act = new Act
            {
                ClassConceptKey = ActClassKeys.Encounter,
                CreationTime    = DateTimeOffset.Now,
                Key             = Guid.NewGuid(),
                MoodConceptKey  = ActMoodKeys.Eventoccurrence,
                Relationships   = new List <ActRelationship>
                {
                    new ActRelationship
                    {
                        RelationshipType = new Concept
                        {
                            Key      = ActRelationshipTypeKeys.HasSubject,
                            Mnemonic = "HasSubject"
                        },
                        TargetAct = new Act
                        {
                            Participations = new List <ActParticipation>
                            {
                                new ActParticipation
                                {
                                    ParticipationRole = new Concept
                                    {
                                        Key      = ActParticipationKey.RecordTarget,
                                        Mnemonic = "RecordTarget"
                                    },
                                    PlayerEntity = this.m_patientUnderTest
                                },
                                new ActParticipation
                                {
                                    ParticipationRole = new Concept
                                    {
                                        Key      = ActParticipationKey.Location,
                                        Mnemonic = "Location"
                                    },
                                    PlayerEntity = new Place
                                    {
                                        Key = Guid.Parse("AE2795E7-C40A-41CF-B77D-855EE2C3BF47")
                                    }
                                }
                            }
                        }
                    },
                    new ActRelationship
                    {
                        RelationshipType = new Concept
                        {
                            Key      = ActRelationshipTypeKeys.HasComponent,
                            Mnemonic = "HasComponent"
                        },
                        TargetAct = new Act
                        {
                            Participations = new List <ActParticipation>
                            {
                                new ActParticipation
                                {
                                    ParticipationRole = new Concept
                                    {
                                        Key      = ActParticipationKey.RecordTarget,
                                        Mnemonic = "RecordTarget"
                                    },
                                    PlayerEntity = this.m_patientUnderTest
                                },
                                new ActParticipation
                                {
                                    ParticipationRole = new Concept
                                    {
                                        Key      = ActParticipationKey.Location,
                                        Mnemonic = "Location"
                                    },
                                    PlayerEntity = new Place
                                    {
                                        Key = Guid.Parse("AE2795E7-C40A-41CF-B77D-855EE2C3BF47")
                                    }
                                }
                            }
                        }
                    }
                    ,
                    new ActRelationship
                    {
                        RelationshipType = new Concept
                        {
                            Key      = ActRelationshipTypeKeys.Fulfills,
                            Mnemonic = "Fulfills"
                        },
                        TargetAct = new Act
                        {
                            Key = Guid.NewGuid()
                        }
                    }
                }
            };

            ViewModelDescription vmd = ViewModelDescription.Load(typeof(ViewModelSerializerTest).Assembly.GetManifestResourceStream("SanteDB.Core.Applets.Test.MinActModel.xml"));

            var serializer = new JsonViewModelSerializer();

            serializer.ViewModel = vmd;
            var actual = serializer.Serialize(act);

            // Must always contain ID even if model doesn't specify it (for ref integrity)
            Assert.IsTrue(actual.Contains(act.Key.ToString()));
            // Must not have fulfills
            Assert.IsFalse(actual.Contains("\"Fulfills\""));

            Assert.IsTrue(actual.Contains(ActMoodKeys.Eventoccurrence.ToString()));
            Assert.IsTrue(actual.Contains(ActRelationshipTypeKeys.HasSubject.ToString()));
        }