public MpMedicalInformation SaveMedicalInfo(MpMedicalInformation mpMedicalInfo, int contactId) { var apiToken = _apiUserRepository.GetToken(); var records = new List <MpMedicalInformation> { mpMedicalInfo }; if (mpMedicalInfo.MedicalInformationId != 0) { _ministryPlatformRest.UsingAuthenticationToken(apiToken).Put(records); return(mpMedicalInfo); } _ministryPlatformRest.UsingAuthenticationToken(apiToken).Post(records); var medicalInformation = GetMedicalInformation(contactId); _ministryPlatformRest.UsingAuthenticationToken(apiToken) .UpdateRecord("Contacts", contactId, new Dictionary <string, object> { { "Contact_ID", contactId }, { "MedicalInformation_ID", medicalInformation.MedicalInformationId } }); return(medicalInformation); }
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()); } }