Ejemplo n.º 1
0
        public string Save(PatientRegistrationDTO registration)
        {
            try
            {
                LookupLogic                   lookupLogic            = new LookupLogic();
                PatientLookupManager          patientLookup          = new PatientLookupManager();
                PatientLookup                 patient                = new PatientLookup();
                PatientRegistrationValidation registrationValidation = new PatientRegistrationValidation();
                //Validate DTO
                string results = registrationValidation.ValidateDTO(registration);
                if (!String.IsNullOrWhiteSpace(results))
                {
                    throw new Exception(results);
                }
                int interopUserId = InteropUser.UserId;
                //Get FacilityId
                int facilityId = Convert.ToInt32(registration.MESSAGE_HEADER.SENDING_FACILITY);
                //Get Gender
                string gender = registration.PATIENT_IDENTIFICATION.SEX == "F" ? "Female" : "Male";
                //IQCare Sex
                int sex = lookupLogic.GetItemIdByGroupAndItemName("Gender", gender)[0].ItemId;
                //Assume this is a new patient
                int patientType = lookupLogic.GetItemIdByGroupAndItemName("PatientType", registration.PATIENT_VISIT.PATIENT_TYPE)[0].ItemId;
                //Get Enrollment Id Type
                int visitType = lookupLogic.GetItemIdByGroupAndItemName("VisitType", "Enrollment")[0].ItemId;
                //Get DOB
                DateTime DOB           = DateTime.ParseExact(registration.PATIENT_IDENTIFICATION.DATE_OF_BIRTH, "yyyyMMdd", null);
                bool     DOB_Precision = true;
                switch (registration.PATIENT_IDENTIFICATION.DATE_OF_BIRTH_PRECISION)
                {
                case "ESTIMATED":
                    DOB_Precision = false;
                    break;

                case "EXACT":
                    DOB_Precision = true;
                    break;

                default:
                    DOB_Precision = true;
                    break;
                }
                //Get Enrollment Date
                DateTime dateOfEnrollment = DateTime.ParseExact(registration.PATIENT_VISIT.HIV_CARE_ENROLLMENT_DATE, "yyyyMMdd", null);
                //Get Patient Names
                string firstName  = registration.PATIENT_IDENTIFICATION.PATIENT_NAME.FIRST_NAME;
                string middleName = registration.PATIENT_IDENTIFICATION.PATIENT_NAME.MIDDLE_NAME;
                string lastName   = registration.PATIENT_IDENTIFICATION.PATIENT_NAME.LAST_NAME;
                //Get gods number
                string godsNumber = registration.PATIENT_IDENTIFICATION.EXTERNAL_PATIENT_ID.ID;
                //get marital status
                string maritalStatusString = String.Empty;
                int    maritalStatusId     = 0;
                switch (registration.PATIENT_IDENTIFICATION.MARITAL_STATUS)
                {
                case "S":
                    maritalStatusString = "Single";
                    break;

                case "W":
                    maritalStatusString = "Widowed";
                    break;

                case "D":
                    maritalStatusString = "Divorced";
                    break;

                case "MP":
                    maritalStatusString = "Married Polygamous";
                    break;

                case "C":
                    maritalStatusString = "Cohabiting";
                    break;

                case "MM":
                    maritalStatusString = "Married Monogamous";
                    break;

                default:
                    maritalStatusString = "Unknown";
                    break;
                }

                maritalStatusId = lookupLogic.GetItemIdByGroupAndItemName("MaritalStatus", maritalStatusString)[0].ItemId;
                //Get patient Address
                string village         = String.Empty;
                string ward            = String.Empty;
                string sub_county      = String.Empty;
                string county          = String.Empty;
                string nearestLandMark = String.Empty;
                string postalAdress    = String.Empty;
                string phoneNumber     = String.Empty;
                string deathDate       = String.Empty;
                var    patient_address = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS;
                if (patient_address != null)
                {
                    var physicalAddress = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS;
                    if (physicalAddress != null)
                    {
                        village         = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.VILLAGE;
                        ward            = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.WARD;
                        sub_county      = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.SUB_COUNTY;
                        county          = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.COUNTY;
                        nearestLandMark = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.PHYSICAL_ADDRESS.NEAREST_LANDMARK;
                    }
                    postalAdress = registration.PATIENT_IDENTIFICATION.PATIENT_ADDRESS.POSTAL_ADDRESS;
                }
                //Lookup Ward, sub_county_county
                int wardId        = 0;
                int subCountyId   = 0;
                int countyId      = 0;
                var countyDetails = lookupLogic.GetCountyDetailsByWardName(ward);
                if (countyDetails != null)
                {
                    wardId      = countyDetails.WardId;
                    subCountyId = countyDetails.SubcountyId;
                    countyId    = countyDetails.CountyId;
                }
                //Get Phone Number
                phoneNumber = registration.PATIENT_IDENTIFICATION.PHONE_NUMBER;
                deathDate   = registration.PATIENT_IDENTIFICATION.DEATH_DATE;
                DateTime?DateOfDeath = null;
                if (!string.IsNullOrWhiteSpace(deathDate))
                {
                    DateOfDeath = DateTime.ParseExact(deathDate, "yyyyMMdd", null);
                }
                //GET NEXT OF KIN
                var nextOfKin = registration.NEXT_OF_KIN;
                //Get CCCNumber and NationalId
                string nationalId        = String.Empty;
                string cccNumber         = String.Empty;
                int    entryPointId      = 0;
                var    lookupEntryPoints = lookupLogic.GetItemIdByGroupAndItemName("Entrypoint", registration.PATIENT_VISIT.PATIENT_SOURCE);
                if (lookupEntryPoints.Count > 0)
                {
                    entryPointId = lookupEntryPoints[0].ItemId;
                }
                else
                {
                    entryPointId = lookupLogic.GetItemIdByGroupAndDisplayName("Entrypoint", "Other")[0].ItemId;
                }


                foreach (var internalpatientid in registration.PATIENT_IDENTIFICATION.INTERNAL_PATIENT_ID)
                {
                    if (internalpatientid.IDENTIFIER_TYPE == "NATIONAL_ID" && internalpatientid.ASSIGNING_AUTHORITY == "GOK")
                    {
                        nationalId = internalpatientid.ID;
                    }

                    if (internalpatientid.IDENTIFIER_TYPE == "CCC_NUMBER" && internalpatientid.ASSIGNING_AUTHORITY == "CCC")
                    {
                        cccNumber = internalpatientid.ID;
                    }
                }

                if (!String.IsNullOrWhiteSpace(cccNumber))
                {
                    patient = patientLookup.GetPatientByCccNumber(cccNumber);
                    if (patient == null)
                    {
                        msg = ProcessPatient.Add(firstName, middleName, lastName, sex, interopUserId, DOB, DOB_Precision, facilityId,
                                                 patientType, nationalId, visitType, dateOfEnrollment, cccNumber, entryPointId, godsNumber,
                                                 maritalStatusId, village, wardId, subCountyId, countyId, nearestLandMark, postalAdress, phoneNumber,
                                                 DateOfDeath, nextOfKin);
                    }
                    else
                    {
                        msg = ProcessPatient.Update(firstName, middleName, lastName, sex, patient.PersonId, patient.Id, patient.ptn_pk, DOB, DOB_Precision, nationalId, facilityId,
                                                    entryPointId, dateOfEnrollment, cccNumber, patient, godsNumber, maritalStatusId, village,
                                                    wardId, subCountyId, countyId, nearestLandMark, postalAdress, phoneNumber, DateOfDeath,
                                                    nextOfKin, interopUserId);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(msg);
        }
Ejemplo n.º 2
0
 public PatientRegistrationDTO Get(int entityId)
 {
     return(ProcessPatient.Get(entityId));
 }