Пример #1
0
        public IHttpActionResult SaveMedicalInformation([FromBody] MedicalInfoDTO medicalInfo, int contactId)
        {
            if (!ModelState.IsValid)
            {
                var errors    = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.Exception.Message);
                var dataError = new ApiErrorDto("Camper Medical Info Invalid", new InvalidOperationException("Invalid Camper Medical Data" + errors));
                throw new HttpResponseException(dataError.HttpResponseMessage);
            }

            return(Authorized(token =>
            {
                try
                {
                    _campService.SaveCamperMedicalInfo(medicalInfo, contactId, token);
                    return Ok();
                }
                catch (Exception e)
                {
                    var apiError = new ApiErrorDto("Camp Medical Info failed", e);
                    throw new HttpResponseException(apiError.HttpResponseMessage);
                }
            }));
        }
Пример #2
0
        public MedicalInfoDTO GetCampMedicalInfo(int eventId, int contactId, string token)
        {
            var loggedInContact = _contactRepository.GetMyProfile(token);
            var family          = _contactRepository.GetHouseholdFamilyMembers(loggedInContact.Household_ID);

            family.AddRange(_contactRepository.GetOtherHouseholdMembers(loggedInContact.Household_ID));

            if (family.Where(f => f.ContactId == contactId).ToList().Count <= 0)
            {
                throw new ContactNotFoundException(contactId);
            }
            var camperMed = _medicalInformationRepository.GetMedicalInformation(contactId);

            if (camperMed == null)
            {
                return(new MedicalInfoDTO());
            }

            var allergies   = _medicalInformationRepository.GetMedicalAllergyInfo(contactId);
            var medications = _medicalInformationRepository.GetMedications(contactId);

            var camperMedInfo = new MedicalInfoDTO
            {
                ContactId               = contactId,
                MedicalInformationId    = camperMed.MedicalInformationId,
                InsuranceCompany        = camperMed.InsuranceCompany == "N/A"? null :camperMed.InsuranceCompany,
                PolicyHolder            = camperMed.PolicyHolder == "N/A"? null : camperMed.PolicyHolder,
                PhysicianName           = camperMed.PhysicianName == "N/A" ? null : camperMed.PhysicianName,
                PhysicianPhone          = camperMed.PhysicianPhone == "N/A" ? null : camperMed.PhysicianPhone,
                MedicationsAdministered = camperMed.MedicationsAdministered?.Split(',').ToList() ?? new List <string>()
            };

            camperMedInfo.Allergies = new List <Allergy>();
            foreach (var medInfo in allergies)
            {
                if (medInfo.AllergyType != string.Empty)
                {
                    var allergy = new Allergy
                    {
                        MedicalInformationAllergyId = medInfo.MedicalInfoAllergyId,
                        AllergyDescription          = medInfo.AllergyDescription,
                        AllergyType   = medInfo.AllergyType,
                        AllergyTypeId = medInfo.AllergyTypeId,
                        AllergyId     = medInfo.AllergyId
                    };
                    camperMedInfo.Allergies.Add(allergy);
                }
            }
            if (camperMedInfo.Allergies.Count > 0)
            {
                camperMedInfo.ShowAllergies = true;
            }

            camperMedInfo.Medications = new List <Medication>();
            foreach (var medication in medications)
            {
                camperMedInfo.Medications.Add(new Medication
                {
                    MedicalInformationMedicationId = medication.MedicalInformationMedicationId,
                    MedicationName   = medication.MedicationName,
                    MedicationTypeId = medication.MedicationTypeId,
                    Dosage           = medication.DosageAmount,
                    TimesOfDay       = medication.DosageTimes
                });
            }
            if (camperMedInfo.Medications.Count > 0)
            {
                camperMedInfo.ShowMedications = true;
            }

            return(camperMedInfo);
        }
Пример #3
0
        public void SaveCamperMedicalInfo(MedicalInfoDTO medicalInfo, int contactId, string token)
        {
            var loggedInContact = _contactRepository.GetMyProfile(token);
            var family          = _contactRepository.GetHouseholdFamilyMembers(loggedInContact.Household_ID);

            family.AddRange(_contactRepository.GetOtherHouseholdMembers(loggedInContact.Household_ID));

            if (family.Where(f => f.ContactId == contactId).ToList().Count <= 0)
            {
                throw new ContactNotFoundException(contactId);
            }
            if (medicalInfo != null)
            {
                var mpMedicalInfo = new MpMedicalInformation
                {
                    MedicalInformationId = medicalInfo.MedicalInformationId,
                    ContactId            = contactId,
                    InsuranceCompany     = medicalInfo.InsuranceCompany ?? "N/A",
                    PhysicianName        = medicalInfo.PhysicianName ?? "N/A",
                    PhysicianPhone       = medicalInfo.PhysicianPhone ?? "N/A",
                    PolicyHolder         = medicalInfo.PolicyHolder ?? "N/A",
                };

                var meds = medicalInfo.MedicationsAdministered?.Where(med => med != null).ToList();
                mpMedicalInfo.MedicationsAdministered = meds.Any() ? meds?.Aggregate((c, n) => c + "," + n) : string.Empty;

                var medicalInformation = _medicalInformationRepository.SaveMedicalInfo(mpMedicalInfo, contactId);
                var updateToDictionary = new Dictionary <String, Object>
                {
                    { "Contact_ID", contactId },
                    { "Medicalinformation_ID", medicalInformation.MedicalInformationId }
                };
                _contactRepository.UpdateContact(contactId, updateToDictionary);

                var updateToAllergyList = new List <MpMedicalAllergy>();
                var createToAllergyList = new List <MpMedicalAllergy>();
                foreach (var allergy in medicalInfo.Allergies)
                {
                    if (allergy.AllergyId != 0)
                    {
                        updateToAllergyList.Add(new MpMedicalAllergy
                        {
                            Allergy = new MpAllergy {
                                AllergyID          = allergy.AllergyId,
                                AllergyType        = allergy.AllergyTypeId,
                                AllergyDescription = allergy.AllergyDescription
                            },
                            MedicalInformationId = medicalInformation.MedicalInformationId,
                            MedicalInfoAllergyId = allergy.MedicalInformationAllergyId
                        });
                    }
                    else if (!string.IsNullOrEmpty(allergy.AllergyDescription))
                    {
                        createToAllergyList.Add(new MpMedicalAllergy
                        {
                            Allergy = new MpAllergy
                            {
                                AllergyType        = GetAllergyType(allergy.AllergyType),
                                AllergyDescription = allergy.AllergyDescription
                            },
                            MedicalInformationId = medicalInformation.MedicalInformationId,
                            MedicalInfoAllergyId = allergy.MedicalInformationAllergyId
                        });
                    }
                }
                _medicalInformationRepository.UpdateOrCreateMedAllergy(updateToAllergyList, createToAllergyList);
                _medicalInformationRepository.UpdateOrCreateMedications(medicalInfo.Medications.Select(m => new MpMedication {
                    MedicalInformationMedicationId = m.MedicalInformationMedicationId, MedicalInformationId = medicalInformation.MedicalInformationId, MedicationName = m.MedicationName, MedicationTypeId = m.MedicationTypeId, DosageAmount = m.Dosage, DosageTimes = m.TimesOfDay, Deleted = m.Deleted
                }).ToList());
            }
        }