public static CodedValue ToCodedValue(this Coding coding) { var uri = new Uri(coding.System); var returnValue = new CodedValue { Value = coding.Code, Version = coding.Version, }; var family = CodeToHealthVaultHelper.GetFamily(uri); if (!string.IsNullOrEmpty(family)) { returnValue.Family = family; } var vocabName = CodeToHealthVaultHelper.GetVocabularyName(uri); if (!string.IsNullOrEmpty(vocabName)) { returnValue.VocabularyName = vocabName; } return(returnValue); }
public static ThingBase ToHealthVault(this MedicationStatement medicationStatement) { var fhirMedication = MedicationStatementHelper.ExtractEmbeddedMedication(medicationStatement); if (fhirMedication == null) { return(null); } var hvMedication = fhirMedication.ToHealthVault() as HVMedication; if (medicationStatement.Dosage.Any()) { var dosage = medicationStatement.Dosage.First(); switch (dosage.Dose) { case null: break; case SimpleQuantity doseQuantity: var dose = new GeneralMeasurement { }; dose.Structured.Add(new StructuredMeasurement { Value = (double)doseQuantity.Value, Units = CodeToHealthVaultHelper.CreateCodableValueFromQuantityValues(doseQuantity.System, doseQuantity.Code, doseQuantity.Unit) }); hvMedication.Dose = dose; break; case Range doseRange: throw new NotImplementedException(); } Timing.RepeatComponent repeat = dosage.Timing?.Repeat; if (repeat?.Period != null && repeat?.PeriodUnit != null) { var frequency = new GeneralMeasurement { }; frequency.Structured.Add(new StructuredMeasurement { Value = (double)repeat.Period, Units = CodeToHealthVaultHelper.GetRecurrenceIntervalFromPeriodUnit(repeat.PeriodUnit.Value) }); hvMedication.Frequency = frequency; } var route = dosage.Route.ToCodableValue(); hvMedication.Route = route; } return(hvMedication); }
public static ThingBase ToHealthVault(this FhirMedication fhirMedication) { var hvMedication = new HVMedication(); var name = fhirMedication.Code.ToCodableValue(); if (name == null) { throw new NotSupportedException($"{nameof(FhirMedication)} should" + $" have {nameof(fhirMedication.Code)}"); } hvMedication.Name = name; var medicationExtension = fhirMedication.GetExtension(HealthVaultExtensions.Medication); if (medicationExtension != null) { var genericName = medicationExtension .GetExtensionValue <CodeableConcept>(HealthVaultExtensions.MedicationGenericName); hvMedication.GenericName = genericName?.ToCodableValue(); var strengthExtension = medicationExtension.GetExtension(HealthVaultExtensions.MedicationStrength); if (strengthExtension != null) { string display = strengthExtension.GetStringExtension(HealthVaultExtensions.MedicationStrengthDisplay); var strength = new GeneralMeasurement(display); foreach (var quantityExtension in strengthExtension.GetExtensions(HealthVaultExtensions.MedicationStrengthQuantity)) { var quantity = quantityExtension.Value as Quantity; if (quantity == null) { continue; } strength.Structured.Add(new StructuredMeasurement { Value = (double)quantity.Value, Units = CodeToHealthVaultHelper.CreateCodableValueFromQuantityValues( quantity.System, quantity.Code, quantity.Unit) }); } hvMedication.Strength = strength; } } return(hvMedication); }
private static string GetExerciseDetail(Extension detail, out ExerciseDetail exerciseDetail) { var key = ""; exerciseDetail = new ExerciseDetail(); foreach (var extension in detail.Extension) { if (extension.Value == null) { continue; } switch (extension.Url) { case HealthVaultExtensions.ExerciseDetailName: key = ((FhirString)extension.Value).Value; break; case HealthVaultExtensions.ExerciseDetailType: exerciseDetail.Name = ((Coding)extension.Value).ToCodedValue(); break; case HealthVaultExtensions.ExerciseDetailValue: var detailQuantity = (Quantity)extension.Value; if (detailQuantity?.Value != null) { exerciseDetail.Value = new StructuredMeasurement( (double)detailQuantity.Value, CodeToHealthVaultHelper.CreateCodableValueFromQuantityValues(detailQuantity.System, detailQuantity.Code, detailQuantity.Unit) ); } break; } } return(key); }
/// <summary> /// This extension method transforms from a FHIR Observation to a HealthVault Thing type /// </summary> /// <param name="observation">The observation source</param> /// <returns>The HealthVault thing</returns> public static ThingBase ToHealthVault(this Observation observation) { return(observation.ToHealthVault(CodeToHealthVaultHelper.DetectHealthVaultTypeFromObservation(observation))); }
/// <summary> /// This extension method transforms from a FHIR DocumentReference to a HealthVault Thing type /// </summary> /// <param name="documentReference">The DocumentReference source</param> /// <returns>The HealthVault thing</returns> public static ThingBase ToHealthVault(this DocumentReference documentReference) { return(documentReference.ToHealthVault(CodeToHealthVaultHelper.DetectHealthVaultTypeFromDocumentReference(documentReference))); }
public static ThingBase ToHealthVault(this MedicationRequest medicationRequest) { var fhirMedication = MedicationRequestHelper.ExtractEmbeddedMedication(medicationRequest); if (fhirMedication == null) { return(null); } var hvMedication = fhirMedication.ToHealthVault() as HVMedication; var practitioner = ExtractEmbeddedPractitioner(medicationRequest); if (practitioner == null) { throw new NotSupportedException($"{nameof(MedicationRequest)} needs to have an embedded Requester Agent"); } var prescription = new Prescription(practitioner.ToHealthVault()); if (medicationRequest.AuthoredOnElement != null) { var dt = medicationRequest.AuthoredOnElement.ToDateTimeOffset(); prescription.DatePrescribed = new ApproximateDateTime( new ApproximateDate(dt.Year, dt.Month, dt.Day), new ApproximateTime(dt.Hour, dt.Minute, dt.Second, dt.Millisecond)); } MedicationRequest.DispenseRequestComponent dispenseRequest = medicationRequest.DispenseRequest; if (dispenseRequest != null) { var numerator = dispenseRequest.Quantity; if (numerator != null) { var structuredMeasurement = new StructuredMeasurement { Value = (double)numerator.Value, Units = CodeToHealthVaultHelper.CreateCodableValueFromQuantityValues(numerator.System, numerator.Code, numerator.Unit) }; prescription.AmountPrescribed = new GeneralMeasurement(); prescription.AmountPrescribed.Structured.Add(structuredMeasurement); } prescription.Refills = dispenseRequest.NumberOfRepeatsAllowed; prescription.DaysSupply = GetDaysFromDuration(dispenseRequest.ExpectedSupplyDuration); FhirDateTime end = dispenseRequest.ValidityPeriod?.EndElement; if (end != null) { var endDate = end.ToDateTimeOffset(); prescription.PrescriptionExpiration = new HealthServiceDate(endDate.Year , endDate.Month, endDate.Day); } } if (medicationRequest.DosageInstruction.Any()) { var dosageInstruction = medicationRequest.DosageInstruction .FirstOrDefault(dosage => dosage.AdditionalInstruction.Any()); if (dosageInstruction != null) { var instruction = dosageInstruction.AdditionalInstruction.First(); prescription.Instructions = instruction.ToCodableValue(); } } if (medicationRequest.Substitution != null) { prescription.Substitution = GetSubstitutionCode(medicationRequest, prescription); } hvMedication.Prescription = prescription; return(hvMedication); }