Пример #1
0
        private static Timing GetTiming(GeneralMeasurement frequency)
        {
            if (frequency.Structured.Any())
            {
                StructuredMeasurement frequencyMeasurement = frequency.Structured.First();

                var repeatComponent = new Timing.RepeatComponent();
                repeatComponent.Period     = new decimal(frequencyMeasurement.Value);
                repeatComponent.PeriodUnit = GetPeriodUnitFromFromRecurrenceIntervals(frequencyMeasurement.Units);

                return(new Timing()
                {
                    Repeat = repeatComponent
                });
            }
            return(null);
        }
Пример #2
0
        public static SimpleQuantity GetSimpleQuantity(GeneralMeasurement measurement)
        {
            if (measurement?.Structured.Any() == true)
            {
                StructuredMeasurement structuredMeasurement = measurement.Structured.First();

                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);
                }

                return(simpleQuantity);
            }
            return(null);
        }
        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);
        }