Exemplo n.º 1
0
        /// <summary>
        /// Create the protocol data from the protocol instance
        /// </summary>
        public void Load(Core.Model.Acts.Protocol protocolData)
        {
            if (protocolData == null)
            {
                throw new ArgumentNullException(nameof(protocolData));
            }
            using (MemoryStream ms = new MemoryStream(protocolData.Definition))
                this.Definition = ProtocolDefinition.Load(ms);

            var context = new CdssContext <Patient>();

            context.Declare("index", typeof(Int32));

            // Add callback rules
            foreach (var rule in this.Definition.Rules)
            {
                for (var index = 0; index < rule.Repeat; index++)
                {
                    foreach (var itm in rule.Variables)
                    {
                        context.Declare(itm.VariableName, itm.VariableType);
                    }
                }
            }

            this.Definition.When?.Compile <Patient>(context);
            foreach (var wc in this.Definition.Rules)
            {
                wc.When.Compile <Patient>(context);
            }
        }
Exemplo n.º 2
0
        public void AddDir(String dir)
        {
            if (!Path.IsPathRooted(dir))
            {
                dir = Path.Combine(this.m_workingDirectory, dir);
            }
            if (!Directory.Exists(dir))
            {
                throw new FileNotFoundException(dir);
            }

            // Add
            foreach (var file in Directory.GetFiles(dir))
            {
                Console.WriteLine("Add {0}", Path.GetFileName(file));
                try
                {
                    using (var fs = File.OpenRead(file))
                    {
                        var protoSource = ProtocolDefinition.Load(fs);
                        var proto       = new XmlClinicalProtocol(protoSource);

                        ApplicationContext.Current.GetService <IClinicalProtocolRepositoryService>().InsertProtocol(proto.GetProtocolData());
                    }
                }
                catch (Exception e)
                {
                    base.PrintStack(e);
                }
            }
        }
Exemplo n.º 3
0
        public void TestShouldSkipWeight()
        {
            ProtocolDefinition  definition = ProtocolDefinition.Load(typeof(TestProtocolApply).Assembly.GetManifestResourceStream("SanteDB.Cdss.Xml.Test.Protocols.Weight.xml"));
            XmlClinicalProtocol xmlCp      = new XmlClinicalProtocol(definition);

            // Patient that is just born = Schedule OPV
            Patient newborn = new Patient()
            {
                Key           = Guid.NewGuid(),
                DateOfBirth   = DateTime.Now,
                GenderConcept = new Core.Model.DataTypes.Concept()
                {
                    Mnemonic = "FEMALE"
                },
                Participations = new List <ActParticipation>()
                {
                    new ActParticipation()
                    {
                        ParticipationRole = new Core.Model.DataTypes.Concept()
                        {
                            Mnemonic = "RecordTarget"
                        },
                        Act = new QuantityObservation()
                        {
                            Value       = (decimal)3.2,
                            TypeConcept = new Core.Model.DataTypes.Concept()
                            {
                                Mnemonic = "VitalSign-Weight"
                            },
                            ActTime = DateTime.Now
                        }
                    },
                    new ActParticipation()
                    {
                        ParticipationRole = new Core.Model.DataTypes.Concept()
                        {
                            Mnemonic = "RecordTarget"
                        },
                        Act = new PatientEncounter()
                        {
                            ActTime = DateTime.Now
                        }
                    }
                }
            };

            // Now apply the protocol
            var    acts           = xmlCp.Calculate(newborn, null);
            var    jsonSerializer = new JsonViewModelSerializer();
            String json           = jsonSerializer.Serialize(newborn);

            Assert.AreEqual(59, acts.Count);
        }
Exemplo n.º 4
0
        public IEnumerable <Core.Model.Acts.Protocol> FindProtocol(Expression <Func <Core.Model.Acts.Protocol, bool> > predicate, int offset, int?count, out int totalResults)
        {
            List <Core.Model.Acts.Protocol> retVal = new List <Core.Model.Acts.Protocol>();

            foreach (var i in typeof(DummyProtocolRepository).Assembly.GetManifestResourceNames())
            {
                if (i.EndsWith(".xml"))
                {
                    ProtocolDefinition definition = ProtocolDefinition.Load(typeof(TestProtocolApply).Assembly.GetManifestResourceStream(i));
                    retVal.Add(new XmlClinicalProtocol(definition).GetProtocolData());
                }
            }
            totalResults = retVal.Count;
            return(retVal);
        }
Exemplo n.º 5
0
        public void Add(String file)
        {
            if (!Path.IsPathRooted(file))
            {
                file = Path.Combine(this.m_workingDirectory, file);
            }
            if (!File.Exists(file))
            {
                throw new FileNotFoundException(file);
            }

            // Add
            using (var fs = File.OpenRead(file))
            {
                var protoSource = ProtocolDefinition.Load(fs);
                var proto       = new XmlClinicalProtocol(protoSource);
                ApplicationContext.Current.GetService <IClinicalProtocolRepositoryService>().InsertProtocol(proto.GetProtocolData());
            }
        }
Exemplo n.º 6
0
        public void TestShouldScheduleOPV()
        {
            ProtocolDefinition  definition = ProtocolDefinition.Load(typeof(TestProtocolApply).Assembly.GetManifestResourceStream("SanteDB.Cdss.Xml.Test.Protocols.OralPolioVaccine.xml"));
            XmlClinicalProtocol xmlCp      = new XmlClinicalProtocol(definition);

            // Patient that is just born = Schedule OPV
            Patient newborn = new Patient()
            {
                Key           = Guid.NewGuid(),
                DateOfBirth   = DateTime.Now,
                GenderConcept = new Core.Model.DataTypes.Concept()
                {
                    Mnemonic = "FEMALE"
                }
            };
            // Now apply the protocol
            var    acts           = xmlCp.Calculate(newborn, new Dictionary <String, Object>());
            var    jsonSerializer = new JsonViewModelSerializer();
            String json           = jsonSerializer.Serialize(newborn);

            Assert.AreEqual(4, acts.Count);
        }
        /// <summary>
        /// Load protocols
        /// </summary>
        private void LoadProtocols()
        {
            try
            {
                // Get protocols from the applet
                var appletManager = ApplicationServiceContext.Current.GetService(typeof(IAppletManagerService)) as IAppletManagerService;
                var protocols     = appletManager.Applets.SelectMany(o => o.Assets).Where(o => o.Name.StartsWith("protocols/"));

                foreach (var f in protocols)
                {
                    XmlSerializer xsz     = new XmlSerializer(typeof(ProtocolDefinition));
                    var           content = f.Content ?? appletManager.Applets.Resolver(f);
                    if (content is String)
                    {
                        using (var rStream = new StringReader(content as String))
                            this.m_protocols.Add(
                                new XmlClinicalProtocol(xsz.Deserialize(rStream) as ProtocolDefinition).GetProtocolData()
                                );
                    }
                    else if (content is byte[])
                    {
                        using (var rStream = new MemoryStream(content as byte[]))
                            this.m_protocols.Add(new XmlClinicalProtocol(ProtocolDefinition.Load(rStream)).GetProtocolData());
                    }
                    else if (content is XElement)
                    {
                        using (var rStream = (content as XElement).CreateReader())
                            this.m_protocols.Add(
                                new XmlClinicalProtocol(xsz.Deserialize(rStream) as ProtocolDefinition).GetProtocolData()
                                );
                    }
                }
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error loading protocols: {0}", e);
            }
        }
Exemplo n.º 8
0
        public void TestShouldScheduleDTP()
        {
            ProtocolDefinition  definition = ProtocolDefinition.Load(typeof(TestProtocolApply).Assembly.GetManifestResourceStream("OpenIZ.Protocol.Xml.Test.Protocols.DTP-HepB-HibTrivalent.xml"));
            XmlClinicalProtocol xmlCp      = new XmlClinicalProtocol(definition);

            // Patient that is just born = Schedule OPV
            Patient newborn = new Patient()
            {
                Key           = Guid.NewGuid(),
                DateOfBirth   = DateTime.Now,
                GenderConcept = new Core.Model.DataTypes.Concept()
                {
                    Mnemonic = "FEMALE"
                }
            };

            // Now apply the protocol
            var    acts           = xmlCp.Calculate(newborn, null);
            var    jsonSerializer = new JsonViewModelSerializer();
            String json           = jsonSerializer.Serialize(newborn);

            Assert.AreEqual(3, acts.Count);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create the protocol data from the protocol instance
        /// </summary>
        public void Load(Core.Model.Acts.Protocol protocolData)
        {
            if (protocolData == null)
            {
                throw new ArgumentNullException(nameof(protocolData));
            }
            using (MemoryStream ms = new MemoryStream(protocolData.Definition))
                this.Definition = ProtocolDefinition.Load(ms);

            // Add callback rules
            foreach (var rule in this.Definition.Rules)
            {
                for (var index = 0; index < rule.Repeat; index++)
                {
                    foreach (var itm in rule.Variables)
                    {
                        if (!s_callbacks.ContainsKey(itm.VariableName))
                        {
                            Func <Object> funcBody = () =>
                            {
                                return(s_variables[itm.VariableName]);
                            };

                            var      varType = Type.GetType(itm.VariableType);
                            Delegate func    = Expression.Lambda(typeof(Func <>).MakeGenericType(varType), Expression.Convert(Expression.Call(funcBody.Target == null ? null : Expression.Constant(funcBody.Target), funcBody.GetMethodInfo()), varType)).Compile();
                            s_callbacks.Add(itm.VariableName, func);
                        }
                    }
                }
            }

            this.Definition.When?.Compile <Patient>(s_callbacks);
            foreach (var wc in this.Definition.Rules)
            {
                wc.When.Compile <Patient>(s_callbacks);
            }
        }