예제 #1
0
        public void WhenHealthVaultMedicationTransformedToFhir_ThenStrengthIsCopiedAsExtension()
        {
            const string strengthDisplay = "600mg";
            var          hvMedication    = new HVMedication()
            {
                Name     = new CodableValue("Ibuprofen"),
                Strength = new GeneralMeasurement(strengthDisplay)
            };

            const int strengthValue = 600;

            hvMedication.Strength.Structured.Add(
                new StructuredMeasurement(strengthValue,
                                          new CodableValue("Milligrams (mg)",
                                                           new CodedValue("mg",
                                                                          family: "wc",
                                                                          vocabularyName: "medication-strength-unit",
                                                                          version: "1"))));

            var fhirMedication = ExtractEmbeddedMedication(hvMedication);

            Assert.IsTrue(((IExtendable)fhirMedication).HasExtensions());

            var medicationExtension = fhirMedication.GetExtension(HealthVaultExtensions.Medication);
            var strength            = medicationExtension?.GetExtension(HealthVaultExtensions.MedicationStrength);

            Assert.AreEqual(strengthDisplay, strength?
                            .GetStringExtension(HealthVaultExtensions.MedicationStrengthDisplay));
            Assert.AreEqual(strengthValue, (strength?
                                            .GetExtensions(HealthVaultExtensions.MedicationStrengthQuantity)
                                            .FirstOrDefault()?.Value as Quantity)?.Value);
        }
        internal static MedicationStatement ToFhirInternal(HVMedication hvMedication, MedicationStatement medicationStatement)
        {
            var embeddedMedication = new FhirMedication();

            embeddedMedication.Id = "med" + Guid.NewGuid();

            medicationStatement.Contained.Add(ToFhirInternal(hvMedication, embeddedMedication));
            medicationStatement.Medication = embeddedMedication.GetContainerReference();

            medicationStatement.SetStatusAsActive();
            medicationStatement.SetTakenAsNotApplicable();

            medicationStatement.Dosage = AddDosage(hvMedication.Dose, hvMedication.Frequency, hvMedication.Route);

            if (hvMedication.Prescription != null)
            {
                var embeddedMedicationRequest = new MedicationRequest();
                embeddedMedicationRequest.Id = "medReq" + Guid.NewGuid();

                Practitioner prescribedBy = hvMedication.Prescription.PrescribedBy.ToFhir();
                prescribedBy.Id = "prac" + Guid.NewGuid();
                medicationStatement.Contained.Add(prescribedBy);

                MedicationRequest request = ToFhirInternal(hvMedication.Prescription, embeddedMedicationRequest);
                request.Medication = embeddedMedication.GetContainerReference();
                request.Requester  = new MedicationRequest.RequesterComponent
                {
                    Agent = prescribedBy.GetContainerReference()
                };
                medicationStatement.Contained.Add(request);
                medicationStatement.BasedOn.Add(embeddedMedicationRequest.GetContainerReference());
            }

            return(medicationStatement);
        }
        internal static FhirMedication ToFhirInternal(HVMedication hvMedication, FhirMedication fhirMedication)
        {
            fhirMedication.Code = hvMedication.Name.ToFhir();

            if (hvMedication.GenericName != null || hvMedication.Strength != null)
            {
                var medicationExtension = new Extension {
                    Url = HealthVaultExtensions.Medication
                };

                if (hvMedication.GenericName != null)
                {
                    var genericName = hvMedication.GenericName?.ToFhir();

                    medicationExtension.AddExtension(HealthVaultExtensions.MedicationGenericName,
                                                     genericName);
                }

                if (hvMedication.Strength != null)
                {
                    var strengthExtension = new Extension {
                        Url = HealthVaultExtensions.MedicationStrength
                    };

                    strengthExtension.AddExtension(HealthVaultExtensions.MedicationStrengthDisplay,
                                                   new FhirString(hvMedication.Strength.Display));

                    foreach (var structuredMeasurement in hvMedication.Strength.Structured)
                    {
                        var simpleQuantity = new SimpleQuantity()
                        {
                            Value = new decimal(structuredMeasurement.Value),
                            Unit  = structuredMeasurement.Units.Text
                        };

                        if (structuredMeasurement.Units.Any())
                        {
                            CodedValue measurementUnit = structuredMeasurement.Units.First();

                            simpleQuantity.Code   = measurementUnit.Value;
                            simpleQuantity.System = HealthVaultVocabularies.GenerateSystemUrl(measurementUnit.VocabularyName, measurementUnit.Family);
                        }

                        strengthExtension.AddExtension(HealthVaultExtensions.MedicationStrengthQuantity, simpleQuantity);
                    }

                    medicationExtension.Extension.Add(strengthExtension);
                }

                fhirMedication.Extension.Add(medicationExtension);
            }

            return(fhirMedication);
        }
예제 #4
0
        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);
        }
예제 #5
0
        public void WhenHealthVaultMedicationTransformedToFhir_ThenNameIsCopiedToCode()
        {
            const string medicationName = "Ibuprofen";
            var          hvMedication   = new HVMedication()
            {
                Name = new CodableValue(medicationName,
                                        new CodedValue("df48b0ac-de8b-4bca-8785-dad6897fb53d",
                                                       family: "wc",
                                                       vocabularyName: "MayoMedications",
                                                       version: "1"))
            };

            var fhirMedication = ExtractEmbeddedMedication(hvMedication);
            var medicationCode = fhirMedication.Code;

            Assert.AreEqual(medicationName, medicationCode.Text);
        }
예제 #6
0
        public void WhenHealthVaultMedicationTransformedToFhir_ThenGenericNameIsCopiedAsExtension()
        {
            const string medicationName = "Ibuprofen / Tolperisone Oral Tablet";
            var          hvMedication   = new HVMedication()
            {
                Name        = new CodableValue("Ibuprofen"),
                GenericName = new CodableValue(medicationName,
                                               new CodedValue("1579080",
                                                              family: "RxNorm",
                                                              vocabularyName: "RxNorm Obsolete Medicines",
                                                              version: "09AB_091102F"))
            };

            var fhirMedication = ExtractEmbeddedMedication(hvMedication);

            Assert.IsTrue(((IExtendable)fhirMedication).HasExtensions());

            var medicationExtension = fhirMedication.GetExtension(HealthVaultExtensions.Medication);
            var genericName         = medicationExtension?
                                      .GetExtensionValue <CodeableConcept>(HealthVaultExtensions.MedicationGenericName);

            Assert.AreEqual(medicationName, genericName?.Text);
        }
예제 #7
0
        private static FhirMedication ExtractEmbeddedMedication(HVMedication hvMedication)
        {
            var medicationStatement = hvMedication.ToFhir();
            var medicationReference = medicationStatement.Medication as ResourceReference;

            if (medicationReference != null)
            {
                if (medicationReference.IsContainedReference)
                {
                    return(medicationStatement.Contained.First(domainResource
                                                               => medicationReference.Matches(domainResource.GetContainerReference())) as FhirMedication);
                }
                throw new AssertInconclusiveException();
            }
            else
            {
                var medicationCodeableConcept = medicationStatement.Medication as CodeableConcept;
                return(new FhirMedication
                {
                    Code = medicationCodeableConcept
                });
            }
        }
 // Register the type on the generic ThingToFhir partial class
 public static MedicationStatement ToFhir(this HVMedication hvMedication)
 {
     return(MedicationToFhir.ToFhirInternal(hvMedication, ToFhirInternal <MedicationStatement>(hvMedication)));
 }
예제 #9
0
 private MedicationRequest ExtractEmbeddedMedicationRequest(HVMedication hvMedication)
 {
     return(ExtractEmbeddedMedicationRequest(hvMedication.ToFhir()));
 }