private static PersonItem GetProvider(FhirProcedure fhirProcedure, int index) { var performerComponent = fhirProcedure.Performer[index]; if (performerComponent.Actor.IsContainedReference) { var containedReference = fhirProcedure.Contained.SingleOrDefault(resouce => resouce.Id.Equals(performerComponent.Actor.Reference) && resouce.GetType().Equals(typeof(Hl7.Fhir.Model.Practitioner))); if (containedReference == null) { return(null); } return((containedReference as Hl7.Fhir.Model.Practitioner).ToHealthVault()); } if (string.IsNullOrEmpty(performerComponent.Actor.Display)) { return(null); } return(new PersonItem() { Name = new Name(performerComponent.Actor.Display) }); }
public static Procedure ToHealthVault(this FhirProcedure fhirProcedure) { Procedure hvProcedure = fhirProcedure.ToThingBase <Procedure>(); //Populate when (if present) if (fhirProcedure.Performed != null) { hvProcedure.When = fhirProcedure.Performed.ToAproximateDateTime(); } if (fhirProcedure.Code.IsNullOrEmpty()) { throw new System.ArgumentException($"Can not transform a {typeof(FhirProcedure)} with no code into {typeof(Procedure)}"); } hvProcedure.Name = fhirProcedure.Code.ToCodableValue(); hvProcedure.AnatomicLocation = fhirProcedure.BodySite?.FirstOrDefault()?.ToCodableValue(); if (!fhirProcedure.Performer.IsNullOrEmpty()) { hvProcedure.PrimaryProvider = GetProvider(fhirProcedure, 0); if (fhirProcedure.Performer.Count > 1) { hvProcedure.SecondaryProvider = GetProvider(fhirProcedure, 1); } } return(hvProcedure); }