public t( FhirDateTime endDate, Func <FhirDateTime, PositiveInt> numberDaysAfterStartDate, FhirDateTime startDate) { this.Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); this.EndDate = endDate; this.NumberDaysAfterStartDate = numberDaysAfterStartDate; this.StartDate = startDate; ImmutableList <FhirDateTime> .Builder builder = ImmutableList.CreateBuilder <FhirDateTime>(); for (DateTime i = startDate.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date; i <= endDate.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date; i = i.AddDays(1)) { builder.Add( new FhirDateTime( new DateTimeOffset( i))); } this.Value = builder.ToImmutableList(); }
private static Patient GetSomePatientWithProfile(string patientId, string profile) { var date = new FhirDateTime(new DateTimeOffset(DateTime.Now)); return(new Patient { Meta = new Meta { LastUpdated = date.ToDateTimeOffset(new TimeSpan()), Profile = new List <string> { profile } }, Id = patientId, Active = true, Name = new List <HumanName> { new HumanName { Family = "Normann", Given = new List <string> { "Ola" } } }, Telecom = new List <ContactPoint> { new ContactPoint { System = ContactPoint.ContactPointSystem.Phone, Value = "123467890" } }, Gender = AdministrativeGender.Male, BirthDate = "2000-01-01" }); }
private static Base MockPatient() { var date = new FhirDateTime(DateTime.Now); return(new Patient { Meta = new Meta { LastUpdated = date.ToDateTimeOffset(), Profile = new List <string> { "http://helse-nord.no/FHIR/profiles/Identification.Patient/Patient" } }, Id = "12345678901", Active = true, Name = new List <HumanName> { new HumanName { Family = "Normann", Given = new List <string> { "Ola" } } }, Telecom = new List <ContactPoint> { new ContactPoint { System = ContactPoint.ContactPointSystem.Phone, Value = "123467890" } }, Gender = AdministrativeGender.Male, BirthDate = "2000-01-01" }); }
public static Period ToPeriod(this FhirDateTime fdt) { var result = new Period(); var dtoStart = fdt.ToDateTimeOffset(); result.StartElement = new FhirDateTime(dtoStart); var dtoEnd = dtoStart; switch (fdt.Precision()) { case FhirDateTimePrecision.Year: dtoEnd = dtoStart.AddYears(1); break; case FhirDateTimePrecision.Month: dtoEnd = dtoStart.AddMonths(1); break; case FhirDateTimePrecision.Day: dtoEnd = dtoStart.AddDays(1); break; case FhirDateTimePrecision.Minute: dtoEnd = dtoStart.AddMinutes(1); break; case FhirDateTimePrecision.Second: dtoEnd = dtoStart.AddSeconds(1); break; default: dtoEnd = dtoStart; break; } result.EndElement = new FhirDateTime(dtoEnd); return(result); }
private static Base MockPatient() { var date = new FhirDateTime(new DateTimeOffset(DateTime.Now)); return(new Patient { Meta = new Meta { LastUpdated = date.ToDateTimeOffset(new TimeSpan()), Profile = new List <string> { "http://helse-nord.no/fhir/StructureDefinition/Clinical.Patient/Patient_HN" } }, Id = "12345678901", Active = true, Name = new List <HumanName> { new HumanName { Family = "Normann", Given = new List <string> { "Ola" } } }, Gender = AdministrativeGender.Male, BirthDate = "2000-01-01" }); }
private static Base MockPatient() { var date = new FhirDateTime(System.DateTime.Now); return(new Patient { Meta = new Meta { LastUpdated = date.ToDateTimeOffset() }, Id = "12345678901", Active = true, Name = new List <HumanName> { new HumanName { Family = new List <string> { "Normann" }, Given = new List <string> { "Ola" } } }, Telecom = new List <ContactPoint> { new ContactPoint { System = ContactPoint.ContactPointSystem.Phone, Value = "123467890" } }, Gender = AdministrativeGender.Male, BirthDate = "2000-01-01" }); }
public DateTimeValue(string datetime) { if (!FhirDateTime.IsValidValue(datetime)) { throw Error.Argument("datetime", "The string [" + datetime + "] cannot be translated to a DateTimeValue"); } var fdt = new FhirDateTime(datetime); Value = fdt.ToDateTimeOffset(TimeSpan.Zero); }
private OperatorType ProcessLastUpdatedParameter(Tuple <string, string> enumerable, out string dateStr, out DateTimeOffset dateTimeOffset) { var dateOperator = GetOperatorForDateOrNumber(enumerable); dateStr = RemovePrefix(enumerable.Item2, dateOperator); var dateTime = new FhirDateTime(dateStr); dateTimeOffset = dateTime.ToDateTimeOffset(); return(dateOperator); }
public static bool IsValidFhirDateTime(string dateTime) { try { FhirDateTime dt = new FhirDateTime(dateTime); DateTimeOffset offset = dt.ToDateTimeOffset(TimeSpan.Zero); } catch { return(false); } return(true); }
private static ApproximateDateTime processDate(FhirDateTime fhirDateTime) { var dt = fhirDateTime.ToDateTimeOffset(); switch (FhirDateTimeExtensions.Precision(fhirDateTime)) { case FhirDateTimeExtensions.FhirDateTimePrecision.Year: return(new ItemTypes.ApproximateDateTime() { ApproximateDate = new ItemTypes.ApproximateDate(dt.Year) }); case FhirDateTimeExtensions.FhirDateTimePrecision.Month: return(new ItemTypes.ApproximateDateTime() { ApproximateDate = new ItemTypes.ApproximateDate(dt.Year, dt.Month) }); case FhirDateTimeExtensions.FhirDateTimePrecision.Day: return(new ItemTypes.ApproximateDateTime() { ApproximateDate = new ItemTypes.ApproximateDate(dt.Year, dt.Month, dt.Day) }); case FhirDateTimeExtensions.FhirDateTimePrecision.Minute: return(new ItemTypes.ApproximateDateTime() { ApproximateDate = new ItemTypes.ApproximateDate(dt.Year, dt.Month, dt.Day), ApproximateTime = new ItemTypes.ApproximateTime(dt.Hour, dt.Minute) }); case FhirDateTimeExtensions.FhirDateTimePrecision.Second: return(new ItemTypes.ApproximateDateTime() { ApproximateDate = new ItemTypes.ApproximateDate(dt.Year, dt.Month, dt.Day), ApproximateTime = new ItemTypes.ApproximateTime(dt.Hour, dt.Minute, dt.Second) }); default: return(new ItemTypes.ApproximateDateTime() { ApproximateDate = new ItemTypes.ApproximateDate(dt.Year, dt.Month, dt.Day), ApproximateTime = new ItemTypes.ApproximateTime(dt.Hour, dt.Minute, dt.Second, dt.Millisecond) }); } }
public IDayCumulativeProbableCases_ResultElement Calculate( FhirDateTime t_IndexElement, It t, IDayProbableCases dayProbableCases) { return(new C19M.M.C.A.Safi2010.Classes.ResultElements.DayCumulativeProbableCases.DayCumulativeProbableCases_ResultElement( t_IndexElement, new FhirDecimal( t.Value .Where(w => w.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date >= t.StartDate.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date&& w.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date <= t_IndexElement.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date) .Select(w => dayProbableCases.GetElementAtAsdecimal(w)) .Max()))); }
public decimal GetElementAtAsdecimal( FhirDateTime t_IndexElement) { return(this.Value .Where(x => x.t_IndexElement.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date == t_IndexElement.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date) .Select(x => x.Value.Value.Value) .SingleOrDefault()); }
private static IMongoQuery DateQuery(String parameterName, Operator optor, String modifier, ValueExpression operand) { if (optor == Operator.IN) { IEnumerable <ValueExpression> opMultiple = ((ChoiceValue)operand).Choices; return(M.Query.Or(opMultiple.Select(choice => DateQuery(parameterName, Operator.EQ, modifier, choice)))); } string start = parameterName + ".start"; string end = parameterName + ".end"; var typedOperand = ((UntypedValue)operand).AsDateValue(); // var value = GroomDate(typedOperand.Value); var fdtValue = new FhirDateTime(typedOperand.Value); var value = BsonDateTime.Create(fdtValue.ToDateTimeOffset()); switch (optor) { case Operator.EQ: return (M.Query.And( M.Query.Or(M.Query.Exists(start), M.Query.Exists(end)), M.Query.Or(M.Query.LTE(start, value), M.Query.NotExists(start)), M.Query.Or(M.Query.GT(end, value), M.Query.NotExists(end)) )); case Operator.GT: return (M.Query.Or( M.Query.GT(parameterName, value), M.Query.GT(start, value) )); case Operator.GTE: return (M.Query.Or( M.Query.GTE(parameterName, value), M.Query.GTE(start, value) )); case Operator.LT: return (M.Query.Or( M.Query.LT(parameterName, value), M.Query.LT(end, value) )); case Operator.LTE: return (M.Query.Or( M.Query.LTE(parameterName, value), M.Query.LTE(end, value) )); case Operator.ISNULL: return(M.Query.EQ(parameterName, null)); //We don't use M.Query.NotExists, because that would exclude resources that have this field with an explicit null in it. case Operator.NOTNULL: return(M.Query.NE(parameterName, null)); //We don't use M.Query.Exists, because that would include resources that have this field with an explicit null in it. default: throw new ArgumentException(String.Format("Invalid operator {0} on date parameter {1}", optor.ToString(), parameterName)); } }
public Figure6_DiseaseTransmission() { C19M.D.Gumel2006.Interfaces.IFigure6 Figure6 = new C19M.D.Gumel2006.Classes.Figure6(); // Use StartDate, EndDate,and NumberDaysAfterStartDate from Gumel et al. (2004) FhirDateTime startDate = new FhirDateTime(new DateTimeOffset(new DateTime(2003, 2, 23))); FhirDateTime endDate = new FhirDateTime(new DateTimeOffset(new DateTime(2003, 2, 23).AddDays(1200))); Func <FhirDateTime, PositiveInt> numberDaysAfterStartDate = (x) => { if (x.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date >= startDate.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date) { return(new PositiveInt((int)Math.Abs(Math.Round((x.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date - startDate.ToDateTimeOffset(TimeSpan.Zero).UtcDateTime.Date).TotalDays)))); } else { return(new PositiveInt(0)); } }; // Context C19M.M.C.A.Gumel2006.Interfaces.Contexts.IGumel2006_Context context = new C19M.M.C.A.Gumel2006.Classes.Contexts.Gumel2006_Context( endDate, numberDaysAfterStartDate, startDate, Figure6.DiseaseInducedMortalityRate, new Hl7.Fhir.Model.FhirDecimal(0), // TODO: Change new Hl7.Fhir.Model.FhirDecimal(10), // TODO: Change new Hl7.Fhir.Model.FhirDecimal(0), // TODO: Change new Hl7.Fhir.Model.FhirDecimal(4000000), // TODO: Change new Hl7.Fhir.Model.FhirDecimal(0), // TODO: Change Figure6.DevelopmentClinicalSymptomsRate, Figure6.EffectiveContactRate, Figure6.RecoveryRate, Figure6.NaturalMortalityRate, Figure6.VaccinationCoverageRate, Figure6.RecruitmentRateSusceptibleHumans, Figure6.VaccineEfficacy); // Export C19M.M.C.A.Gumel2006.Interfaces.Exports.IDiseaseTransmission_Export export = new C19M.M.C.A.Gumel2006.Classes.Exports.DiseaseTransmission_Export( context); export.Solve(); this.DayCumulativeDiseaseInducedDeaths = export.DayCumulativeDiseaseInducedDeaths; this.DayCumulativeProbableCases = export.DayCumulativeProbableCases; this.DayDiseaseInducedDeaths = export.DayDiseaseInducedDeaths; this.DayProbableCases = export.DayProbableCases; this.DayLatentIndividuals = export.DayLatentIndividuals; this.DayInfectedIndividuals = export.DayInfectedIndividuals; this.DayTreatedIndividuals = export.DayTreatedIndividuals; this.DaySusceptibleIndividuals = export.DaySusceptibleIndividuals; this.DayVaccinatedIndividuals = export.DayVaccinatedIndividuals; }
public static DateTimeOffset LowerBound(this FhirDateTime fdt) { return(fdt.ToDateTimeOffset()); }
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); }
(FhirDateTimePrecision)Math.Min(fdt.Value.Length, 18); //Ignore timezone for stating precision. public static DateTimeOffset LowerBound(this FhirDateTime fdt) => fdt.ToDateTimeOffset(TimeSpan.Zero);