public SiteArray setupMultiSourcePatientQuery(string pwd, string context)
{
SiteArray result = new SiteArray();
//Make sure we have all the args we need
if (mySession == null || mySession.SiteTable == null)
{
result.fault = new FaultTO("No site table");
}
else if (mySession.Patient == null)
{
result.fault = new FaultTO("No patient", "Need to select a patient?");
}
else if (String.IsNullOrEmpty(mySession.Patient.MpiPid))
{
result.fault = new FaultTO("Patient has no ICN", "Need to select the patient?");
}
else if (mySession.Patient.SiteIDs == null || mySession.Patient.SiteIDs.Length == 0)
{
result.fault = new FaultTO("Patient has no sites", "Need to select the patient?");
}
if (result.fault != null)
{
return result;
}
if (String.IsNullOrEmpty(context))
{
context = mySession.DefaultPermissionString;
}
try
{
Site[] sites = mySession.SiteTable.getSites(mySession.Patient.SiteIDs);
List<DataSource> sources = new List<DataSource>(sites.Length);
for (int i = 0; i < sites.Length; i++)
{
if (sites[i] == null)
{
continue;
}
DataSource src = sites[i].getDataSourceByModality("HIS");
if (src != null)
{
sources.Add(src);
}
}
TaggedTextArray tta = setupMultiSourceQuery(pwd, sources, context);
PatientApi patientApi = new PatientApi();
IndexedHashtable t = patientApi.setLocalPids(mySession.ConnectionSet, mySession.Patient.MpiPid);
// we need to check confidentiality everywhere and issue bulletin if found at any site
IndexedHashtable confidentialResults = patientApi.getConfidentiality(mySession.ConnectionSet);
if (confidentialResults != null && confidentialResults.Count > 0)
{
KeyValuePair<int, string> highestConfidentialityResult = new KeyValuePair<int,string>(0, "");
for (int i = 0; i < confidentialResults.Count; i++)
{
KeyValuePair<int, string> siteResult = (KeyValuePair<int, string>)confidentialResults.GetValue(i);
if (siteResult.Key > highestConfidentialityResult.Key)
{
highestConfidentialityResult = siteResult;
}
}
if (highestConfidentialityResult.Key == 1)
{
// do nothing here - M code takes care of this per documentation
}
else if (highestConfidentialityResult.Key == 2)
{
patientApi.issueConfidentialityBulletin(mySession.ConnectionSet);
}
else if (highestConfidentialityResult.Key > 2)
{
// catch block below takes care of disconnecting all sites
throw new ApplicationException(highestConfidentialityResult.Value);
}
}
// end confidentiality
result = new SiteArray(sites);
for (int i = 0; i < result.sites.Length; i++)
{
if (mySession.ConnectionSet.ExcludeSite200 && result.sites[i].sitecode == "200")
{
result.sites[i].fault = new FaultTO("Site excluded");
}
else if (t.ContainsKey(result.sites[i].sitecode))
{
// TBD: fault in t?
result.sites[i].pid = (string)t.GetValue(result.sites[i].sitecode);
}
}
// copy faults over if any found
foreach (TaggedText tt in tta.results)
{
if (tt.fault != null)
{
foreach (SiteTO s in result.sites)
{
if (String.Equals(s.sitecode, tt.tag))
{
s.fault = tt.fault;
}
}
}
}
}
catch (Exception e)
{
result = new SiteArray();
result.fault = new FaultTO(e.Message);
mySession.ConnectionSet.disconnectAll();
}
return result;
}