private async Task <PersonConsent> MapFromServerAsync(PersonConsentTable source,
                                                              CancellationToken token = default(CancellationToken))
        {
            InternalContract.RequireNotNull(source, nameof(source));
            InternalContract.RequireValidated(source, nameof(source));
            var serverConsentTask = _storage.Consent.ReadAsync(source.ConsentId, token);
            var serverPersonTask  = _storage.Person.ReadAsync(source.PersonId, token);
            var serverConsent     = await serverConsentTask;
            var serverPerson      = await serverPersonTask;

            if (serverConsent == null)
            {
                throw new FulcrumNotFoundException($"Could not find consent with id {source.ConsentId}");
            }
            if (serverPerson == null)
            {
                throw new FulcrumNotFoundException($"Could not find person with id {source.PersonId}");
            }
            var target = new PersonConsent
            {
                Id              = MapperHelper.MapToType <string, Guid>(source.Id),
                ConsentId       = MapperHelper.MapToType <string, Guid>(source.ConsentId),
                PersonName      = serverPerson.Name,
                ConsentName     = serverConsent.Name,
                Etag            = source.Etag,
                PersonId        = MapperHelper.MapToType <string, Guid>(source.PersonId),
                HasGivenConsent = source.HasGivenConsent
            };

            FulcrumAssert.IsValidated(target);
            return(target);
        }
        /// <inheritdoc />
        public Task UpdateAsync(string masterId, string slaveId, PersonConsent item,
                                CancellationToken token = new CancellationToken())
        {
            InternalContract.RequireNotDefaultValue(masterId, nameof(masterId));
            InternalContract.RequireNotDefaultValue(slaveId, nameof(slaveId));
            var serverMasterId = MapperHelper.MapToType <Guid, string>(masterId);
            var serverSlaveId  = MapperHelper.MapToType <Guid, string>(slaveId);
            var serverItem     = MapToServer(item);

            return(_storage.PersonConsent.UpdateAsync(serverMasterId, serverSlaveId, serverItem, token));
        }
        private PersonConsentTable MapToServer(PersonConsent source)
        {
            InternalContract.RequireNotNull(source, nameof(source));
            InternalContract.RequireValidated(source, nameof(source));
            var target = new PersonConsentTable
            {
                Id              = MapperHelper.MapToType <Guid, string>(source.Id),
                Etag            = source.Etag,
                HasGivenConsent = source.HasGivenConsent,
                PersonId        = MapperHelper.MapToType <Guid, string>(source.PersonId),
                ConsentId       = MapperHelper.MapToType <Guid, string>(source.ConsentId),
            };

            FulcrumAssert.IsValidated(target);
            return(target);
        }
Beispiel #4
0
        public async Task <Result <AddPersonEmergencyContactResponse> > Handle(PersonEmergencyContactCommand request, CancellationToken cancellationToken)
        {
            try
            {
                RegisterPersonService rs = new RegisterPersonService(_unitOfWork);
                if (request.emergencycontacts != null || request.emergencycontacts.Count > 0)
                {
                    foreach (EmergencyContact em in request.emergencycontacts)
                    {
                        if (em.PersonId > 0)
                        {
                            if (em.EmergencyContactPersonId > 0)
                            {
                                PersonEmergencyContact pme = new PersonEmergencyContact();
                                PersonEmergencyContact pmt = new PersonEmergencyContact();
                                if (em.emgEmergencyContactType > 0)
                                {
                                    pme = await rs.GetSpecificEmergencyContacts(Convert.ToInt32(em.EmergencyContactPersonId), em.PersonId);

                                    //pmt = await rs.GetNextofkinEmergencyContacts(Convert.ToInt32(em.EmergencyContactPersonId), em.PersonId);
                                    if (pme != null)
                                    {
                                        pme.PersonId = em.PersonId;
                                        pme.EmergencyContactPersonId = em.EmergencyContactPersonId;
                                        pme.MobileContact            = em.MobileContact;
                                        pme.CreatedBy   = em.CreatedBy;
                                        pme.DeleteFlag  = em.DeleteFlag;
                                        pme.ContactType = em.emgEmergencyContactType;

                                        pme.RegisteredToClinic = em.RegisteredToClinic;

                                        int res = await rs.UpdatePersonEmergencyContact(pme);

                                        if (res > 0)
                                        {
                                            msg += "Person Emergency Mobile Contact Updated Successfully";
                                            personEmergencyContactId = em.EmergencyContactPersonId;
                                        }
                                    }
                                    else
                                    {
                                        PersonEmergencyContact pmm = new PersonEmergencyContact()
                                        {
                                            PersonId = em.PersonId,
                                            EmergencyContactPersonId = em.EmergencyContactPersonId,
                                            MobileContact            = em.MobileContact,
                                            CreatedBy          = em.CreatedBy,
                                            DeleteFlag         = em.DeleteFlag,
                                            ContactType        = em.emgEmergencyContactType,
                                            RegisteredToClinic = em.RegisteredToClinic
                                        };

                                        PersonEmergencyContact pmeid = new PersonEmergencyContact();
                                        pmeid = await rs.AddPersonEmergencyContact(pmm);

                                        if (pmeid != null)
                                        {
                                            msg += "New Person Emergencycontact Added successfully";
                                        }
                                    }
                                    var personconsent = await rs.GetCurrentPersonConsent(em.EmergencyContactPersonId, Convert.ToInt32(em.PersonId));

                                    if (personconsent != null)
                                    {
                                        personconsent.ConsentType   = em.ConsentType;
                                        personconsent.ConsentValue  = em.ConsentValue;
                                        personconsent.ConsentDate   = DateTime.Now;
                                        personconsent.ConsentReason = em.ConsentReason;

                                        int consent = await rs.UpdatePersonConsent(personconsent);

                                        if (consent > 0)
                                        {
                                            msg += "Person Consent has been updated successfully";
                                        }
                                    }
                                    else
                                    {
                                        PersonConsent pcs = new PersonConsent();
                                        pcs.PersonId           = em.PersonId;
                                        pcs.EmergencyContactId = em.EmergencyContactPersonId;
                                        pcs.ConsentType        = em.ConsentType;
                                        pcs.ConsentValue       = em.ConsentValue;
                                        pcs.ConsentDate        = DateTime.Now;
                                        pcs.ConsentReason      = em.ConsentReason;

                                        var perc = await rs.AddPersonConsent(pcs);

                                        if (perc != null)
                                        {
                                            msg += "Person Consent Has been added successfully";
                                        }
                                    }



                                    Person per = new Person();

                                    per.FirstName = em.firstname;
                                    per.MidName   = em.middlename;
                                    per.LastName  = em.lastname;
                                    per.Sex       = em.gender;
                                    per.Id        = em.EmergencyContactPersonId;


                                    var resupd = await rs.UpdateEmergencyPerson(per);

                                    if (resupd != null)
                                    {
                                        msg += "PersonEmergencyContact updated successfully";
                                    }
                                }
                                if (em.emgNextofKinContactType > 0)
                                {
                                    pmt = await rs.GetNextofkinEmergencyContacts(Convert.ToInt32(em.EmergencyContactPersonId), em.PersonId);

                                    if (pmt != null)
                                    {
                                        pmt.PersonId = em.PersonId;
                                        pmt.EmergencyContactPersonId = em.EmergencyContactPersonId;
                                        pmt.MobileContact            = em.MobileContact;
                                        pmt.CreatedBy   = em.CreatedBy;
                                        pmt.DeleteFlag  = em.DeleteFlag;
                                        pmt.ContactType = em.emgNextofKinContactType;

                                        pmt.RegisteredToClinic = em.RegisteredToClinic;

                                        int res = await rs.UpdatePersonEmergencyContact(pmt);

                                        if (res > 0)
                                        {
                                            msg += "Person Emergency Mobile Contact Updated Successfully";
                                            personEmergencyContactId = em.EmergencyContactPersonId;
                                        }
                                    }
                                    else
                                    {
                                        PersonEmergencyContact pmm = new PersonEmergencyContact()
                                        {
                                            PersonId = em.PersonId,
                                            EmergencyContactPersonId = em.EmergencyContactPersonId,
                                            MobileContact            = em.MobileContact,
                                            CreatedBy          = em.CreatedBy,
                                            DeleteFlag         = em.DeleteFlag,
                                            ContactType        = em.emgEmergencyContactType,
                                            RegisteredToClinic = em.RegisteredToClinic
                                        };

                                        PersonEmergencyContact pmeid = new PersonEmergencyContact();
                                        pmeid = await rs.AddPersonEmergencyContact(pmm);

                                        if (pmeid != null)
                                        {
                                            msg += "New Person Emergencycontact Added successfully";
                                        }
                                    }
                                    var personconsent = await rs.GetCurrentPersonConsent(em.EmergencyContactPersonId, Convert.ToInt32(em.PersonId));

                                    if (personconsent != null)
                                    {
                                        personconsent.ConsentType   = em.ConsentType;
                                        personconsent.ConsentValue  = em.ConsentValue;
                                        personconsent.ConsentDate   = DateTime.Now;
                                        personconsent.ConsentReason = em.ConsentReason;

                                        int consent = await rs.UpdatePersonConsent(personconsent);

                                        if (consent > 0)
                                        {
                                            msg += "Person Consent has been updated successfully";
                                        }
                                    }
                                    else
                                    {
                                        if (em.ConsentValue > 0)
                                        {
                                            PersonConsent pcs = new PersonConsent();
                                            pcs.PersonId           = em.PersonId;
                                            pcs.EmergencyContactId = pme.Id;
                                            pcs.ConsentType        = em.ConsentType;
                                            pcs.ConsentValue       = em.ConsentValue;
                                            pcs.ConsentDate        = DateTime.Now;
                                            pcs.ConsentReason      = em.ConsentReason;

                                            var perc = await rs.AddPersonConsent(pcs);

                                            if (perc != null)
                                            {
                                                msg += "Person Consent Has been added successfully";
                                            }
                                        }
                                    }



                                    Person per = new Person();

                                    per.FirstName = em.firstname;
                                    per.MidName   = em.middlename;
                                    per.LastName  = em.lastname;
                                    per.Sex       = em.gender;
                                    per.Id        = em.EmergencyContactPersonId;


                                    var resupda = await rs.UpdateEmergencyPerson(per);

                                    if (resupda != null)
                                    {
                                        msg += "PersonEmergencyContact updated successfully";
                                    }
                                }
                            }
                            else
                            {
                                var personEmerg = await rs.InsertPerson(em.firstname, em.middlename, em.lastname, em.gender, em.CreatedBy);

                                if (personEmerg != null)
                                {
                                    personEmergencyContactId = personEmerg.Id;
                                    if (em.emgEmergencyContactType > 0)
                                    {
                                        PersonEmergencyContact pmm = new PersonEmergencyContact()
                                        {
                                            PersonId = em.PersonId,
                                            EmergencyContactPersonId = personEmerg.Id,
                                            MobileContact            = em.MobileContact,
                                            CreatedBy          = em.CreatedBy,
                                            DeleteFlag         = em.DeleteFlag,
                                            ContactType        = em.emgEmergencyContactType,
                                            RegisteredToClinic = em.RegisteredToClinic
                                        };

                                        PersonEmergencyContact pmeid = new PersonEmergencyContact();
                                        pmeid = await rs.AddPersonEmergencyContact(pmm);

                                        if (pmeid != null)
                                        {
                                            msg += "New Person Emergencycontact Added successfully";
                                        }
                                    }
                                    if (em.emgNextofKinContactType > 0)
                                    {
                                        PersonEmergencyContact pmm = new PersonEmergencyContact()
                                        {
                                            PersonId = em.PersonId,
                                            EmergencyContactPersonId = personEmerg.Id,
                                            MobileContact            = em.MobileContact,
                                            CreatedBy          = em.CreatedBy,
                                            DeleteFlag         = em.DeleteFlag,
                                            ContactType        = em.emgNextofKinContactType,
                                            RegisteredToClinic = em.RegisteredToClinic
                                        };

                                        PersonEmergencyContact pmeid = new PersonEmergencyContact();
                                        pmeid = await rs.AddPersonEmergencyContact(pmm);

                                        if (pmeid != null)
                                        {
                                            msg += "New Person Emergencycontact Added successfully";
                                        }
                                    }
                                    if (em.ConsentValue > 0)
                                    {
                                        PersonConsent pcs = new PersonConsent();
                                        pcs.PersonId           = em.PersonId;
                                        pcs.EmergencyContactId = personEmergencyContactId;
                                        pcs.ConsentType        = em.ConsentType;
                                        pcs.ConsentValue       = em.ConsentValue;
                                        pcs.ConsentDate        = DateTime.Now;
                                        pcs.ConsentReason      = em.ConsentReason;

                                        var perc = await rs.AddPersonConsent(pcs);

                                        if (perc != null)
                                        {
                                            msg += "Person Consent Has been added successfully";
                                        }
                                    }
                                    PersonRelationship pl = new PersonRelationship();
                                    var personrel         = await rs.AddPersonRelationship(em.PersonId, personEmerg.Id, em.RelationshipType, em.CreatedBy);

                                    if (personrel != null)
                                    {
                                        msg += "Person EmergencyContact relationship added successfully";
                                    }
                                }
                            }
                        }
                    }
                }



                return(Result <AddPersonEmergencyContactResponse> .Valid(new AddPersonEmergencyContactResponse()
                {
                    Message = msg,
                    PersonEmergencyContactId = personEmergencyContactId
                }));
            }
            catch (Exception e)
            {
                return(Result <AddPersonEmergencyContactResponse> .Invalid(e.Message));
            }
        }
Beispiel #5
0
        public async Task <Result <AddPersonEmergencyContactResponse> > Handle(PersonEmergencyContactCommand request, CancellationToken cancellationToken)
        {
            try
            {
                RegisterPersonService rs = new RegisterPersonService(_unitOfWork);

                if (request.PersonId > 0)
                {
                    if (request.EmergencyContactPersonId > 0)
                    {
                        PersonEmergencyContact pme = new PersonEmergencyContact();
                        pme = await Task.Run(() => rs.GetSpecificEmergencyContacts(Convert.ToInt32(request.EmergencyContactPersonId), request.PersonId));

                        if (pme != null)
                        {
                            pme.PersonId = request.PersonId;
                            pme.EmergencyContactPersonId = request.EmergencyContactPersonId;
                            pme.MobileContact            = request.MobileContact;
                            pme.CreatedBy  = request.CreatedBy;
                            pme.DeleteFlag = request.DeleteFlag;


                            int res = await Task.Run(() => rs.UpdatePersonEmergencyContact(pme));

                            if (res > 0)
                            {
                                msg += "Person Emergency Mobile Contact Updated Successfully";
                                personEmergencyContactId = request.EmergencyContactPersonId;
                            }
                            var personconsent = await Task.Run(() => rs.GetCurrentPersonConsent(pme.Id, Convert.ToInt32(request.PersonId)));

                            if (personconsent != null)
                            {
                                personconsent.ConsentType   = request.ConsentType;
                                personconsent.ConsentValue  = request.ConsentValue;
                                personconsent.ConsentDate   = DateTime.Now;
                                personconsent.ConsentReason = request.ConsentReason;

                                int consent = await Task.Run(() => rs.UpdatePersonConsent(personconsent));

                                if (consent > 0)
                                {
                                    msg += "Person Consent has been updated successfully";
                                }
                            }
                            else
                            {
                                PersonConsent pcs = new PersonConsent();
                                pcs.PersonId           = request.PersonId;
                                pcs.EmergencyContactId = pme.Id;
                                pcs.ConsentType        = request.ConsentType;
                                pcs.ConsentValue       = request.ConsentValue;
                                pcs.ConsentDate        = DateTime.Now;
                                pcs.ConsentReason      = request.ConsentReason;

                                var perc = await Task.Run(() => rs.AddPersonConsent(pcs));

                                if (perc != null)
                                {
                                    msg += "Person Consent Has been added successfully";
                                }
                            }



                            Person per = new Person();

                            per.FirstName = request.firstname;
                            per.MidName   = request.middlename;
                            per.LastName  = request.lastname;
                            per.Sex       = request.gender;
                            per.Id        = request.EmergencyContactPersonId;


                            int resupda = await Task.Run(() => rs.UpdatePerson(per, request.EmergencyContactPersonId));

                            if (resupda > 0)
                            {
                                msg += "PersonEmergencyContact updated successfully";
                            }
                        }
                    }
                }


                else
                {
                    var personEmerg = await Task.Run(() => rs.InsertPerson(request.firstname, request.middlename, request.lastname, request.gender, request.CreatedBy));

                    if (personEmerg != null)
                    {
                        personEmergencyContactId = personEmerg.Id;
                        PersonEmergencyContact pmm = new PersonEmergencyContact()
                        {
                            PersonId = request.PersonId,
                            EmergencyContactPersonId = personEmerg.Id,
                            MobileContact            = request.MobileContact,
                            CreatedBy  = request.CreatedBy,
                            DeleteFlag = request.DeleteFlag
                        };

                        int pmeid = await Task.Run(() => rs.AddPersonEmergencyContact(pmm));

                        if (pmeid > 0)
                        {
                            msg += "New Person Emergencycontact Added successfully";
                        }

                        PersonConsent pcs = new PersonConsent();
                        pcs.PersonId           = request.PersonId;
                        pcs.EmergencyContactId = pmeid;
                        pcs.ConsentType        = request.ConsentType;
                        pcs.ConsentValue       = request.ConsentValue;
                        pcs.ConsentDate        = DateTime.Now;
                        pcs.ConsentReason      = request.ConsentReason;

                        var perc = await Task.Run(() => rs.AddPersonConsent(pcs));

                        if (perc != null)
                        {
                            msg += "Person Consent Has been added successfully";
                        }


                        PersonRelation pl        = new PersonRelation();
                        var            personrel = await Task.Run(() => rs.AddPersonRelationship(request.PersonId, personEmerg.Id, request.RelationshipType, request.CreatedBy));

                        if (personrel != null)
                        {
                            msg += "Person EmergencyContact relationship added successfully";
                        }
                    }
                }



                return(Result <AddPersonEmergencyContactResponse> .Valid(new AddPersonEmergencyContactResponse()
                {
                    Message = msg,
                    PersonEmergencyContactId = personEmergencyContactId
                }));
            }

            catch (Exception e)
            {
                return(Result <AddPersonEmergencyContactResponse> .Invalid(e.Message));
            }
        }