示例#1
0
        public async Task <ADT_A08_Message> GetADT_A08_Message(string appointmentRecId, string caseId, string patientGuId)
        {
            try
            {
                ADT_A08_Message Adt_A08_Msg      = new ADT_A08_Message();
                ADT_A04_Message _obj_A04_Message = new ADT_A04_Message();
                var             result           = await _obj_A04_Message.GetADT_A04_Message(appointmentRecId, caseId, patientGuId);

                Adt_A08_Msg.PID = result.PID;
                Adt_A08_Msg.PV1 = result.PV1;
                Adt_A08_Msg.EVN = result.EVN;
                return(Adt_A08_Msg);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        public async Task <HL7_ORM_O01> GetRIS_ORM_O01_Message(string patientId, string orderId, string appointmentRecId, string caseId, string OrderStatus)
        {
            PatientRadiologyOrder pOrd        = new PatientRadiologyOrder();
            HL7_ORM_O01           ORM_O01_Msg = new HL7_ORM_O01();
            var resultorder = await pOrd.getPatientOrder(string.Empty, string.Empty, string.Empty, string.Empty, DateTime.MinValue, DateTime.MinValue, false, orderId, null, true);

            foreach (PatientRadiologyOrder pOrder in resultorder)
            {
                ORM_O01_Msg.MSH = new HL7_MSH();

                ORM_O01_Msg.EventType = new HL7_EventType();
                ORM_O01_Msg.EventType.DateTimeOccurred    = DateTime.Now.ToString("yyyyMMddHHmm");
                ORM_O01_Msg.EventType.RecordedDateTime    = DateTime.Now.ToString("yyyyMMddHHmm");
                ORM_O01_Msg.EventType.DateTimePlanneEvent = DateTime.Now.ToString("yyyyMMddHHmm");


                ORM_O01_Msg.ORC = new HL7_ORC();
                switch (pOrder.OrderStatus)
                {
                case "1":
                    ORM_O01_Msg.ORC.OrderStatus      = "SC";
                    ORM_O01_Msg.ORC.OrderControlCode = "NW";
                    break;

                case "2":
                    ORM_O01_Msg.ORC.OrderStatus      = "CA";
                    ORM_O01_Msg.ORC.OrderControlCode = "CA";
                    break;

                case "3":
                    ORM_O01_Msg.ORC.OrderStatus      = "SC";
                    ORM_O01_Msg.ORC.OrderControlCode = "NW";
                    break;

                case "11":
                    ORM_O01_Msg.ORC.OrderStatus      = "SC";
                    ORM_O01_Msg.ORC.OrderControlCode = "NW";
                    break;

                case "12":
                    ORM_O01_Msg.ORC.OrderStatus      = "CM";
                    ORM_O01_Msg.ORC.OrderControlCode = "NW";
                    break;

                default:
                    break;
                }
                ORM_O01_Msg.ORC.StartDateTime                 = pOrder.ScheduleStartDateTime.ToString("yyyyMMddHHmm");
                ORM_O01_Msg.ORC.EndDateTime                   = pOrder.ScheduleEndDateTime.ToString("yyyyMMddHHmm");
                ORM_O01_Msg.ORC.PlacerOrderNumber             = new HL7_OrderNumber();
                ORM_O01_Msg.ORC.PlacerOrderNumber.ID          = pOrder.OrderNumber;
                ORM_O01_Msg.ORC.PlacerOrderNumber.NamespaceID = "NA";
                ORM_O01_Msg.ORC.FillerOrderNumber             = new HL7_OrderNumber();
                ORM_O01_Msg.ORC.FillerOrderNumber.ID          = pOrder.OrderNumber;
                ORM_O01_Msg.ORC.FillerOrderNumber.NamespaceID = "NA";
                ORM_O01_Msg.ORC.OrderingProvider              = new HL7_Provider();

                if (pOrder.orderingProvider != null)
                {
                    if (string.IsNullOrEmpty(pOrder.orderingProvider.lastName))
                    {
                        pOrder.orderingProvider.lastName = "NA";
                    }
                    if (string.IsNullOrEmpty(pOrder.orderingProvider.firstName))
                    {
                        pOrder.orderingProvider.firstName = "NA";
                    }
                    if (string.IsNullOrEmpty(pOrder.orderingProvider.middleName))
                    {
                        pOrder.orderingProvider.middleName = "NA";
                    }
                    if (string.IsNullOrEmpty(pOrder.orderingProvider.code))
                    {
                        pOrder.orderingProvider.code = "NA";
                    }

                    ORM_O01_Msg.ORC.OrderingProvider.FamilyName = pOrder.orderingProvider.lastName;
                    ORM_O01_Msg.ORC.OrderingProvider.GivenName  = pOrder.orderingProvider.firstName;
                    ORM_O01_Msg.ORC.OrderingProvider.Initial    = pOrder.orderingProvider.middleName;
                    ORM_O01_Msg.ORC.OrderingProvider.ID         = pOrder.orderingProvider.code;
                }
                else
                {
                    ORM_O01_Msg.ORC.OrderingProvider.FamilyName = "NA";
                    ORM_O01_Msg.ORC.OrderingProvider.GivenName  = "NA";
                    ORM_O01_Msg.ORC.OrderingProvider.Initial    = "NA";
                    ORM_O01_Msg.ORC.OrderingProvider.ID         = "NA";
                }


                ORM_O01_Msg.ORC.EnteredBy            = new HL7_Provider();
                ORM_O01_Msg.ORC.EnteredBy.FamilyName = "NA";
                ORM_O01_Msg.ORC.EnteredBy.GivenName  = "NA";
                ORM_O01_Msg.ORC.EnteredBy.ID         = "NA";
                ORM_O01_Msg.ORC.EnteredBy.Initial    = "NA";


                ORM_O01_Msg.ORC.OrderingFacility = new HL7_OrderingFacility();
                ORM_O01_Msg.ORC.OrderingFacility.AssigningAuthority = "NA";
                ORM_O01_Msg.ORC.OrderingFacility.ID = "NA";

                ORM_O01_Msg.OBR = new HL7_OBR();
                ORM_O01_Msg.OBR.FillerOrderNumber          = new HL7_OrderNumber();
                ORM_O01_Msg.OBR.PlacerOrderNumber          = new HL7_OrderNumber();
                ORM_O01_Msg.OBR.UniversalServiceIdentifier = new HL7_UniversalServiceIdentifier();

                if (string.IsNullOrEmpty(pOrder.ProductFamilyCode))
                {
                    pOrder.ProductFamilyCode = "NA";
                }

                ORM_O01_Msg.OBR.DiagnosticServSectId = pOrder.ProductFamilyCode;

                ORM_O01_Msg.OBR.ID = "NA";
                if (string.IsNullOrEmpty(pOrder.ClinicalNotes))
                {
                    pOrder.ClinicalNotes = "NA";
                }
                if (string.IsNullOrEmpty(pOrder.OrderNumber))
                {
                    pOrder.OrderNumber = "NA";
                }
                ORM_O01_Msg.OBR.Accessionnumber = pOrder.Id;
                ORM_O01_Msg.OBR.PlacerField1    = pOrder.Id;
                //  ORM_O01_Msg.OBR.PlacerField1 =  pOrder.OrderNumber;
                ORM_O01_Msg.OBR.PlacerField2                  = pOrder.Id;
                ORM_O01_Msg.OBR.FillderField1                 = pOrder.OrderNumber;
                ORM_O01_Msg.OBR.FillerOrderNumber.ID          = pOrder.OrderNumber;
                ORM_O01_Msg.OBR.FillerOrderNumber.NamespaceID = "NA";
                ORM_O01_Msg.OBR.ResultStatusCode              = "NA";
                ORM_O01_Msg.OBR.StartDateTime                 = pOrder.ScheduleStartDateTime.ToString("yyyyMMddHHmm");
                ORM_O01_Msg.OBR.EndDateTime = pOrder.ScheduleEndDateTime.ToString("yyyyMMddHHmm");
                if (string.IsNullOrEmpty(pOrder.TestId))
                {
                    pOrder.TestId = "NA";
                }
                if (string.IsNullOrEmpty(pOrder.TestName))
                {
                    pOrder.TestName = "NA";
                }


                ORM_O01_Msg.OBR.UniversalServiceIdentifier.ID   = pOrder.TestId;
                ORM_O01_Msg.OBR.UniversalServiceIdentifier.Text = pOrder.TestName;
                ORM_O01_Msg.OBR.UniversalServiceIdentifier.Nameofcodingsystem = "NA";

                ORM_O01_Msg.OBR.ReasonforStudy = "NA";
                if (string.IsNullOrEmpty(pOrder.ClinicalNotes))
                {
                    pOrder.ClinicalNotes = "NA";
                }
                ORM_O01_Msg.OBR.RelevantClinicalInf = Helper.encodeEscapeChar(pOrder.ClinicalNotes);

                ORM_O01_Msg.OBR.ScheduledDateTime = pOrder.ScheduleStartDateTime.ToString("yyyyMMddHHmm");//we update start date
                ORM_O01_Msg.OBR.UniversalServiceIdentifier.AlternateIdentifier = "NA";
                ORM_O01_Msg.OBR.UniversalServiceIdentifier.AlternateText       = "NA";
                if (string.IsNullOrEmpty(pOrder.OrderNumber))
                {
                    ORM_O01_Msg.OBR.PlacerOrderNumber.ID = "NA";
                }
                else
                {
                    ORM_O01_Msg.OBR.PlacerOrderNumber.ID = pOrder.OrderNumber;
                }

                ORM_O01_Msg.OBR.FillerOrderNumber.NamespaceID = "NA";
                ORM_O01_Msg.OBR.PlacerOrderNumber.NamespaceID = "NA";

                if (string.IsNullOrEmpty(pOrder.OrderNumber))
                {
                    ORM_O01_Msg.OBR.FillerOrderNumber.ID = "NA";
                }
                else
                {
                    ORM_O01_Msg.OBR.FillerOrderNumber.ID = pOrder.OrderNumber;
                }

                ORM_O01_Msg.ORC.PlacerOrderNumber.NamespaceID = "NA";
                ORM_O01_Msg.ORC.PlacerGroupNumber             = "NA";
                ORM_O01_Msg.ORC.FillerOrderNumber.NamespaceID = "NA";

                ORM_O01_Msg.ORC.EnteringOrganization    = new HL7_EnteringOrganization();
                ORM_O01_Msg.ORC.EnteringOrganization.ID = "NazirBupa";
                ORM_O01_Msg.ORC.EnteringOrganization.Nameofcodingsystem = "";
                ORM_O01_Msg.ORC.EnteringOrganization.Text = "NazirBupa";

                ORM_O01_Msg.OBR.OrderingProvider = new HL7_Provider();

                if (pOrder.orderingProvider != null)
                {
                    if (string.IsNullOrEmpty(pOrder.orderingProvider.lastName))
                    {
                        pOrder.orderingProvider.lastName = "NA";
                    }
                    if (string.IsNullOrEmpty(pOrder.orderingProvider.firstName))
                    {
                        pOrder.orderingProvider.firstName = "NA";
                    }
                    if (string.IsNullOrEmpty(pOrder.orderingProvider.middleName))
                    {
                        pOrder.orderingProvider.middleName = "NA";
                    }
                    if (string.IsNullOrEmpty(pOrder.orderingProvider.code))
                    {
                        pOrder.orderingProvider.code = "NA";
                    }

                    ORM_O01_Msg.OBR.OrderingProvider.FamilyName = pOrder.orderingProvider.lastName;
                    ORM_O01_Msg.OBR.OrderingProvider.GivenName  = pOrder.orderingProvider.firstName;
                    ORM_O01_Msg.OBR.OrderingProvider.Initial    = pOrder.orderingProvider.middleName;
                    ORM_O01_Msg.OBR.OrderingProvider.ID         = pOrder.orderingProvider.code;
                }
                else
                {
                    ORM_O01_Msg.OBR.OrderingProvider.FamilyName = "NA";
                    ORM_O01_Msg.OBR.OrderingProvider.GivenName  = "NA";
                    ORM_O01_Msg.OBR.OrderingProvider.Initial    = "NA";
                    ORM_O01_Msg.OBR.OrderingProvider.ID         = "NA";
                }
                ORM_O01_Msg.ORC.TransactionDateTime = DateTime.Now.ToString("yyyyMMddHHmm");
                if (pOrder.UrgencyId == "1")
                {
                    ORM_O01_Msg.OBR.Priority = "R";
                }
                else if (pOrder.UrgencyId == "2")
                {
                    ORM_O01_Msg.OBR.Priority = "A";
                }
                else
                {
                    ORM_O01_Msg.OBR.Priority = "";
                }
                if (string.IsNullOrEmpty(pOrder.LocationCode))
                {
                    ORM_O01_Msg.OBR.OrderLocation = "";
                }
                else
                {
                    ORM_O01_Msg.OBR.OrderLocation = pOrder.LocationCode;
                }

                break;
            }

            ADT_A04_Message _obj_A04_Message = new ADT_A04_Message();
            var             adt = await _obj_A04_Message.GetADT_A04_Message(appointmentRecId, "", patientId);

            ORM_O01_Msg.PID = adt.PID;
            ORM_O01_Msg.PV1 = adt.PV1;
            if (ORM_O01_Msg.OBR.OrderingProvider != null)
            {
                adt.PV1.AttendingDoctor.IDNumber = ORM_O01_Msg.OBR.OrderingProvider.ID;
                if (string.IsNullOrEmpty(adt.PV1.AttendingDoctor.GivenName))
                {
                    adt.PV1.AttendingDoctor.IDNumber = "NA";
                }
                adt.PV1.AttendingDoctor.FamilyName = ORM_O01_Msg.OBR.OrderingProvider.FamilyName;
                if (string.IsNullOrEmpty(adt.PV1.AttendingDoctor.GivenName))
                {
                    adt.PV1.AttendingDoctor.FamilyName = "NA";
                }
                adt.PV1.AttendingDoctor.GivenName = ORM_O01_Msg.OBR.OrderingProvider.GivenName;
                if (string.IsNullOrEmpty(adt.PV1.AttendingDoctor.GivenName))
                {
                    adt.PV1.AttendingDoctor.GivenName = "NA";
                }
            }
            else
            {
                adt.PV1.AttendingDoctor.GivenName  = "NA";
                adt.PV1.AttendingDoctor.FamilyName = "NA";
                adt.PV1.AttendingDoctor.IDNumber   = "NA";
            }

            ORM_O01_Msg.NTE             = new HL7_NTE();
            ORM_O01_Msg.NTE.SetID       = "NA";
            ORM_O01_Msg.NTE.Comment     = "NA";
            ORM_O01_Msg.NTE.CommentType = "PC"; //CI,PC
            ORM_O01_Msg.NTE.Identifier  = "NA";


            return(ORM_O01_Msg);

            #region defualt values
            //HL7_ORM_O01 ORM_O01_Msg = new HL7_ORM_O01();
            //ORM_O01_Msg.MSH = new HL7_MSH();
            //ORM_O01_Msg.EventType = new HL7_EventType();
            //ORM_O01_Msg.ORC = new HL7_ORC();
            //ORM_O01_Msg.ORC.OrderControlCode = "NW";
            //ORM_O01_Msg.ORC.OrderStatus = "SC";
            //ORM_O01_Msg.ORC.StartDateTime = System.DateTime.Now.ToString("yyyyMMddHHmm");
            //ORM_O01_Msg.ORC.EndDateTime = System.DateTime.Now.ToString("yyyyMMddHHmm");
            //ORM_O01_Msg.ORC.TransactionDateTime = System.DateTime.Now.ToString("yyyyMMddHHmm");
            //ORM_O01_Msg.ORC.PlacerOrderNumber = new HL7_OrderNumber();
            //ORM_O01_Msg.ORC.PlacerOrderNumber.NamespaceID = "EPIC";
            //ORM_O01_Msg.ORC.PlacerOrderNumber.ID = "987654";
            //ORM_O01_Msg.ORC.FillerOrderNumber = new HL7_OrderNumber();
            //ORM_O01_Msg.ORC.FillerOrderNumber.NamespaceID = "EPC";
            //ORM_O01_Msg.ORC.FillerOrderNumber.ID = "76543";
            //ORM_O01_Msg.ORC.OrderingProvider = new HL7_Provider();
            //ORM_O01_Msg.ORC.OrderingProvider.ID = "1173";
            //ORM_O01_Msg.ORC.OrderingProvider.FamilyName = "MATTHEWS";
            //ORM_O01_Msg.ORC.OrderingProvider.GivenName = "JAMES";
            //ORM_O01_Msg.ORC.OrderingProvider.Initial = "A";

            //ORM_O01_Msg.ORC.EnteredBy = new HL7_Provider();
            //ORM_O01_Msg.ORC.EnteredBy.FamilyName = "PATTERSON";
            //ORM_O01_Msg.ORC.EnteredBy.GivenName = "JAMES";
            //ORM_O01_Msg.ORC.OrderingProvider = new HL7_Provider();
            //ORM_O01_Msg.ORC.OrderingFacility = new HL7_OrderingFacility();

            //ORM_O01_Msg.OBR = new HL7_OBR();
            //ORM_O01_Msg.OBR.FillerOrderNumber = new HL7_OrderNumber();
            //ORM_O01_Msg.OBR.PlacerOrderNumber = new HL7_OrderNumber();
            //ORM_O01_Msg.OBR.UniversalServiceIdentifier = new HL7_UniversalServiceIdentifier();
            //ORM_O01_Msg.OBR.OrderingProvider = new HL7_Provider();
            //ORM_O01_Msg.OBR.ID = "1";
            //ORM_O01_Msg.OBR.PlacerField2 = "Placer";
            //ORM_O01_Msg.OBR.FillderField1 = "Placer+";
            //ORM_O01_Msg.OBR.ResultStatusCode = "R";
            //ORM_O01_Msg.OBR.StartDateTime = System.DateTime.Now.ToString("yyyyMMddHHmm");
            //ORM_O01_Msg.OBR.EndDateTime = System.DateTime.Now.ToString("yyyyMMddHHmm");
            //ORM_O01_Msg.OBR.UniversalServiceIdentifier.Text = "MRI Abdomen with Contrast";
            //ORM_O01_Msg.OBR.UniversalServiceIdentifier.AlternateIdentifier = "MI-MR-0002";
            //ORM_O01_Msg.OBR.PlacerOrderNumber.ID = "363463";
            //ORM_O01_Msg.OBR.PlacerOrderNumber.NamespaceID = "EPC";
            //ORM_O01_Msg.OBR.FillerOrderNumber.NamespaceID = "MI-MR-0001";
            //ORM_O01_Msg.OBR.FillerOrderNumber.ID = "1858";
            //ORM_O01_Msg.OBR.OrderingProvider.FamilyName = "MATTHEWS";
            //ORM_O01_Msg.OBR.OrderingProvider.GivenName = "JAMES";
            //ORM_O01_Msg.OBR.OrderingProvider.Initial = "A";
            //ORM_O01_Msg.OBR.OrderingProvider.ID = "1173";
            //ORM_O01_Msg.PID.Address = new Address();
            //ORM_O01_Msg.PID.PhoneNumberHome = new HL7_Contact();
            //ORM_O01_Msg.PID.PhoneNumberBusiness = new HL7_Contact();

            #endregion
        }
        public async Task <ADT_A04_Message> GetADT_A04_Message(string appointmentRecId, string caseId, string patientId)
        {
            try
            {
                ADT_A04_Message  Adt_A04_Msg = new ADT_A04_Message();
                HL7_Patient      patient = new HL7_Patient();
                HL7_PatientVIsit PatientVisit = new HL7_PatientVIsit();
                Patient          contract = new Patient();
                long             patintId = 0, appointmentId = 0;
                if (!string.IsNullOrEmpty(patientId))
                {
                    patintId = Convert.ToInt64(patientId);
                }
                if (!string.IsNullOrEmpty(appointmentRecId))
                {
                    appointmentId = Convert.ToInt64(appointmentRecId);
                }
                if (string.IsNullOrEmpty(caseId))
                {
                    caseId = string.Empty;
                }

                var result = contract.getPatientVisitDetails(appointmentId, caseId, patintId).Result as Activity;

                contract = result.patient;


                if (string.IsNullOrEmpty(contract.mrn))
                {
                    patient.PatientID = " ";
                }
                else
                {
                    patient.PatientID = contract.mrn;
                }


                if (string.IsNullOrEmpty(contract.mrn))
                {
                    patient.MRNNumber = " ";
                }
                else
                {
                    patient.MRNNumber = contract.mrn;
                }


                if (string.IsNullOrEmpty(contract.lastName))
                {
                    patient.FamilyName = " ";
                }
                else
                {
                    patient.FamilyName = contract.lastName;
                }

                if (string.IsNullOrEmpty(contract.firstName))
                {
                    patient.GivenName = " ";
                }
                else
                {
                    patient.GivenName = contract.firstName;
                }

                if (string.IsNullOrEmpty(contract.middleName))
                {
                    patient.Initials = " ";
                }
                else
                {
                    patient.Initials = contract.middleName;
                }

                if (string.IsNullOrEmpty(contract.dateOfBirth.ToString()))
                {
                    patient.Dateofbirth = " ";
                }
                else
                {
                    patient.Dateofbirth = contract.dateOfBirth.ToString("yyyyMMddHHmm");
                }
                //1 is male
                //2 female
                if (contract.genderValue == 1)
                {
                    patient.AdministrativeSex = "M";
                }
                if (contract.genderValue == 2)
                {
                    patient.AdministrativeSex = "F";
                }

                if (string.IsNullOrEmpty(contract.maritalStatus))
                {
                    patient.MaritalStatus = " ";
                }
                else
                {
                    patient.MaritalStatus = contract.maritalStatus;
                }

                if (string.IsNullOrEmpty(contract.mrn))
                {
                    patient.AccountNumber = " ";
                }
                else
                {
                    patient.AccountNumber = contract.mrn;
                }

                if (string.IsNullOrEmpty(contract.nationalIdValue))
                {
                    patient.SSNNumber = " ";
                }
                else
                {
                    patient.SSNNumber = contract.nationalIdValue;
                }

                patient.Address = new HL7_Address();
                if (contract.primaryAddress != null)
                {
                    if (string.IsNullOrEmpty(contract.primaryAddress.addressType))
                    {
                        patient.Address.addressType = " ";
                    }
                    else
                    {
                        patient.Address.addressType = contract.primaryAddress.addressType;
                    }

                    if (string.IsNullOrEmpty(contract.primaryAddress.city))
                    {
                        patient.Address.city = " ";
                    }
                    else
                    {
                        patient.Address.city = contract.primaryAddress.city;
                    }

                    if (string.IsNullOrEmpty(contract.primaryAddress.state))
                    {
                        patient.Address.state = " ";
                    }
                    else
                    {
                        patient.Address.state = contract.primaryAddress.state;
                    }

                    if (string.IsNullOrEmpty(contract.primaryAddress.street))
                    {
                        patient.Address.street = " ";
                    }
                    else
                    {
                        patient.Address.street = Helper.encodeEscapeChar(contract.primaryAddress.street);
                    }

                    if (string.IsNullOrEmpty(contract.primaryAddress.country))
                    {
                        patient.Address.country = " ";
                    }
                    else
                    {
                        patient.Address.country = contract.primaryAddress.country;
                    }

                    if (string.IsNullOrEmpty(contract.primaryAddress.zipCode))
                    {
                        patient.Address.zipCode = " ";
                    }
                    else
                    {
                        patient.Address.zipCode = contract.primaryAddress.zipCode;
                    }
                }

                patient.PhoneNumberHome = new HL7_Contact();

                if (string.IsNullOrEmpty(contract.homePhone))
                {
                    patient.PhoneNumberHome.TelephoneNumber = " ";
                }
                else
                {
                    patient.PhoneNumberHome.TelephoneNumber = contract.homePhone;
                }

                patient.PhoneNumberHome.TelecommunicatorUsecode       = "PRN";
                patient.PhoneNumberHome.TelecommunicatorEquipmentType = "PH";

                patient.PhoneNumberBusiness = new HL7_Contact();

                if (string.IsNullOrEmpty(contract.workPhone))
                {
                    patient.PhoneNumberBusiness.TelephoneNumber = " ";
                }
                else
                {
                    patient.PhoneNumberBusiness.TelephoneNumber = contract.workPhone;
                }

                patient.PhoneNumberBusiness.TelecommunicatorUsecode       = "WPN";
                patient.PhoneNumberBusiness.TelecommunicatorEquipmentType = "PH";

                patient.AssingingAuthority = "NazirBupa";
                patient.AssigningAuthorityIdentifierCode = "PI";
                if (string.IsNullOrEmpty(contract.mrn))
                {
                    PatientVisit.SetID = contract.mrn = " ";
                }
                else
                {
                    PatientVisit.SetID = contract.mrn;
                }

                PatientVisit.PatientClass = "O";
                if (result.type == 2)
                {
                    PatientVisit.PatientClass = "O";
                }
                if (result.type == 6)
                {
                    PatientVisit.PatientClass = "E";
                }


                if (result.appointment != null)
                {
                    PatientVisit.VisitNumber = result.appointment.appointmentNumber;
                }

                if (string.IsNullOrEmpty(PatientVisit.VisitNumber))
                {
                    PatientVisit.VisitNumber = " ";
                }

                PatientVisit.AssignedPatientLocation = new HL7_AssignedPatientLocation();

                PatientVisit.AssignedPatientLocation.Bed = " ";

                if (string.IsNullOrEmpty(result.roomName))
                {
                    PatientVisit.AssignedPatientLocation.Room = " ";
                }
                else
                {
                    PatientVisit.AssignedPatientLocation.Room = result.roomName;
                }


                if (string.IsNullOrEmpty(result.clinicName))
                {
                    PatientVisit.AssignedPatientLocation.PointOfCare = " ";
                }
                else
                {
                    PatientVisit.AssignedPatientLocation.PointOfCare = result.clinicCode;
                }
                //PatientVisit.AssignedPatientLocation.PointOfCare = "OP – Clinic"; //result.clinicName;


                PatientVisit.AttendingDoctor = new HL7_AttendingDoctor();
                if (result.careTeam != null && result.careTeam.Count > 0)
                {
                    PatientVisit.AttendingDoctor.Initials = " ";
                    PatientVisit.AttendingDoctor.IDNumber = result.careTeam.First().code;
                    if (string.IsNullOrEmpty(PatientVisit.AttendingDoctor.IDNumber))
                    {
                        PatientVisit.AttendingDoctor.IDNumber = " ";
                    }
                    PatientVisit.AttendingDoctor.FamilyName = result.careTeam.First().lastName;
                    if (string.IsNullOrEmpty(PatientVisit.AttendingDoctor.FamilyName))
                    {
                        PatientVisit.AttendingDoctor.FamilyName = " ";
                    }
                    PatientVisit.AttendingDoctor.GivenName = result.careTeam.First().firstName;
                    if (string.IsNullOrEmpty(PatientVisit.AttendingDoctor.GivenName))
                    {
                        PatientVisit.AttendingDoctor.GivenName = " ";
                    }
                }
                else
                {
                    PatientVisit.AttendingDoctor.IDNumber   = " ";
                    PatientVisit.AttendingDoctor.FamilyName = " ";
                    PatientVisit.AttendingDoctor.GivenName  = " ";
                    PatientVisit.AttendingDoctor.Initials   = " ";
                }
                PatientVisit.AttendingDoctor.IDNumber = "4782";
                Adt_A04_Msg.EVN = new HL7_EventType();
                Adt_A04_Msg.EVN.RecordedDateTime = DateTime.Now.ToString("yyyyMMddHHmm");
                Adt_A04_Msg.EVN.DateTimeOccurred = DateTime.Now.ToString("yyyyMMddHHmm");
                Adt_A04_Msg.PID = patient;
                Adt_A04_Msg.PV1 = PatientVisit;
                return(Adt_A04_Msg);

                #region commented code
                //patient.PatientID = "CEU-000001";
                //patient.MRNNumber = "CEU-000001";
                //patient.FamilyName = "XYZ";
                //patient.GivenName = "YZX";
                //patient.Initials = "SYED";
                //patient.Dateofbirth = DateTime.Now;
                //patient.AdministrativeSex = "M";
                //patient.MaritalStatus = "Single";
                //patient.AccountNumber = "CEU-000001";
                //patient.SSNNumber = "12345678";
                //if (contract.primaryAddress != null)
                //{
                //patient.Address.addressType = contract.primaryAddress.parmAddressType;
                //patient.Address.city = "Riyad";
                //patient.Address.state = "SAU";
                //patient.Address.street = "ABD";
                //patient.Address.country = "SAU";
                //patient.Address.zipCode = "FDDG3434";
                //}
                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }