예제 #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);
            }
        }
예제 #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);
                }
            }
        }
예제 #3
0
 public override void ExportProtocolDefinition(ProtocolDefinition protocol)
 {
     //protocol.PortName = "test";
     //protocol.BindingName = "Testt";
     //protocol.SoapAddressLocation = "http://localhost:4011/";
     protocol.SoapAddressLocation = "https://localhost:6013/";
     base.ExportProtocolDefinition(protocol);
 }
예제 #4
0
 public ProtocolGeneration(
     NoggolloquyGenerator gen,
     ProtocolDefinition def,
     DirectoryInfo defFileLocation = null)
 {
     this.Definition = def;
     this.Gen        = gen;
     this.DefFileLocationOverride = defFileLocation;
 }
예제 #5
0
        public override void ExportProtocolDefinition(ProtocolDefinition protocolDefinition)
        {
            base.ExportProtocolDefinition(protocolDefinition);

            foreach (var version in Enumerable.Range(1, 3))
            {
                protocolDefinition.SupportedVersions.Add((uint)version);
            }
        }
예제 #6
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);
        }
예제 #7
0
 /// <summary>
 /// Create a Client using a Pre-accepted TcpClient
 /// </summary>
 /// <param name="client">the Pre-Accepted client.</param>
 internal TcpClient(System.Net.Sockets.TcpClient client, ProtocolDefinition def, PacketReceived packetReceived)
 {
     _cts              = new CancellationTokenSource();
     _client           = client;
     _stream           = _client.GetStream();
     _isRemoteClient   = true;
     _sendQueue        = new Queue <PacketSendInfo>();
     _streamSemaphore  = new SemaphoreSlim(1, 1);
     Protocol          = def;
     OnPacketReceived += packetReceived;
     SetupThreads();
 }
        public static ParsedMessage Parse(RawMessage message, ProtocolDefinition proto)
        {
            ParsedMessage msg = (m_SpecializedTypes.ContainsKey(proto.Name)) ?
                                (ParsedMessage)Activator.CreateInstance(m_SpecializedTypes[proto.Name]) :
                                new ParsedMessage();

            msg.OpCode = message.OpCode;
            msg.Time   = message.Time;
            using (MessageReader reader = new MessageReader(message))
            {
                msg.Content = ReadRecursive(proto.Lines, reader);
            }
            return(msg);
        }
예제 #9
0
        public override void ExportProtocolDefinition(ProtocolDefinition protocolDefinition)
        {
            base.ExportProtocolDefinition(protocolDefinition);

            if (stringSerializationMode == StringSerializationMode.WrappedInCData)
            {
                protocolDefinition.Style = new CDataRpcEncodedStyle();
            }

            foreach (var version in Enumerable.Range(1, 3))
            {
                protocolDefinition.SupportedVersions.Add((uint)version);
            }
        }
예제 #10
0
        public static void WriteMissingAttributes(this XmlWriter writer, ProtocolDefinition protocolDefinition)
        {
            if (protocolDefinition == null)
            {
                return;
            }

            foreach (var kvp in protocolDefinition.GlobalNamespacePrefixes)
            {
                if (writer.LookupPrefix(kvp.Key.NamespaceName) == null)
                {
                    writer.WriteAttributeString(PrefixConstants.XMLNS, kvp.Value, NamespaceConstants.XMLNS, kvp.Key.NamespaceName);
                }
            }
        }
예제 #11
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);
        }
예제 #12
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());
            }
        }
예제 #13
0
        /// <summary>
        /// Initializes new X-Road message protocol instance.
        /// <param name="name">Identifies protocol instance.</param>
        /// <param name="schemaExporter">Schema customization provider.</param>
        /// </summary>
        public XRoadProtocol(string name, ISchemaExporter schemaExporter)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (schemaExporter == null)
            {
                throw new ArgumentNullException(nameof(schemaExporter));
            }

            Name = name;

            schemaDefinitionProvider = new SchemaDefinitionProvider(schemaExporter);

            HeaderDefinition   = schemaDefinitionProvider.GetXRoadHeaderDefinition();
            ProtocolDefinition = schemaDefinitionProvider.ProtocolDefinition;

            SetContractAssembly();
        }
예제 #14
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);
            }
        }
예제 #16
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);
        }
예제 #17
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);
            }
        }
예제 #18
0
        /// <summary>
        /// Serializes beginning of SOAP envelope into X-Road message.
        /// </summary>
        public static void WriteSoapEnvelope(this XmlWriter writer, IMessageFormatter messageFormatter, ProtocolDefinition protocolDefinition)
        {
            var soapEnvPrefix = protocolDefinition != null ? protocolDefinition.GlobalNamespacePrefixes[messageFormatter.Namespace] : PrefixConstants.SOAP_ENV;

            messageFormatter.WriteStartEnvelope(writer, soapEnvPrefix);

            if (protocolDefinition == null)
            {
                return;
            }

            foreach (var kvp in protocolDefinition.GlobalNamespacePrefixes)
            {
                writer.WriteAttributeString(PrefixConstants.XMLNS, kvp.Value, NamespaceConstants.XMLNS, kvp.Key.NamespaceName);
            }

            if (protocolDefinition.Style is RpcEncodedStyle)
            {
                writer.WriteAttributeString("encodingStyle", messageFormatter.Namespace, NamespaceConstants.SOAP_ENC);
            }
        }
예제 #19
0
 /// <summary>
 /// Create a new CDSS evaluation exception
 /// </summary>
 public CdssEvaluationException(String message, ProtocolDefinition protocol, Exception cause) : base(message, cause)
 {
     this.Protocol = protocol;
 }
 public override ParsedMessage Process(RawMessage raw)
 {
     ProtocolDefinition def = m_ProtocolDatabase.GetProtocol(raw.OpCode);
     return def != null ? MessageFactory.Parse(raw, def) : null;
 }
예제 #21
0
 /// <summary>
 /// Creates a new protocol from the specified definition
 /// </summary>
 /// <param name="defn"></param>
 public XmlClinicalProtocol(ProtocolDefinition defn)
 {
     this.Definition = defn;
 }