예제 #1
0
        public void ShouldUpdateCreateAndDeleteMedications()
        {
            var mockMeds = MockMedications();

            _ministryPlatformRestRepository.Setup(m => m.Post(new List <MpMedication> {
                mockMeds[1]
            }));
            _ministryPlatformRestRepository.Setup(m => m.Put(new List <MpMedication> {
                mockMeds[0]
            }));
            _ministryPlatformRestRepository.Setup(m => m.Delete <MpMedication>(new List <int> {
                mockMeds[2].MedicalInformationMedicationId
            }));

            _fixture.UpdateOrCreateMedications(mockMeds);

            _apiUserRepository.VerifyAll();
            _ministryPlatformRestRepository.VerifyAll();
        }
예제 #2
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());
            }
        }