public void SaveExistingPatientWithNoneExistingAddress()
        {
            PatientDto updatedPatient = new PatientDto()
            {
                PatientId     = 24,
                FirstName     = "Qinisela Elvis",
                LastName      = "Molefe",
                EmailAddress  = "*****@*****.**",
                PostalAddress = new PatientAddressDto()
                {
                    PatientAddressId = int.MinValue,
                    CountryId        = 1,
                    Line1            = "Postal Address Line 1",
                    Line2            = "Postal Address Line 2"
                },
                PhysicalAddress = new PatientAddressDto()
                {
                    PatientAddressId = int.MinValue,
                    CountryId        = 1,
                    Line1            = "Physical Address Line 1",
                    Line2            = "Physical Address Line 2"
                },
                CrudOperation = CrudOperations.Update
            };

            PatientDetailResponse response = _PhekoServiceClient.SavePatient(updatedPatient);

            Assert.IsFalse(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count == 0);
            Assert.IsNotNull(response.Patient);
        }
Example #2
0
        public PatientDetailResponse GetPatientDetails(int patientId)
        {
            PatientDetailResponse response = new PatientDetailResponse();

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                Patient patient = unitOfWork.PatientRepository.GetByID(p => p.PatientId == patientId, "PostalAddress, PhysicalAddress, PatientMedicalAidDependancies");

                if (patient == null)
                {
                    response.HasErrors = true;
                    response.FieldErrors.Add(new FieldError()
                    {
                        ErrorMessage = "The patient entry you trying to retrieve does not exist."
                    });
                    return(response);
                }

                response.Patient = _PatientMapper.MapToPatientDto(patient);
                response.PatientMedicalAidDependancies = patient.PatientMedicalAidDependancies.Select(item => _PatientMedicalAidDependancyMapper.MapToPatientMedicalAidDependancyDto(item))
                                                         .ToList <PatientMedicalAidDependancyDto>();
            }

            return(response);
        }
Example #3
0
        public PatientDetailResponse CreateCheck(PatientDto patient)
        {
            PatientDetailResponse response = new PatientDetailResponse();

            if (patient == null)
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    ErrorMessage = "The entry you trying to create does not exist."
                });
                return(response);
            }

            if (string.IsNullOrEmpty(patient.FirstName))
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    FieldName = "FirstName", ErrorMessage = "First name is requeired when you create a patient."
                });
            }

            if (string.IsNullOrEmpty(patient.LastName))
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    FieldName = "LastName", ErrorMessage = "Last name is required when you create a patient."
                });
            }

            return(response);
        }
Example #4
0
        public PatientViewModel GetPatientDetails(int patientId, List <PatientMedicalAidDependancyViewModel> patientMedicalAidDepandancies)
        {
            PatientDetailResponse response = _PhekoServiceClient.GetPatientDetails(patientId);
            ServiceResponse <PatientViewModel> serviceResponse = new ServiceResponse <PatientViewModel>();

            serviceResponse.IsModelValid = response.HasErrors;

            if (response.HasErrors)
            {
                ModelException modelException = new ModelException();

                response.FieldErrors.ToList <FieldError>().ForEach(item => modelException.ModelErrors.Add(new ModelError()
                {
                    FieldName = item.FieldName, Message = item.ErrorMessage
                }));

                throw modelException;
            }

            PatientViewModel model = _PatientViewModelMapper.MapToPatientViewModel(response.Patient);

            if (response.PatientMedicalAidDependancies != null && response.PatientMedicalAidDependancies.Count() > 0)
            {
                response.PatientMedicalAidDependancies.ToList().ForEach(item => patientMedicalAidDepandancies.Add(_PatientMedicalAidDependancyViewModelMapper.MapToPatientMedicalAidDependancyViewModel(item)));
            }

            return(model);
        }
Example #5
0
        private PatientDetailResponse UpdatePatient(PatientDto updatedPatient)
        {
            PatientDetailResponse response = _PatientBusinessRules.UpdateCheck(updatedPatient);

            if (response.HasErrors)
            {
                return(response);
            }

            using (TransactionScope scope = new TransactionScope())
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    Patient patient = unitOfWork.PatientRepository.GetByID(p => p.PatientId == updatedPatient.PatientId, "PostalAddress, PhysicalAddress");

                    _PatientMapper.MapToPatient(patient, updatedPatient);

                    if (updatedPatient.MedicalAidInd == null || !updatedPatient.MedicalAidInd.Value)
                    {
                        patient.PatientMedicalAidDependancies.ToList().ForEach(item => unitOfWork.PatientMedicalAidDependancyRepository.Delete(item));
                    }

                    unitOfWork.PatientRepository.Update(patient);
                    unitOfWork.Save();

                    response.Patient = _PatientMapper.MapToPatientDto(unitOfWork.PatientRepository.GetByID(p => p.PatientId == patient.PatientId, "PostalAddress, PhysicalAddress"));
                }

                scope.Complete();
            }

            return(response);
        }
Example #6
0
        private PatientDetailResponse CreatePatient(PatientDto insertedPatient)
        {
            PatientDetailResponse response = _PatientBusinessRules.CreateCheck(insertedPatient);

            if (response.HasErrors)
            {
                return(response);
            }

            Patient patient = new Patient();

            _PatientMapper.MapToPatient(patient, insertedPatient);

            using (TransactionScope scope = new TransactionScope())
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    unitOfWork.PatientRepository.Insert(patient);
                    unitOfWork.Save();

                    response.Patient = _PatientMapper.MapToPatientDto(unitOfWork.PatientRepository.GetByID(p => p.PatientId == patient.PatientId, "PostalAddress, PhysicalAddress"));
                }

                scope.Complete();
            }

            return(response);
        }
Example #7
0
        public PatientDetailResponse UpdateCheck(PatientDto patientDto)
        {
            PatientDetailResponse response = new PatientDetailResponse();

            if (patientDto == null ||
                patientDto.PatientId == null ||
                patientDto.PatientId.Value == int.MinValue)
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    ErrorMessage = "The entry you trying to update does not exist."
                });
                return(response);
            }

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                Patient patient = unitOfWork.PatientRepository.GetByID(p => p.PatientId == patientDto.PatientId.Value);

                if (patient == null)
                {
                    response.HasErrors = true;
                    response.FieldErrors.Add(new FieldError()
                    {
                        ErrorMessage = "The patient entry you trying to update does not exist."
                    });
                    return(response);
                }

                if (patientDto.PrincipalMemberInd != null && patientDto.PrincipalMemberInd.Value && patient.PatientMedicalAidDependancies.Where(item => item.PrincipalInd).Count() > 0)
                {
                    response.HasErrors = true;
                    response.FieldErrors.Add(new FieldError()
                    {
                        FieldName = "PrincipalInd", ErrorMessage = "There is already the medical aid principal member."
                    });
                }
            }

            if (string.IsNullOrEmpty(patientDto.FirstName))
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    FieldName = "FirstName", ErrorMessage = "First name is requeired when you create a patient."
                });
            }

            if (string.IsNullOrEmpty(patientDto.LastName))
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    FieldName = "LastName", ErrorMessage = "Last name is required when you create a patient."
                });
            }

            return(response);
        }
Example #8
0
        public void GetNoneExistingPatient()
        {
            PatientDetailResponse response = _PhekoServiceClient.GetPatientDetails(int.MinValue);

            Assert.IsTrue(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count > 0);
            Assert.IsNull(response.Patient);
        }
Example #9
0
        public void GetExistingPatient()
        {
            PatientDetailResponse response = _PhekoServiceClient.GetPatientDetails(1);

            Assert.IsFalse(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count == 0);
            Assert.IsNotNull(response.Patient);
        }
        public void SaveNullPatient()
        {
            PatientDto            updatedPatient = null;
            PatientDetailResponse response       = _PhekoServiceClient.SavePatient(updatedPatient);

            Assert.IsTrue(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count > 0);
            Assert.IsNull(response.Patient);
        }
        public void SaveEmptyPatient()
        {
            PatientDto updatedPatient = new PatientDto()
            {
                CrudOperation = CrudOperations.Update
            };
            PatientDetailResponse response = _PhekoServiceClient.SavePatient(updatedPatient);

            Assert.IsTrue(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count > 0);
            Assert.IsNull(response.Patient);
        }
        public void CreateLastNameOnlyPatient()
        {
            PatientDto newPatient = new PatientDto()
            {
                LastName = "Molefe", CrudOperation = CrudOperations.Create
            };
            PatientDetailResponse response = _PhekoServiceClient.SavePatient(newPatient);

            Assert.IsTrue(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count > 0);
            Assert.IsNull(response.Patient);
        }
        public void CreatePatient()
        {
            PatientDto newPatient = new PatientDto()
            {
                FirstName = "Qinisela", LastName = "Molefe", CrudOperation = CrudOperations.Create
            };
            PatientDetailResponse response = _PhekoServiceClient.SavePatient(newPatient);

            Assert.IsFalse(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count == 0);
            Assert.IsNotNull(response.Patient);
            Assert.IsNotNull(response.Patient.PatientId);
        }
Example #14
0
        public PatientDetailResponse SaveCheck(PatientDto patient)
        {
            PatientDetailResponse response = new PatientDetailResponse();

            if (patient == null)
            {
                response.HasErrors = true;
                response.FieldErrors.Add(new FieldError()
                {
                    ErrorMessage = "The entry you trying to save does not exist."
                });
            }

            return(response);
        }
        public void SaveNoneExistingPatient()
        {
            PatientDto updatedPatient = new PatientDto()
            {
                PatientId     = int.MinValue,
                FirstName     = "Qinisela Elvis",
                LastName      = "Molefe",
                EmailAddress  = "*****@*****.**",
                CrudOperation = CrudOperations.Update
            };

            PatientDetailResponse response = _PhekoServiceClient.SavePatient(updatedPatient);

            Assert.IsTrue(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count > 0);
            Assert.IsNull(response.Patient);
        }
Example #16
0
        public PatientViewModel CreatePatient(CreatePatientViewModel createPatientViewModel)
        {
            PatientDetailResponse response = _PhekoServiceClient.SavePatient(_PatientViewModelMapper.MapCreatePatientViewModelToPatientDto(createPatientViewModel));

            if (response.HasErrors)
            {
                ModelException modelException = new ModelException();

                response.FieldErrors.ToList <FieldError>().ForEach(item => modelException.ModelErrors.Add(new ModelError()
                {
                    FieldName = item.FieldName, Message = item.ErrorMessage
                }));

                throw modelException;
            }

            return(_PatientViewModelMapper.MapToPatientViewModel(response.Patient));
        }
Example #17
0
        public PatientDetailResponse SavePatient(PatientDto patientDto)
        {
            PatientDetailResponse response = _PatientBusinessRules.SaveCheck(patientDto);

            if (response.HasErrors)
            {
                return(response);
            }

            switch (patientDto.CrudOperation)
            {
            case CrudOperations.Create:
                return(CreatePatient(patientDto));

            case CrudOperations.Update:
                return(UpdatePatient(patientDto));

            default:
                throw new ArgumentException("Invalid crud operation.");
            }
        }
Example #18
0
        public async Task <IActionResult> GetPatient(string patientId)
        {
            var patient = await this.Patients.GetOne(patientId);

            if (patient == null)
            {
                return(this.NotFound());
            }

            var allergies = await this.Allergies.GetAll(patientId);

            var problems = await this.Diagnoses.GetAll(patientId);

            var medications = await this.Medications.GetAll(patientId);

            var contacts = await this.Contacts.GetAll(patientId);

            var patientResponse = new PatientDetailResponse
            {
                Address     = patient.Address,
                DateOfBirth = patient.DateOfBirth,
                Gender      = patient.Gender,
                GpAddress   = patient.GpAddress,
                GpName      = patient.GpName,
                Id          = patient.NhsNumber,
                Name        = patient.Name,
                PasNumber   = patient.PasNo,
                NhsNumber   = patient.NhsNumber,
                Telephone   = patient.Phone,
                Allergies   = allergies.ToSourceTextInfoList(),
                Problems    = problems.ToSourceTextInfoList(),
                Medications = medications.ToSourceTextInfoList(),
                Contacts    = contacts.ToSourceTextInfoList(),
                Transfers   = new object[] {}
            };

            return(this.Ok(patientResponse));
        }
        public void SavePatient()
        {
            PatientDto updatedPatient = new PatientDto()
            {
                PatientId              = 1,
                Title                  = "Mr",
                FirstName              = "Qinisela Elvis",
                MiddleName             = "Mr Que",
                LastName               = "Molefe",
                BirthDate              = new DateTime(1987, 7, 25),
                EthnicGroup            = "Black",
                IDType                 = "RSA ID",
                IDNumber               = "8707255584080",
                Gender                 = "Male",
                HomeTelephoneCode      = "011",
                HomeTelephoneNumber    = "4475206",
                MaritalStatus          = "Single",
                WorkTelephoneCode      = "011",
                WorkTelephoneNumber    = "5368791",
                SourceOfDiscovery      = "Internet",
                PrefferedContactMethod = "Mobile",
                PrefferedContactType   = "Post",
                MobileNumber           = "0846750093",
                PrincipalMemberInd     = true,
                MedicalAidInd          = true,
                MedicalAidNumber       = "45635252352",
                MedicalAidName         = "Discovery Medical Aid",
                MedicalAidScheme       = "Classic Priority",
                MarriageType           = "Married In Community Of Property",
                EmailAddress           = "*****@*****.**",
                PostalAddress          = new PatientAddressDto()
                {
                    PatientAddressId = int.MinValue,
                    CountryId        = 1,
                    ProvinceId       = 1,
                    City             = "Johannesburg",
                    PostalCode       = "2001",
                    Suburb           = "Braamfontein",
                    Line1            = "Postal Address Line 1",
                    Line2            = "Postal Address Line 2"
                },
                PhysicalAddress = new PatientAddressDto()
                {
                    PatientAddressId = int.MinValue,
                    CountryId        = 1,
                    ProvinceId       = 1,
                    City             = "Sandton",
                    PostalCode       = "2091",
                    Suburb           = "Mandel Square",
                    Line1            = "Physical Address Line 1",
                    Line2            = "Physical Address Line 2"
                },
                CrudOperation = CrudOperations.Update
            };

            PatientDetailResponse response = _PhekoServiceClient.SavePatient(updatedPatient);

            Assert.IsFalse(response.HasErrors);
            Assert.IsTrue(response.FieldErrors.Count == 0);
            Assert.IsNotNull(response.Patient);
        }