Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vr): fix time based partial date times #208

Merged
merged 12 commits into from
Jan 22, 2025
81 changes: 44 additions & 37 deletions projects/BFDR/NatalityRecord_submissionProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
{
AddBirthDateToPatient(Subject, false);
}
Date newDate = UpdateFhirDate(Subject.BirthDateElement, value, PartialDateYearUrl, true);
Date newDate = UpdateFhirDateElement(Subject.BirthDateElement, value, PartialDateYearUrl, true);
if (newDate != null)
{
Subject.BirthDateElement = newDate;
Expand Down Expand Up @@ -197,7 +197,7 @@
{
AddBirthDateToPatient(Subject, false);
}
Date newDate = UpdateFhirDate(Subject.BirthDateElement, value, PartialDateMonthUrl, true);
Date newDate = UpdateFhirDateElement(Subject.BirthDateElement, value, PartialDateMonthUrl, true);
if (newDate != null)
{
Subject.BirthDateElement = newDate;
Expand All @@ -222,7 +222,7 @@
{
AddBirthDateToPatient(Subject, false);
}
Date newDate = UpdateFhirDate(Subject.BirthDateElement, value, PartialDateDayUrl, true);
Date newDate = UpdateFhirDateElement(Subject.BirthDateElement, value, PartialDateDayUrl, true);
if (newDate != null)
{
Subject.BirthDateElement = newDate;
Expand All @@ -234,18 +234,21 @@
/// </summary>
protected string GetBirthTime()
{
if (Subject == null || Subject.BirthDateElement == null)
{
return null;
}
// First check for a time in the patient.birthDate PatientBirthTime extension.
if (Subject.BirthDateElement.Extension.Any(ext => ext.Url == VR.ExtensionURL.PatientBirthTime))
{
FhirDateTime dateTime = (FhirDateTime)Subject.BirthDateElement.GetExtension(VR.ExtensionURL.PatientBirthTime).Value;
return GetTimeFragment(dateTime);
if (Subject == null || Subject.BirthDateElement == null)
{
return null;
}
// First check for a time in the patient.birthDate PatientBirthTime extension.
if (Subject.BirthDateElement.Extension.Any(ext => ext.Url == VR.ExtensionURL.PatientBirthTime))
{
FhirDateTime dateTime = (FhirDateTime)Subject.BirthDateElement.GetExtension(VR.ExtensionURL.PatientBirthTime).Value;
string time = GetTimeFragment(dateTime);
if (time != null) {
return time;
}
// If it's not there, check for a PartialDateTime.
return this.GetPartialTime(this.Subject.BirthDateElement.GetExtension(PartialDateTimeUrl));
}
// If it's not there, check for a PartialDateTime.
return this.GetPartialTime(this.Subject.BirthDateElement.GetExtension(PartialDateTimeUrl));
}

/// <summary>
Expand All @@ -262,7 +265,11 @@
{
AddBirthDateToPatient(Subject, true);
}
AddTimeToDate(Subject.BirthDateElement, GetBirthYear(), GetBirthMonth(), GetBirthDay(), value, true);
Date newDate = UpdateFhirDateTimeElement(Subject.BirthDateElement, value, true);
if (newDate != null)
{
Subject.BirthDateElement = newDate;
}
}

/// <summary>
Expand Down Expand Up @@ -2469,7 +2476,7 @@
{
AddBirthDateToPatient(Mother, false);
}
Date newDate = UpdateFhirDate(Mother.BirthDateElement, value, PartialDateDayUrl);
Date newDate = UpdateFhirDateElement(Mother.BirthDateElement, value, PartialDateDayUrl);
if (newDate != null)
{
Mother.BirthDateElement = newDate;
Expand Down Expand Up @@ -2499,7 +2506,7 @@
{
AddBirthDateToPatient(Mother, false);
}
Date newDate = UpdateFhirDate(Mother.BirthDateElement, value, PartialDateMonthUrl);
Date newDate = UpdateFhirDateElement(Mother.BirthDateElement, value, PartialDateMonthUrl);
if (newDate != null)
{
Mother.BirthDateElement = newDate;
Expand Down Expand Up @@ -2529,7 +2536,7 @@
{
AddBirthDateToPatient(Mother, false);
}
Date newDate = UpdateFhirDate(Mother.BirthDateElement, value, PartialDateYearUrl);
Date newDate = UpdateFhirDateElement(Mother.BirthDateElement, value, PartialDateYearUrl);
if (newDate != null)
{
Mother.BirthDateElement = newDate;
Expand Down Expand Up @@ -2779,7 +2786,7 @@
Father.BirthDateElement = new Date();
Father.BirthDateElement.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
Date newDate = UpdateFhirDate(Father.BirthDateElement, value, PartialDateDayUrl);
Date newDate = UpdateFhirDateElement(Father.BirthDateElement, value, PartialDateDayUrl);
if (newDate != null)
{
Father.BirthDateElement = newDate;
Expand Down Expand Up @@ -2810,7 +2817,7 @@
Father.BirthDateElement = new Date();
Father.BirthDateElement.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
Date newDate = UpdateFhirDate(Father.BirthDateElement, value, PartialDateMonthUrl);
Date newDate = UpdateFhirDateElement(Father.BirthDateElement, value, PartialDateMonthUrl);
if (newDate != null)
{
Father.BirthDateElement = newDate;
Expand Down Expand Up @@ -2841,7 +2848,7 @@
Father.BirthDateElement = new Date();
Father.BirthDateElement.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
Date newDate = UpdateFhirDate(Father.BirthDateElement, value, PartialDateYearUrl);
Date newDate = UpdateFhirDateElement(Father.BirthDateElement, value, PartialDateYearUrl);
if (newDate != null)
{
Father.BirthDateElement = newDate;
Expand Down Expand Up @@ -6066,7 +6073,7 @@
obs.Value = new FhirDateTime();
obs.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateDayUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateDayUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -6105,7 +6112,7 @@
obs.Value = new FhirDateTime();
obs.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateMonthUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateMonthUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -6144,7 +6151,7 @@
obs.Value = new FhirDateTime();
obs.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateYearUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateYearUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -6213,7 +6220,7 @@
obs.Value = new FhirDateTime();
obs.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateDayUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateDayUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -6252,7 +6259,7 @@
obs.Value = new FhirDateTime();
obs.Value.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateMonthUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateMonthUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -6291,7 +6298,7 @@
obs.Value = new FhirDateTime();
obs.Value.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateYearUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateYearUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -6715,7 +6722,7 @@
}
}

protected int? GetWeight(string code)

Check warning on line 6725 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / coverage

Missing XML comment for publicly visible type or member 'NatalityRecord.GetWeight(string)'

Check warning on line 6725 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (2.1.815)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetWeight(string)'

Check warning on line 6725 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (3.1.408)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetWeight(string)'

Check warning on line 6725 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (6.0.100)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetWeight(string)'
{
var entry = Bundle.Entry.Where(e => e.Resource is Observation obs && CodeableConceptToDict(obs.Code)["code"] == code).FirstOrDefault();
if (entry != null)
Expand All @@ -6726,7 +6733,7 @@
return null;
}

protected Observation SetWeight(string code, int? value, string unit, string section, string subjectId)

Check warning on line 6736 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / coverage

Missing XML comment for publicly visible type or member 'NatalityRecord.SetWeight(string, int?, string, string, string)'

Check warning on line 6736 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (2.1.815)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetWeight(string, int?, string, string, string)'

Check warning on line 6736 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (3.1.408)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetWeight(string, int?, string, string, string)'

Check warning on line 6736 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (6.0.100)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetWeight(string, int?, string, string, string)'
{
var entry = Bundle.Entry.Where(e => e.Resource is Observation o && CodeableConceptToDict(o.Code)["code"] == code).FirstOrDefault();
if (!(entry?.Resource is Observation obs))
Expand Down Expand Up @@ -8029,7 +8036,7 @@
obs.Value = new FhirDateTime();
obs.Value.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateYearUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateYearUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -8062,7 +8069,7 @@
obs.Value = new FhirDateTime();
obs.Value.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateMonthUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateMonthUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -8096,7 +8103,7 @@
obs.Value = new FhirDateTime();
obs.Value.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateDayUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateDayUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -8204,7 +8211,7 @@
obs.Value = new FhirDateTime();
obs.Value.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateYearUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateYearUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -8237,7 +8244,7 @@
obs.Value = new FhirDateTime();
obs.Value.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateMonthUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateMonthUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -8270,7 +8277,7 @@
obs.Value = new FhirDateTime();
obs.Value.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(obs.Value as FhirDateTime), value, PartialDateDayUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(obs.Value as FhirDateTime, value, PartialDateDayUrl);
if (newDate != null)
{
obs.Value = newDate;
Expand Down Expand Up @@ -8328,7 +8335,7 @@
this.Composition.DateElement = new FhirDateTime();
this.Composition.DateElement.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate =ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(this.Composition.DateElement), value, PartialDateYearUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(this.Composition.DateElement, value, PartialDateYearUrl);
if (newDate != null)
{
this.Composition.DateElement = newDate;
Expand Down Expand Up @@ -8364,7 +8371,7 @@
this.Composition.DateElement = new FhirDateTime();
this.Composition.DateElement.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(this.Composition.DateElement), value, PartialDateMonthUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(this.Composition.DateElement, value, PartialDateMonthUrl);
if (newDate != null)
{
this.Composition.DateElement = newDate;
Expand Down Expand Up @@ -8400,7 +8407,7 @@
this.Composition.DateElement = new FhirDateTime();
this.Composition.DateElement.Extension.Add(NewBlankPartialDateTimeExtension(false));
}
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(this.Composition.DateElement), value, PartialDateDayUrl));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(this.Composition.DateElement, value, PartialDateDayUrl);
if (newDate != null)
{
this.Composition.DateElement = newDate;
Expand Down Expand Up @@ -9336,7 +9343,7 @@
}
}

protected int? GetCertifiedDateElement(Encounter encounter, string dateUrl)

Check warning on line 9346 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / coverage

Missing XML comment for publicly visible type or member 'NatalityRecord.GetCertifiedDateElement(Encounter, string)'

Check warning on line 9346 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (2.1.815)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetCertifiedDateElement(Encounter, string)'

Check warning on line 9346 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (3.1.408)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetCertifiedDateElement(Encounter, string)'

Check warning on line 9346 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (6.0.100)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetCertifiedDateElement(Encounter, string)'
{
if (encounter == null)
{
Expand Down Expand Up @@ -9364,7 +9371,7 @@
return GetDateFragmentOrPartialDate(certifier.Period.StartElement, dateUrl);
}

protected void SetCertifiedDateElement(Encounter encounter, string dateUrl, int? value)

Check warning on line 9374 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / coverage

Missing XML comment for publicly visible type or member 'NatalityRecord.SetCertifiedDateElement(Encounter, string, int?)'

Check warning on line 9374 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (2.1.815)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetCertifiedDateElement(Encounter, string, int?)'

Check warning on line 9374 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (3.1.408)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetCertifiedDateElement(Encounter, string, int?)'

Check warning on line 9374 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (6.0.100)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetCertifiedDateElement(Encounter, string, int?)'
{
if (value == null)
{
Expand All @@ -9391,7 +9398,7 @@
stateComp.Period = p;
}
// TODO create new helper function specific to FHIRDateTimes so we don't drop time information
FhirDateTime newDate = ConvertDateToFhirDateTime(UpdateFhirDate(ConvertFhirDateTimeToDate(stateComp.Period.StartElement), value, dateUrl, true));
FhirDateTime newDate = UpdateFhirDateTimeDateElement(stateComp.Period.StartElement, value, dateUrl);
if (newDate != null)
{
stateComp.Period.StartElement = newDate;
Expand All @@ -9417,12 +9424,12 @@
// }
}

protected string GetCertificationDate(Encounter encounter)

Check warning on line 9427 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / coverage

Missing XML comment for publicly visible type or member 'NatalityRecord.GetCertificationDate(Encounter)'

Check warning on line 9427 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (2.1.815)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetCertificationDate(Encounter)'

Check warning on line 9427 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (3.1.408)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetCertificationDate(Encounter)'

Check warning on line 9427 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (6.0.100)

Missing XML comment for publicly visible type or member 'NatalityRecord.GetCertificationDate(Encounter)'
{
Encounter.ParticipantComponent certifier = encounter?.Participant?.FirstOrDefault(entry => ((Encounter.ParticipantComponent)entry).Type.Any(t => t.Coding.Any(c => c.Code == "87287-9")));
return certifier?.Period?.Start;
}
protected void SetCertificationDate(Encounter encounter, string value)

Check warning on line 9432 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / coverage

Missing XML comment for publicly visible type or member 'NatalityRecord.SetCertificationDate(Encounter, string)'

Check warning on line 9432 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (2.1.815)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetCertificationDate(Encounter, string)'

Check warning on line 9432 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (3.1.408)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetCertificationDate(Encounter, string)'

Check warning on line 9432 in projects/BFDR/NatalityRecord_submissionProperties.cs

View workflow job for this annotation

GitHub Actions / test (6.0.100)

Missing XML comment for publicly visible type or member 'NatalityRecord.SetCertificationDate(Encounter, string)'
{
Encounter.ParticipantComponent certifier = encounter.Participant.FirstOrDefault(entry => ((Encounter.ParticipantComponent)entry).Type.Any(t => t.Coding.Any(c => c.Code == "87287-9")));
if (certifier != null)
Expand Down
20 changes: 1 addition & 19 deletions projects/VitalRecord/VitalRecord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading