public PRPA_IN201306UV02 PRPA_IN201305UV02(string CURRENT_USER, Int32 CURRENT_REGISTRY_ID, PATIENT p)
        {
            PRPA_IN201306UV02 objReturn = null;

            try
            {
                PRPA_MT201306UV02ParameterList patientParameters = GetDemographicParameters(p);
                if (patientParameters == null)
                {
                    return(null);
                }
                QUQI_MT021001UV01DataEnterer[] currentUser = GetDataEnterer(CURRENT_USER, CURRENT_REGISTRY_ID);

                if (rsMain == null)
                {
                    InitProxy();
                }

                string createDateTime = DateTime.Now.ToString("yyyyMMddhhmmss");

                PRPA_IN201305UV02 PRPA_IN201305UV021 = new PRPA_IN201305UV02()
                {
                    id = new II()
                    {
                        root = vaRoot, extension = string.Format("{0}-{1}", "MCID", createDateTime)
                    },
                    creationTime = new TS()
                    {
                        value = createDateTime
                    },
                    versionCode = new CS()
                    {
                        code = verCode
                    },
                    interactionId = new II()
                    {
                        extension = "PRPA_IN201305UV02", root = iiRoot
                    },
                    processingCode = new CS()
                    {
                        code = prcCode
                    },
                    processingModeCode = new CS()
                    {
                        code = "T"
                    },
                    acceptAckCode = new CS()
                    {
                        code = "AL"
                    },

                    receiver = new MCCI_MT000100UV01Receiver[]
                    {
                        new MCCI_MT000100UV01Receiver()
                        {
                            typeCode = CommunicationFunctionType.RCV,
                            device   = new MCCI_MT000100UV01Device()
                            {
                                determinerCode = "INSTANCE",
                                classCode      = EntityClassDevice.DEV,
                                id             = new II[] { new II()
                                                            {
                                                                root = vaRoot
                                                            } }
                            }
                        }
                    },

                    sender = new MCCI_MT000100UV01Sender()
                    {
                        typeCode = CommunicationFunctionType.SND,
                        device   = new MCCI_MT000100UV01Device()
                        {
                            determinerCode = "INSTANCE",
                            classCode      = EntityClassDevice.DEV,
                            id             = new II[] { new II()
                                                        {
                                                            root = vaRoot, extension = "200CRSE"
                                                        } }
                        }
                    },

                    controlActProcess = new PRPA_IN201305UV02QUQI_MT021001UV01ControlActProcess()
                    {
                        dataEnterer = currentUser,
                        classCode   = ActClassControlAct.CACT,
                        moodCode    = x_ActMoodIntentEvent.EVN,
                        code        = new CD()
                        {
                            code = "PRPA_TE201305UV02", codeSystem = iiRoot
                        },

                        queryByParameter = new PRPA_MT201306UV02QueryByParameter()
                        {
                            queryId = new II()
                            {
                                root = vaRoot, extension = createDateTime
                            },
                            statusCode = new CS()
                            {
                                code = "new"
                            },
                            modifyCode = new CS()
                            {
                                code = "MVI.COMP1"
                            },
                            initialQuantity = new INT()
                            {
                                value = "1"
                            },
                            parameterList = patientParameters
                        },
                    }
                };

                ////Used for debugging request
                //SoapEnvelope envelope = new SoapEnvelope();
                //envelope.body = new Body();
                //envelope.body.PRPA_IN201305UV02 = PRPA_IN201305UV021;

                //XmlSerializer ser = new XmlSerializer(typeof(SoapEnvelope));
                //TextWriter writer = new StreamWriter("C:\\temp\\PRPA_IN201305UV02.xml");
                //ser.Serialize(writer, envelope);
                //writer.Close();

                LogDetails logDetails = new LogDetails(String.Format("{0}.{1}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodBase.GetCurrentMethod().Name), CURRENT_USER, CURRENT_REGISTRY_ID);
                objReturn = rsMain.PRPA_IN201305UV02(PRPA_IN201305UV021);
                LogManager.LogTiming(logDetails);

                ////Used for debugging response
                //if (objReturn != null)
                //{
                //    envelope = new SoapEnvelope();
                //    envelope.body = new Body();
                //    envelope.body.PRPA_IN201306UV02 = objReturn;

                //    ser = new XmlSerializer(typeof(SoapEnvelope));
                //    writer = new StreamWriter("C:\\temp\\PRPA_IN201306UV02.xml");
                //    ser.Serialize(writer, envelope);
                //    writer.Close();
                //}
            }
            catch (WebException ex)
            {
                LogManager.LogError(ex.Message, String.Format("{0}.{1}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodBase.GetCurrentMethod().Name), CURRENT_USER, CURRENT_REGISTRY_ID);
                throw ex;
            }
            catch (Exception ex)
            {
                LogManager.LogError(ex.Message, String.Format("{0}.{1}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodBase.GetCurrentMethod().Name), CURRENT_USER, CURRENT_REGISTRY_ID);
                throw ex;
            }

            return(objReturn);
        }
        private PRPA_MT201306UV02ParameterList GetDemographicParameters(PATIENT p)
        {
            PRPA_MT201306UV02ParameterList objReturn = null;

            if (p != null)
            {
                objReturn = new PRPA_MT201306UV02ParameterList();

                if (p.SPATIENT != null)
                {
                    if (!string.IsNullOrEmpty(p.SPATIENT.Gender))
                    {
                        objReturn.livingSubjectAdministrativeGender = new PRPA_MT201306UV02LivingSubjectAdministrativeGender[]
                        {
                            new PRPA_MT201306UV02LivingSubjectAdministrativeGender()
                            {
                                value = new CE[] { new CE()
                                                   {
                                                       code = p.SPATIENT.Gender.Trim().ToUpper().Substring(0, 1)
                                                   } },
                                semanticsText = "Gender"
                            }
                        };
                    }

                    DateTime?dob = null;
                    if (p.SPATIENT.DateOfBirth != null)
                    {
                        dob = p.SPATIENT.DateOfBirth;
                    }
                    else if (p.BIRTH_DATE != null)
                    {
                        dob = p.BIRTH_DATE;
                    }

                    if (dob != null)
                    {
                        objReturn.livingSubjectBirthTime = new PRPA_MT201306UV02LivingSubjectBirthTime[]
                        {
                            new PRPA_MT201306UV02LivingSubjectBirthTime()
                            {
                                value = new IVL_TS[] { new IVL_TS()
                                                       {
                                                           value = dob.Value.ToString("yyyyMMdd")
                                                       } },
                                semanticsText = "Date of Birth"
                            }
                        };
                    }

                    if (!string.IsNullOrEmpty(p.SPATIENT.PatientSSN))
                    {
                        //TODO: May need to add additional SSN validation at some point
                        objReturn.livingSubjectId = new PRPA_MT201306UV02LivingSubjectId[]
                        {
                            new PRPA_MT201306UV02LivingSubjectId()
                            {
                                value = new II[] { new II()
                                                   {
                                                       extension = p.SPATIENT.PatientSSN.Trim().ToUpper(), root = "2.16.840.1.113883.4.1"
                                                   } },
                                semanticsText = "SSN"
                            }
                        };
                    }

                    string firstName = string.Empty;
                    //string middleName = string.Empty;
                    string lastName = string.Empty;

                    if (!string.IsNullOrEmpty(p.SPATIENT.PatientFirstName))
                    {
                        firstName = p.SPATIENT.PatientFirstName;
                    }
                    else if (!string.IsNullOrEmpty(p.FIRST_NAME))
                    {
                        firstName = p.FIRST_NAME;
                    }

                    //if (!string.IsNullOrEmpty(p.MIDDLE_NAME))
                    //    middleName = p.MIDDLE_NAME;

                    if (!string.IsNullOrEmpty(p.SPATIENT.PatientLastName))
                    {
                        lastName = p.SPATIENT.PatientLastName;
                    }
                    else if (!string.IsNullOrEmpty(p.LAST_NAME))
                    {
                        lastName = p.LAST_NAME;
                    }

                    objReturn.livingSubjectName = new PRPA_MT201306UV02LivingSubjectName[]
                    {
                        new PRPA_MT201306UV02LivingSubjectName()
                        {
                            value = new EN[]
                            {
                                new EN()
                                {
                                    use = new string[] { "L" },
                                    ItemsElementName = new ItemsChoiceType8[] { ItemsChoiceType8.given, ItemsChoiceType8.family },
                                    Items            = new string[] { firstName, lastName }
                                }
                            },
                            semanticsText = "Legal Name"
                        }
                    };
                }
            }

            return(objReturn);
        }