gov.va.medora.mdws.AccountLib.cprsLaunch C# (CSharp) Method

cprsLaunch() public method

This method assumes there has been no login and therefore no credentials or user so it makes a new ConnectionSet, new credentials, etc.
public cprsLaunch ( string pwd, string sourceId, string userId, string patientId ) : PersonsTO
pwd string Client app's BSE security phrase
sourceId string Station number
userId string DUZ
patientId string DFN
return gov.va.medora.mdws.dto.PersonsTO
        public PersonsTO cprsLaunch(string pwd, string sourceId, string userId, string patientId)
        {
            PersonsTO result = new PersonsTO();

            if (String.IsNullOrEmpty(sourceId))
            {
                result.fault = new FaultTO("No sitecode!");
            }
            else if (String.IsNullOrEmpty(userId))
            {
                result.fault = new FaultTO("No DUZ!");
            }
            else if (String.IsNullOrEmpty(patientId))
            {
                result.fault = new FaultTO("No DFN!");
            }
            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?");
            }
            if (result.fault != null)
            {
                return result;
            }

            // Get the site
            // Note the visit site and user site are the same!
            Site site = mySession.SiteTable.getSite(sourceId);
            if (site == null)
            {
                result.fault = new FaultTO("No site " + sourceId + " in sites table");
                return result;
            }

            // Now select the patient
            try
            {
                User trueUser = getVisitorData(sourceId, userId, pwd);

                // Now visit as the real user
                // Note context has to be CPRS!
                result.user = visitAndAuthorize(
                    pwd,
                    sourceId,
                    sourceId,
                    trueUser.Name.getLastNameFirst(),
                    userId,
                    trueUser.SSN.toString(),
                    mySession.DefaultPermissionString);

                if (result.user.fault != null)
                {
                    result.fault = result.user.fault;
                    return result;
                }
                PatientApi patientApi = new PatientApi();
                mySession.Patient = patientApi.select(mySession.ConnectionSet.getConnection(sourceId), patientId);
                result.patient = new PatientTO(mySession.Patient);
            }
            catch (Exception e)
            {
                //mySession.cxnMgr.disconnect();
                if (e.Message.StartsWith("Patient unknown to CPRS"))
                {
                    result.patient.fault = new FaultTO(e.Message);
                }
                else
                {
                    result.fault = new FaultTO(e.Message);
                }
            }
            return result;
        }