private async Task <MedicationDetail> PrepareMedicationDetailAsync(IDictionary <int, string> attributes) { var medicationDetail = new MedicationDetail(); medicationDetail.CustomAttributes = _modelExtensionBuilder.BuildModelExtension <PatientMedication>(); //medicationDetail = _mapper.Map<MedicationDetail>(medicationForUpdate); foreach (var newAttribute in attributes) { var customAttribute = await _customAttributeRepository.GetAsync(ca => ca.Id == newAttribute.Key); if (customAttribute == null) { throw new KeyNotFoundException($"Unable to locate custom attribute {newAttribute.Key}"); } var attributeDetail = medicationDetail.CustomAttributes.SingleOrDefault(ca => ca.AttributeKey == customAttribute.AttributeKey); if (attributeDetail == null) { throw new KeyNotFoundException($"Unable to locate custom attribute on patient medication {newAttribute.Key}"); } attributeDetail.Value = newAttribute.Value; } return(medicationDetail); }
private List <MedicationDetail> PrepareMedicationDetail() { List <MedicationDetail> medications = new List <MedicationDetail>(); var rowCount = GetRowCountFromArray(2); if (rowCount > 0) { for (int i = 0; i < rowCount; i++) { var medicationDetail = new MedicationDetail(); medicationDetail.CustomAttributes = _modelExtensionBuilder.BuildModelExtension <PatientMedication>(); // Prepare first class medicationDetail.DateStart = Convert.ToDateTime(GetAttributeValueFromArrayRow(2, i, "startDate")); medicationDetail.MedicationSource = GetAttributeValueFromArrayRow(2, i, "medication"); medicationDetail.DateEnd = String.IsNullOrWhiteSpace(GetAttributeValueFromArrayRow(2, i, "endDate")) ? (DateTime?)null : Convert.ToDateTime(GetAttributeValueFromArrayRow(2, i, "endDate")); medicationDetail.Dose = GetAttributeValueFromArrayRow(2, i, "dose"); medicationDetail.DoseFrequency = GetAttributeValueFromArrayRow(2, i, "frequency"); medications.Add(medicationDetail); } } return(medications); }