private async Task CustomConditionMapAsync(Patient patientFromRepo, PatientExpandedDto mappedPatient) { int[] terms = _patientConditionRepository.List(pc => pc.Patient.Id == mappedPatient.Id && pc.TerminologyMedDra != null && !pc.Archived && !pc.Patient.Archived, null, new string[] { "Condition" }) .Select(p => p.TerminologyMedDra.Id) .ToArray(); var conditionMeddras = await _conditionMeddraRepository.ListAsync(cm => terms.Contains(cm.TerminologyMedDra.Id), null, new string[] { "Condition", "TerminologyMedDra" }); List <PatientConditionGroupDto> groupArray = new List <PatientConditionGroupDto>(); foreach (var conditionMeddra in conditionMeddras) { var tempCondition = conditionMeddra.GetConditionForPatient(patientFromRepo); if (tempCondition != null) { var group = new PatientConditionGroupDto() { ConditionGroup = conditionMeddra.Condition.Description, Status = tempCondition.OutcomeDate != null ? "Case Closed" : "Case Open", PatientConditionId = tempCondition.Id, StartDate = tempCondition.OnsetDate.ToString("yyyy-MM-dd"), Detail = String.Format("{0} started on {1}", tempCondition.TerminologyMedDra.DisplayName, tempCondition.OnsetDate.ToString("yyyy-MM-dd")) }; groupArray.Add(group); } } mappedPatient.ConditionGroups = groupArray; }
private async Task CustomMapAsync(Encounter encounterFromRepo, EncounterExpandedDto mappedEncounter) { if (encounterFromRepo == null) { throw new ArgumentNullException(nameof(encounterFromRepo)); } mappedEncounter.Patient = _mapper.Map <PatientDetailDto>(encounterFromRepo.Patient); var datasetInstanceFromRepo = await _datasetInstanceRepository.GetAsync(di => di.Dataset.ContextType.Id == (int)ContextTypes.Encounter && di.ContextId == mappedEncounter.Id && di.EncounterTypeWorkPlan.EncounterType.Id == encounterFromRepo.EncounterType.Id , new string[] { "Dataset.ContextType" , "EncounterTypeWorkPlan.EncounterType" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetCategory" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetCategory" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetElement.Field.FieldType" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetElement.Field.FieldValues" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetElement.DatasetElementSubs" , "Dataset.DatasetCategories.DatasetCategoryElements.DatasetCategoryElementConditions" , "DatasetInstanceValues" }); if (datasetInstanceFromRepo != null) { var groupedDatasetCategories = datasetInstanceFromRepo.Dataset.DatasetCategories .SelectMany(dc => dc.DatasetCategoryElements).OrderBy(dc => dc.FieldOrder) .GroupBy(dce => dce.DatasetCategory) .ToList(); mappedEncounter.DatasetCategories = groupedDatasetCategories .Select(dsc => new DatasetCategoryViewDto { DatasetCategoryId = dsc.Key.Id, DatasetCategoryName = dsc.Key.DatasetCategoryName, DatasetCategoryDisplayed = ShouldCategoryBeDisplayed(encounterFromRepo, dsc.Key), DatasetElements = dsc.Select(element => new DatasetElementViewDto { DatasetElementId = element.DatasetElement.Id, DatasetElementName = element.DatasetElement.ElementName, DatasetElementDisplayName = element.FriendlyName ?? element.DatasetElement.ElementName, DatasetElementHelp = element.Help, DatasetElementDisplayed = ShouldElementBeDisplayed(encounterFromRepo, element), DatasetElementChronic = IsElementChronic(encounterFromRepo, element), DatasetElementSystem = element.DatasetElement.System, DatasetElementType = element.DatasetElement.Field.FieldType.Description, DatasetElementValue = datasetInstanceFromRepo.GetInstanceValue(element.DatasetElement.ElementName), StringMaxLength = element.DatasetElement.Field.MaxLength, NumericMinValue = element.DatasetElement.Field.MinSize, NumericMaxValue = element.DatasetElement.Field.MaxSize, Required = element.DatasetElement.Field.Mandatory, SelectionDataItems = element.DatasetElement.Field.FieldValues.Select(fv => new SelectionDataItemDto() { SelectionKey = fv.Value, Value = fv.Value }).ToList(), DatasetElementSubs = element.DatasetElement.DatasetElementSubs.Select(elementSub => new DatasetElementSubViewDto { DatasetElementSubId = elementSub.Id, DatasetElementSubName = elementSub.ElementName, DatasetElementSubType = elementSub.Field.FieldType.Description }).ToArray() }) .ToArray() }) .ToArray(); } // Condition groups int[] terms = _patientConditionRepository.List(pc => pc.Patient.Id == encounterFromRepo.Patient.Id && !pc.Archived && !pc.Patient.Archived, null, new string[] { "TerminologyMedDra" }) .Select(p => p.TerminologyMedDra.Id) .ToArray(); List <PatientConditionGroupDto> groupArray = new List <PatientConditionGroupDto>(); foreach (var conditionMeddra in _conditionMeddraRepository.List(cm => terms.Contains(cm.TerminologyMedDra.Id), null, new string[] { "Condition" }) .ToList()) { var tempCondition = conditionMeddra.GetConditionForPatient(encounterFromRepo.Patient); if (tempCondition != null) { var group = new PatientConditionGroupDto() { ConditionGroup = conditionMeddra.Condition.Description, Status = tempCondition.OutcomeDate != null ? "Case Closed" : "Case Open", PatientConditionId = tempCondition.Id, StartDate = tempCondition.OnsetDate.ToString("yyyy-MM-dd"), Detail = $"{tempCondition.TerminologyMedDra.DisplayName} started on {tempCondition.OnsetDate.ToString("yyyy-MM-dd")}" }; groupArray.Add(group); } } mappedEncounter.ConditionGroups = groupArray; // Weight history mappedEncounter.WeightSeries = _patientService.GetElementValues(encounterFromRepo.Patient.Id, "Weight (kg)", 5); // patient custom mapping IExtendable patientExtended = encounterFromRepo.Patient; var attribute = patientExtended.GetAttributeValue("Medical Record Number"); mappedEncounter.Patient.MedicalRecordNumber = attribute != null?attribute.ToString() : ""; }