Exemplo n.º 1
0
        public async Task <Response> SaveResident(ResidentRequest residentResquest)
        {
            var residentId            = GetMaterializeResidentId(residentResquest.BlockNumber, residentResquest.HouseNumber);
            var getResidentDuplicated = _securityPaymentContext.ResidentInformation.ToList()
                                        .Find(x => x.ResidentInformationId == residentId);

            if (getResidentDuplicated == null)
            {
                ControlTransactionFields transactionInfo = TransactionInfo.GetTransactionInfo();

                IDbContextTransaction transaction         = _securityPaymentContext.Database.BeginTransaction();
                ResidentInformation   residentInformation = MaterializeGeneralResidentInformation(residentResquest, residentId, transactionInfo);
                PhoneContact          phoneContact        = MaterializeContactInformation(residentResquest, residentId, transactionInfo);
                EmailContact          emailContact        = MaterializeEmailContact(residentResquest, residentId, transactionInfo);
                HouseInformation      houseInformation    = MaterializeHouseInformation(residentResquest, residentId, transactionInfo);

                await _securityPaymentContext.AddAsync <ResidentInformation>(residentInformation);

                await _securityPaymentContext.AddAsync <PhoneContact>(phoneContact);

                await _securityPaymentContext.AddAsync <EmailContact>(emailContact);

                await _securityPaymentContext.AddAsync <HouseInformation>(houseInformation);

                await _securityPaymentContext.SaveChangesAsync();

                transaction.Commit();
                return(new Response {
                    Data = residentInformation
                });
            }
            return(new Response {
                Message = "Failed, the resident already exist!"
            });
        }
        public IHttpActionResult AdmitEnquiry(string referenceId, [FromBody] ResidentRequest resident)
        {
            if (resident == null || string.IsNullOrEmpty(referenceId))
            {
                return(BadRequest("Missing resident data or reference id"));
            }
            if (!GuidConverter.IsValid(resident.EnquiryReferenceId.ToString()))
            {
                return(BadRequest("Connot convert enquiry refence id"));
            }
            if (resident.AdmissionDate == null || resident.AdmissionDate.ToString() == "")
            {
                return(BadRequest("Missing admission date"));
            }

            // ensure enquiry exists?
            var enqExists = _enquiryService.GetByReferenceId(resident.EnquiryReferenceId);

            if (enqExists == null)
            {
                return(BadRequest("Cannot locate enquiry in database. Please verify data"));
            }

            var loggedInUser = HttpContext.Current.User as SecurityPrincipal;

            logger.Info($"Admit an enquiry by {loggedInUser.ForeName}");
            resident.UpdatedBy = loggedInUser.Id;

            var updEnquiry = _residentService.AdmitEnquiry(resident);

            return(Ok(updEnquiry));
        }
Exemplo n.º 3
0
        private ResidentEntity ConvertToResidentEntity(ResidentRequest resident)
        {
            ResidentEntity residentEntity = new ResidentEntity()
            {
                CareHomeId       = resident.CareHomeId,
                LocalAuthorityId = resident.LocalAuthorityId,
                NhsNumber        = resident.NhsNumber,
                PoNumber         = resident.PoNumber,
                LaId             = resident.LaId,
                NymsId           = resident.NymsId,
                ForeName         = resident.ForeName,
                SurName          = resident.SurName,
                MiddleName       = resident.MiddleName,
                Dob                = resident.Dob ?? Convert.ToDateTime("1800-01-01"),
                Gender             = resident.Gender,
                MaritalStatus      = resident.MaritalStatus,
                CareCategoryId     = resident.CareCategoryId,
                CareNeed           = resident.CareNeed,
                StayType           = resident.StayType,
                RoomLocation       = resident.RoomLocation,
                RoomNumber         = resident.RoomNumber,
                AdmissionDate      = (DateTime)resident.AdmissionDate,
                Comments           = resident.Comments,
                UpdatedById        = resident.UpdatedBy,
                ExitDate           = Convert.ToDateTime("9999-12-31"),
                EnquiryReferenceId = resident.ReferenceId,
                Address            = null,
                NextOfKins         = null,
                EmailAddress       = resident.EmailAddress,
                PhoneNumber        = resident.PhoneNumber,
                CareHomeDivisionId = resident.CareHomeDivisionId
            };

            // fill in if resident address found?
            if (resident.Address != null && !string.IsNullOrEmpty(resident.Address.Street1))
            {
                residentEntity.Address = CreateAddress(
                    resident.Address,
                    resident.Address.AddrType ?? ADDRESS_TYPE.home.ToString());
            }

            // fill in if nok found?
            if (resident.NextOfKins != null && resident.NextOfKins.Any())
            {
                // safeguard. ensure atleast the 1st record has forename
                var fn = resident.NextOfKins.FirstOrDefault().ForeName;
                if (!string.IsNullOrEmpty(fn))
                {
                    residentEntity.NextOfKins = CreateNextOfKinList(resident);
                }
            }

            if (resident.SocialWorker != null && !string.IsNullOrEmpty(resident.SocialWorker.ForeName))
            {
                residentEntity.SocialWorker = resident.SocialWorker;
            }

            return(residentEntity);
        }
Exemplo n.º 4
0
 private EmailContact MaterializeEmailContact(ResidentRequest residentResquest, string residentId, ControlTransactionFields transactionInfo)
 {
     return(new EmailContact
     {
         Email = residentResquest.Email,
         ResidentId = residentId,
         TransactionDate = transactionInfo.TransactionDate,
         ComputerName = transactionInfo.ComputerName,
         UserTransaction = transactionInfo.UserTransaction
     });
 }
Exemplo n.º 5
0
 private PhoneContact MaterializeContactInformation(ResidentRequest residentResquest, string residentId, ControlTransactionFields transactionInfo)
 {
     return(new PhoneContact
     {
         PhoneNumber = residentResquest.PhoneNumber,
         CountryCode = residentResquest.CountryCode,
         ResidentId = residentId,
         TransactionDate = transactionInfo.TransactionDate,
         ComputerName = transactionInfo.ComputerName,
         UserTransaction = transactionInfo.UserTransaction
     });
 }
Exemplo n.º 6
0
 private HouseInformation MaterializeHouseInformation(ResidentRequest residentResquest, string residentId, ControlTransactionFields transactionInfo)
 {
     return(new HouseInformation
     {
         HouseNumber = residentResquest.HouseNumber,
         BlockNumber = residentResquest.BlockNumber,
         ResidentId = residentId,
         TransactionDate = transactionInfo.TransactionDate,
         ComputerName = transactionInfo.ComputerName,
         UserTransaction = transactionInfo.UserTransaction
     });
 }
Exemplo n.º 7
0
        private ResidentInformation MaterializeGeneralResidentInformation(ResidentRequest residentResquest, string residentId, ControlTransactionFields transactionInfo)
        {
            ResidentInformation residentInformation = new ResidentInformation.Builder(residentId, residentResquest.Name, residentResquest.LastName)
                                                      .WithResidentInformationId(residentId)
                                                      .WithName(residentResquest.Name)
                                                      .WithLastName(residentResquest.LastName)
                                                      .Build();

            residentInformation.TransactionDate = transactionInfo.TransactionDate;
            residentInformation.ComputerName    = transactionInfo.ComputerName;
            residentInformation.UserTransaction = transactionInfo.UserTransaction;

            return(residentInformation);
        }
Exemplo n.º 8
0
        public Task <Resident> AdmitEnquiry(ResidentRequest resident)
        {
            var residentEntity = ConvertToResidentEntity(resident);

            // Add required values for creation
            residentEntity.ReferenceId = Guid.NewGuid();

            var residentEntityUpdated = _residentDataProvider.Create(residentEntity).Result;

            // todo: return new resident...
            var residentCreated = new Resident()
            {
                ReferenceId = residentEntity.ReferenceId
            };

            return(Task.FromResult(residentCreated));
        }
        public IHttpActionResult UpdateResident(string referenceId, ResidentRequest resident)
        {
            if (string.IsNullOrEmpty(referenceId))
            {
                throw new ArgumentNullException(nameof(referenceId));
            }
            if (resident == null)
            {
                throw new ArgumentNullException(nameof(resident));
            }

            var loggedInUser = HttpContext.Current.User as SecurityPrincipal;

            logger.Info($"Resident updated by {loggedInUser.ForeName}");
            resident.UpdatedBy = loggedInUser.Id;

            var result = _residentService.Update(resident);

            return(Ok(result));
        }
Exemplo n.º 10
0
        private IEnumerable <NextOfKin> CreateNextOfKinList(ResidentRequest resident)
        {
            List <NextOfKin> noks = new List <NextOfKin>();

            resident.NextOfKins.ForEach(n =>
            {
                // create next of kin obj
                var newNok = new NextOfKin()
                {
                    ForeName     = n.ForeName,
                    SurName      = n.SurName,
                    Relationship = n.Relationship,
                };
                // if nok has address?
                if (n.Address != null && n.Address.Street1 != "")
                {
/*                    newNok.Address = CreateAddress(
 *                      n.Address,
 *                      n.Address.RefType ?? REF_TYPE.nok.ToString(),
 *                      n.Address.AddrType ?? ADDRESS_TYPE.home.ToString());*/
                }
                // if nok has contact info?
                if (n.ContactInfos != null && n.ContactInfos.Any())
                {
                    var cts = n.ContactInfos.Select(c =>
                    {
                        return(new ContactInfo()
                        {
                            ContactType = c.ContactType,
                            Data = c.Data
                        });
                    });
                    newNok.ContactInfos = cts.ToArray();
                }
                noks.Add(newNok);
            });
            return(noks.ToArray());
        }
        public async Task <IActionResult> SaveResident([FromBody] ResidentRequest residentResquest)
        {
            var message = await _residentInformationService.SaveResident(residentResquest);

            return(Ok(message));
        }
Exemplo n.º 12
0
        public Task <Resident> Update(ResidentRequest resident)
        {
            var residentExisting = GetResident(resident.ReferenceId);

            if (residentExisting == null)
            {
                throw new ArgumentNullException(nameof(resident));
            }

            var residentEntity = ConvertToResidentEntity(resident);

            residentEntity.Id = residentExisting.Id;

            // Contact Info. Issue: Contact info is separate table but Email and Phone comes as values
            // Need to find if already exists? if so update else insert..
            var existingResidentContacts = _residentContactDataProvider.GetResidentContactsByResidentId(residentEntity.Id);    // _residentDataProvider.GetResidentContactsByResidentId(residentEntity.Id);
            List <ResidentContact> rcs   = new List <ResidentContact>();

            if (existingResidentContacts.Any())
            {
                // get existing email address or phone
                existingResidentContacts.ForEach((rc) =>
                {
                    if (!string.IsNullOrEmpty(rc.ContactType) && rc.ContactType == CONTACT_TYPE.email.ToString())
                    {
                        rc.Id   = rc.Id;
                        rc.Data = resident.EmailAddress;
                    }
                    if (!string.IsNullOrEmpty(rc.ContactType) && rc.ContactType == CONTACT_TYPE.phone.ToString())
                    {
                        rc.Id   = rc.Id;
                        rc.Data = resident.PhoneNumber;
                    }
                    rcs.Add(rc);
                });
            }
            else
            {
                // No existing contacts found
                if (!string.IsNullOrEmpty(residentEntity.EmailAddress))
                {
                    ResidentContact rc = new ResidentContact()
                    {
                        ContactType = CONTACT_TYPE.email.ToString(),
                        Data        = residentEntity.EmailAddress
                    };
                    rcs.Add(rc);
                }
                if (!string.IsNullOrEmpty(residentEntity.PhoneNumber))
                {
                    ResidentContact rc = new ResidentContact()
                    {
                        ContactType = CONTACT_TYPE.phone.ToString(),
                        Data        = residentEntity.PhoneNumber
                    };
                    rcs.Add(rc);
                }
            }
            residentEntity.ResidentContacts = rcs.ToArray();

            // SocialWorker Info. Issue: SW info is separate table
            SocialWorker swToBeUpdIns = new SocialWorker();

            if (resident.SocialWorker != null && resident.SocialWorker.ForeName != "")
            {
                swToBeUpdIns.ForeName     = resident.SocialWorker.ForeName;
                swToBeUpdIns.SurName      = resident.SocialWorker.SurName;
                swToBeUpdIns.EmailAddress = resident.SocialWorker.EmailAddress;
                swToBeUpdIns.PhoneNumber  = resident.SocialWorker.PhoneNumber;
            }
            // Need to find if already exists? if so update else insert..
            SocialWorker existingSocialWorker = _socialWorkerDataProvider.GetSocialWorkerByResidentId(residentEntity.Id);  //_residentDataProvider.GetSocialWorker(residentEntity.Id);

            if (existingSocialWorker != null)
            {
                swToBeUpdIns.Id = existingSocialWorker.Id;
            }
            residentEntity.SocialWorker = swToBeUpdIns;

            var residentEntityUpdated = _residentDataProvider.Update(residentEntity);

            // todo: return new resident...
            var residentCreated = new Resident()
            {
                ReferenceId = residentEntity.ReferenceId
            };

            return(Task.FromResult(residentCreated));
        }