/// <summary>
/// patientVisit
/// This method is used by MHV and will probably be used by other PHR apps.
/// </summary>
/// <param name="pwd">Client app's BSE security phrase</param>
/// <param name="homeSitecode">Station number</param>
/// <param name="mpiPid">ICN</param>
/// <param name="multiSite">Set to false for now</param>
/// <returns>SiteArray: Nothing really in it though, except error messages</returns>
public SiteArray patientVisit(string pwd, string homeSitecode, string mpiPid, bool multiSite)
{
SiteArray result = new SiteArray();
//Make sure we have all the args we need
if (mySession == null || mySession.SiteTable == null)
{
result.fault = new FaultTO("No session has been started");
}
else if (String.IsNullOrEmpty(homeSitecode))
{
result.fault = new FaultTO("No homeSitecode");
}
else if (mySession.SiteTable.getSite(homeSitecode) == null)
{
result.fault = new FaultTO("No site " + homeSitecode + " in the site table");
}
else if (mySession.ConnectionSet != null &&
mySession.ConnectionSet.Count > 0 &&
mySession.ConnectionSet.HasConnection(homeSitecode))
{
result.fault = new FaultTO("Site " + homeSitecode + " already connected");
}
else if (mySession.ConnectionSet != null && mySession.ConnectionSet.Count > 0)
{
result.fault = new FaultTO("This session has pre-existing connections and this method should be the base connection.", "Do a disconnect?");
}
else if (mpiPid == "")
{
result.fault = new FaultTO("No MPI PID");
}
if (result.fault != null)
{
return result;
}
Site homeSite = mySession.SiteTable.getSite(homeSitecode);
mySession.Credentials = getAdministrativeCredentials(homeSite);
mySession.Credentials.SecurityPhrase = pwd;
string context = MdwsConstants.MDWS_CONTEXT;
if (mySession.DefaultVisitMethod == MdwsConstants.NON_BSE_CREDENTIALS)
{
context = MdwsConstants.CPRS_CONTEXT;
}
mySession.PrimaryPermission = new MenuOption(context);
try
{
mySession.User = doTheVisit(homeSitecode, mySession.Credentials, mySession.PrimaryPermission);
PatientApi patientApi = new PatientApi();
string localPid = patientApi.getLocalPid(myCxn, mpiPid);
if (localPid == "")
{
myCxn.disconnect();
result.fault = new FaultTO("No such patient at this site");
return result;
}
mySession.Patient = patientApi.select(myCxn, localPid);
addMyCxn2CxnSet();
}
catch (Exception e)
{
myCxn.disconnect();
result.fault = new FaultTO(e.Message);
return result;
}
return result;
}