private static HCIM_IN_GetDemographicsRequest CreateRequest(OIDType oIDType, string identifierValue)
        {
            using (Source.StartActivity("CreatePatientSOAPRequest"))
            {
                HCIM_IN_GetDemographics request = new HCIM_IN_GetDemographics();
                request.id = new II()
                {
                    root = "2.16.840.1.113883.3.51.1.1.1", extension = DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString(System.Globalization.CultureInfo.InvariantCulture)
                };
                request.creationTime = new TS()
                {
                    value = System.DateTime.Now.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture)
                };
                request.versionCode = new CS()
                {
                    code = "V3PR1"
                };
                request.interactionId = new II()
                {
                    root = "2.16.840.1.113883.3.51.1.1.2", extension = "HCIM_IN_GetDemographics"
                };
                request.processingCode = new CS()
                {
                    code = "P"
                };
                request.processingModeCode = new CS()
                {
                    code = "T"
                };
                request.acceptAckCode = new CS()
                {
                    code = "NE"
                };

                request.receiver = new MCCI_MT000100Receiver()
                {
                    typeCode = "RCV"
                };
                request.receiver.device = new MCCI_MT000100Device()
                {
                    determinerCode = "INSTANCE", classCode = "DEV"
                };
                request.receiver.device.id = new II()
                {
                    root = "2.16.840.1.113883.3.51.1.1.4", extension = "192.168.0.1"
                };
                request.receiver.device.asAgent = new MCCI_MT000100Agent()
                {
                    classCode = "AGNT"
                };
                request.receiver.device.asAgent.representedOrganization = new MCCI_MT000100Organization()
                {
                    determinerCode = "INSTANCE", classCode = "ORG"
                };
                request.receiver.device.asAgent.representedOrganization = new MCCI_MT000100Organization()
                {
                    determinerCode = "INSTANCE", classCode = "ORG"
                };
                request.receiver.device.asAgent.representedOrganization.id = new II()
                {
                    root = "2.16.840.1.113883.3.51.1.1.3", extension = "HCIM"
                };

                request.sender = new MCCI_MT000100Sender()
                {
                    typeCode = "SND"
                };
                request.sender.device = new MCCI_MT000100Device()
                {
                    determinerCode = "INSTANCE", classCode = "DEV"
                };
                request.sender.device.id = new II()
                {
                    root = "2.16.840.1.113883.3.51.1.1.5", extension = "MOH_CRS"
                };
                request.sender.device.asAgent = new MCCI_MT000100Agent()
                {
                    classCode = "AGNT"
                };
                request.sender.device.asAgent.representedOrganization = new MCCI_MT000100Organization()
                {
                    determinerCode = "INSTANCE", classCode = "ORG"
                };
                request.sender.device.asAgent.representedOrganization = new MCCI_MT000100Organization()
                {
                    determinerCode = "INSTANCE", classCode = "ORG"
                };
                request.sender.device.asAgent.representedOrganization.id = new II()
                {
                    root = "2.16.840.1.113883.3.51.1.1.3", extension = "HGWAY"
                };

                request.controlActProcess = new HCIM_IN_GetDemographicsQUQI_MT020001ControlActProcess()
                {
                    classCode = "ACCM", moodCode = "EVN"
                };
                request.controlActProcess.effectiveTime = new IVL_TS()
                {
                    value = System.DateTime.Now.ToString("yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture)
                };
                request.controlActProcess.dataEnterer = new QUQI_MT020001DataEnterer()
                {
                    typeCode = "CST", time = null, typeId = null
                };
                request.controlActProcess.dataEnterer.assignedPerson = new COCT_MT090100AssignedPerson()
                {
                    classCode = "ENT"
                };

                // TODO: We should likely send the actual username instead of HLTHGTWAY
                request.controlActProcess.dataEnterer.assignedPerson.id = new II()
                {
                    root = "2.16.840.1.113883.3.51.1.1.7", extension = "HLTHGTWAY"
                };

                request.controlActProcess.queryByParameter = new HCIM_IN_GetDemographicsQUQI_MT020001QueryByParameter();
                request.controlActProcess.queryByParameter.queryByParameterPayload                = new HCIM_IN_GetDemographicsQueryByParameterPayload();
                request.controlActProcess.queryByParameter.queryByParameterPayload.personid       = new HCIM_IN_GetDemographicsPersonid();
                request.controlActProcess.queryByParameter.queryByParameterPayload.personid.value = new II()
                {
                    root = oIDType.ToString(), extension = identifierValue, assigningAuthorityName = "LCTZ_IAS"
                };

                return(new HCIM_IN_GetDemographicsRequest(request));
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            while (!quit)
            {
                if (node == null)
                {
                    Console.Write(">");
                }
                else
                {
                    Console.Write(String.Join('.', getPath(node)) + " $ ");
                }
                string[] command = Console.ReadLine().Split(" ");
                if (command[0] == "quit" && command.Length == 1)
                {
                    quit = true;
                }
                else if (command[0] == "test" && command.Length == 1)
                {
                    var str = new OIDType(null, Int64.MinValue, Int64.MaxValue, null, null, null).encode("{ISO(1) org(3) dod(6) internet(257)}");

                    string hex = String.Concat(
                        Regex.Matches(str, "....").Cast <Match>()
                        .Select(m => Convert.ToInt32(m.Value, 2)
                                .ToString("x1"))
                        );
                    Console.WriteLine(str);
                    Console.WriteLine(hex);

                    var test = file.decodeType(str);
                    Console.WriteLine(test);
                }
                else if (command[0] == "start" && command.Length == 1)
                {
                    Console.WriteLine("parsing file RFC1213 - MIB.txt");
                    file = new ASPFile(File.ReadAllText("RFC1213-MIB.txt"));
                    node = file.root;
                }
                else if (command[0] == "decode" && command.Length > 1)
                {
                    var toDecode = Regex.Replace(string.Join(' ', command.AsSpan(1, command.Length - 1).ToArray()), @"\s+", "");
                    toDecode = String.Join(String.Empty, toDecode.Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')));
                    var info = file.decodeType(toDecode);
                    Console.WriteLine(info.Item1.decode(file, info.Item3));
                }
                else if (command[0] == "cls" && command.Length == 1)
                {
                    Console.Clear();
                }
                else if (command[0] == "parse" && command.Length == 2)
                {
                    Console.WriteLine("parsing file " + command[1]);
                    file = new ASPFile(File.ReadAllText(command[1]));
                    node = file.root;
                }
                else if (command[0] == "cd" && command.Length == 2)
                {
                    ITreeNode newNode = file.findPath(command[1].Split('.'), node);
                    if (newNode != null)
                    {
                        node = newNode;
                    }
                    else
                    {
                        Console.WriteLine("node not found");
                    }
                }
                else if (command[0] == "ls" && command.Length == 1)
                {
                    printChildren(node);
                }
                else if (command[0] == "discard" && command.Length == 1)
                {
                    file = null;
                    node = null;
                }
                else if (command[0] == "find" && command.Length == 2)
                {
                    ITreeNode newNode = file.findNode(command[1]);
                    if (newNode != null)
                    {
                        node = newNode;
                    }
                    else
                    {
                        Console.WriteLine("node not found");
                    }
                }
                else if (command[0] == "info" && command.Length == 1)
                {
                    printInfo(node);
                }
                else if (command[0] == "new" && command.Length == 1)
                {
                    file = new ASPFile("");
                    node = file.root;
                }
                else if (command[0] == "def" && command.Length > 1)
                {
                    string line = string.Join(' ', command.AsSpan(1, command.Length - 1).ToArray());
                    new Parser(file).parseAnyType(Utils.preprocessText(line + ' '));
                }
                else if (command[0] == "encode" && command.Length > 2)
                {
                    string value   = string.Join(' ', command.AsSpan(2, command.Length - 2).ToArray());
                    string encoded = file.fetchType(command[1]).encode(value);
                    if (encoded != null)
                    {
                        Console.WriteLine(Regex.Replace(encoded, ".{8}", "$0 "));
                        var hex = string.Join("       ",
                                              Enumerable.Range(0, encoded.Length / 8).Select(i => Convert.ToByte(encoded.Substring(i * 8, 8), 2).ToString("X2")));
                        Console.WriteLine(hex);
                    }
                    else
                    {
                        Console.WriteLine("invalid input");
                    }
                }
                else if (command[0] == "encode-node" && command.Length > 1)
                {
                    if (node.GetType() == typeof(ObjectType))
                    {
                        ObjectType objType  = (ObjectType)node;
                        string     toEncode = string.Join(' ', command.AsSpan(1, command.Length - 1).ToArray());
                        string     encoded  = objType.type.encode(toEncode);
                        if (encoded != null)
                        {
                            Console.WriteLine(Regex.Replace(encoded, ".{8}", "$0 "));
                            var hex = string.Join("       ",
                                                  Enumerable.Range(0, encoded.Length / 8).Select(i => Convert.ToByte(encoded.Substring(i * 8, 8), 2).ToString("X2")));
                            Console.WriteLine(hex);
                        }
                        else
                        {
                            Console.WriteLine("invalid input");
                        }
                    }
                    else
                    {
                        Console.WriteLine("node not encodable");
                    }
                }
                else if (command[0] == "listen" && command.Length == 1)
                {
                    IPEndPoint serverEndpoint = new IPEndPoint(IPAddress.Any, 161);
                    UdpClient  socket         = new UdpClient(serverEndpoint);
                    IPEndPoint remote         = new IPEndPoint(IPAddress.Any, 0);

                    var data     = socket.Receive(ref remote);
                    var byteData = string.Join("", Enumerable.Range(0, data.Length).Select(i => data[i].ToString("X2")));
                    byteData = String.Join(String.Empty, byteData.Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')));
                    var info    = file.decodeType(byteData);
                    var decoded = info.Item1.decode(file, info.Item3);
                    Console.WriteLine(decoded);

                    var requestId = Regex.Match(decoded, @"GetRequestPDU: { INTEGER: ([0-9]+),").Groups[1];
                    var oid       = Regex.Match(decoded, @"OBJECT IDENTIFIER: ([.0-9]+),").Groups[1];
                    var resp      = file.fetchType("Message").encode("{ version 0, community public, data { requestid " + requestId + ", errorstatus 0, errorindex 0, variablebindings { { name " + oid + ", value str AAAAA } } } }");
                    resp = string.Join("", Enumerable.Range(0, resp.Length / 8).Select(i => Convert.ToByte(resp.Substring(i * 8, 8), 2).ToString("X2")));
                    data = new byte[1024];
                    for (int i = 0; i < resp.Length; i += 2)
                    {
                        data[i / 2] = Byte.Parse(resp.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
                    }

                    socket.Send(data, resp.Length / 2, remote);
                }
                else
                {
                    Console.WriteLine("unknown command");
                }
            }
        }