C# Code connecting to VistA using Medsphere RPC dlls...

242 views
Skip to first unread message

Sam Habiel

unread,
Apr 7, 2010, 4:22:46 AM4/7/10
to hardhats
This example builds and expands upon Casey's (may his VISTA soul rest
in peace)... Casey's didn't have context settings, which is important
in VISTA.

using System;
using Medsphere.OpenVista.Remoting;
using Medsphere.OpenVista.Shared;

namespace RPCTester1a
{
class Program
{
static void Main(string[] args)
{
try
{
// Connect
DataConnection dc = new DataConnection("RPCTest1a",
"192.168.1.1", 9230, true);
Console.WriteLine("Connected!");

// Enter Access and Verify Codes
Console.Write("Enter Access Code: ");
string accessCode = Console.ReadLine();
Console.Write("Enter Verify Code: ");
string verifyCode = Console.ReadLine();

// Set-up for Sign-on
string NO_ARG = RpcFormatter.FormatArgs(true, new string[0]);
string res = dc.CallRPC("XUS SIGNON SETUP", NO_ARG);

// Sign-on
string AV_ARG = RpcFormatter.FormatArgs(true,
Cypher.Encrypt(accessCode + ";" + verifyCode));
res = dc.CallRPC("XUS AV CODE", AV_ARG);

// Get DUZ
string[] results = Common.Split(res);
int DUZ = Convert.ToInt16(results[0]);
Console.WriteLine("DUZ: " + DUZ);
// TODO: If results[1] is not 0, something is wrong
and need to deal with it. See XUS AV CODE RPC for valid values
// TODO: If multiple divisions and no default, user
can't sign on without picking one.
string context = "UJOR RPC";


dc.CallRPC("XWB CREATE CONTEXT",
RpcFormatter.FormatArgs(true, Cypher.Encrypt(context)));
// Get possible patient sensitivity levels
string sen_lvls=dc.CallRPC("UJOR GET PT REC SEC
OPTIONS", NO_ARG);
Console.WriteLine("Sec Lvl: " + sen_lvls);

SoapHashtable testSHt = new SoapHashtable();
testSHt.Add(1, "VALUE 1");
testSHt.Add(2, "VALUE 2");
testSHt.Add(3, "VALUE 3");

res = dc.CallRPC("KBANEX8 EN",
RpcFormatter.FormatArgs(true, testSHt, "SWAN"));
Console.WriteLine("Result of KBANEX8 EN: " + res);

// Get User Keys
string keys = dc.CallRPC("UJOR GET USR KEYS", NO_ARG);
Console.WriteLine(keys);

Console.WriteLine("Adding patient...");
string PT_ARG = RpcFormatter.FormatArgs(true, new
string[] { "WEASLEY,GINNY", "F", "12/8/2000", "5557778867" });
string result = dc.CallRPC("UJOR ADD NEW PATIENT", PT_ARG);
Console.WriteLine("Result: " + result);
string arabic_name = "جيني ويزلي";
char[] arabic_nm_ch = arabic_name.ToCharArray();
System.Text.Encoding cp1256 =
System.Text.Encoding.GetEncoding("windows-1256");
byte[] arabic_nm_by = cp1256.GetBytes(arabic_nm_ch);
string arabic_name2="";
foreach (byte eachbyte in arabic_nm_by)
{
arabic_name2 += ((char)eachbyte);
}
//ShowArray(arabic_nm_by);
result = dc.CallRPC("UJOR ADD ARABIC
NAME",RpcFormatter.FormatArgs(false,2,arabic_name2));
Console.WriteLine("Testing multiple entry values...");
SoapHashtable PatientData = new SoapHashtable();
PatientData.Add("\"ADD1\"", "30 Meadow Way");
PatientData.Add("\"ADD2\"", "PO BOX 22");
PatientData.Add("\"ADD3\"", "ABC 1234");
result = dc.CallRPC("UJOR TEST",
RpcFormatter.FormatArgs(false,"9",PatientData,"11"));

//Switch to CPRS Context
context = "OR CPRS GUI CHART";
res = dc.CallRPC("XWB CREATE CONTEXT",
RpcFormatter.FormatArgs(false, Cypher.Encrypt(context)));

// Call RPC to Get all New Person entries in the system
string[] args3={"A","1"}; // Start with "A", $Order is
forward direction
res = dc.CallRPC("ORWU NEWPERS",
RpcFormatter.FormatArgs(true,args3));
Console.WriteLine("Results: " + res);

// Close
Console.ReadKey();
dc.Close();
}
catch (RpcSecurityException ex)
{
Console.WriteLine("Security Authorization Failure. " +
ex.Message);
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine("Oops..." + ex.Message);
Console.ReadKey();
}

}
public static void ShowArray(Array theArray)
{
foreach (Object o in theArray)
{
Console.Write("[{0}]", o);
}
Console.WriteLine("\n");
}
}
}

David Whitten

unread,
Apr 7, 2010, 10:27:25 AM4/7/10
to hard...@googlegroups.com
Sam, could you give us some annotations for why you wrote this code this way,
and what the overall structure of it might be ? I'm sure those who are just starting
in VistA and C# coding would appreciate it.


--
http://groups.google.com/group/Hardhats
To unsubscribe, send email to Hardhats+u...@googlegroups.com

To unsubscribe, reply using "remove me" as the subject.

Sam Habiel

unread,
Apr 8, 2010, 2:41:51 AM4/8/10
to hard...@googlegroups.com
The code is just a pot-boiler. It does nothing but demonstrate how to
use RPCs from C#. It really doesn't have a structure just beyond
connecting, preparing for sign-on, signing on, setting a context, then
executing a bunch of RPCs.

Sam

Reply all
Reply to author
Forward
0 new messages