diff --git a/backend/pkg/database/sqlite_repository.go b/backend/pkg/database/sqlite_repository.go index c2803f842..200070e0e 100644 --- a/backend/pkg/database/sqlite_repository.go +++ b/backend/pkg/database/sqlite_repository.go @@ -330,12 +330,14 @@ func (sr *SqliteRepository) UpsertResource(ctx context.Context, wrappedResourceM } wrappedFhirResourceModel.SetOriginBase(wrappedResourceModel.OriginBase) - //wrappedFhirResourceModel.SetResourceRaw(wrappedResourceModel.ResourceRaw) + wrappedFhirResourceModel.SetSortTitle(wrappedResourceModel.SortTitle) + wrappedFhirResourceModel.SetSortDate(wrappedResourceModel.SortDate) //TODO: this takes too long, we need to find a way to do this processing faster or in the background async. err = wrappedFhirResourceModel.PopulateAndExtractSearchParameters(json.RawMessage(wrappedResourceModel.ResourceRaw)) if err != nil { - return false, fmt.Errorf("An error ocurred while extracting SearchParameters using FHIRPath (%s/%s): %v", wrappedResourceModel.SourceResourceType, wrappedResourceModel.SourceResourceID, err) + sr.Logger.Warnf("ignoring: an error occurred while extracting SearchParameters using FHIRPath (%s/%s): %v", wrappedResourceModel.SourceResourceType, wrappedResourceModel.SourceResourceID, err) + //wrappedFhirResourceModel.SetResourceRaw(wrappedResourceModel.ResourceRaw) } createResult := sr.GormClient.WithContext(ctx).Where(models.OriginBase{ diff --git a/backend/pkg/models/database/fhir_account.go b/backend/pkg/models/database/fhir_account.go index 8cf7efff7..f1e584527 100644 --- a/backend/pkg/models/database/fhir_account.go +++ b/backend/pkg/models/database/fhir_account.go @@ -22,7 +22,7 @@ type FhirAccount struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Human-readable label // https://hl7.org/fhir/r4/search.html#string Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` @@ -31,7 +31,7 @@ type FhirAccount struct { Owner datatypes.JSON `gorm:"column:owner;type:text;serializer:json" json:"owner,omitempty"` // Transaction window // https://hl7.org/fhir/r4/search.html#date - Period time.Time `gorm:"column:period;type:datetime" json:"period,omitempty"` + Period *time.Time `gorm:"column:period;type:datetime" json:"period,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -137,7 +137,12 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -179,7 +184,12 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -189,7 +199,12 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Name @@ -241,8 +256,12 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -250,20 +269,23 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes // extracting Owner ownerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Account.owner'))") if err == nil && ownerResult.String() != "undefined" { - s.Owner = []byte(ownerResult.String()) } // extracting Period periodResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Account.servicePeriod')[0]") if err == nil && periodResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, periodResult.String()) if err == nil { - s.Period = t + s.Period = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", periodResult.String()) + if err == nil { + s.Period = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -307,7 +329,12 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -315,7 +342,6 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Account.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -354,7 +380,12 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_adverse_event.go b/backend/pkg/models/database/fhir_adverse_event.go index f810565bf..b11be091b 100644 --- a/backend/pkg/models/database/fhir_adverse_event.go +++ b/backend/pkg/models/database/fhir_adverse_event.go @@ -22,7 +22,7 @@ type FhirAdverseEvent struct { Category datatypes.JSON `gorm:"column:category;type:text;serializer:json" json:"category,omitempty"` // When the event occurred // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // Type of the event itself in relation to the subject // https://hl7.org/fhir/r4/search.html#token Event datatypes.JSON `gorm:"column:event;type:text;serializer:json" json:"event,omitempty"` @@ -31,7 +31,7 @@ type FhirAdverseEvent struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Location where adverse event occurred // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` @@ -161,7 +161,12 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(ActualityProcessed) + if(ActualityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActualityProcessed) + } `) if err == nil && actualityResult.String() != "undefined" { s.Actuality = []byte(actualityResult.String()) @@ -203,7 +208,12 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -213,7 +223,12 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Event @@ -253,7 +268,12 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(EventProcessed) + if(EventProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EventProcessed) + } `) if err == nil && eventResult.String() != "undefined" { s.Event = []byte(eventResult.String()) @@ -295,7 +315,12 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -305,28 +330,29 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'AdverseEvent.location'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Recorder recorderResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'AdverseEvent.recorder'))") if err == nil && recorderResult.String() != "undefined" { - s.Recorder = []byte(recorderResult.String()) } // extracting Resultingcondition resultingconditionResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'AdverseEvent.resultingCondition'))") if err == nil && resultingconditionResult.String() != "undefined" { - s.Resultingcondition = []byte(resultingconditionResult.String()) } // extracting Seriousness seriousnessResult, err := vm.RunString(` @@ -365,7 +391,12 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(SeriousnessProcessed) + if(SeriousnessProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SeriousnessProcessed) + } `) if err == nil && seriousnessResult.String() != "undefined" { s.Seriousness = []byte(seriousnessResult.String()) @@ -407,7 +438,12 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(SeverityProcessed) + if(SeverityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SeverityProcessed) + } `) if err == nil && severityResult.String() != "undefined" { s.Severity = []byte(severityResult.String()) @@ -420,17 +456,14 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Study studyResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'AdverseEvent.study'))") if err == nil && studyResult.String() != "undefined" { - s.Study = []byte(studyResult.String()) } // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'AdverseEvent.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Substance substanceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'AdverseEvent.suspectEntity.instance'))") if err == nil && substanceResult.String() != "undefined" { - s.Substance = []byte(substanceResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -469,7 +502,12 @@ func (s *FhirAdverseEvent) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_allergy_intolerance.go b/backend/pkg/models/database/fhir_allergy_intolerance.go index e3e5d1577..2885e4765 100644 --- a/backend/pkg/models/database/fhir_allergy_intolerance.go +++ b/backend/pkg/models/database/fhir_allergy_intolerance.go @@ -68,7 +68,7 @@ type FhirAllergyIntolerance struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -110,16 +110,16 @@ type FhirAllergyIntolerance struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // Date(/time) of last known occurrence of a reaction // https://hl7.org/fhir/r4/search.html#date - LastDate time.Time `gorm:"column:lastDate;type:datetime" json:"lastDate,omitempty"` + LastDate *time.Time `gorm:"column:lastDate;type:datetime" json:"lastDate,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Clinical symptoms/signs associated with the Event // https://hl7.org/fhir/r4/search.html#token Manifestation datatypes.JSON `gorm:"column:manifestation;type:text;serializer:json" json:"manifestation,omitempty"` // Date(/time) when manifestations showed // https://hl7.org/fhir/r4/search.html#date - Onset time.Time `gorm:"column:onset;type:datetime" json:"onset,omitempty"` + Onset *time.Time `gorm:"column:onset;type:datetime" json:"onset,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -205,7 +205,6 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw // extracting Asserter asserterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'AllergyIntolerance.asserter'))") if err == nil && asserterResult.String() != "undefined" { - s.Asserter = []byte(asserterResult.String()) } // extracting Category categoryResult, err := vm.RunString(` @@ -244,7 +243,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -286,7 +290,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(ClinicalStatusProcessed) + if(ClinicalStatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ClinicalStatusProcessed) + } `) if err == nil && clinicalStatusResult.String() != "undefined" { s.ClinicalStatus = []byte(clinicalStatusResult.String()) @@ -328,7 +337,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -370,7 +384,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(CriticalityProcessed) + if(CriticalityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CriticalityProcessed) + } `) if err == nil && criticalityResult.String() != "undefined" { s.Criticality = []byte(criticalityResult.String()) @@ -380,7 +399,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Identifier @@ -420,7 +444,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -462,7 +491,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -472,7 +506,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw if err == nil && lastDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastDateResult.String()) if err == nil { - s.LastDate = t + s.LastDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastDateResult.String()) + if err == nil { + s.LastDate = &d + } } } // extracting LastUpdated @@ -480,7 +519,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Manifestation @@ -520,7 +564,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(ManifestationProcessed) + if(ManifestationProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ManifestationProcessed) + } `) if err == nil && manifestationResult.String() != "undefined" { s.Manifestation = []byte(manifestationResult.String()) @@ -530,18 +579,21 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw if err == nil && onsetResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, onsetResult.String()) if err == nil { - s.Onset = t + s.Onset = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", onsetResult.String()) + if err == nil { + s.Onset = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Recorder recorderResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'AllergyIntolerance.recorder'))") if err == nil && recorderResult.String() != "undefined" { - s.Recorder = []byte(recorderResult.String()) } // extracting Route routeResult, err := vm.RunString(` @@ -580,7 +632,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(RouteProcessed) + if(RouteProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RouteProcessed) + } `) if err == nil && routeResult.String() != "undefined" { s.Route = []byte(routeResult.String()) @@ -622,7 +679,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(SeverityProcessed) + if(SeverityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SeverityProcessed) + } `) if err == nil && severityResult.String() != "undefined" { s.Severity = []byte(severityResult.String()) @@ -669,7 +731,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -711,7 +778,12 @@ func (s *FhirAllergyIntolerance) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(VerificationStatusProcessed) + if(VerificationStatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(VerificationStatusProcessed) + } `) if err == nil && verificationStatusResult.String() != "undefined" { s.VerificationStatus = []byte(verificationStatusResult.String()) diff --git a/backend/pkg/models/database/fhir_appointment.go b/backend/pkg/models/database/fhir_appointment.go index f4ff7fbea..785945834 100644 --- a/backend/pkg/models/database/fhir_appointment.go +++ b/backend/pkg/models/database/fhir_appointment.go @@ -25,7 +25,7 @@ type FhirAppointment struct { BasedOn datatypes.JSON `gorm:"column:basedOn;type:text;serializer:json" json:"basedOn,omitempty"` // Appointment date/time. // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // An Identifier of the Appointment // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -34,7 +34,7 @@ type FhirAppointment struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // This location is listed in the participants of the appointment // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` @@ -143,7 +143,6 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting Actor actorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Appointment.participant.actor'))") if err == nil && actorResult.String() != "undefined" { - s.Actor = []byte(actorResult.String()) } // extracting AppointmentType appointmentTypeResult, err := vm.RunString(` @@ -182,7 +181,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(AppointmentTypeProcessed) + if(AppointmentTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AppointmentTypeProcessed) + } `) if err == nil && appointmentTypeResult.String() != "undefined" { s.AppointmentType = []byte(appointmentTypeResult.String()) @@ -190,14 +194,18 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Appointment.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting Date dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Appointment.start')[0]") if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Identifier @@ -237,7 +245,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -279,7 +292,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -289,13 +307,17 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Appointment.participant.actor.where(resolve() is Location)'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting PartStatus partStatusResult, err := vm.RunString(` @@ -334,7 +356,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(PartStatusProcessed) + if(PartStatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PartStatusProcessed) + } `) if err == nil && partStatusResult.String() != "undefined" { s.PartStatus = []byte(partStatusResult.String()) @@ -342,12 +369,10 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting Practitioner practitionerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Appointment.participant.actor.where(resolve() is Practitioner)'))") if err == nil && practitionerResult.String() != "undefined" { - s.Practitioner = []byte(practitionerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting ReasonCode reasonCodeResult, err := vm.RunString(` @@ -386,7 +411,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ReasonCodeProcessed) + if(ReasonCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ReasonCodeProcessed) + } `) if err == nil && reasonCodeResult.String() != "undefined" { s.ReasonCode = []byte(reasonCodeResult.String()) @@ -394,7 +424,6 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting ReasonReference reasonReferenceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Appointment.reasonReference'))") if err == nil && reasonReferenceResult.String() != "undefined" { - s.ReasonReference = []byte(reasonReferenceResult.String()) } // extracting ServiceCategory serviceCategoryResult, err := vm.RunString(` @@ -433,7 +462,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ServiceCategoryProcessed) + if(ServiceCategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ServiceCategoryProcessed) + } `) if err == nil && serviceCategoryResult.String() != "undefined" { s.ServiceCategory = []byte(serviceCategoryResult.String()) @@ -475,7 +509,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ServiceTypeProcessed) + if(ServiceTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ServiceTypeProcessed) + } `) if err == nil && serviceTypeResult.String() != "undefined" { s.ServiceType = []byte(serviceTypeResult.String()) @@ -483,7 +522,6 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting Slot slotResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Appointment.slot'))") if err == nil && slotResult.String() != "undefined" { - s.Slot = []byte(slotResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -527,7 +565,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(SpecialtyProcessed) + if(SpecialtyProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SpecialtyProcessed) + } `) if err == nil && specialtyResult.String() != "undefined" { s.Specialty = []byte(specialtyResult.String()) @@ -569,7 +612,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -577,7 +625,6 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting SupportingInfo supportingInfoResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Appointment.supportingInformation'))") if err == nil && supportingInfoResult.String() != "undefined" { - s.SupportingInfo = []byte(supportingInfoResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -616,7 +663,12 @@ func (s *FhirAppointment) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_binary.go b/backend/pkg/models/database/fhir_binary.go index da98cc9ef..1239d7fcc 100644 --- a/backend/pkg/models/database/fhir_binary.go +++ b/backend/pkg/models/database/fhir_binary.go @@ -19,7 +19,7 @@ type FhirBinary struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -113,7 +113,12 @@ func (s *FhirBinary) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -123,13 +128,17 @@ func (s *FhirBinary) PopulateAndExtractSearchParameters(resourceRaw json.RawMess if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -173,7 +182,12 @@ func (s *FhirBinary) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_care_plan.go b/backend/pkg/models/database/fhir_care_plan.go index 6d181be23..7d3d5fd61 100644 --- a/backend/pkg/models/database/fhir_care_plan.go +++ b/backend/pkg/models/database/fhir_care_plan.go @@ -19,7 +19,7 @@ type FhirCarePlan struct { ActivityCode datatypes.JSON `gorm:"column:activityCode;type:text;serializer:json" json:"activityCode,omitempty"` // Specified date occurs within period specified by CarePlan.activity.detail.scheduled[x] // https://hl7.org/fhir/r4/search.html#date - ActivityDate time.Time `gorm:"column:activityDate;type:datetime" json:"activityDate,omitempty"` + ActivityDate *time.Time `gorm:"column:activityDate;type:datetime" json:"activityDate,omitempty"` // Activity details defined in specific resource // https://hl7.org/fhir/r4/search.html#reference ActivityReference datatypes.JSON `gorm:"column:activityReference;type:text;serializer:json" json:"activityReference,omitempty"` @@ -57,7 +57,7 @@ type FhirCarePlan struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // Encounter created as part of // https://hl7.org/fhir/r4/search.html#reference Encounter datatypes.JSON `gorm:"column:encounter;type:text;serializer:json" json:"encounter,omitempty"` @@ -114,7 +114,7 @@ type FhirCarePlan struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Part of referenced CarePlan // https://hl7.org/fhir/r4/search.html#reference PartOf datatypes.JSON `gorm:"column:partOf;type:text;serializer:json" json:"partOf,omitempty"` @@ -242,7 +242,12 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(ActivityCodeProcessed) + if(ActivityCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActivityCodeProcessed) + } `) if err == nil && activityCodeResult.String() != "undefined" { s.ActivityCode = []byte(activityCodeResult.String()) @@ -252,23 +257,25 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && activityDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, activityDateResult.String()) if err == nil { - s.ActivityDate = t + s.ActivityDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", activityDateResult.String()) + if err == nil { + s.ActivityDate = &d + } } } // extracting ActivityReference activityReferenceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.activity.reference'))") if err == nil && activityReferenceResult.String() != "undefined" { - s.ActivityReference = []byte(activityReferenceResult.String()) } // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting CareTeam careTeamResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.careTeam'))") if err == nil && careTeamResult.String() != "undefined" { - s.CareTeam = []byte(careTeamResult.String()) } // extracting Category categoryResult, err := vm.RunString(` @@ -307,7 +314,12 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -315,25 +327,27 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Condition conditionResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.addresses'))") if err == nil && conditionResult.String() != "undefined" { - s.Condition = []byte(conditionResult.String()) } // extracting Date dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'AllergyIntolerance.recordedDate | CarePlan.period | CareTeam.period | ClinicalImpression.date | Composition.date | Consent.dateTime | DiagnosticReport.effective | Encounter.period | EpisodeOfCare.period | FamilyMemberHistory.date | Flag.period | (Immunization.occurrenceDateTime) | List.date | Observation.effective | Procedure.performed | (RiskAssessment.occurrenceDateTime) | SupplyRequest.authoredOn')[0]") if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Goal goalResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.goal'))") if err == nil && goalResult.String() != "undefined" { - s.Goal = []byte(goalResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -372,7 +386,12 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -380,7 +399,6 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting InstantiatesCanonical instantiatesCanonicalResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.instantiatesCanonical'))") if err == nil && instantiatesCanonicalResult.String() != "undefined" { - s.InstantiatesCanonical = []byte(instantiatesCanonicalResult.String()) } // extracting InstantiatesUri instantiatesUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'CarePlan.instantiatesUri')[0]") @@ -424,7 +442,12 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(IntentProcessed) + if(IntentProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IntentProcessed) + } `) if err == nil && intentResult.String() != "undefined" { s.Intent = []byte(intentResult.String()) @@ -466,7 +489,12 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -476,28 +504,29 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting PartOf partOfResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.partOf'))") if err == nil && partOfResult.String() != "undefined" { - s.PartOf = []byte(partOfResult.String()) } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.activity.detail.performer'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Replaces replacesResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.replaces'))") if err == nil && replacesResult.String() != "undefined" { - s.Replaces = []byte(replacesResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -541,7 +570,12 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -549,7 +583,6 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CarePlan.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -588,7 +621,12 @@ func (s *FhirCarePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_care_team.go b/backend/pkg/models/database/fhir_care_team.go index fa233eee6..228cec426 100644 --- a/backend/pkg/models/database/fhir_care_team.go +++ b/backend/pkg/models/database/fhir_care_team.go @@ -39,7 +39,7 @@ type FhirCareTeam struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // Encounter created as part of // https://hl7.org/fhir/r4/search.html#reference Encounter datatypes.JSON `gorm:"column:encounter;type:text;serializer:json" json:"encounter,omitempty"` @@ -84,7 +84,7 @@ type FhirCareTeam struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Who is involved // https://hl7.org/fhir/r4/search.html#reference Participant datatypes.JSON `gorm:"column:participant;type:text;serializer:json" json:"participant,omitempty"` @@ -194,7 +194,12 @@ func (s *FhirCareTeam) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -204,13 +209,17 @@ func (s *FhirCareTeam) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CareTeam.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -249,7 +258,12 @@ func (s *FhirCareTeam) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -291,7 +305,12 @@ func (s *FhirCareTeam) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -301,18 +320,21 @@ func (s *FhirCareTeam) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Participant participantResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CareTeam.participant.member'))") if err == nil && participantResult.String() != "undefined" { - s.Participant = []byte(participantResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -356,7 +378,12 @@ func (s *FhirCareTeam) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -364,7 +391,6 @@ func (s *FhirCareTeam) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CareTeam.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -403,7 +429,12 @@ func (s *FhirCareTeam) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_claim.go b/backend/pkg/models/database/fhir_claim.go index fb63f1f4d..6a77fb4e0 100644 --- a/backend/pkg/models/database/fhir_claim.go +++ b/backend/pkg/models/database/fhir_claim.go @@ -19,7 +19,7 @@ type FhirClaim struct { CareTeam datatypes.JSON `gorm:"column:careTeam;type:text;serializer:json" json:"careTeam,omitempty"` // The creation date for the Claim // https://hl7.org/fhir/r4/search.html#date - Created time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` + Created *time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` // UDI associated with a line item, detail product or service // https://hl7.org/fhir/r4/search.html#reference DetailUdi datatypes.JSON `gorm:"column:detailUdi;type:text;serializer:json" json:"detailUdi,omitempty"` @@ -46,7 +46,7 @@ type FhirClaim struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The party receiving any payment for the Claim // https://hl7.org/fhir/r4/search.html#reference Payee datatypes.JSON `gorm:"column:payee;type:text;serializer:json" json:"payee,omitempty"` @@ -143,35 +143,35 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa // extracting CareTeam careTeamResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.careTeam.provider'))") if err == nil && careTeamResult.String() != "undefined" { - s.CareTeam = []byte(careTeamResult.String()) } // extracting Created createdResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Claim.created')[0]") if err == nil && createdResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, createdResult.String()) if err == nil { - s.Created = t + s.Created = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", createdResult.String()) + if err == nil { + s.Created = &d + } } } // extracting DetailUdi detailUdiResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.item.detail.udi'))") if err == nil && detailUdiResult.String() != "undefined" { - s.DetailUdi = []byte(detailUdiResult.String()) } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.item.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Enterer entererResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.enterer'))") if err == nil && entererResult.String() != "undefined" { - s.Enterer = []byte(entererResult.String()) } // extracting Facility facilityResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.facility'))") if err == nil && facilityResult.String() != "undefined" { - s.Facility = []byte(facilityResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -210,7 +210,12 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -218,12 +223,10 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa // extracting Insurer insurerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.insurer'))") if err == nil && insurerResult.String() != "undefined" { - s.Insurer = []byte(insurerResult.String()) } // extracting ItemUdi itemUdiResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.item.udi'))") if err == nil && itemUdiResult.String() != "undefined" { - s.ItemUdi = []byte(itemUdiResult.String()) } // extracting Language languageResult, err := vm.RunString(` @@ -262,7 +265,12 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -272,13 +280,17 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Payee payeeResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.payee.party'))") if err == nil && payeeResult.String() != "undefined" { - s.Payee = []byte(payeeResult.String()) } // extracting Priority priorityResult, err := vm.RunString(` @@ -317,7 +329,12 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(PriorityProcessed) + if(PriorityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PriorityProcessed) + } `) if err == nil && priorityResult.String() != "undefined" { s.Priority = []byte(priorityResult.String()) @@ -325,17 +342,14 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa // extracting ProcedureUdi procedureUdiResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.procedure.udi'))") if err == nil && procedureUdiResult.String() != "undefined" { - s.ProcedureUdi = []byte(procedureUdiResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Provider providerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.provider'))") if err == nil && providerResult.String() != "undefined" { - s.Provider = []byte(providerResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -379,7 +393,12 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -387,7 +406,6 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa // extracting SubdetailUdi subdetailUdiResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Claim.item.detail.subDetail.udi'))") if err == nil && subdetailUdiResult.String() != "undefined" { - s.SubdetailUdi = []byte(subdetailUdiResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -426,7 +444,12 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -468,7 +491,12 @@ func (s *FhirClaim) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(UseProcessed) + if(UseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(UseProcessed) + } `) if err == nil && useResult.String() != "undefined" { s.Use = []byte(useResult.String()) diff --git a/backend/pkg/models/database/fhir_claim_response.go b/backend/pkg/models/database/fhir_claim_response.go index ae3dca7cd..0472753b5 100644 --- a/backend/pkg/models/database/fhir_claim_response.go +++ b/backend/pkg/models/database/fhir_claim_response.go @@ -16,7 +16,7 @@ type FhirClaimResponse struct { models.ResourceBase // The creation date // https://hl7.org/fhir/r4/search.html#date - Created time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` + Created *time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` // The contents of the disposition message // https://hl7.org/fhir/r4/search.html#string Disposition datatypes.JSON `gorm:"column:disposition;type:text;serializer:json" json:"disposition,omitempty"` @@ -31,13 +31,13 @@ type FhirClaimResponse struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The processing outcome // https://hl7.org/fhir/r4/search.html#token Outcome datatypes.JSON `gorm:"column:outcome;type:text;serializer:json" json:"outcome,omitempty"` // The expected payment date // https://hl7.org/fhir/r4/search.html#date - PaymentDate time.Time `gorm:"column:paymentDate;type:datetime" json:"paymentDate,omitempty"` + PaymentDate *time.Time `gorm:"column:paymentDate;type:datetime" json:"paymentDate,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -121,7 +121,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && createdResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, createdResult.String()) if err == nil { - s.Created = t + s.Created = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", createdResult.String()) + if err == nil { + s.Created = &d + } } } // extracting Disposition @@ -173,8 +178,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(DispositionProcessed) + if(DispositionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DispositionProcessed) + } `) if err == nil && dispositionResult.String() != "undefined" { s.Disposition = []byte(dispositionResult.String()) @@ -216,7 +225,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -224,7 +238,6 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. // extracting Insurer insurerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ClaimResponse.insurer'))") if err == nil && insurerResult.String() != "undefined" { - s.Insurer = []byte(insurerResult.String()) } // extracting Language languageResult, err := vm.RunString(` @@ -263,7 +276,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -273,7 +291,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Outcome @@ -313,7 +336,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(OutcomeProcessed) + if(OutcomeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(OutcomeProcessed) + } `) if err == nil && outcomeResult.String() != "undefined" { s.Outcome = []byte(outcomeResult.String()) @@ -323,23 +351,25 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && paymentDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, paymentDateResult.String()) if err == nil { - s.PaymentDate = t + s.PaymentDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", paymentDateResult.String()) + if err == nil { + s.PaymentDate = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Request requestResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ClaimResponse.request'))") if err == nil && requestResult.String() != "undefined" { - s.Request = []byte(requestResult.String()) } // extracting Requestor requestorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ClaimResponse.requestor'))") if err == nil && requestorResult.String() != "undefined" { - s.Requestor = []byte(requestorResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -383,7 +413,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -425,7 +460,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -467,7 +507,12 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(UseProcessed) + if(UseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(UseProcessed) + } `) if err == nil && useResult.String() != "undefined" { s.Use = []byte(useResult.String()) diff --git a/backend/pkg/models/database/fhir_composition.go b/backend/pkg/models/database/fhir_composition.go index 32a6fa519..2bbade2a9 100644 --- a/backend/pkg/models/database/fhir_composition.go +++ b/backend/pkg/models/database/fhir_composition.go @@ -51,7 +51,7 @@ type FhirComposition struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -114,10 +114,10 @@ type FhirComposition struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The period covered by the documentation // https://hl7.org/fhir/r4/search.html#date - Period time.Time `gorm:"column:period;type:datetime" json:"period,omitempty"` + Period *time.Time `gorm:"column:period;type:datetime" json:"period,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -211,12 +211,10 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting Attester attesterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.attester.party'))") if err == nil && attesterResult.String() != "undefined" { - s.Attester = []byte(attesterResult.String()) } // extracting Author authorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.author'))") if err == nil && authorResult.String() != "undefined" { - s.Author = []byte(authorResult.String()) } // extracting Category categoryResult, err := vm.RunString(` @@ -255,7 +253,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -297,7 +300,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ConfidentialityProcessed) + if(ConfidentialityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ConfidentialityProcessed) + } `) if err == nil && confidentialityResult.String() != "undefined" { s.Confidentiality = []byte(confidentialityResult.String()) @@ -339,7 +347,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ContextProcessed) + if(ContextProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ContextProcessed) + } `) if err == nil && contextResult.String() != "undefined" { s.Context = []byte(contextResult.String()) @@ -349,18 +362,21 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Entry entryResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.section.entry'))") if err == nil && entryResult.String() != "undefined" { - s.Entry = []byte(entryResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -399,7 +415,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -441,7 +462,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -451,7 +477,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Period @@ -459,13 +490,17 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra if err == nil && periodResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, periodResult.String()) if err == nil { - s.Period = t + s.Period = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", periodResult.String()) + if err == nil { + s.Period = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting RelatedId relatedIdResult, err := vm.RunString(` @@ -504,7 +539,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(RelatedIdProcessed) + if(RelatedIdProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RelatedIdProcessed) + } `) if err == nil && relatedIdResult.String() != "undefined" { s.RelatedId = []byte(relatedIdResult.String()) @@ -512,7 +552,6 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting RelatedRef relatedRefResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, '(Composition.relatesTo.targetReference)'))") if err == nil && relatedRefResult.String() != "undefined" { - s.RelatedRef = []byte(relatedRefResult.String()) } // extracting Section sectionResult, err := vm.RunString(` @@ -551,7 +590,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(SectionProcessed) + if(SectionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SectionProcessed) + } `) if err == nil && sectionResult.String() != "undefined" { s.Section = []byte(sectionResult.String()) @@ -598,7 +642,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -606,7 +655,6 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -645,7 +693,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -699,8 +752,12 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra return accumulator }, []) - - JSON.stringify(TitleProcessed) + if(TitleProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TitleProcessed) + } `) if err == nil && titleResult.String() != "undefined" { s.Title = []byte(titleResult.String()) diff --git a/backend/pkg/models/database/fhir_condition.go b/backend/pkg/models/database/fhir_condition.go index 754872db9..8f13d674d 100644 --- a/backend/pkg/models/database/fhir_condition.go +++ b/backend/pkg/models/database/fhir_condition.go @@ -19,7 +19,7 @@ type FhirCondition struct { AbatementAge datatypes.JSON `gorm:"column:abatementAge;type:text;serializer:json" json:"abatementAge,omitempty"` // Date-related abatements (dateTime and period) // https://hl7.org/fhir/r4/search.html#date - AbatementDate time.Time `gorm:"column:abatementDate;type:datetime" json:"abatementDate,omitempty"` + AbatementDate *time.Time `gorm:"column:abatementDate;type:datetime" json:"abatementDate,omitempty"` // Abatement as a string // https://hl7.org/fhir/r4/search.html#string AbatementString datatypes.JSON `gorm:"column:abatementString;type:text;serializer:json" json:"abatementString,omitempty"` @@ -105,13 +105,13 @@ type FhirCondition struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Onsets as age or age range // https://hl7.org/fhir/r4/search.html#quantity OnsetAge datatypes.JSON `gorm:"column:onsetAge;type:text;serializer:json" json:"onsetAge,omitempty"` // Date related onsets (dateTime and Period) // https://hl7.org/fhir/r4/search.html#date - OnsetDate time.Time `gorm:"column:onsetDate;type:datetime" json:"onsetDate,omitempty"` + OnsetDate *time.Time `gorm:"column:onsetDate;type:datetime" json:"onsetDate,omitempty"` // Onsets as a string // https://hl7.org/fhir/r4/search.html#string OnsetInfo datatypes.JSON `gorm:"column:onsetInfo;type:text;serializer:json" json:"onsetInfo,omitempty"` @@ -120,7 +120,7 @@ type FhirCondition struct { Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` // Date record was first recorded // https://hl7.org/fhir/r4/search.html#date - RecordedDate time.Time `gorm:"column:recordedDate;type:datetime" json:"recordedDate,omitempty"` + RecordedDate *time.Time `gorm:"column:recordedDate;type:datetime" json:"recordedDate,omitempty"` // The severity of the condition // https://hl7.org/fhir/r4/search.html#token Severity datatypes.JSON `gorm:"column:severity;type:text;serializer:json" json:"severity,omitempty"` @@ -216,7 +216,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM if err == nil && abatementDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, abatementDateResult.String()) if err == nil { - s.AbatementDate = t + s.AbatementDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", abatementDateResult.String()) + if err == nil { + s.AbatementDate = &d + } } } // extracting AbatementString @@ -268,8 +273,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM return accumulator }, []) - - JSON.stringify(AbatementStringProcessed) + if(AbatementStringProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AbatementStringProcessed) + } `) if err == nil && abatementStringResult.String() != "undefined" { s.AbatementString = []byte(abatementStringResult.String()) @@ -277,7 +286,6 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Asserter asserterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Condition.asserter'))") if err == nil && asserterResult.String() != "undefined" { - s.Asserter = []byte(asserterResult.String()) } // extracting BodySite bodySiteResult, err := vm.RunString(` @@ -316,7 +324,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(BodySiteProcessed) + if(BodySiteProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(BodySiteProcessed) + } `) if err == nil && bodySiteResult.String() != "undefined" { s.BodySite = []byte(bodySiteResult.String()) @@ -358,7 +371,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -400,7 +418,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(ClinicalStatusProcessed) + if(ClinicalStatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ClinicalStatusProcessed) + } `) if err == nil && clinicalStatusResult.String() != "undefined" { s.ClinicalStatus = []byte(clinicalStatusResult.String()) @@ -442,7 +465,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -450,7 +478,6 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Condition.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Evidence evidenceResult, err := vm.RunString(` @@ -489,7 +516,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(EvidenceProcessed) + if(EvidenceProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EvidenceProcessed) + } `) if err == nil && evidenceResult.String() != "undefined" { s.Evidence = []byte(evidenceResult.String()) @@ -497,7 +529,6 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting EvidenceDetail evidenceDetailResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Condition.evidence.detail'))") if err == nil && evidenceDetailResult.String() != "undefined" { - s.EvidenceDetail = []byte(evidenceDetailResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -536,7 +567,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -578,7 +614,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -588,7 +629,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting OnsetAge @@ -601,7 +647,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM if err == nil && onsetDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, onsetDateResult.String()) if err == nil { - s.OnsetDate = t + s.OnsetDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", onsetDateResult.String()) + if err == nil { + s.OnsetDate = &d + } } } // extracting OnsetInfo @@ -653,8 +704,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM return accumulator }, []) - - JSON.stringify(OnsetInfoProcessed) + if(OnsetInfoProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(OnsetInfoProcessed) + } `) if err == nil && onsetInfoResult.String() != "undefined" { s.OnsetInfo = []byte(onsetInfoResult.String()) @@ -662,14 +717,18 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting RecordedDate recordedDateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Condition.recordedDate')[0]") if err == nil && recordedDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, recordedDateResult.String()) if err == nil { - s.RecordedDate = t + s.RecordedDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", recordedDateResult.String()) + if err == nil { + s.RecordedDate = &d + } } } // extracting Severity @@ -709,7 +768,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(SeverityProcessed) + if(SeverityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SeverityProcessed) + } `) if err == nil && severityResult.String() != "undefined" { s.Severity = []byte(severityResult.String()) @@ -756,7 +820,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(StageProcessed) + if(StageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StageProcessed) + } `) if err == nil && stageResult.String() != "undefined" { s.Stage = []byte(stageResult.String()) @@ -764,7 +833,6 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Condition.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -803,7 +871,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -845,7 +918,12 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(VerificationStatusProcessed) + if(VerificationStatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(VerificationStatusProcessed) + } `) if err == nil && verificationStatusResult.String() != "undefined" { s.VerificationStatus = []byte(verificationStatusResult.String()) diff --git a/backend/pkg/models/database/fhir_consent.go b/backend/pkg/models/database/fhir_consent.go index d7f6b9dd2..85bff1090 100644 --- a/backend/pkg/models/database/fhir_consent.go +++ b/backend/pkg/models/database/fhir_consent.go @@ -51,7 +51,7 @@ type FhirConsent struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -93,13 +93,13 @@ type FhirConsent struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Custodian of the consent // https://hl7.org/fhir/r4/search.html#reference Organization datatypes.JSON `gorm:"column:organization;type:text;serializer:json" json:"organization,omitempty"` // Timeframe for this rule // https://hl7.org/fhir/r4/search.html#date - Period time.Time `gorm:"column:period;type:datetime" json:"period,omitempty"` + Period *time.Time `gorm:"column:period;type:datetime" json:"period,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -222,7 +222,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(ActionProcessed) + if(ActionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActionProcessed) + } `) if err == nil && actionResult.String() != "undefined" { s.Action = []byte(actionResult.String()) @@ -230,7 +235,6 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes // extracting Actor actorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.provision.actor.reference'))") if err == nil && actorResult.String() != "undefined" { - s.Actor = []byte(actorResult.String()) } // extracting Category categoryResult, err := vm.RunString(` @@ -269,7 +273,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -277,19 +286,22 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes // extracting Consentor consentorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.performer'))") if err == nil && consentorResult.String() != "undefined" { - s.Consentor = []byte(consentorResult.String()) } // extracting Data dataResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.provision.data.reference'))") if err == nil && dataResult.String() != "undefined" { - s.Data = []byte(dataResult.String()) } // extracting Date dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'AllergyIntolerance.recordedDate | CarePlan.period | CareTeam.period | ClinicalImpression.date | Composition.date | Consent.dateTime | DiagnosticReport.effective | Encounter.period | EpisodeOfCare.period | FamilyMemberHistory.date | Flag.period | (Immunization.occurrenceDateTime) | List.date | Observation.effective | Procedure.performed | (RiskAssessment.occurrenceDateTime) | SupplyRequest.authoredOn')[0]") if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Identifier @@ -329,7 +341,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -371,7 +388,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -381,26 +403,34 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.organization'))") if err == nil && organizationResult.String() != "undefined" { - s.Organization = []byte(organizationResult.String()) } // extracting Period periodResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Consent.provision.period')[0]") if err == nil && periodResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, periodResult.String()) if err == nil { - s.Period = t + s.Period = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", periodResult.String()) + if err == nil { + s.Period = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Purpose purposeResult, err := vm.RunString(` @@ -439,7 +469,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(PurposeProcessed) + if(PurposeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PurposeProcessed) + } `) if err == nil && purposeResult.String() != "undefined" { s.Purpose = []byte(purposeResult.String()) @@ -481,7 +516,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(ScopeProcessed) + if(ScopeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ScopeProcessed) + } `) if err == nil && scopeResult.String() != "undefined" { s.Scope = []byte(scopeResult.String()) @@ -523,7 +563,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(SecurityLabelProcessed) + if(SecurityLabelProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SecurityLabelProcessed) + } `) if err == nil && securityLabelResult.String() != "undefined" { s.SecurityLabel = []byte(securityLabelResult.String()) @@ -531,7 +576,6 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes // extracting SourceReference sourceReferenceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.source'))") if err == nil && sourceReferenceResult.String() != "undefined" { - s.SourceReference = []byte(sourceReferenceResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -575,7 +619,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -617,7 +666,12 @@ func (s *FhirConsent) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_coverage.go b/backend/pkg/models/database/fhir_coverage.go index 2278031b3..11527e677 100644 --- a/backend/pkg/models/database/fhir_coverage.go +++ b/backend/pkg/models/database/fhir_coverage.go @@ -34,7 +34,7 @@ type FhirCoverage struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The identity of the insurer or party paying for services // https://hl7.org/fhir/r4/search.html#reference Payor datatypes.JSON `gorm:"column:payor;type:text;serializer:json" json:"payor,omitempty"` @@ -115,7 +115,6 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Beneficiary beneficiaryResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Coverage.beneficiary'))") if err == nil && beneficiaryResult.String() != "undefined" { - s.Beneficiary = []byte(beneficiaryResult.String()) } // extracting ClassType classTypeResult, err := vm.RunString(` @@ -154,7 +153,12 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(ClassTypeProcessed) + if(ClassTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ClassTypeProcessed) + } `) if err == nil && classTypeResult.String() != "undefined" { s.ClassType = []byte(classTypeResult.String()) @@ -208,8 +212,12 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(ClassValueProcessed) + if(ClassValueProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ClassValueProcessed) + } `) if err == nil && classValueResult.String() != "undefined" { s.ClassValue = []byte(classValueResult.String()) @@ -263,8 +271,12 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(DependentProcessed) + if(DependentProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DependentProcessed) + } `) if err == nil && dependentResult.String() != "undefined" { s.Dependent = []byte(dependentResult.String()) @@ -306,7 +318,12 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -348,7 +365,12 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -358,23 +380,25 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Payor payorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Coverage.payor'))") if err == nil && payorResult.String() != "undefined" { - s.Payor = []byte(payorResult.String()) } // extracting PolicyHolder policyHolderResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Coverage.policyHolder'))") if err == nil && policyHolderResult.String() != "undefined" { - s.PolicyHolder = []byte(policyHolderResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -418,7 +442,12 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -426,7 +455,6 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Subscriber subscriberResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Coverage.subscriber'))") if err == nil && subscriberResult.String() != "undefined" { - s.Subscriber = []byte(subscriberResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -465,7 +493,12 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_coverage_eligibility_request.go b/backend/pkg/models/database/fhir_coverage_eligibility_request.go index 485508a2c..0e081ff4c 100644 --- a/backend/pkg/models/database/fhir_coverage_eligibility_request.go +++ b/backend/pkg/models/database/fhir_coverage_eligibility_request.go @@ -16,7 +16,7 @@ type FhirCoverageEligibilityRequest struct { models.ResourceBase // The creation date for the EOB // https://hl7.org/fhir/r4/search.html#date - Created time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` + Created *time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` // The party who is responsible for the request // https://hl7.org/fhir/r4/search.html#reference Enterer datatypes.JSON `gorm:"column:enterer;type:text;serializer:json" json:"enterer,omitempty"` @@ -31,7 +31,7 @@ type FhirCoverageEligibilityRequest struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -105,18 +105,21 @@ func (s *FhirCoverageEligibilityRequest) PopulateAndExtractSearchParameters(reso if err == nil && createdResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, createdResult.String()) if err == nil { - s.Created = t + s.Created = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", createdResult.String()) + if err == nil { + s.Created = &d + } } } // extracting Enterer entererResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CoverageEligibilityRequest.enterer'))") if err == nil && entererResult.String() != "undefined" { - s.Enterer = []byte(entererResult.String()) } // extracting Facility facilityResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CoverageEligibilityRequest.facility'))") if err == nil && facilityResult.String() != "undefined" { - s.Facility = []byte(facilityResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -155,7 +158,12 @@ func (s *FhirCoverageEligibilityRequest) PopulateAndExtractSearchParameters(reso }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -197,7 +205,12 @@ func (s *FhirCoverageEligibilityRequest) PopulateAndExtractSearchParameters(reso }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -207,18 +220,21 @@ func (s *FhirCoverageEligibilityRequest) PopulateAndExtractSearchParameters(reso if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Provider providerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CoverageEligibilityRequest.provider'))") if err == nil && providerResult.String() != "undefined" { - s.Provider = []byte(providerResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -262,7 +278,12 @@ func (s *FhirCoverageEligibilityRequest) PopulateAndExtractSearchParameters(reso }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -304,7 +325,12 @@ func (s *FhirCoverageEligibilityRequest) PopulateAndExtractSearchParameters(reso }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_coverage_eligibility_response.go b/backend/pkg/models/database/fhir_coverage_eligibility_response.go index 8a5e45dfa..3a614818b 100644 --- a/backend/pkg/models/database/fhir_coverage_eligibility_response.go +++ b/backend/pkg/models/database/fhir_coverage_eligibility_response.go @@ -16,7 +16,7 @@ type FhirCoverageEligibilityResponse struct { models.ResourceBase // The creation date // https://hl7.org/fhir/r4/search.html#date - Created time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` + Created *time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` // The contents of the disposition message // https://hl7.org/fhir/r4/search.html#string Disposition datatypes.JSON `gorm:"column:disposition;type:text;serializer:json" json:"disposition,omitempty"` @@ -31,7 +31,7 @@ type FhirCoverageEligibilityResponse struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The processing outcome // https://hl7.org/fhir/r4/search.html#token Outcome datatypes.JSON `gorm:"column:outcome;type:text;serializer:json" json:"outcome,omitempty"` @@ -113,7 +113,12 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res if err == nil && createdResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, createdResult.String()) if err == nil { - s.Created = t + s.Created = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", createdResult.String()) + if err == nil { + s.Created = &d + } } } // extracting Disposition @@ -165,8 +170,12 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res return accumulator }, []) - - JSON.stringify(DispositionProcessed) + if(DispositionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DispositionProcessed) + } `) if err == nil && dispositionResult.String() != "undefined" { s.Disposition = []byte(dispositionResult.String()) @@ -208,7 +217,12 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -216,7 +230,6 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res // extracting Insurer insurerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CoverageEligibilityResponse.insurer'))") if err == nil && insurerResult.String() != "undefined" { - s.Insurer = []byte(insurerResult.String()) } // extracting Language languageResult, err := vm.RunString(` @@ -255,7 +268,12 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -265,7 +283,12 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Outcome @@ -305,7 +328,12 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res }, []) - JSON.stringify(OutcomeProcessed) + if(OutcomeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(OutcomeProcessed) + } `) if err == nil && outcomeResult.String() != "undefined" { s.Outcome = []byte(outcomeResult.String()) @@ -313,17 +341,14 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Request requestResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CoverageEligibilityResponse.request'))") if err == nil && requestResult.String() != "undefined" { - s.Request = []byte(requestResult.String()) } // extracting Requestor requestorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'CoverageEligibilityResponse.requestor'))") if err == nil && requestorResult.String() != "undefined" { - s.Requestor = []byte(requestorResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -367,7 +392,12 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -409,7 +439,12 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_device.go b/backend/pkg/models/database/fhir_device.go index 4e30b5d7f..582c9a65b 100644 --- a/backend/pkg/models/database/fhir_device.go +++ b/backend/pkg/models/database/fhir_device.go @@ -25,7 +25,7 @@ type FhirDevice struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // A location, where the resource is found // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` @@ -165,8 +165,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(DeviceNameProcessed) + if(DeviceNameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DeviceNameProcessed) + } `) if err == nil && deviceNameResult.String() != "undefined" { s.DeviceName = []byte(deviceNameResult.String()) @@ -208,7 +212,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -250,7 +259,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -260,13 +274,17 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Device.location'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting Manufacturer manufacturerResult, err := vm.RunString(` @@ -317,8 +335,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(ManufacturerProcessed) + if(ManufacturerProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ManufacturerProcessed) + } `) if err == nil && manufacturerResult.String() != "undefined" { s.Manufacturer = []byte(manufacturerResult.String()) @@ -372,8 +394,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(ModelProcessed) + if(ModelProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ModelProcessed) + } `) if err == nil && modelResult.String() != "undefined" { s.Model = []byte(modelResult.String()) @@ -381,12 +407,10 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Device.owner'))") if err == nil && organizationResult.String() != "undefined" { - s.Organization = []byte(organizationResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -430,7 +454,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -472,7 +501,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -526,8 +560,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(UdiCarrierProcessed) + if(UdiCarrierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(UdiCarrierProcessed) + } `) if err == nil && udiCarrierResult.String() != "undefined" { s.UdiCarrier = []byte(udiCarrierResult.String()) @@ -581,8 +619,12 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(UdiDiProcessed) + if(UdiDiProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(UdiDiProcessed) + } `) if err == nil && udiDiResult.String() != "undefined" { s.UdiDi = []byte(udiDiResult.String()) diff --git a/backend/pkg/models/database/fhir_device_request.go b/backend/pkg/models/database/fhir_device_request.go index 6560e7808..cb6321a89 100644 --- a/backend/pkg/models/database/fhir_device_request.go +++ b/backend/pkg/models/database/fhir_device_request.go @@ -16,7 +16,7 @@ type FhirDeviceRequest struct { models.ResourceBase // When the request transitioned to being actionable // https://hl7.org/fhir/r4/search.html#date - AuthoredOn time.Time `gorm:"column:authoredOn;type:datetime" json:"authoredOn,omitempty"` + AuthoredOn *time.Time `gorm:"column:authoredOn;type:datetime" json:"authoredOn,omitempty"` // Plan/proposal/order fulfilled by this request // https://hl7.org/fhir/r4/search.html#reference BasedOn datatypes.JSON `gorm:"column:basedOn;type:text;serializer:json" json:"basedOn,omitempty"` @@ -63,7 +63,7 @@ type FhirDeviceRequest struct { Encounter datatypes.JSON `gorm:"column:encounter;type:text;serializer:json" json:"encounter,omitempty"` // When service should occur // https://hl7.org/fhir/r4/search.html#date - EventDate time.Time `gorm:"column:eventDate;type:datetime" json:"eventDate,omitempty"` + EventDate *time.Time `gorm:"column:eventDate;type:datetime" json:"eventDate,omitempty"` // Composite request this is part of // https://hl7.org/fhir/r4/search.html#token GroupIdentifier datatypes.JSON `gorm:"column:groupIdentifier;type:text;serializer:json" json:"groupIdentifier,omitempty"` @@ -120,7 +120,7 @@ type FhirDeviceRequest struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Desired performer for service // https://hl7.org/fhir/r4/search.html#reference Performer datatypes.JSON `gorm:"column:performer;type:text;serializer:json" json:"performer,omitempty"` @@ -214,13 +214,17 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && authoredOnResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, authoredOnResult.String()) if err == nil { - s.AuthoredOn = t + s.AuthoredOn = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", authoredOnResult.String()) + if err == nil { + s.AuthoredOn = &d + } } } // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DeviceRequest.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting Code codeResult, err := vm.RunString(` @@ -259,7 +263,12 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -267,19 +276,22 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. // extracting Device deviceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, '(DeviceRequest.codeReference)'))") if err == nil && deviceResult.String() != "undefined" { - s.Device = []byte(deviceResult.String()) } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting EventDate eventDateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, '(DeviceRequest.occurrenceDateTime) | (DeviceRequest.occurrencePeriod)')[0]") if err == nil && eventDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, eventDateResult.String()) if err == nil { - s.EventDate = t + s.EventDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", eventDateResult.String()) + if err == nil { + s.EventDate = &d + } } } // extracting GroupIdentifier @@ -319,7 +331,12 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(GroupIdentifierProcessed) + if(GroupIdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(GroupIdentifierProcessed) + } `) if err == nil && groupIdentifierResult.String() != "undefined" { s.GroupIdentifier = []byte(groupIdentifierResult.String()) @@ -361,7 +378,12 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -369,7 +391,6 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. // extracting InstantiatesCanonical instantiatesCanonicalResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DeviceRequest.instantiatesCanonical'))") if err == nil && instantiatesCanonicalResult.String() != "undefined" { - s.InstantiatesCanonical = []byte(instantiatesCanonicalResult.String()) } // extracting InstantiatesUri instantiatesUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'DeviceRequest.instantiatesUri')[0]") @@ -379,7 +400,6 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. // extracting Insurance insuranceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DeviceRequest.insurance'))") if err == nil && insuranceResult.String() != "undefined" { - s.Insurance = []byte(insuranceResult.String()) } // extracting Intent intentResult, err := vm.RunString(` @@ -418,7 +438,12 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(IntentProcessed) + if(IntentProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IntentProcessed) + } `) if err == nil && intentResult.String() != "undefined" { s.Intent = []byte(intentResult.String()) @@ -460,7 +485,12 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -470,28 +500,29 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DeviceRequest.performer'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting PriorRequest priorRequestResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DeviceRequest.priorRequest'))") if err == nil && priorRequestResult.String() != "undefined" { - s.PriorRequest = []byte(priorRequestResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Requester requesterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DeviceRequest.requester'))") if err == nil && requesterResult.String() != "undefined" { - s.Requester = []byte(requesterResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -535,7 +566,12 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -543,7 +579,6 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DeviceRequest.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -582,7 +617,12 @@ func (s *FhirDeviceRequest) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_diagnostic_report.go b/backend/pkg/models/database/fhir_diagnostic_report.go index 29a68e892..b6f261040 100644 --- a/backend/pkg/models/database/fhir_diagnostic_report.go +++ b/backend/pkg/models/database/fhir_diagnostic_report.go @@ -65,7 +65,7 @@ type FhirDiagnosticReport struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -122,13 +122,13 @@ type FhirDiagnosticReport struct { Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` // When the report was issued // https://hl7.org/fhir/r4/search.html#date - Issued time.Time `gorm:"column:issued;type:datetime" json:"issued,omitempty"` + Issued *time.Time `gorm:"column:issued;type:datetime" json:"issued,omitempty"` // Language of the resource content // https://hl7.org/fhir/r4/search.html#token Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // A reference to the image source. // https://hl7.org/fhir/r4/search.html#reference Media datatypes.JSON `gorm:"column:media;type:text;serializer:json" json:"media,omitempty"` @@ -224,7 +224,6 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DiagnosticReport.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting Category categoryResult, err := vm.RunString(` @@ -263,7 +262,12 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -305,7 +309,12 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -347,7 +356,12 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(ConclusionProcessed) + if(ConclusionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ConclusionProcessed) + } `) if err == nil && conclusionResult.String() != "undefined" { s.Conclusion = []byte(conclusionResult.String()) @@ -357,13 +371,17 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -402,7 +420,12 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -412,7 +435,12 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js if err == nil && issuedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, issuedResult.String()) if err == nil { - s.Issued = t + s.Issued = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", issuedResult.String()) + if err == nil { + s.Issued = &d + } } } // extracting Language @@ -452,7 +480,12 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -462,33 +495,33 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Media mediaResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DiagnosticReport.media.link'))") if err == nil && mediaResult.String() != "undefined" { - s.Media = []byte(mediaResult.String()) } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DiagnosticReport.performer'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Result resultResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DiagnosticReport.result'))") if err == nil && resultResult.String() != "undefined" { - s.Result = []byte(resultResult.String()) } // extracting ResultsInterpreter resultsInterpreterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DiagnosticReport.resultsInterpreter'))") if err == nil && resultsInterpreterResult.String() != "undefined" { - s.ResultsInterpreter = []byte(resultsInterpreterResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -498,7 +531,6 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js // extracting Specimen specimenResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DiagnosticReport.specimen'))") if err == nil && specimenResult.String() != "undefined" { - s.Specimen = []byte(specimenResult.String()) } // extracting Status statusResult, err := vm.RunString(` @@ -537,7 +569,12 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -545,7 +582,6 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DiagnosticReport.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -584,7 +620,12 @@ func (s *FhirDiagnosticReport) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_document_manifest.go b/backend/pkg/models/database/fhir_document_manifest.go index 089d13ee0..15d85c3a0 100644 --- a/backend/pkg/models/database/fhir_document_manifest.go +++ b/backend/pkg/models/database/fhir_document_manifest.go @@ -19,7 +19,7 @@ type FhirDocumentManifest struct { Author datatypes.JSON `gorm:"column:author;type:text;serializer:json" json:"author,omitempty"` // When this document manifest created // https://hl7.org/fhir/r4/search.html#date - Created time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` + Created *time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` // Human-readable description (title) // https://hl7.org/fhir/r4/search.html#string Description datatypes.JSON `gorm:"column:description;type:text;serializer:json" json:"description,omitempty"` @@ -67,7 +67,7 @@ type FhirDocumentManifest struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -156,14 +156,18 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js // extracting Author authorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentManifest.author'))") if err == nil && authorResult.String() != "undefined" { - s.Author = []byte(authorResult.String()) } // extracting Created createdResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'DocumentManifest.created')[0]") if err == nil && createdResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, createdResult.String()) if err == nil { - s.Created = t + s.Created = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", createdResult.String()) + if err == nil { + s.Created = &d + } } } // extracting Description @@ -215,8 +219,12 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js return accumulator }, []) - - JSON.stringify(DescriptionProcessed) + if(DescriptionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DescriptionProcessed) + } `) if err == nil && descriptionResult.String() != "undefined" { s.Description = []byte(descriptionResult.String()) @@ -258,7 +266,12 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -266,7 +279,6 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js // extracting Item itemResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentManifest.content'))") if err == nil && itemResult.String() != "undefined" { - s.Item = []byte(itemResult.String()) } // extracting Language languageResult, err := vm.RunString(` @@ -305,7 +317,12 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -315,18 +332,21 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Recipient recipientResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentManifest.recipient'))") if err == nil && recipientResult.String() != "undefined" { - s.Recipient = []byte(recipientResult.String()) } // extracting RelatedId relatedIdResult, err := vm.RunString(` @@ -365,7 +385,12 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(RelatedIdProcessed) + if(RelatedIdProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RelatedIdProcessed) + } `) if err == nil && relatedIdResult.String() != "undefined" { s.RelatedId = []byte(relatedIdResult.String()) @@ -373,7 +398,6 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js // extracting RelatedRef relatedRefResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentManifest.related.ref'))") if err == nil && relatedRefResult.String() != "undefined" { - s.RelatedRef = []byte(relatedRefResult.String()) } // extracting Source sourceResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'DocumentManifest.source')[0]") @@ -422,7 +446,12 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -430,7 +459,6 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentManifest.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -469,7 +497,12 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_document_reference.go b/backend/pkg/models/database/fhir_document_reference.go index 09a084654..3611f019a 100644 --- a/backend/pkg/models/database/fhir_document_reference.go +++ b/backend/pkg/models/database/fhir_document_reference.go @@ -31,7 +31,7 @@ type FhirDocumentReference struct { Custodian datatypes.JSON `gorm:"column:custodian;type:text;serializer:json" json:"custodian,omitempty"` // When this document reference was created // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // Human-readable description // https://hl7.org/fhir/r4/search.html#string Description datatypes.JSON `gorm:"column:description;type:text;serializer:json" json:"description,omitempty"` @@ -103,13 +103,13 @@ type FhirDocumentReference struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Uri where the data can be found // https://hl7.org/fhir/r4/search.html#uri Location string `gorm:"column:location;type:text" json:"location,omitempty"` // Time of service that is being documented // https://hl7.org/fhir/r4/search.html#date - Period time.Time `gorm:"column:period;type:datetime" json:"period,omitempty"` + Period *time.Time `gorm:"column:period;type:datetime" json:"period,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -211,12 +211,10 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j // extracting Authenticator authenticatorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentReference.authenticator'))") if err == nil && authenticatorResult.String() != "undefined" { - s.Authenticator = []byte(authenticatorResult.String()) } // extracting Author authorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentReference.author'))") if err == nil && authorResult.String() != "undefined" { - s.Author = []byte(authorResult.String()) } // extracting Category categoryResult, err := vm.RunString(` @@ -255,7 +253,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -297,7 +300,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(ContenttypeProcessed) + if(ContenttypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ContenttypeProcessed) + } `) if err == nil && contenttypeResult.String() != "undefined" { s.Contenttype = []byte(contenttypeResult.String()) @@ -305,14 +313,18 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j // extracting Custodian custodianResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentReference.custodian'))") if err == nil && custodianResult.String() != "undefined" { - s.Custodian = []byte(custodianResult.String()) } // extracting Date dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'DocumentReference.date')[0]") if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Description @@ -364,8 +376,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j return accumulator }, []) - - JSON.stringify(DescriptionProcessed) + if(DescriptionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DescriptionProcessed) + } `) if err == nil && descriptionResult.String() != "undefined" { s.Description = []byte(descriptionResult.String()) @@ -373,7 +389,6 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Event eventResult, err := vm.RunString(` @@ -412,7 +427,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(EventProcessed) + if(EventProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EventProcessed) + } `) if err == nil && eventResult.String() != "undefined" { s.Event = []byte(eventResult.String()) @@ -454,7 +474,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(FacilityProcessed) + if(FacilityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(FacilityProcessed) + } `) if err == nil && facilityResult.String() != "undefined" { s.Facility = []byte(facilityResult.String()) @@ -496,7 +521,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(FormatProcessed) + if(FormatProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(FormatProcessed) + } `) if err == nil && formatResult.String() != "undefined" { s.Format = []byte(formatResult.String()) @@ -538,7 +568,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -580,7 +615,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -590,7 +630,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location @@ -603,23 +648,25 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j if err == nil && periodResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, periodResult.String()) if err == nil { - s.Period = t + s.Period = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", periodResult.String()) + if err == nil { + s.Period = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Related relatedResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentReference.context.related'))") if err == nil && relatedResult.String() != "undefined" { - s.Related = []byte(relatedResult.String()) } // extracting Relatesto relatestoResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentReference.relatesTo.target'))") if err == nil && relatestoResult.String() != "undefined" { - s.Relatesto = []byte(relatestoResult.String()) } // extracting Relation relationResult, err := vm.RunString(` @@ -658,7 +705,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(RelationProcessed) + if(RelationProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RelationProcessed) + } `) if err == nil && relationResult.String() != "undefined" { s.Relation = []byte(relationResult.String()) @@ -700,7 +752,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(SecurityLabelProcessed) + if(SecurityLabelProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SecurityLabelProcessed) + } `) if err == nil && securityLabelResult.String() != "undefined" { s.SecurityLabel = []byte(securityLabelResult.String()) @@ -742,7 +799,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(SettingProcessed) + if(SettingProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SettingProcessed) + } `) if err == nil && settingResult.String() != "undefined" { s.Setting = []byte(settingResult.String()) @@ -789,7 +851,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -797,7 +864,6 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'DocumentReference.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -836,7 +902,12 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_encounter.go b/backend/pkg/models/database/fhir_encounter.go index 3918b45f9..c75ca8f29 100644 --- a/backend/pkg/models/database/fhir_encounter.go +++ b/backend/pkg/models/database/fhir_encounter.go @@ -48,7 +48,7 @@ type FhirEncounter struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // The diagnosis or procedure relevant to the encounter // https://hl7.org/fhir/r4/search.html#reference Diagnosis datatypes.JSON `gorm:"column:diagnosis;type:text;serializer:json" json:"diagnosis,omitempty"` @@ -96,7 +96,7 @@ type FhirEncounter struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Length of encounter in days // https://hl7.org/fhir/r4/search.html#quantity Length datatypes.JSON `gorm:"column:length;type:text;serializer:json" json:"length,omitempty"` @@ -105,7 +105,7 @@ type FhirEncounter struct { Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` // Time period during which the patient was present at the location // https://hl7.org/fhir/r4/search.html#date - LocationPeriod time.Time `gorm:"column:locationPeriod;type:datetime" json:"locationPeriod,omitempty"` + LocationPeriod *time.Time `gorm:"column:locationPeriod;type:datetime" json:"locationPeriod,omitempty"` // Another Encounter this encounter is part of // https://hl7.org/fhir/r4/search.html#reference PartOf datatypes.JSON `gorm:"column:partOf;type:text;serializer:json" json:"partOf,omitempty"` @@ -216,17 +216,14 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Account accountResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.account'))") if err == nil && accountResult.String() != "undefined" { - s.Account = []byte(accountResult.String()) } // extracting Appointment appointmentResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.appointment'))") if err == nil && appointmentResult.String() != "undefined" { - s.Appointment = []byte(appointmentResult.String()) } // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting Class classResult, err := vm.RunString(` @@ -265,7 +262,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(ClassProcessed) + if(ClassProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ClassProcessed) + } `) if err == nil && classResult.String() != "undefined" { s.Class = []byte(classResult.String()) @@ -275,18 +277,21 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Diagnosis diagnosisResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.diagnosis.condition'))") if err == nil && diagnosisResult.String() != "undefined" { - s.Diagnosis = []byte(diagnosisResult.String()) } // extracting EpisodeOfCare episodeOfCareResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.episodeOfCare'))") if err == nil && episodeOfCareResult.String() != "undefined" { - s.EpisodeOfCare = []byte(episodeOfCareResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -325,7 +330,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -367,7 +377,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -377,7 +392,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Length @@ -388,25 +408,27 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.location.location'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting LocationPeriod locationPeriodResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Encounter.location.period')[0]") if err == nil && locationPeriodResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, locationPeriodResult.String()) if err == nil { - s.LocationPeriod = t + s.LocationPeriod = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", locationPeriodResult.String()) + if err == nil { + s.LocationPeriod = &d + } } } // extracting PartOf partOfResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.partOf'))") if err == nil && partOfResult.String() != "undefined" { - s.PartOf = []byte(partOfResult.String()) } // extracting Participant participantResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.participant.individual'))") if err == nil && participantResult.String() != "undefined" { - s.Participant = []byte(participantResult.String()) } // extracting ParticipantType participantTypeResult, err := vm.RunString(` @@ -445,7 +467,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(ParticipantTypeProcessed) + if(ParticipantTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ParticipantTypeProcessed) + } `) if err == nil && participantTypeResult.String() != "undefined" { s.ParticipantType = []byte(participantTypeResult.String()) @@ -453,12 +480,10 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Practitioner practitionerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.participant.individual.where(resolve() is Practitioner)'))") if err == nil && practitionerResult.String() != "undefined" { - s.Practitioner = []byte(practitionerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting ReasonCode reasonCodeResult, err := vm.RunString(` @@ -497,7 +522,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(ReasonCodeProcessed) + if(ReasonCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ReasonCodeProcessed) + } `) if err == nil && reasonCodeResult.String() != "undefined" { s.ReasonCode = []byte(reasonCodeResult.String()) @@ -505,12 +535,10 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting ReasonReference reasonReferenceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.reasonReference'))") if err == nil && reasonReferenceResult.String() != "undefined" { - s.ReasonReference = []byte(reasonReferenceResult.String()) } // extracting ServiceProvider serviceProviderResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.serviceProvider'))") if err == nil && serviceProviderResult.String() != "undefined" { - s.ServiceProvider = []byte(serviceProviderResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -554,7 +582,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(SpecialArrangementProcessed) + if(SpecialArrangementProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SpecialArrangementProcessed) + } `) if err == nil && specialArrangementResult.String() != "undefined" { s.SpecialArrangement = []byte(specialArrangementResult.String()) @@ -596,7 +629,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -604,7 +642,6 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Encounter.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -643,7 +680,12 @@ func (s *FhirEncounter) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_endpoint.go b/backend/pkg/models/database/fhir_endpoint.go index 616a3ac5a..e2ae862e7 100644 --- a/backend/pkg/models/database/fhir_endpoint.go +++ b/backend/pkg/models/database/fhir_endpoint.go @@ -25,7 +25,7 @@ type FhirEndpoint struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // A name that this endpoint can be identified by // https://hl7.org/fhir/r4/search.html#string Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` @@ -137,7 +137,12 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(ConnectionTypeProcessed) + if(ConnectionTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ConnectionTypeProcessed) + } `) if err == nil && connectionTypeResult.String() != "undefined" { s.ConnectionType = []byte(connectionTypeResult.String()) @@ -179,7 +184,12 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -221,7 +231,12 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -231,7 +246,12 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Name @@ -283,8 +303,12 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -292,7 +316,6 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Endpoint.managingOrganization'))") if err == nil && organizationResult.String() != "undefined" { - s.Organization = []byte(organizationResult.String()) } // extracting PayloadType payloadTypeResult, err := vm.RunString(` @@ -331,7 +354,12 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(PayloadTypeProcessed) + if(PayloadTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PayloadTypeProcessed) + } `) if err == nil && payloadTypeResult.String() != "undefined" { s.PayloadType = []byte(payloadTypeResult.String()) @@ -339,7 +367,6 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -383,7 +410,12 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -425,7 +457,12 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_enrollment_request.go b/backend/pkg/models/database/fhir_enrollment_request.go index b9dbc3505..f0ecb5a06 100644 --- a/backend/pkg/models/database/fhir_enrollment_request.go +++ b/backend/pkg/models/database/fhir_enrollment_request.go @@ -22,7 +22,7 @@ type FhirEnrollmentRequest struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -125,7 +125,12 @@ func (s *FhirEnrollmentRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -167,7 +172,12 @@ func (s *FhirEnrollmentRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -177,13 +187,17 @@ func (s *FhirEnrollmentRequest) PopulateAndExtractSearchParameters(resourceRaw j if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -227,7 +241,12 @@ func (s *FhirEnrollmentRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -235,7 +254,6 @@ func (s *FhirEnrollmentRequest) PopulateAndExtractSearchParameters(resourceRaw j // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'EnrollmentRequest.candidate'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -274,7 +292,12 @@ func (s *FhirEnrollmentRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_enrollment_response.go b/backend/pkg/models/database/fhir_enrollment_response.go index bf568e17d..c2c62334e 100644 --- a/backend/pkg/models/database/fhir_enrollment_response.go +++ b/backend/pkg/models/database/fhir_enrollment_response.go @@ -22,7 +22,7 @@ type FhirEnrollmentResponse struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -125,7 +125,12 @@ func (s *FhirEnrollmentResponse) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -167,7 +172,12 @@ func (s *FhirEnrollmentResponse) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -177,18 +187,21 @@ func (s *FhirEnrollmentResponse) PopulateAndExtractSearchParameters(resourceRaw if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Request requestResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'EnrollmentResponse.request'))") if err == nil && requestResult.String() != "undefined" { - s.Request = []byte(requestResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -232,7 +245,12 @@ func (s *FhirEnrollmentResponse) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -274,7 +292,12 @@ func (s *FhirEnrollmentResponse) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_explanation_of_benefit.go b/backend/pkg/models/database/fhir_explanation_of_benefit.go index 9184ab82a..42c57bdd0 100644 --- a/backend/pkg/models/database/fhir_explanation_of_benefit.go +++ b/backend/pkg/models/database/fhir_explanation_of_benefit.go @@ -25,7 +25,7 @@ type FhirExplanationOfBenefit struct { Coverage datatypes.JSON `gorm:"column:coverage;type:text;serializer:json" json:"coverage,omitempty"` // The creation date for the EOB // https://hl7.org/fhir/r4/search.html#date - Created time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` + Created *time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` // UDI associated with a line item detail product or service // https://hl7.org/fhir/r4/search.html#reference DetailUdi datatypes.JSON `gorm:"column:detailUdi;type:text;serializer:json" json:"detailUdi,omitempty"` @@ -52,7 +52,7 @@ type FhirExplanationOfBenefit struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The party receiving any payment for the Claim // https://hl7.org/fhir/r4/search.html#reference Payee datatypes.JSON `gorm:"column:payee;type:text;serializer:json" json:"payee,omitempty"` @@ -143,30 +143,31 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa // extracting CareTeam careTeamResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.careTeam.provider'))") if err == nil && careTeamResult.String() != "undefined" { - s.CareTeam = []byte(careTeamResult.String()) } // extracting Claim claimResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.claim'))") if err == nil && claimResult.String() != "undefined" { - s.Claim = []byte(claimResult.String()) } // extracting Coverage coverageResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.insurance.coverage'))") if err == nil && coverageResult.String() != "undefined" { - s.Coverage = []byte(coverageResult.String()) } // extracting Created createdResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.created')[0]") if err == nil && createdResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, createdResult.String()) if err == nil { - s.Created = t + s.Created = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", createdResult.String()) + if err == nil { + s.Created = &d + } } } // extracting DetailUdi detailUdiResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.item.detail.udi'))") if err == nil && detailUdiResult.String() != "undefined" { - s.DetailUdi = []byte(detailUdiResult.String()) } // extracting Disposition dispositionResult, err := vm.RunString(` @@ -217,8 +218,12 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa return accumulator }, []) - - JSON.stringify(DispositionProcessed) + if(DispositionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DispositionProcessed) + } `) if err == nil && dispositionResult.String() != "undefined" { s.Disposition = []byte(dispositionResult.String()) @@ -226,17 +231,14 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.item.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Enterer entererResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.enterer'))") if err == nil && entererResult.String() != "undefined" { - s.Enterer = []byte(entererResult.String()) } // extracting Facility facilityResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.facility'))") if err == nil && facilityResult.String() != "undefined" { - s.Facility = []byte(facilityResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -275,7 +277,12 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -283,7 +290,6 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa // extracting ItemUdi itemUdiResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.item.udi'))") if err == nil && itemUdiResult.String() != "undefined" { - s.ItemUdi = []byte(itemUdiResult.String()) } // extracting Language languageResult, err := vm.RunString(` @@ -322,7 +328,12 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -332,28 +343,29 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Payee payeeResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.payee.party'))") if err == nil && payeeResult.String() != "undefined" { - s.Payee = []byte(payeeResult.String()) } // extracting ProcedureUdi procedureUdiResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.procedure.udi'))") if err == nil && procedureUdiResult.String() != "undefined" { - s.ProcedureUdi = []byte(procedureUdiResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Provider providerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.provider'))") if err == nil && providerResult.String() != "undefined" { - s.Provider = []byte(providerResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -397,7 +409,12 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -405,7 +422,6 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa // extracting SubdetailUdi subdetailUdiResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.item.detail.subDetail.udi'))") if err == nil && subdetailUdiResult.String() != "undefined" { - s.SubdetailUdi = []byte(subdetailUdiResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -444,7 +460,12 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_family_member_history.go b/backend/pkg/models/database/fhir_family_member_history.go index 62cd46ab6..008aeaf53 100644 --- a/backend/pkg/models/database/fhir_family_member_history.go +++ b/backend/pkg/models/database/fhir_family_member_history.go @@ -56,7 +56,7 @@ type FhirFamilyMemberHistory struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -104,7 +104,7 @@ type FhirFamilyMemberHistory struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -215,7 +215,12 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -225,7 +230,12 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Identifier @@ -265,7 +275,12 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -273,7 +288,6 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw // extracting InstantiatesCanonical instantiatesCanonicalResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'FamilyMemberHistory.instantiatesCanonical'))") if err == nil && instantiatesCanonicalResult.String() != "undefined" { - s.InstantiatesCanonical = []byte(instantiatesCanonicalResult.String()) } // extracting InstantiatesUri instantiatesUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'FamilyMemberHistory.instantiatesUri')[0]") @@ -317,7 +331,12 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -327,13 +346,17 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Relationship relationshipResult, err := vm.RunString(` @@ -372,7 +395,12 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(RelationshipProcessed) + if(RelationshipProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RelationshipProcessed) + } `) if err == nil && relationshipResult.String() != "undefined" { s.Relationship = []byte(relationshipResult.String()) @@ -414,7 +442,12 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(SexProcessed) + if(SexProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SexProcessed) + } `) if err == nil && sexResult.String() != "undefined" { s.Sex = []byte(sexResult.String()) @@ -461,7 +494,12 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -503,7 +541,12 @@ func (s *FhirFamilyMemberHistory) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_goal.go b/backend/pkg/models/database/fhir_goal.go index 48e76004f..faa14b588 100644 --- a/backend/pkg/models/database/fhir_goal.go +++ b/backend/pkg/models/database/fhir_goal.go @@ -61,7 +61,7 @@ type FhirGoal struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // proposed | planned | accepted | active | on-hold | completed | cancelled | entered-in-error | rejected // https://hl7.org/fhir/r4/search.html#token LifecycleStatus datatypes.JSON `gorm:"column:lifecycleStatus;type:text;serializer:json" json:"lifecycleStatus,omitempty"` @@ -73,7 +73,7 @@ type FhirGoal struct { SourceUri string `gorm:"column:sourceUri;type:text" json:"sourceUri,omitempty"` // When goal pursuit begins // https://hl7.org/fhir/r4/search.html#date - StartDate time.Time `gorm:"column:startDate;type:datetime" json:"startDate,omitempty"` + StartDate *time.Time `gorm:"column:startDate;type:datetime" json:"startDate,omitempty"` // Who this goal is intended for // https://hl7.org/fhir/r4/search.html#reference Subject datatypes.JSON `gorm:"column:subject;type:text;serializer:json" json:"subject,omitempty"` @@ -82,7 +82,7 @@ type FhirGoal struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Reach goal on or before // https://hl7.org/fhir/r4/search.html#date - TargetDate time.Time `gorm:"column:targetDate;type:datetime" json:"targetDate,omitempty"` + TargetDate *time.Time `gorm:"column:targetDate;type:datetime" json:"targetDate,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` @@ -174,7 +174,12 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(AchievementStatusProcessed) + if(AchievementStatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AchievementStatusProcessed) + } `) if err == nil && achievementStatusResult.String() != "undefined" { s.AchievementStatus = []byte(achievementStatusResult.String()) @@ -216,7 +221,12 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -258,7 +268,12 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -300,7 +315,12 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -310,7 +330,12 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting LifecycleStatus @@ -350,7 +375,12 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(LifecycleStatusProcessed) + if(LifecycleStatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LifecycleStatusProcessed) + } `) if err == nil && lifecycleStatusResult.String() != "undefined" { s.LifecycleStatus = []byte(lifecycleStatusResult.String()) @@ -358,7 +388,6 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -370,13 +399,17 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag if err == nil && startDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, startDateResult.String()) if err == nil { - s.StartDate = t + s.StartDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", startDateResult.String()) + if err == nil { + s.StartDate = &d + } } } // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Goal.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -415,7 +448,12 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -425,7 +463,12 @@ func (s *FhirGoal) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag if err == nil && targetDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, targetDateResult.String()) if err == nil { - s.TargetDate = t + s.TargetDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", targetDateResult.String()) + if err == nil { + s.TargetDate = &d + } } } return nil diff --git a/backend/pkg/models/database/fhir_imaging_study.go b/backend/pkg/models/database/fhir_imaging_study.go index 46e1e5dad..918b1d11e 100644 --- a/backend/pkg/models/database/fhir_imaging_study.go +++ b/backend/pkg/models/database/fhir_imaging_study.go @@ -76,7 +76,7 @@ type FhirImagingStudy struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The modality of the series // https://hl7.org/fhir/r4/search.html#token Modality datatypes.JSON `gorm:"column:modality;type:text;serializer:json" json:"modality,omitempty"` @@ -100,7 +100,7 @@ type FhirImagingStudy struct { SourceUri string `gorm:"column:sourceUri;type:text" json:"sourceUri,omitempty"` // When the study was started // https://hl7.org/fhir/r4/search.html#date - Started time.Time `gorm:"column:started;type:datetime" json:"started,omitempty"` + Started *time.Time `gorm:"column:started;type:datetime" json:"started,omitempty"` // The status of the study // https://hl7.org/fhir/r4/search.html#token Status datatypes.JSON `gorm:"column:status;type:text;serializer:json" json:"status,omitempty"` @@ -176,7 +176,6 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Basedon basedonResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ImagingStudy.basedOn'))") if err == nil && basedonResult.String() != "undefined" { - s.Basedon = []byte(basedonResult.String()) } // extracting Bodysite bodysiteResult, err := vm.RunString(` @@ -215,7 +214,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(BodysiteProcessed) + if(BodysiteProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(BodysiteProcessed) + } `) if err == nil && bodysiteResult.String() != "undefined" { s.Bodysite = []byte(bodysiteResult.String()) @@ -257,7 +261,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(DicomClassProcessed) + if(DicomClassProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DicomClassProcessed) + } `) if err == nil && dicomClassResult.String() != "undefined" { s.DicomClass = []byte(dicomClassResult.String()) @@ -265,12 +274,10 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ImagingStudy.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Endpoint endpointResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ImagingStudy.endpoint | ImagingStudy.series.endpoint'))") if err == nil && endpointResult.String() != "undefined" { - s.Endpoint = []byte(endpointResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -309,7 +316,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -351,7 +363,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(InstanceProcessed) + if(InstanceProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(InstanceProcessed) + } `) if err == nil && instanceResult.String() != "undefined" { s.Instance = []byte(instanceResult.String()) @@ -359,7 +376,6 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Interpreter interpreterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ImagingStudy.interpreter'))") if err == nil && interpreterResult.String() != "undefined" { - s.Interpreter = []byte(interpreterResult.String()) } // extracting Language languageResult, err := vm.RunString(` @@ -398,7 +414,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -408,7 +429,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Modality @@ -448,7 +474,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(ModalityProcessed) + if(ModalityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ModalityProcessed) + } `) if err == nil && modalityResult.String() != "undefined" { s.Modality = []byte(modalityResult.String()) @@ -456,12 +487,10 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ImagingStudy.series.performer.actor'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Reason reasonResult, err := vm.RunString(` @@ -500,7 +529,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(ReasonProcessed) + if(ReasonProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ReasonProcessed) + } `) if err == nil && reasonResult.String() != "undefined" { s.Reason = []byte(reasonResult.String()) @@ -508,7 +542,6 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Referrer referrerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ImagingStudy.referrer'))") if err == nil && referrerResult.String() != "undefined" { - s.Referrer = []byte(referrerResult.String()) } // extracting Series seriesResult, err := vm.RunString(` @@ -547,7 +580,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(SeriesProcessed) + if(SeriesProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SeriesProcessed) + } `) if err == nil && seriesResult.String() != "undefined" { s.Series = []byte(seriesResult.String()) @@ -562,7 +600,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R if err == nil && startedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, startedResult.String()) if err == nil { - s.Started = t + s.Started = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", startedResult.String()) + if err == nil { + s.Started = &d + } } } // extracting Status @@ -602,7 +645,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -610,7 +658,6 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ImagingStudy.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -649,7 +696,12 @@ func (s *FhirImagingStudy) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_immunization.go b/backend/pkg/models/database/fhir_immunization.go index 10c75f2ce..72563948a 100644 --- a/backend/pkg/models/database/fhir_immunization.go +++ b/backend/pkg/models/database/fhir_immunization.go @@ -36,7 +36,7 @@ type FhirImmunization struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -78,7 +78,7 @@ type FhirImmunization struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The service delivery location or facility in which the vaccine was / was to be administered // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` @@ -99,7 +99,7 @@ type FhirImmunization struct { Reaction datatypes.JSON `gorm:"column:reaction;type:text;serializer:json" json:"reaction,omitempty"` // When reaction started // https://hl7.org/fhir/r4/search.html#date - ReactionDate time.Time `gorm:"column:reactionDate;type:datetime" json:"reactionDate,omitempty"` + ReactionDate *time.Time `gorm:"column:reactionDate;type:datetime" json:"reactionDate,omitempty"` // Reason why the vaccine was administered // https://hl7.org/fhir/r4/search.html#token ReasonCode datatypes.JSON `gorm:"column:reasonCode;type:text;serializer:json" json:"reasonCode,omitempty"` @@ -194,7 +194,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Identifier @@ -234,7 +239,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -276,7 +286,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -286,13 +301,17 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Immunization.location'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting LotNumber lotNumberResult, err := vm.RunString(` @@ -343,8 +362,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(LotNumberProcessed) + if(LotNumberProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LotNumberProcessed) + } `) if err == nil && lotNumberResult.String() != "undefined" { s.LotNumber = []byte(lotNumberResult.String()) @@ -352,29 +375,30 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Manufacturer manufacturerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Immunization.manufacturer'))") if err == nil && manufacturerResult.String() != "undefined" { - s.Manufacturer = []byte(manufacturerResult.String()) } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Immunization.performer.actor'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Reaction reactionResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Immunization.reaction.detail'))") if err == nil && reactionResult.String() != "undefined" { - s.Reaction = []byte(reactionResult.String()) } // extracting ReactionDate reactionDateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Immunization.reaction.date')[0]") if err == nil && reactionDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, reactionDateResult.String()) if err == nil { - s.ReactionDate = t + s.ReactionDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", reactionDateResult.String()) + if err == nil { + s.ReactionDate = &d + } } } // extracting ReasonCode @@ -414,7 +438,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(ReasonCodeProcessed) + if(ReasonCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ReasonCodeProcessed) + } `) if err == nil && reasonCodeResult.String() != "undefined" { s.ReasonCode = []byte(reasonCodeResult.String()) @@ -422,7 +451,6 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting ReasonReference reasonReferenceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Immunization.reasonReference'))") if err == nil && reasonReferenceResult.String() != "undefined" { - s.ReasonReference = []byte(reasonReferenceResult.String()) } // extracting Series seriesResult, err := vm.RunString(` @@ -473,8 +501,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(SeriesProcessed) + if(SeriesProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SeriesProcessed) + } `) if err == nil && seriesResult.String() != "undefined" { s.Series = []byte(seriesResult.String()) @@ -521,7 +553,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -563,7 +600,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(StatusReasonProcessed) + if(StatusReasonProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusReasonProcessed) + } `) if err == nil && statusReasonResult.String() != "undefined" { s.StatusReason = []byte(statusReasonResult.String()) @@ -605,7 +647,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -647,7 +694,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(TargetDiseaseProcessed) + if(TargetDiseaseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TargetDiseaseProcessed) + } `) if err == nil && targetDiseaseResult.String() != "undefined" { s.TargetDisease = []byte(targetDiseaseResult.String()) @@ -689,7 +741,12 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(VaccineCodeProcessed) + if(VaccineCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(VaccineCodeProcessed) + } `) if err == nil && vaccineCodeResult.String() != "undefined" { s.VaccineCode = []byte(vaccineCodeResult.String()) diff --git a/backend/pkg/models/database/fhir_insurance_plan.go b/backend/pkg/models/database/fhir_insurance_plan.go index 97b07ea9c..86565807f 100644 --- a/backend/pkg/models/database/fhir_insurance_plan.go +++ b/backend/pkg/models/database/fhir_insurance_plan.go @@ -46,7 +46,7 @@ type FhirInsurancePlan struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // A portion of the organization's name or alias // https://hl7.org/fhir/r4/search.html#string Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` @@ -177,8 +177,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressProcessed) + if(AddressProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressProcessed) + } `) if err == nil && addressResult.String() != "undefined" { s.Address = []byte(addressResult.String()) @@ -232,8 +236,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressCityProcessed) + if(AddressCityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCityProcessed) + } `) if err == nil && addressCityResult.String() != "undefined" { s.AddressCity = []byte(addressCityResult.String()) @@ -287,8 +295,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressCountryProcessed) + if(AddressCountryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCountryProcessed) + } `) if err == nil && addressCountryResult.String() != "undefined" { s.AddressCountry = []byte(addressCountryResult.String()) @@ -342,8 +354,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressPostalcodeProcessed) + if(AddressPostalcodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressPostalcodeProcessed) + } `) if err == nil && addressPostalcodeResult.String() != "undefined" { s.AddressPostalcode = []byte(addressPostalcodeResult.String()) @@ -397,8 +413,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressStateProcessed) + if(AddressStateProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressStateProcessed) + } `) if err == nil && addressStateResult.String() != "undefined" { s.AddressState = []byte(addressStateResult.String()) @@ -440,7 +460,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(AddressUseProcessed) + if(AddressUseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressUseProcessed) + } `) if err == nil && addressUseResult.String() != "undefined" { s.AddressUse = []byte(addressUseResult.String()) @@ -448,12 +473,10 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. // extracting AdministeredBy administeredByResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'InsurancePlan.administeredBy'))") if err == nil && administeredByResult.String() != "undefined" { - s.AdministeredBy = []byte(administeredByResult.String()) } // extracting Endpoint endpointResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'InsurancePlan.endpoint'))") if err == nil && endpointResult.String() != "undefined" { - s.Endpoint = []byte(endpointResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -492,7 +515,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -534,7 +562,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -544,7 +577,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Name @@ -596,8 +634,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -605,7 +647,6 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. // extracting OwnedBy ownedByResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'InsurancePlan.ownedBy'))") if err == nil && ownedByResult.String() != "undefined" { - s.OwnedBy = []byte(ownedByResult.String()) } // extracting Phonetic phoneticResult, err := vm.RunString(` @@ -656,8 +697,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(PhoneticProcessed) + if(PhoneticProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneticProcessed) + } `) if err == nil && phoneticResult.String() != "undefined" { s.Phonetic = []byte(phoneticResult.String()) @@ -665,7 +710,6 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -709,7 +753,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -751,7 +800,12 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_location.go b/backend/pkg/models/database/fhir_location.go index c92d9686e..a04512a1d 100644 --- a/backend/pkg/models/database/fhir_location.go +++ b/backend/pkg/models/database/fhir_location.go @@ -43,7 +43,7 @@ type FhirLocation struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // A portion of the location's name or alias // https://hl7.org/fhir/r4/search.html#string Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` @@ -177,8 +177,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(AddressProcessed) + if(AddressProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressProcessed) + } `) if err == nil && addressResult.String() != "undefined" { s.Address = []byte(addressResult.String()) @@ -232,8 +236,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(AddressCityProcessed) + if(AddressCityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCityProcessed) + } `) if err == nil && addressCityResult.String() != "undefined" { s.AddressCity = []byte(addressCityResult.String()) @@ -287,8 +295,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(AddressCountryProcessed) + if(AddressCountryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCountryProcessed) + } `) if err == nil && addressCountryResult.String() != "undefined" { s.AddressCountry = []byte(addressCountryResult.String()) @@ -342,8 +354,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(AddressPostalcodeProcessed) + if(AddressPostalcodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressPostalcodeProcessed) + } `) if err == nil && addressPostalcodeResult.String() != "undefined" { s.AddressPostalcode = []byte(addressPostalcodeResult.String()) @@ -397,8 +413,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(AddressStateProcessed) + if(AddressStateProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressStateProcessed) + } `) if err == nil && addressStateResult.String() != "undefined" { s.AddressState = []byte(addressStateResult.String()) @@ -440,7 +460,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(AddressUseProcessed) + if(AddressUseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressUseProcessed) + } `) if err == nil && addressUseResult.String() != "undefined" { s.AddressUse = []byte(addressUseResult.String()) @@ -448,7 +473,6 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Endpoint endpointResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Location.endpoint'))") if err == nil && endpointResult.String() != "undefined" { - s.Endpoint = []byte(endpointResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -487,7 +511,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -529,7 +558,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -539,7 +573,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Name @@ -591,8 +630,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -634,7 +677,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(OperationalStatusProcessed) + if(OperationalStatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(OperationalStatusProcessed) + } `) if err == nil && operationalStatusResult.String() != "undefined" { s.OperationalStatus = []byte(operationalStatusResult.String()) @@ -642,17 +690,14 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Location.managingOrganization'))") if err == nil && organizationResult.String() != "undefined" { - s.Organization = []byte(organizationResult.String()) } // extracting Partof partofResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Location.partOf'))") if err == nil && partofResult.String() != "undefined" { - s.Partof = []byte(partofResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -696,7 +741,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -738,7 +788,12 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_media.go b/backend/pkg/models/database/fhir_media.go index 889f497ee..4a0fe6f5b 100644 --- a/backend/pkg/models/database/fhir_media.go +++ b/backend/pkg/models/database/fhir_media.go @@ -19,7 +19,7 @@ type FhirMedia struct { BasedOn datatypes.JSON `gorm:"column:basedOn;type:text;serializer:json" json:"basedOn,omitempty"` // When Media was collected // https://hl7.org/fhir/r4/search.html#date - Created time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` + Created *time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` // Observing Device // https://hl7.org/fhir/r4/search.html#reference Device datatypes.JSON `gorm:"column:device;type:text;serializer:json" json:"device,omitempty"` @@ -34,7 +34,7 @@ type FhirMedia struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The type of acquisition equipment/process // https://hl7.org/fhir/r4/search.html#token Modality datatypes.JSON `gorm:"column:modality;type:text;serializer:json" json:"modality,omitempty"` @@ -123,25 +123,27 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Media.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting Created createdResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Media.created')[0]") if err == nil && createdResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, createdResult.String()) if err == nil { - s.Created = t + s.Created = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", createdResult.String()) + if err == nil { + s.Created = &d + } } } // extracting Device deviceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Media.device'))") if err == nil && deviceResult.String() != "undefined" { - s.Device = []byte(deviceResult.String()) } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Media.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -180,7 +182,12 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -222,7 +229,12 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -232,7 +244,12 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Modality @@ -272,7 +289,12 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(ModalityProcessed) + if(ModalityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ModalityProcessed) + } `) if err == nil && modalityResult.String() != "undefined" { s.Modality = []byte(modalityResult.String()) @@ -280,12 +302,10 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa // extracting Operator operatorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Media.operator'))") if err == nil && operatorResult.String() != "undefined" { - s.Operator = []byte(operatorResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Site siteResult, err := vm.RunString(` @@ -324,7 +344,12 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(SiteProcessed) + if(SiteProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SiteProcessed) + } `) if err == nil && siteResult.String() != "undefined" { s.Site = []byte(siteResult.String()) @@ -371,7 +396,12 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -379,7 +409,6 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Media.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -418,7 +447,12 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -460,7 +494,12 @@ func (s *FhirMedia) PopulateAndExtractSearchParameters(resourceRaw json.RawMessa }, []) - JSON.stringify(ViewProcessed) + if(ViewProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ViewProcessed) + } `) if err == nil && viewResult.String() != "undefined" { s.View = []byte(viewResult.String()) diff --git a/backend/pkg/models/database/fhir_medication.go b/backend/pkg/models/database/fhir_medication.go index 8a4fd67db..b8bc28053 100644 --- a/backend/pkg/models/database/fhir_medication.go +++ b/backend/pkg/models/database/fhir_medication.go @@ -36,7 +36,7 @@ type FhirMedication struct { Code datatypes.JSON `gorm:"column:code;type:text;serializer:json" json:"code,omitempty"` // Returns medications in a batch with this expiration date // https://hl7.org/fhir/r4/search.html#date - ExpirationDate time.Time `gorm:"column:expirationDate;type:datetime" json:"expirationDate,omitempty"` + ExpirationDate *time.Time `gorm:"column:expirationDate;type:datetime" json:"expirationDate,omitempty"` // Returns medications for a specific dose form // https://hl7.org/fhir/r4/search.html#token Form datatypes.JSON `gorm:"column:form;type:text;serializer:json" json:"form,omitempty"` @@ -54,7 +54,7 @@ type FhirMedication struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Returns medications in a batch with this lot number // https://hl7.org/fhir/r4/search.html#token LotNumber datatypes.JSON `gorm:"column:lotNumber;type:text;serializer:json" json:"lotNumber,omitempty"` @@ -166,7 +166,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -176,7 +181,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw if err == nil && expirationDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, expirationDateResult.String()) if err == nil { - s.ExpirationDate = t + s.ExpirationDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", expirationDateResult.String()) + if err == nil { + s.ExpirationDate = &d + } } } // extracting Form @@ -216,7 +226,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(FormProcessed) + if(FormProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(FormProcessed) + } `) if err == nil && formResult.String() != "undefined" { s.Form = []byte(formResult.String()) @@ -258,7 +273,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -266,7 +286,6 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw // extracting Ingredient ingredientResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, '(Medication.ingredient.itemReference)'))") if err == nil && ingredientResult.String() != "undefined" { - s.Ingredient = []byte(ingredientResult.String()) } // extracting IngredientCode ingredientCodeResult, err := vm.RunString(` @@ -305,7 +324,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(IngredientCodeProcessed) + if(IngredientCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IngredientCodeProcessed) + } `) if err == nil && ingredientCodeResult.String() != "undefined" { s.IngredientCode = []byte(ingredientCodeResult.String()) @@ -347,7 +371,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -357,7 +386,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting LotNumber @@ -397,7 +431,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(LotNumberProcessed) + if(LotNumberProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LotNumberProcessed) + } `) if err == nil && lotNumberResult.String() != "undefined" { s.LotNumber = []byte(lotNumberResult.String()) @@ -405,12 +444,10 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw // extracting Manufacturer manufacturerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Medication.manufacturer'))") if err == nil && manufacturerResult.String() != "undefined" { - s.Manufacturer = []byte(manufacturerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -454,7 +491,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -496,7 +538,12 @@ func (s *FhirMedication) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_medication_administration.go b/backend/pkg/models/database/fhir_medication_administration.go index 676097226..0b59ea442 100644 --- a/backend/pkg/models/database/fhir_medication_administration.go +++ b/backend/pkg/models/database/fhir_medication_administration.go @@ -42,7 +42,7 @@ type FhirMedicationAdministration struct { Device datatypes.JSON `gorm:"column:device;type:text;serializer:json" json:"device,omitempty"` // Date administration happened (or did not happen) // https://hl7.org/fhir/r4/search.html#date - EffectiveTime time.Time `gorm:"column:effectiveTime;type:datetime" json:"effectiveTime,omitempty"` + EffectiveTime *time.Time `gorm:"column:effectiveTime;type:datetime" json:"effectiveTime,omitempty"` /* Multiple Resources: @@ -84,7 +84,7 @@ type FhirMedicationAdministration struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` /* Multiple Resources: @@ -225,7 +225,12 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -233,19 +238,22 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour // extracting Context contextResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationAdministration.context'))") if err == nil && contextResult.String() != "undefined" { - s.Context = []byte(contextResult.String()) } // extracting Device deviceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationAdministration.device'))") if err == nil && deviceResult.String() != "undefined" { - s.Device = []byte(deviceResult.String()) } // extracting EffectiveTime effectiveTimeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'MedicationAdministration.effective')[0]") if err == nil && effectiveTimeResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, effectiveTimeResult.String()) if err == nil { - s.EffectiveTime = t + s.EffectiveTime = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", effectiveTimeResult.String()) + if err == nil { + s.EffectiveTime = &d + } } } // extracting Identifier @@ -285,7 +293,12 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -327,7 +340,12 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -337,23 +355,25 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Medication medicationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, '(MedicationAdministration.medicationReference) | (MedicationDispense.medicationReference) | (MedicationRequest.medicationReference) | (MedicationStatement.medicationReference)'))") if err == nil && medicationResult.String() != "undefined" { - s.Medication = []byte(medicationResult.String()) } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationAdministration.performer.actor'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting ReasonGiven reasonGivenResult, err := vm.RunString(` @@ -392,7 +412,12 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour }, []) - JSON.stringify(ReasonGivenProcessed) + if(ReasonGivenProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ReasonGivenProcessed) + } `) if err == nil && reasonGivenResult.String() != "undefined" { s.ReasonGiven = []byte(reasonGivenResult.String()) @@ -434,7 +459,12 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour }, []) - JSON.stringify(ReasonNotGivenProcessed) + if(ReasonNotGivenProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ReasonNotGivenProcessed) + } `) if err == nil && reasonNotGivenResult.String() != "undefined" { s.ReasonNotGiven = []byte(reasonNotGivenResult.String()) @@ -442,7 +472,6 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour // extracting Request requestResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationAdministration.request'))") if err == nil && requestResult.String() != "undefined" { - s.Request = []byte(requestResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -486,7 +515,12 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -494,7 +528,6 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationAdministration.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -533,7 +566,12 @@ func (s *FhirMedicationAdministration) PopulateAndExtractSearchParameters(resour }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_medication_dispense.go b/backend/pkg/models/database/fhir_medication_dispense.go index 8628d7970..676bfa0b0 100644 --- a/backend/pkg/models/database/fhir_medication_dispense.go +++ b/backend/pkg/models/database/fhir_medication_dispense.go @@ -81,7 +81,7 @@ type FhirMedicationDispense struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` /* Multiple Resources: @@ -138,10 +138,10 @@ type FhirMedicationDispense struct { Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` // Returns dispenses handed over on this date // https://hl7.org/fhir/r4/search.html#date - Whenhandedover time.Time `gorm:"column:whenhandedover;type:datetime" json:"whenhandedover,omitempty"` + Whenhandedover *time.Time `gorm:"column:whenhandedover;type:datetime" json:"whenhandedover,omitempty"` // Returns dispenses prepared on this date // https://hl7.org/fhir/r4/search.html#date - Whenprepared time.Time `gorm:"column:whenprepared;type:datetime" json:"whenprepared,omitempty"` + Whenprepared *time.Time `gorm:"column:whenprepared;type:datetime" json:"whenprepared,omitempty"` } func (s *FhirMedicationDispense) GetSearchParameters() map[string]string { @@ -233,7 +233,12 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -241,12 +246,10 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw // extracting Context contextResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationDispense.context'))") if err == nil && contextResult.String() != "undefined" { - s.Context = []byte(contextResult.String()) } // extracting Destination destinationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationDispense.destination'))") if err == nil && destinationResult.String() != "undefined" { - s.Destination = []byte(destinationResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -285,7 +288,12 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -327,7 +335,12 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -337,38 +350,37 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Medication medicationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, '(MedicationAdministration.medicationReference) | (MedicationDispense.medicationReference) | (MedicationRequest.medicationReference) | (MedicationStatement.medicationReference)'))") if err == nil && medicationResult.String() != "undefined" { - s.Medication = []byte(medicationResult.String()) } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationDispense.performer.actor'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting Prescription prescriptionResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationDispense.authorizingPrescription'))") if err == nil && prescriptionResult.String() != "undefined" { - s.Prescription = []byte(prescriptionResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Receiver receiverResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationDispense.receiver'))") if err == nil && receiverResult.String() != "undefined" { - s.Receiver = []byte(receiverResult.String()) } // extracting Responsibleparty responsiblepartyResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationDispense.substitution.responsibleParty'))") if err == nil && responsiblepartyResult.String() != "undefined" { - s.Responsibleparty = []byte(responsiblepartyResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -412,7 +424,12 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -420,7 +437,6 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationDispense.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -459,7 +475,12 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -469,7 +490,12 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw if err == nil && whenhandedoverResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, whenhandedoverResult.String()) if err == nil { - s.Whenhandedover = t + s.Whenhandedover = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", whenhandedoverResult.String()) + if err == nil { + s.Whenhandedover = &d + } } } // extracting Whenprepared @@ -477,7 +503,12 @@ func (s *FhirMedicationDispense) PopulateAndExtractSearchParameters(resourceRaw if err == nil && whenpreparedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, whenpreparedResult.String()) if err == nil { - s.Whenprepared = t + s.Whenprepared = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", whenpreparedResult.String()) + if err == nil { + s.Whenprepared = &d + } } } return nil diff --git a/backend/pkg/models/database/fhir_medication_request.go b/backend/pkg/models/database/fhir_medication_request.go index 0463811ff..7154ddad9 100644 --- a/backend/pkg/models/database/fhir_medication_request.go +++ b/backend/pkg/models/database/fhir_medication_request.go @@ -16,7 +16,7 @@ type FhirMedicationRequest struct { models.ResourceBase // Return prescriptions written on this date // https://hl7.org/fhir/r4/search.html#date - Authoredon time.Time `gorm:"column:authoredon;type:datetime" json:"authoredon,omitempty"` + Authoredon *time.Time `gorm:"column:authoredon;type:datetime" json:"authoredon,omitempty"` // Returns prescriptions with different categories // https://hl7.org/fhir/r4/search.html#token Category datatypes.JSON `gorm:"column:category;type:text;serializer:json" json:"category,omitempty"` @@ -46,7 +46,7 @@ type FhirMedicationRequest struct { * [MedicationRequest](medicationrequest.html): Returns medication request to be administered on a specific date */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -107,7 +107,7 @@ type FhirMedicationRequest struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` /* Multiple Resources: @@ -213,7 +213,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j if err == nil && authoredonResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, authoredonResult.String()) if err == nil { - s.Authoredon = t + s.Authoredon = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", authoredonResult.String()) + if err == nil { + s.Authoredon = &d + } } } // extracting Category @@ -253,7 +258,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -295,7 +305,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -305,13 +320,17 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationRequest.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -350,7 +369,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -358,12 +382,10 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j // extracting IntendedDispenser intendedDispenserResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationRequest.dispenseRequest.performer'))") if err == nil && intendedDispenserResult.String() != "undefined" { - s.IntendedDispenser = []byte(intendedDispenserResult.String()) } // extracting IntendedPerformer intendedPerformerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationRequest.performer'))") if err == nil && intendedPerformerResult.String() != "undefined" { - s.IntendedPerformer = []byte(intendedPerformerResult.String()) } // extracting IntendedPerformertype intendedPerformertypeResult, err := vm.RunString(` @@ -402,7 +424,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(IntendedPerformertypeProcessed) + if(IntendedPerformertypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IntendedPerformertypeProcessed) + } `) if err == nil && intendedPerformertypeResult.String() != "undefined" { s.IntendedPerformertype = []byte(intendedPerformertypeResult.String()) @@ -444,7 +471,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(IntentProcessed) + if(IntentProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IntentProcessed) + } `) if err == nil && intentResult.String() != "undefined" { s.Intent = []byte(intentResult.String()) @@ -486,7 +518,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -496,13 +533,17 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Medication medicationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, '(MedicationAdministration.medicationReference) | (MedicationDispense.medicationReference) | (MedicationRequest.medicationReference) | (MedicationStatement.medicationReference)'))") if err == nil && medicationResult.String() != "undefined" { - s.Medication = []byte(medicationResult.String()) } // extracting Priority priorityResult, err := vm.RunString(` @@ -541,7 +582,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(PriorityProcessed) + if(PriorityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PriorityProcessed) + } `) if err == nil && priorityResult.String() != "undefined" { s.Priority = []byte(priorityResult.String()) @@ -549,12 +595,10 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Requester requesterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationRequest.requester'))") if err == nil && requesterResult.String() != "undefined" { - s.Requester = []byte(requesterResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -598,7 +642,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -606,7 +655,6 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationRequest.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -645,7 +693,12 @@ func (s *FhirMedicationRequest) PopulateAndExtractSearchParameters(resourceRaw j }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_medication_statement.go b/backend/pkg/models/database/fhir_medication_statement.go index e18ff8bd1..749e281e3 100644 --- a/backend/pkg/models/database/fhir_medication_statement.go +++ b/backend/pkg/models/database/fhir_medication_statement.go @@ -42,7 +42,7 @@ type FhirMedicationStatement struct { Context datatypes.JSON `gorm:"column:context;type:text;serializer:json" json:"context,omitempty"` // Date when patient was taking (or not taking) the medication // https://hl7.org/fhir/r4/search.html#date - Effective time.Time `gorm:"column:effective;type:datetime" json:"effective,omitempty"` + Effective *time.Time `gorm:"column:effective;type:datetime" json:"effective,omitempty"` /* Multiple Resources: @@ -84,7 +84,7 @@ type FhirMedicationStatement struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` /* Multiple Resources: @@ -217,7 +217,12 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -259,7 +264,12 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -267,14 +277,18 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw // extracting Context contextResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationStatement.context'))") if err == nil && contextResult.String() != "undefined" { - s.Context = []byte(contextResult.String()) } // extracting Effective effectiveResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'MedicationStatement.effective')[0]") if err == nil && effectiveResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, effectiveResult.String()) if err == nil { - s.Effective = t + s.Effective = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", effectiveResult.String()) + if err == nil { + s.Effective = &d + } } } // extracting Identifier @@ -314,7 +328,12 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -356,7 +375,12 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -366,28 +390,29 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Medication medicationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, '(MedicationAdministration.medicationReference) | (MedicationDispense.medicationReference) | (MedicationRequest.medicationReference) | (MedicationStatement.medicationReference)'))") if err == nil && medicationResult.String() != "undefined" { - s.Medication = []byte(medicationResult.String()) } // extracting PartOf partOfResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationStatement.partOf'))") if err == nil && partOfResult.String() != "undefined" { - s.PartOf = []byte(partOfResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Source sourceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationStatement.informationSource'))") if err == nil && sourceResult.String() != "undefined" { - s.Source = []byte(sourceResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -431,7 +456,12 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -439,7 +469,6 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'MedicationStatement.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -478,7 +507,12 @@ func (s *FhirMedicationStatement) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_nutrition_order.go b/backend/pkg/models/database/fhir_nutrition_order.go index d1119c76e..00ad8fbb2 100644 --- a/backend/pkg/models/database/fhir_nutrition_order.go +++ b/backend/pkg/models/database/fhir_nutrition_order.go @@ -19,7 +19,7 @@ type FhirNutritionOrder struct { Additive datatypes.JSON `gorm:"column:additive;type:text;serializer:json" json:"additive,omitempty"` // Return nutrition orders requested on this date // https://hl7.org/fhir/r4/search.html#date - Datetime time.Time `gorm:"column:datetime;type:datetime" json:"datetime,omitempty"` + Datetime *time.Time `gorm:"column:datetime;type:datetime" json:"datetime,omitempty"` /* Multiple Resources: @@ -88,7 +88,7 @@ type FhirNutritionOrder struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Type of diet that can be consumed orally (i.e., take via the mouth). // https://hl7.org/fhir/r4/search.html#token Oraldiet datatypes.JSON `gorm:"column:oraldiet;type:text;serializer:json" json:"oraldiet,omitempty"` @@ -205,7 +205,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(AdditiveProcessed) + if(AdditiveProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AdditiveProcessed) + } `) if err == nil && additiveResult.String() != "undefined" { s.Additive = []byte(additiveResult.String()) @@ -215,13 +220,17 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json if err == nil && datetimeResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, datetimeResult.String()) if err == nil { - s.Datetime = t + s.Datetime = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", datetimeResult.String()) + if err == nil { + s.Datetime = &d + } } } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Formula formulaResult, err := vm.RunString(` @@ -260,7 +269,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(FormulaProcessed) + if(FormulaProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(FormulaProcessed) + } `) if err == nil && formulaResult.String() != "undefined" { s.Formula = []byte(formulaResult.String()) @@ -302,7 +316,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -310,7 +329,6 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json // extracting InstantiatesCanonical instantiatesCanonicalResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'NutritionOrder.instantiatesCanonical'))") if err == nil && instantiatesCanonicalResult.String() != "undefined" { - s.InstantiatesCanonical = []byte(instantiatesCanonicalResult.String()) } // extracting InstantiatesUri instantiatesUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'NutritionOrder.instantiatesUri')[0]") @@ -354,7 +372,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -364,7 +387,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Oraldiet @@ -404,7 +432,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(OraldietProcessed) + if(OraldietProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(OraldietProcessed) + } `) if err == nil && oraldietResult.String() != "undefined" { s.Oraldiet = []byte(oraldietResult.String()) @@ -412,12 +445,10 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Provider providerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'NutritionOrder.orderer'))") if err == nil && providerResult.String() != "undefined" { - s.Provider = []byte(providerResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -461,7 +492,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -503,7 +539,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(SupplementProcessed) + if(SupplementProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SupplementProcessed) + } `) if err == nil && supplementResult.String() != "undefined" { s.Supplement = []byte(supplementResult.String()) @@ -545,7 +586,12 @@ func (s *FhirNutritionOrder) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_observation.go b/backend/pkg/models/database/fhir_observation.go index 450cd2aad..100b4b7b5 100644 --- a/backend/pkg/models/database/fhir_observation.go +++ b/backend/pkg/models/database/fhir_observation.go @@ -89,7 +89,7 @@ type FhirObservation struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // Related measurements the observation is made from // https://hl7.org/fhir/r4/search.html#reference DerivedFrom datatypes.JSON `gorm:"column:derivedFrom;type:text;serializer:json" json:"derivedFrom,omitempty"` @@ -161,7 +161,7 @@ type FhirObservation struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The method used for the observation // https://hl7.org/fhir/r4/search.html#token Method datatypes.JSON `gorm:"column:method;type:text;serializer:json" json:"method,omitempty"` @@ -200,7 +200,7 @@ type FhirObservation struct { ValueConcept datatypes.JSON `gorm:"column:valueConcept;type:text;serializer:json" json:"valueConcept,omitempty"` // The value of the observation, if the value is a date or period of time // https://hl7.org/fhir/r4/search.html#date - ValueDate time.Time `gorm:"column:valueDate;type:datetime" json:"valueDate,omitempty"` + ValueDate *time.Time `gorm:"column:valueDate;type:datetime" json:"valueDate,omitempty"` // The value of the observation, if the value is a Quantity, or a SampledData (just search on the bounds of the values in sampled data) // https://hl7.org/fhir/r4/search.html#quantity ValueQuantity datatypes.JSON `gorm:"column:valueQuantity;type:text;serializer:json" json:"valueQuantity,omitempty"` @@ -280,7 +280,6 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting Category categoryResult, err := vm.RunString(` @@ -319,7 +318,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -361,7 +365,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -403,7 +412,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ComboCodeProcessed) + if(ComboCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ComboCodeProcessed) + } `) if err == nil && comboCodeResult.String() != "undefined" { s.ComboCode = []byte(comboCodeResult.String()) @@ -445,7 +459,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ComboDataAbsentReasonProcessed) + if(ComboDataAbsentReasonProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ComboDataAbsentReasonProcessed) + } `) if err == nil && comboDataAbsentReasonResult.String() != "undefined" { s.ComboDataAbsentReason = []byte(comboDataAbsentReasonResult.String()) @@ -487,7 +506,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ComboValueConceptProcessed) + if(ComboValueConceptProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ComboValueConceptProcessed) + } `) if err == nil && comboValueConceptResult.String() != "undefined" { s.ComboValueConcept = []byte(comboValueConceptResult.String()) @@ -534,7 +558,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ComponentCodeProcessed) + if(ComponentCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ComponentCodeProcessed) + } `) if err == nil && componentCodeResult.String() != "undefined" { s.ComponentCode = []byte(componentCodeResult.String()) @@ -576,7 +605,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ComponentDataAbsentReasonProcessed) + if(ComponentDataAbsentReasonProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ComponentDataAbsentReasonProcessed) + } `) if err == nil && componentDataAbsentReasonResult.String() != "undefined" { s.ComponentDataAbsentReason = []byte(componentDataAbsentReasonResult.String()) @@ -618,7 +652,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ComponentValueConceptProcessed) + if(ComponentValueConceptProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ComponentValueConceptProcessed) + } `) if err == nil && componentValueConceptResult.String() != "undefined" { s.ComponentValueConcept = []byte(componentValueConceptResult.String()) @@ -665,7 +704,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(DataAbsentReasonProcessed) + if(DataAbsentReasonProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DataAbsentReasonProcessed) + } `) if err == nil && dataAbsentReasonResult.String() != "undefined" { s.DataAbsentReason = []byte(dataAbsentReasonResult.String()) @@ -675,33 +719,33 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting DerivedFrom derivedFromResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.derivedFrom'))") if err == nil && derivedFromResult.String() != "undefined" { - s.DerivedFrom = []byte(derivedFromResult.String()) } // extracting Device deviceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.device'))") if err == nil && deviceResult.String() != "undefined" { - s.Device = []byte(deviceResult.String()) } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Focus focusResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.focus'))") if err == nil && focusResult.String() != "undefined" { - s.Focus = []byte(focusResult.String()) } // extracting HasMember hasMemberResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.hasMember'))") if err == nil && hasMemberResult.String() != "undefined" { - s.HasMember = []byte(hasMemberResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -740,7 +784,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -782,7 +831,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -792,7 +846,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Method @@ -832,7 +891,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(MethodProcessed) + if(MethodProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(MethodProcessed) + } `) if err == nil && methodResult.String() != "undefined" { s.Method = []byte(methodResult.String()) @@ -840,17 +904,14 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting PartOf partOfResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.partOf'))") if err == nil && partOfResult.String() != "undefined" { - s.PartOf = []byte(partOfResult.String()) } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.performer'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -860,7 +921,6 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting Specimen specimenResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.specimen'))") if err == nil && specimenResult.String() != "undefined" { - s.Specimen = []byte(specimenResult.String()) } // extracting Status statusResult, err := vm.RunString(` @@ -899,7 +959,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -907,7 +972,6 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Observation.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -946,7 +1010,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -988,7 +1057,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra }, []) - JSON.stringify(ValueConceptProcessed) + if(ValueConceptProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ValueConceptProcessed) + } `) if err == nil && valueConceptResult.String() != "undefined" { s.ValueConcept = []byte(valueConceptResult.String()) @@ -998,7 +1072,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra if err == nil && valueDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, valueDateResult.String()) if err == nil { - s.ValueDate = t + s.ValueDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", valueDateResult.String()) + if err == nil { + s.ValueDate = &d + } } } // extracting ValueQuantity @@ -1055,8 +1134,12 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra return accumulator }, []) - - JSON.stringify(ValueStringProcessed) + if(ValueStringProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ValueStringProcessed) + } `) if err == nil && valueStringResult.String() != "undefined" { s.ValueString = []byte(valueStringResult.String()) diff --git a/backend/pkg/models/database/fhir_organization.go b/backend/pkg/models/database/fhir_organization.go index 875d8d601..282d6a1af 100644 --- a/backend/pkg/models/database/fhir_organization.go +++ b/backend/pkg/models/database/fhir_organization.go @@ -46,7 +46,7 @@ type FhirOrganization struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // A portion of the organization's name or alias // https://hl7.org/fhir/r4/search.html#string Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` @@ -161,7 +161,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(ActiveProcessed) + if(ActiveProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActiveProcessed) + } `) if err == nil && activeResult.String() != "undefined" { s.Active = []byte(activeResult.String()) @@ -215,8 +220,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressProcessed) + if(AddressProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressProcessed) + } `) if err == nil && addressResult.String() != "undefined" { s.Address = []byte(addressResult.String()) @@ -270,8 +279,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressCityProcessed) + if(AddressCityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCityProcessed) + } `) if err == nil && addressCityResult.String() != "undefined" { s.AddressCity = []byte(addressCityResult.String()) @@ -325,8 +338,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressCountryProcessed) + if(AddressCountryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCountryProcessed) + } `) if err == nil && addressCountryResult.String() != "undefined" { s.AddressCountry = []byte(addressCountryResult.String()) @@ -380,8 +397,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressPostalcodeProcessed) + if(AddressPostalcodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressPostalcodeProcessed) + } `) if err == nil && addressPostalcodeResult.String() != "undefined" { s.AddressPostalcode = []byte(addressPostalcodeResult.String()) @@ -435,8 +456,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressStateProcessed) + if(AddressStateProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressStateProcessed) + } `) if err == nil && addressStateResult.String() != "undefined" { s.AddressState = []byte(addressStateResult.String()) @@ -478,7 +503,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(AddressUseProcessed) + if(AddressUseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressUseProcessed) + } `) if err == nil && addressUseResult.String() != "undefined" { s.AddressUse = []byte(addressUseResult.String()) @@ -486,7 +516,6 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Endpoint endpointResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Organization.endpoint'))") if err == nil && endpointResult.String() != "undefined" { - s.Endpoint = []byte(endpointResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -525,7 +554,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -567,7 +601,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -577,7 +616,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Name @@ -629,8 +673,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -638,7 +686,6 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Partof partofResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Organization.partOf'))") if err == nil && partofResult.String() != "undefined" { - s.Partof = []byte(partofResult.String()) } // extracting Phonetic phoneticResult, err := vm.RunString(` @@ -689,8 +736,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(PhoneticProcessed) + if(PhoneticProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneticProcessed) + } `) if err == nil && phoneticResult.String() != "undefined" { s.Phonetic = []byte(phoneticResult.String()) @@ -698,7 +749,6 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -742,7 +792,12 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_organization_affiliation.go b/backend/pkg/models/database/fhir_organization_affiliation.go index 4cf302626..c1ea0e036 100644 --- a/backend/pkg/models/database/fhir_organization_affiliation.go +++ b/backend/pkg/models/database/fhir_organization_affiliation.go @@ -19,7 +19,7 @@ type FhirOrganizationAffiliation struct { Active datatypes.JSON `gorm:"column:active;type:text;serializer:json" json:"active,omitempty"` // The period during which the participatingOrganization is affiliated with the primary organization // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // A value in an email contact // https://hl7.org/fhir/r4/search.html#token Email datatypes.JSON `gorm:"column:email;type:text;serializer:json" json:"email,omitempty"` @@ -34,7 +34,7 @@ type FhirOrganizationAffiliation struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The location(s) at which the role occurs // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` @@ -169,7 +169,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(ActiveProcessed) + if(ActiveProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActiveProcessed) + } `) if err == nil && activeResult.String() != "undefined" { s.Active = []byte(activeResult.String()) @@ -179,7 +184,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Email @@ -219,7 +229,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(EmailProcessed) + if(EmailProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EmailProcessed) + } `) if err == nil && emailResult.String() != "undefined" { s.Email = []byte(emailResult.String()) @@ -227,7 +242,6 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc // extracting Endpoint endpointResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.endpoint'))") if err == nil && endpointResult.String() != "undefined" { - s.Endpoint = []byte(endpointResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -266,7 +280,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -308,7 +327,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -318,23 +342,25 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.location'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting Network networkResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.network'))") if err == nil && networkResult.String() != "undefined" { - s.Network = []byte(networkResult.String()) } // extracting ParticipatingOrganization participatingOrganizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.participatingOrganization'))") if err == nil && participatingOrganizationResult.String() != "undefined" { - s.ParticipatingOrganization = []byte(participatingOrganizationResult.String()) } // extracting Phone phoneResult, err := vm.RunString(` @@ -373,7 +399,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(PhoneProcessed) + if(PhoneProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneProcessed) + } `) if err == nil && phoneResult.String() != "undefined" { s.Phone = []byte(phoneResult.String()) @@ -381,12 +412,10 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc // extracting PrimaryOrganization primaryOrganizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.organization'))") if err == nil && primaryOrganizationResult.String() != "undefined" { - s.PrimaryOrganization = []byte(primaryOrganizationResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Role roleResult, err := vm.RunString(` @@ -425,7 +454,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(RoleProcessed) + if(RoleProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RoleProcessed) + } `) if err == nil && roleResult.String() != "undefined" { s.Role = []byte(roleResult.String()) @@ -433,7 +467,6 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc // extracting Service serviceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.healthcareService'))") if err == nil && serviceResult.String() != "undefined" { - s.Service = []byte(serviceResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -477,7 +510,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(SpecialtyProcessed) + if(SpecialtyProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SpecialtyProcessed) + } `) if err == nil && specialtyResult.String() != "undefined" { s.Specialty = []byte(specialtyResult.String()) @@ -519,7 +557,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -561,7 +604,12 @@ func (s *FhirOrganizationAffiliation) PopulateAndExtractSearchParameters(resourc }, []) - JSON.stringify(TelecomProcessed) + if(TelecomProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TelecomProcessed) + } `) if err == nil && telecomResult.String() != "undefined" { s.Telecom = []byte(telecomResult.String()) diff --git a/backend/pkg/models/database/fhir_patient.go b/backend/pkg/models/database/fhir_patient.go index 13e086e64..c49094ad7 100644 --- a/backend/pkg/models/database/fhir_patient.go +++ b/backend/pkg/models/database/fhir_patient.go @@ -85,10 +85,10 @@ type FhirPatient struct { * [RelatedPerson](relatedperson.html): The Related Person's date of birth */ // https://hl7.org/fhir/r4/search.html#date - Birthdate time.Time `gorm:"column:birthdate;type:datetime" json:"birthdate,omitempty"` + Birthdate *time.Time `gorm:"column:birthdate;type:datetime" json:"birthdate,omitempty"` // The date of death has been provided and satisfies this search value // https://hl7.org/fhir/r4/search.html#date - DeathDate time.Time `gorm:"column:deathDate;type:datetime" json:"deathDate,omitempty"` + DeathDate *time.Time `gorm:"column:deathDate;type:datetime" json:"deathDate,omitempty"` // This patient has been marked as deceased, or has a death date entered // https://hl7.org/fhir/r4/search.html#token Deceased datatypes.JSON `gorm:"column:deceased;type:text;serializer:json" json:"deceased,omitempty"` @@ -140,7 +140,7 @@ type FhirPatient struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // All patients linked to the given patient // https://hl7.org/fhir/r4/search.html#reference Link datatypes.JSON `gorm:"column:link;type:text;serializer:json" json:"link,omitempty"` @@ -297,7 +297,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(ActiveProcessed) + if(ActiveProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActiveProcessed) + } `) if err == nil && activeResult.String() != "undefined" { s.Active = []byte(activeResult.String()) @@ -351,8 +356,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(AddressProcessed) + if(AddressProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressProcessed) + } `) if err == nil && addressResult.String() != "undefined" { s.Address = []byte(addressResult.String()) @@ -406,8 +415,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(AddressCityProcessed) + if(AddressCityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCityProcessed) + } `) if err == nil && addressCityResult.String() != "undefined" { s.AddressCity = []byte(addressCityResult.String()) @@ -461,8 +474,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(AddressCountryProcessed) + if(AddressCountryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCountryProcessed) + } `) if err == nil && addressCountryResult.String() != "undefined" { s.AddressCountry = []byte(addressCountryResult.String()) @@ -516,8 +533,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(AddressPostalcodeProcessed) + if(AddressPostalcodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressPostalcodeProcessed) + } `) if err == nil && addressPostalcodeResult.String() != "undefined" { s.AddressPostalcode = []byte(addressPostalcodeResult.String()) @@ -571,8 +592,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(AddressStateProcessed) + if(AddressStateProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressStateProcessed) + } `) if err == nil && addressStateResult.String() != "undefined" { s.AddressState = []byte(addressStateResult.String()) @@ -614,7 +639,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(AddressUseProcessed) + if(AddressUseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressUseProcessed) + } `) if err == nil && addressUseResult.String() != "undefined" { s.AddressUse = []byte(addressUseResult.String()) @@ -624,7 +654,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes if err == nil && birthdateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, birthdateResult.String()) if err == nil { - s.Birthdate = t + s.Birthdate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", birthdateResult.String()) + if err == nil { + s.Birthdate = &d + } } } // extracting DeathDate @@ -632,7 +667,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes if err == nil && deathDateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, deathDateResult.String()) if err == nil { - s.DeathDate = t + s.DeathDate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", deathDateResult.String()) + if err == nil { + s.DeathDate = &d + } } } // extracting Deceased @@ -672,7 +712,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(DeceasedProcessed) + if(DeceasedProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DeceasedProcessed) + } `) if err == nil && deceasedResult.String() != "undefined" { s.Deceased = []byte(deceasedResult.String()) @@ -714,7 +759,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(EmailProcessed) + if(EmailProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EmailProcessed) + } `) if err == nil && emailResult.String() != "undefined" { s.Email = []byte(emailResult.String()) @@ -768,8 +818,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(FamilyProcessed) + if(FamilyProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(FamilyProcessed) + } `) if err == nil && familyResult.String() != "undefined" { s.Family = []byte(familyResult.String()) @@ -811,7 +865,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(GenderProcessed) + if(GenderProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(GenderProcessed) + } `) if err == nil && genderResult.String() != "undefined" { s.Gender = []byte(genderResult.String()) @@ -819,7 +878,6 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes // extracting GeneralPractitioner generalPractitionerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Patient.generalPractitioner'))") if err == nil && generalPractitionerResult.String() != "undefined" { - s.GeneralPractitioner = []byte(generalPractitionerResult.String()) } // extracting Given givenResult, err := vm.RunString(` @@ -870,8 +928,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(GivenProcessed) + if(GivenProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(GivenProcessed) + } `) if err == nil && givenResult.String() != "undefined" { s.Given = []byte(givenResult.String()) @@ -913,7 +975,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -955,7 +1022,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -965,13 +1037,17 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Link linkResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Patient.link.other'))") if err == nil && linkResult.String() != "undefined" { - s.Link = []byte(linkResult.String()) } // extracting Name nameResult, err := vm.RunString(` @@ -1022,8 +1098,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -1031,7 +1111,6 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Patient.managingOrganization'))") if err == nil && organizationResult.String() != "undefined" { - s.Organization = []byte(organizationResult.String()) } // extracting Phone phoneResult, err := vm.RunString(` @@ -1070,7 +1149,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(PhoneProcessed) + if(PhoneProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneProcessed) + } `) if err == nil && phoneResult.String() != "undefined" { s.Phone = []byte(phoneResult.String()) @@ -1124,8 +1208,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes return accumulator }, []) - - JSON.stringify(PhoneticProcessed) + if(PhoneticProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneticProcessed) + } `) if err == nil && phoneticResult.String() != "undefined" { s.Phonetic = []byte(phoneticResult.String()) @@ -1133,7 +1221,6 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -1177,7 +1264,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -1219,7 +1311,12 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes }, []) - JSON.stringify(TelecomProcessed) + if(TelecomProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TelecomProcessed) + } `) if err == nil && telecomResult.String() != "undefined" { s.Telecom = []byte(telecomResult.String()) diff --git a/backend/pkg/models/database/fhir_patient_test.go b/backend/pkg/models/database/fhir_patient_test.go index ca1c047d4..a04d80131 100644 --- a/backend/pkg/models/database/fhir_patient_test.go +++ b/backend/pkg/models/database/fhir_patient_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" "os" "testing" + "time" ) func TestFhirPatient_ExtractSearchParameters(t *testing.T) { @@ -24,6 +25,7 @@ func TestFhirPatient_ExtractSearchParameters(t *testing.T) { type CodeType struct { Code bool `json:"code"` } + var testCode []CodeType require.NoError(t, err) err = json.Unmarshal(json.RawMessage(patientModel.Active), &testCode) @@ -47,4 +49,7 @@ func TestFhirPatient_ExtractSearchParameters(t *testing.T) { require.Equal(t, []string{ "534 Erewhon St PleasantVille Vic 3999", }, testAddress) + + require.Equal(t, time.Date(1974, 12, 25, 0, 0, 0, 0, time.UTC), patientModel.Birthdate) + } diff --git a/backend/pkg/models/database/fhir_person.go b/backend/pkg/models/database/fhir_person.go index 483c732c5..2cac4223d 100644 --- a/backend/pkg/models/database/fhir_person.go +++ b/backend/pkg/models/database/fhir_person.go @@ -82,7 +82,7 @@ type FhirPerson struct { * [RelatedPerson](relatedperson.html): The Related Person's date of birth */ // https://hl7.org/fhir/r4/search.html#date - Birthdate time.Time `gorm:"column:birthdate;type:datetime" json:"birthdate,omitempty"` + Birthdate *time.Time `gorm:"column:birthdate;type:datetime" json:"birthdate,omitempty"` /* Multiple Resources: @@ -112,7 +112,7 @@ type FhirPerson struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Any link has this Patient, Person, RelatedPerson or Practitioner reference // https://hl7.org/fhir/r4/search.html#reference Link datatypes.JSON `gorm:"column:link;type:text;serializer:json" json:"link,omitempty"` @@ -283,8 +283,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(AddressProcessed) + if(AddressProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressProcessed) + } `) if err == nil && addressResult.String() != "undefined" { s.Address = []byte(addressResult.String()) @@ -338,8 +342,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(AddressCityProcessed) + if(AddressCityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCityProcessed) + } `) if err == nil && addressCityResult.String() != "undefined" { s.AddressCity = []byte(addressCityResult.String()) @@ -393,8 +401,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(AddressCountryProcessed) + if(AddressCountryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCountryProcessed) + } `) if err == nil && addressCountryResult.String() != "undefined" { s.AddressCountry = []byte(addressCountryResult.String()) @@ -448,8 +460,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(AddressPostalcodeProcessed) + if(AddressPostalcodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressPostalcodeProcessed) + } `) if err == nil && addressPostalcodeResult.String() != "undefined" { s.AddressPostalcode = []byte(addressPostalcodeResult.String()) @@ -503,8 +519,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(AddressStateProcessed) + if(AddressStateProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressStateProcessed) + } `) if err == nil && addressStateResult.String() != "undefined" { s.AddressState = []byte(addressStateResult.String()) @@ -546,7 +566,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(AddressUseProcessed) + if(AddressUseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressUseProcessed) + } `) if err == nil && addressUseResult.String() != "undefined" { s.AddressUse = []byte(addressUseResult.String()) @@ -556,7 +581,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess if err == nil && birthdateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, birthdateResult.String()) if err == nil { - s.Birthdate = t + s.Birthdate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", birthdateResult.String()) + if err == nil { + s.Birthdate = &d + } } } // extracting Email @@ -596,7 +626,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(EmailProcessed) + if(EmailProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EmailProcessed) + } `) if err == nil && emailResult.String() != "undefined" { s.Email = []byte(emailResult.String()) @@ -638,7 +673,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(GenderProcessed) + if(GenderProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(GenderProcessed) + } `) if err == nil && genderResult.String() != "undefined" { s.Gender = []byte(genderResult.String()) @@ -680,7 +720,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -722,7 +767,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -732,13 +782,17 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Link linkResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Person.link.target'))") if err == nil && linkResult.String() != "undefined" { - s.Link = []byte(linkResult.String()) } // extracting Name nameResult, err := vm.RunString(` @@ -789,8 +843,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -798,7 +856,6 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Person.managingOrganization'))") if err == nil && organizationResult.String() != "undefined" { - s.Organization = []byte(organizationResult.String()) } // extracting Phone phoneResult, err := vm.RunString(` @@ -837,7 +894,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(PhoneProcessed) + if(PhoneProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneProcessed) + } `) if err == nil && phoneResult.String() != "undefined" { s.Phone = []byte(phoneResult.String()) @@ -891,8 +953,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess return accumulator }, []) - - JSON.stringify(PhoneticProcessed) + if(PhoneticProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneticProcessed) + } `) if err == nil && phoneticResult.String() != "undefined" { s.Phonetic = []byte(phoneticResult.String()) @@ -900,17 +966,14 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess // extracting Practitioner practitionerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Person.link.target.where(resolve() is Practitioner)'))") if err == nil && practitionerResult.String() != "undefined" { - s.Practitioner = []byte(practitionerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Relatedperson relatedpersonResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Person.link.target.where(resolve() is RelatedPerson)'))") if err == nil && relatedpersonResult.String() != "undefined" { - s.Relatedperson = []byte(relatedpersonResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -954,7 +1017,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -996,7 +1064,12 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess }, []) - JSON.stringify(TelecomProcessed) + if(TelecomProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TelecomProcessed) + } `) if err == nil && telecomResult.String() != "undefined" { s.Telecom = []byte(telecomResult.String()) diff --git a/backend/pkg/models/database/fhir_practitioner.go b/backend/pkg/models/database/fhir_practitioner.go index db184bbdd..2fb894745 100644 --- a/backend/pkg/models/database/fhir_practitioner.go +++ b/backend/pkg/models/database/fhir_practitioner.go @@ -125,7 +125,7 @@ type FhirPractitioner struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // A server defined search that may match any of the string fields in the HumanName, including family, give, prefix, suffix, suffix, and/or text // https://hl7.org/fhir/r4/search.html#string Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` @@ -271,7 +271,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(ActiveProcessed) + if(ActiveProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActiveProcessed) + } `) if err == nil && activeResult.String() != "undefined" { s.Active = []byte(activeResult.String()) @@ -325,8 +330,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressProcessed) + if(AddressProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressProcessed) + } `) if err == nil && addressResult.String() != "undefined" { s.Address = []byte(addressResult.String()) @@ -380,8 +389,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressCityProcessed) + if(AddressCityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCityProcessed) + } `) if err == nil && addressCityResult.String() != "undefined" { s.AddressCity = []byte(addressCityResult.String()) @@ -435,8 +448,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressCountryProcessed) + if(AddressCountryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCountryProcessed) + } `) if err == nil && addressCountryResult.String() != "undefined" { s.AddressCountry = []byte(addressCountryResult.String()) @@ -490,8 +507,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressPostalcodeProcessed) + if(AddressPostalcodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressPostalcodeProcessed) + } `) if err == nil && addressPostalcodeResult.String() != "undefined" { s.AddressPostalcode = []byte(addressPostalcodeResult.String()) @@ -545,8 +566,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(AddressStateProcessed) + if(AddressStateProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressStateProcessed) + } `) if err == nil && addressStateResult.String() != "undefined" { s.AddressState = []byte(addressStateResult.String()) @@ -588,7 +613,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(AddressUseProcessed) + if(AddressUseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressUseProcessed) + } `) if err == nil && addressUseResult.String() != "undefined" { s.AddressUse = []byte(addressUseResult.String()) @@ -630,7 +660,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(CommunicationProcessed) + if(CommunicationProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CommunicationProcessed) + } `) if err == nil && communicationResult.String() != "undefined" { s.Communication = []byte(communicationResult.String()) @@ -672,7 +707,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(EmailProcessed) + if(EmailProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EmailProcessed) + } `) if err == nil && emailResult.String() != "undefined" { s.Email = []byte(emailResult.String()) @@ -726,8 +766,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(FamilyProcessed) + if(FamilyProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(FamilyProcessed) + } `) if err == nil && familyResult.String() != "undefined" { s.Family = []byte(familyResult.String()) @@ -769,7 +813,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(GenderProcessed) + if(GenderProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(GenderProcessed) + } `) if err == nil && genderResult.String() != "undefined" { s.Gender = []byte(genderResult.String()) @@ -823,8 +872,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(GivenProcessed) + if(GivenProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(GivenProcessed) + } `) if err == nil && givenResult.String() != "undefined" { s.Given = []byte(givenResult.String()) @@ -866,7 +919,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -908,7 +966,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -918,7 +981,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Name @@ -970,8 +1038,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -1013,7 +1085,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(PhoneProcessed) + if(PhoneProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneProcessed) + } `) if err == nil && phoneResult.String() != "undefined" { s.Phone = []byte(phoneResult.String()) @@ -1067,8 +1144,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R return accumulator }, []) - - JSON.stringify(PhoneticProcessed) + if(PhoneticProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneticProcessed) + } `) if err == nil && phoneticResult.String() != "undefined" { s.Phonetic = []byte(phoneticResult.String()) @@ -1076,7 +1157,6 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -1120,7 +1200,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -1162,7 +1247,12 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R }, []) - JSON.stringify(TelecomProcessed) + if(TelecomProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TelecomProcessed) + } `) if err == nil && telecomResult.String() != "undefined" { s.Telecom = []byte(telecomResult.String()) diff --git a/backend/pkg/models/database/fhir_practitioner_role.go b/backend/pkg/models/database/fhir_practitioner_role.go index bbe42d233..c5e357609 100644 --- a/backend/pkg/models/database/fhir_practitioner_role.go +++ b/backend/pkg/models/database/fhir_practitioner_role.go @@ -19,7 +19,7 @@ type FhirPractitionerRole struct { Active datatypes.JSON `gorm:"column:active;type:text;serializer:json" json:"active,omitempty"` // The period during which the practitioner is authorized to perform in these role(s) // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -42,7 +42,7 @@ type FhirPractitionerRole struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // One of the locations at which this practitioner provides care // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` @@ -189,7 +189,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(ActiveProcessed) + if(ActiveProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActiveProcessed) + } `) if err == nil && activeResult.String() != "undefined" { s.Active = []byte(activeResult.String()) @@ -199,7 +204,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Email @@ -239,7 +249,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(EmailProcessed) + if(EmailProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EmailProcessed) + } `) if err == nil && emailResult.String() != "undefined" { s.Email = []byte(emailResult.String()) @@ -247,7 +262,6 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js // extracting Endpoint endpointResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'PractitionerRole.endpoint'))") if err == nil && endpointResult.String() != "undefined" { - s.Endpoint = []byte(endpointResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -286,7 +300,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -328,7 +347,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -338,18 +362,21 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'PractitionerRole.location'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'PractitionerRole.organization'))") if err == nil && organizationResult.String() != "undefined" { - s.Organization = []byte(organizationResult.String()) } // extracting Phone phoneResult, err := vm.RunString(` @@ -388,7 +415,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(PhoneProcessed) + if(PhoneProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneProcessed) + } `) if err == nil && phoneResult.String() != "undefined" { s.Phone = []byte(phoneResult.String()) @@ -396,12 +428,10 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js // extracting Practitioner practitionerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'PractitionerRole.practitioner'))") if err == nil && practitionerResult.String() != "undefined" { - s.Practitioner = []byte(practitionerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Role roleResult, err := vm.RunString(` @@ -440,7 +470,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(RoleProcessed) + if(RoleProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RoleProcessed) + } `) if err == nil && roleResult.String() != "undefined" { s.Role = []byte(roleResult.String()) @@ -448,7 +483,6 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js // extracting Service serviceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'PractitionerRole.healthcareService'))") if err == nil && serviceResult.String() != "undefined" { - s.Service = []byte(serviceResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -492,7 +526,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(SpecialtyProcessed) + if(SpecialtyProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SpecialtyProcessed) + } `) if err == nil && specialtyResult.String() != "undefined" { s.Specialty = []byte(specialtyResult.String()) @@ -534,7 +573,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -576,7 +620,12 @@ func (s *FhirPractitionerRole) PopulateAndExtractSearchParameters(resourceRaw js }, []) - JSON.stringify(TelecomProcessed) + if(TelecomProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TelecomProcessed) + } `) if err == nil && telecomResult.String() != "undefined" { s.Telecom = []byte(telecomResult.String()) diff --git a/backend/pkg/models/database/fhir_procedure.go b/backend/pkg/models/database/fhir_procedure.go index acd431f1a..e7f49d5df 100644 --- a/backend/pkg/models/database/fhir_procedure.go +++ b/backend/pkg/models/database/fhir_procedure.go @@ -62,7 +62,7 @@ type FhirProcedure struct { * [SupplyRequest](supplyrequest.html): When the request was made */ // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: @@ -128,7 +128,7 @@ type FhirProcedure struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Where the procedure happened // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` @@ -224,7 +224,6 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Procedure.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting Category categoryResult, err := vm.RunString(` @@ -263,7 +262,12 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -305,7 +309,12 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -315,13 +324,17 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -360,7 +373,12 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -368,7 +386,6 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting InstantiatesCanonical instantiatesCanonicalResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Procedure.instantiatesCanonical'))") if err == nil && instantiatesCanonicalResult.String() != "undefined" { - s.InstantiatesCanonical = []byte(instantiatesCanonicalResult.String()) } // extracting InstantiatesUri instantiatesUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Procedure.instantiatesUri')[0]") @@ -412,7 +429,12 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -422,28 +444,29 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Procedure.location'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting PartOf partOfResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Procedure.partOf'))") if err == nil && partOfResult.String() != "undefined" { - s.PartOf = []byte(partOfResult.String()) } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Procedure.performer.actor'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting ReasonCode reasonCodeResult, err := vm.RunString(` @@ -482,7 +505,12 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(ReasonCodeProcessed) + if(ReasonCodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ReasonCodeProcessed) + } `) if err == nil && reasonCodeResult.String() != "undefined" { s.ReasonCode = []byte(reasonCodeResult.String()) @@ -490,7 +518,6 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting ReasonReference reasonReferenceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Procedure.reasonReference'))") if err == nil && reasonReferenceResult.String() != "undefined" { - s.ReasonReference = []byte(reasonReferenceResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -534,7 +561,12 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -542,7 +574,6 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Procedure.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -581,7 +612,12 @@ func (s *FhirProcedure) PopulateAndExtractSearchParameters(resourceRaw json.RawM }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_provenance.go b/backend/pkg/models/database/fhir_provenance.go index 5ecf93177..19e285170 100644 --- a/backend/pkg/models/database/fhir_provenance.go +++ b/backend/pkg/models/database/fhir_provenance.go @@ -31,7 +31,7 @@ type FhirProvenance struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Where the activity occurred, if relevant // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` @@ -40,7 +40,7 @@ type FhirProvenance struct { Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` // When the activity was recorded / updated // https://hl7.org/fhir/r4/search.html#date - Recorded time.Time `gorm:"column:recorded;type:datetime" json:"recorded,omitempty"` + Recorded *time.Time `gorm:"column:recorded;type:datetime" json:"recorded,omitempty"` // Indication of the reason the entity signed the object(s) // https://hl7.org/fhir/r4/search.html#token SignatureType datatypes.JSON `gorm:"column:signatureType;type:text;serializer:json" json:"signatureType,omitempty"` @@ -61,7 +61,7 @@ type FhirProvenance struct { Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` // When the activity occurred // https://hl7.org/fhir/r4/search.html#date - When time.Time `gorm:"column:when;type:datetime" json:"when,omitempty"` + When *time.Time `gorm:"column:when;type:datetime" json:"when,omitempty"` } func (s *FhirProvenance) GetSearchParameters() map[string]string { @@ -115,7 +115,6 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw // extracting Agent agentResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Provenance.agent.who'))") if err == nil && agentResult.String() != "undefined" { - s.Agent = []byte(agentResult.String()) } // extracting AgentRole agentRoleResult, err := vm.RunString(` @@ -154,7 +153,12 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(AgentRoleProcessed) + if(AgentRoleProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AgentRoleProcessed) + } `) if err == nil && agentRoleResult.String() != "undefined" { s.AgentRole = []byte(agentRoleResult.String()) @@ -196,7 +200,12 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(AgentTypeProcessed) + if(AgentTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AgentTypeProcessed) + } `) if err == nil && agentTypeResult.String() != "undefined" { s.AgentType = []byte(agentTypeResult.String()) @@ -204,7 +213,6 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw // extracting Entity entityResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Provenance.entity.what'))") if err == nil && entityResult.String() != "undefined" { - s.Entity = []byte(entityResult.String()) } // extracting Language languageResult, err := vm.RunString(` @@ -243,7 +251,12 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -253,25 +266,33 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Location locationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Provenance.location'))") if err == nil && locationResult.String() != "undefined" { - s.Location = []byte(locationResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Recorded recordedResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Provenance.recorded')[0]") if err == nil && recordedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, recordedResult.String()) if err == nil { - s.Recorded = t + s.Recorded = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", recordedResult.String()) + if err == nil { + s.Recorded = &d + } } } // extracting SignatureType @@ -311,7 +332,12 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(SignatureTypeProcessed) + if(SignatureTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SignatureTypeProcessed) + } `) if err == nil && signatureTypeResult.String() != "undefined" { s.SignatureType = []byte(signatureTypeResult.String()) @@ -358,7 +384,12 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -366,14 +397,18 @@ func (s *FhirProvenance) PopulateAndExtractSearchParameters(resourceRaw json.Raw // extracting Target targetResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Provenance.target'))") if err == nil && targetResult.String() != "undefined" { - s.Target = []byte(targetResult.String()) } // extracting When whenResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, '(Provenance.occurredDateTime)')[0]") if err == nil && whenResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, whenResult.String()) if err == nil { - s.When = t + s.When = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", whenResult.String()) + if err == nil { + s.When = &d + } } } return nil diff --git a/backend/pkg/models/database/fhir_questionnaire.go b/backend/pkg/models/database/fhir_questionnaire.go index a620d9181..4316e1ecb 100644 --- a/backend/pkg/models/database/fhir_questionnaire.go +++ b/backend/pkg/models/database/fhir_questionnaire.go @@ -28,7 +28,7 @@ type FhirQuestionnaire struct { ContextType datatypes.JSON `gorm:"column:contextType;type:text;serializer:json" json:"contextType,omitempty"` // The questionnaire publication date // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // ElementDefinition - details for the item // https://hl7.org/fhir/r4/search.html#uri Definition string `gorm:"column:definition;type:text" json:"definition,omitempty"` @@ -37,7 +37,7 @@ type FhirQuestionnaire struct { Description datatypes.JSON `gorm:"column:description;type:text;serializer:json" json:"description,omitempty"` // The time during which the questionnaire is intended to be in use // https://hl7.org/fhir/r4/search.html#date - Effective time.Time `gorm:"column:effective;type:datetime" json:"effective,omitempty"` + Effective *time.Time `gorm:"column:effective;type:datetime" json:"effective,omitempty"` // External identifier for the questionnaire // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -49,7 +49,7 @@ type FhirQuestionnaire struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Computationally friendly name of the questionnaire // https://hl7.org/fhir/r4/search.html#string Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` @@ -181,7 +181,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -223,7 +228,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(ContextProcessed) + if(ContextProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ContextProcessed) + } `) if err == nil && contextResult.String() != "undefined" { s.Context = []byte(contextResult.String()) @@ -270,7 +280,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(ContextTypeProcessed) + if(ContextTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ContextTypeProcessed) + } `) if err == nil && contextTypeResult.String() != "undefined" { s.ContextType = []byte(contextTypeResult.String()) @@ -280,7 +295,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Definition @@ -337,8 +357,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(DescriptionProcessed) + if(DescriptionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(DescriptionProcessed) + } `) if err == nil && descriptionResult.String() != "undefined" { s.Description = []byte(descriptionResult.String()) @@ -348,7 +372,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && effectiveResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, effectiveResult.String()) if err == nil { - s.Effective = t + s.Effective = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", effectiveResult.String()) + if err == nil { + s.Effective = &d + } } } // extracting Identifier @@ -388,7 +417,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -430,7 +464,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(JurisdictionProcessed) + if(JurisdictionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(JurisdictionProcessed) + } `) if err == nil && jurisdictionResult.String() != "undefined" { s.Jurisdiction = []byte(jurisdictionResult.String()) @@ -472,7 +511,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -482,7 +526,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Name @@ -534,8 +583,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -543,7 +596,6 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Publisher publisherResult, err := vm.RunString(` @@ -594,8 +646,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(PublisherProcessed) + if(PublisherProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PublisherProcessed) + } `) if err == nil && publisherResult.String() != "undefined" { s.Publisher = []byte(publisherResult.String()) @@ -642,7 +698,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -684,7 +745,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(SubjectTypeProcessed) + if(SubjectTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SubjectTypeProcessed) + } `) if err == nil && subjectTypeResult.String() != "undefined" { s.SubjectType = []byte(subjectTypeResult.String()) @@ -726,7 +792,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -780,8 +851,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(TitleProcessed) + if(TitleProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TitleProcessed) + } `) if err == nil && titleResult.String() != "undefined" { s.Title = []byte(titleResult.String()) @@ -828,7 +903,12 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(VersionProcessed) + if(VersionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(VersionProcessed) + } `) if err == nil && versionResult.String() != "undefined" { s.Version = []byte(versionResult.String()) diff --git a/backend/pkg/models/database/fhir_questionnaire_response.go b/backend/pkg/models/database/fhir_questionnaire_response.go index c993e5840..9a5deb8c9 100644 --- a/backend/pkg/models/database/fhir_questionnaire_response.go +++ b/backend/pkg/models/database/fhir_questionnaire_response.go @@ -19,7 +19,7 @@ type FhirQuestionnaireResponse struct { Author datatypes.JSON `gorm:"column:author;type:text;serializer:json" json:"author,omitempty"` // When the questionnaire response was last changed // https://hl7.org/fhir/r4/search.html#date - Authored time.Time `gorm:"column:authored;type:datetime" json:"authored,omitempty"` + Authored *time.Time `gorm:"column:authored;type:datetime" json:"authored,omitempty"` // Plan/proposal/order fulfilled by this questionnaire response // https://hl7.org/fhir/r4/search.html#reference BasedOn datatypes.JSON `gorm:"column:basedOn;type:text;serializer:json" json:"basedOn,omitempty"` @@ -34,7 +34,7 @@ type FhirQuestionnaireResponse struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Procedure or observation this questionnaire response was performed as a part of // https://hl7.org/fhir/r4/search.html#reference PartOf datatypes.JSON `gorm:"column:partOf;type:text;serializer:json" json:"partOf,omitempty"` @@ -119,25 +119,27 @@ func (s *FhirQuestionnaireResponse) PopulateAndExtractSearchParameters(resourceR // extracting Author authorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'QuestionnaireResponse.author'))") if err == nil && authorResult.String() != "undefined" { - s.Author = []byte(authorResult.String()) } // extracting Authored authoredResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'QuestionnaireResponse.authored')[0]") if err == nil && authoredResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, authoredResult.String()) if err == nil { - s.Authored = t + s.Authored = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", authoredResult.String()) + if err == nil { + s.Authored = &d + } } } // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'QuestionnaireResponse.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'QuestionnaireResponse.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -176,7 +178,12 @@ func (s *FhirQuestionnaireResponse) PopulateAndExtractSearchParameters(resourceR }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -218,7 +225,12 @@ func (s *FhirQuestionnaireResponse) PopulateAndExtractSearchParameters(resourceR }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -228,28 +240,29 @@ func (s *FhirQuestionnaireResponse) PopulateAndExtractSearchParameters(resourceR if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting PartOf partOfResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'QuestionnaireResponse.partOf'))") if err == nil && partOfResult.String() != "undefined" { - s.PartOf = []byte(partOfResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Questionnaire questionnaireResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'QuestionnaireResponse.questionnaire'))") if err == nil && questionnaireResult.String() != "undefined" { - s.Questionnaire = []byte(questionnaireResult.String()) } // extracting Source sourceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'QuestionnaireResponse.source'))") if err == nil && sourceResult.String() != "undefined" { - s.Source = []byte(sourceResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -293,7 +306,12 @@ func (s *FhirQuestionnaireResponse) PopulateAndExtractSearchParameters(resourceR }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -301,7 +319,6 @@ func (s *FhirQuestionnaireResponse) PopulateAndExtractSearchParameters(resourceR // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'QuestionnaireResponse.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -340,7 +357,12 @@ func (s *FhirQuestionnaireResponse) PopulateAndExtractSearchParameters(resourceR }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_related_person.go b/backend/pkg/models/database/fhir_related_person.go index 037fd756f..c2d40b93a 100644 --- a/backend/pkg/models/database/fhir_related_person.go +++ b/backend/pkg/models/database/fhir_related_person.go @@ -85,7 +85,7 @@ type FhirRelatedPerson struct { * [RelatedPerson](relatedperson.html): The Related Person's date of birth */ // https://hl7.org/fhir/r4/search.html#date - Birthdate time.Time `gorm:"column:birthdate;type:datetime" json:"birthdate,omitempty"` + Birthdate *time.Time `gorm:"column:birthdate;type:datetime" json:"birthdate,omitempty"` /* Multiple Resources: @@ -115,7 +115,7 @@ type FhirRelatedPerson struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // A server defined search that may match any of the string fields in the HumanName, including family, give, prefix, suffix, suffix, and/or text // https://hl7.org/fhir/r4/search.html#string Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` @@ -263,7 +263,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(ActiveProcessed) + if(ActiveProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActiveProcessed) + } `) if err == nil && activeResult.String() != "undefined" { s.Active = []byte(activeResult.String()) @@ -317,8 +322,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressProcessed) + if(AddressProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressProcessed) + } `) if err == nil && addressResult.String() != "undefined" { s.Address = []byte(addressResult.String()) @@ -372,8 +381,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressCityProcessed) + if(AddressCityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCityProcessed) + } `) if err == nil && addressCityResult.String() != "undefined" { s.AddressCity = []byte(addressCityResult.String()) @@ -427,8 +440,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressCountryProcessed) + if(AddressCountryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressCountryProcessed) + } `) if err == nil && addressCountryResult.String() != "undefined" { s.AddressCountry = []byte(addressCountryResult.String()) @@ -482,8 +499,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressPostalcodeProcessed) + if(AddressPostalcodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressPostalcodeProcessed) + } `) if err == nil && addressPostalcodeResult.String() != "undefined" { s.AddressPostalcode = []byte(addressPostalcodeResult.String()) @@ -537,8 +558,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(AddressStateProcessed) + if(AddressStateProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressStateProcessed) + } `) if err == nil && addressStateResult.String() != "undefined" { s.AddressState = []byte(addressStateResult.String()) @@ -580,7 +605,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(AddressUseProcessed) + if(AddressUseProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AddressUseProcessed) + } `) if err == nil && addressUseResult.String() != "undefined" { s.AddressUse = []byte(addressUseResult.String()) @@ -590,7 +620,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && birthdateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, birthdateResult.String()) if err == nil { - s.Birthdate = t + s.Birthdate = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", birthdateResult.String()) + if err == nil { + s.Birthdate = &d + } } } // extracting Email @@ -630,7 +665,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(EmailProcessed) + if(EmailProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(EmailProcessed) + } `) if err == nil && emailResult.String() != "undefined" { s.Email = []byte(emailResult.String()) @@ -672,7 +712,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(GenderProcessed) + if(GenderProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(GenderProcessed) + } `) if err == nil && genderResult.String() != "undefined" { s.Gender = []byte(genderResult.String()) @@ -714,7 +759,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -756,7 +806,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -766,7 +821,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Name @@ -818,8 +878,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(NameProcessed) + if(NameProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(NameProcessed) + } `) if err == nil && nameResult.String() != "undefined" { s.Name = []byte(nameResult.String()) @@ -861,7 +925,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(PhoneProcessed) + if(PhoneProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneProcessed) + } `) if err == nil && phoneResult.String() != "undefined" { s.Phone = []byte(phoneResult.String()) @@ -915,8 +984,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. return accumulator }, []) - - JSON.stringify(PhoneticProcessed) + if(PhoneticProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PhoneticProcessed) + } `) if err == nil && phoneticResult.String() != "undefined" { s.Phonetic = []byte(phoneticResult.String()) @@ -924,7 +997,6 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Relationship relationshipResult, err := vm.RunString(` @@ -963,7 +1035,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(RelationshipProcessed) + if(RelationshipProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RelationshipProcessed) + } `) if err == nil && relationshipResult.String() != "undefined" { s.Relationship = []byte(relationshipResult.String()) @@ -1010,7 +1087,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) @@ -1052,7 +1134,12 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. }, []) - JSON.stringify(TelecomProcessed) + if(TelecomProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TelecomProcessed) + } `) if err == nil && telecomResult.String() != "undefined" { s.Telecom = []byte(telecomResult.String()) diff --git a/backend/pkg/models/database/fhir_schedule.go b/backend/pkg/models/database/fhir_schedule.go index c03b2014b..f64b9f620 100644 --- a/backend/pkg/models/database/fhir_schedule.go +++ b/backend/pkg/models/database/fhir_schedule.go @@ -22,7 +22,7 @@ type FhirSchedule struct { Actor datatypes.JSON `gorm:"column:actor;type:text;serializer:json" json:"actor,omitempty"` // Search for Schedule resources that have a period that contains this date specified // https://hl7.org/fhir/r4/search.html#date - Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` + Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // A Schedule Identifier // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -31,7 +31,7 @@ type FhirSchedule struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -141,7 +141,12 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(ActiveProcessed) + if(ActiveProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ActiveProcessed) + } `) if err == nil && activeResult.String() != "undefined" { s.Active = []byte(activeResult.String()) @@ -149,14 +154,18 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Actor actorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Schedule.actor'))") if err == nil && actorResult.String() != "undefined" { - s.Actor = []byte(actorResult.String()) } // extracting Date dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Schedule.planningHorizon')[0]") if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { - s.Date = t + s.Date = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", dateResult.String()) + if err == nil { + s.Date = &d + } } } // extracting Identifier @@ -196,7 +205,12 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -238,7 +252,12 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -248,13 +267,17 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting ServiceCategory serviceCategoryResult, err := vm.RunString(` @@ -293,7 +316,12 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(ServiceCategoryProcessed) + if(ServiceCategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ServiceCategoryProcessed) + } `) if err == nil && serviceCategoryResult.String() != "undefined" { s.ServiceCategory = []byte(serviceCategoryResult.String()) @@ -335,7 +363,12 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(ServiceTypeProcessed) + if(ServiceTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ServiceTypeProcessed) + } `) if err == nil && serviceTypeResult.String() != "undefined" { s.ServiceType = []byte(serviceTypeResult.String()) @@ -382,7 +415,12 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(SpecialtyProcessed) + if(SpecialtyProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SpecialtyProcessed) + } `) if err == nil && specialtyResult.String() != "undefined" { s.Specialty = []byte(specialtyResult.String()) @@ -424,7 +462,12 @@ func (s *FhirSchedule) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_service_request.go b/backend/pkg/models/database/fhir_service_request.go index 82db645cb..767a28d89 100644 --- a/backend/pkg/models/database/fhir_service_request.go +++ b/backend/pkg/models/database/fhir_service_request.go @@ -16,7 +16,7 @@ type FhirServiceRequest struct { models.ResourceBase // Date request signed // https://hl7.org/fhir/r4/search.html#date - Authored time.Time `gorm:"column:authored;type:datetime" json:"authored,omitempty"` + Authored *time.Time `gorm:"column:authored;type:datetime" json:"authored,omitempty"` // What request fulfills // https://hl7.org/fhir/r4/search.html#reference BasedOn datatypes.JSON `gorm:"column:basedOn;type:text;serializer:json" json:"basedOn,omitempty"` @@ -114,10 +114,10 @@ type FhirServiceRequest struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // When service should occur // https://hl7.org/fhir/r4/search.html#date - Occurrence time.Time `gorm:"column:occurrence;type:datetime" json:"occurrence,omitempty"` + Occurrence *time.Time `gorm:"column:occurrence;type:datetime" json:"occurrence,omitempty"` // Requested performer // https://hl7.org/fhir/r4/search.html#reference Performer datatypes.JSON `gorm:"column:performer;type:text;serializer:json" json:"performer,omitempty"` @@ -226,13 +226,17 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json if err == nil && authoredResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, authoredResult.String()) if err == nil { - s.Authored = t + s.Authored = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", authoredResult.String()) + if err == nil { + s.Authored = &d + } } } // extracting BasedOn basedOnResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ServiceRequest.basedOn'))") if err == nil && basedOnResult.String() != "undefined" { - s.BasedOn = []byte(basedOnResult.String()) } // extracting BodySite bodySiteResult, err := vm.RunString(` @@ -271,7 +275,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(BodySiteProcessed) + if(BodySiteProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(BodySiteProcessed) + } `) if err == nil && bodySiteResult.String() != "undefined" { s.BodySite = []byte(bodySiteResult.String()) @@ -313,7 +322,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(CategoryProcessed) + if(CategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CategoryProcessed) + } `) if err == nil && categoryResult.String() != "undefined" { s.Category = []byte(categoryResult.String()) @@ -355,7 +369,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(CodeProcessed) + if(CodeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(CodeProcessed) + } `) if err == nil && codeResult.String() != "undefined" { s.Code = []byte(codeResult.String()) @@ -363,7 +382,6 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -402,7 +420,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -410,7 +433,6 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json // extracting InstantiatesCanonical instantiatesCanonicalResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ServiceRequest.instantiatesCanonical'))") if err == nil && instantiatesCanonicalResult.String() != "undefined" { - s.InstantiatesCanonical = []byte(instantiatesCanonicalResult.String()) } // extracting InstantiatesUri instantiatesUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'ServiceRequest.instantiatesUri')[0]") @@ -454,7 +476,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(IntentProcessed) + if(IntentProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IntentProcessed) + } `) if err == nil && intentResult.String() != "undefined" { s.Intent = []byte(intentResult.String()) @@ -496,7 +523,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -506,7 +538,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Occurrence @@ -514,13 +551,17 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json if err == nil && occurrenceResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, occurrenceResult.String()) if err == nil { - s.Occurrence = t + s.Occurrence = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", occurrenceResult.String()) + if err == nil { + s.Occurrence = &d + } } } // extracting Performer performerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ServiceRequest.performer'))") if err == nil && performerResult.String() != "undefined" { - s.Performer = []byte(performerResult.String()) } // extracting PerformerType performerTypeResult, err := vm.RunString(` @@ -559,7 +600,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(PerformerTypeProcessed) + if(PerformerTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PerformerTypeProcessed) + } `) if err == nil && performerTypeResult.String() != "undefined" { s.PerformerType = []byte(performerTypeResult.String()) @@ -601,7 +647,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(PriorityProcessed) + if(PriorityProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(PriorityProcessed) + } `) if err == nil && priorityResult.String() != "undefined" { s.Priority = []byte(priorityResult.String()) @@ -609,17 +660,14 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Replaces replacesResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ServiceRequest.replaces'))") if err == nil && replacesResult.String() != "undefined" { - s.Replaces = []byte(replacesResult.String()) } // extracting Requester requesterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ServiceRequest.requester'))") if err == nil && requesterResult.String() != "undefined" { - s.Requester = []byte(requesterResult.String()) } // extracting Requisition requisitionResult, err := vm.RunString(` @@ -658,7 +706,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(RequisitionProcessed) + if(RequisitionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(RequisitionProcessed) + } `) if err == nil && requisitionResult.String() != "undefined" { s.Requisition = []byte(requisitionResult.String()) @@ -671,7 +724,6 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json // extracting Specimen specimenResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ServiceRequest.specimen'))") if err == nil && specimenResult.String() != "undefined" { - s.Specimen = []byte(specimenResult.String()) } // extracting Status statusResult, err := vm.RunString(` @@ -710,7 +762,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -718,7 +775,6 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ServiceRequest.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -757,7 +813,12 @@ func (s *FhirServiceRequest) PopulateAndExtractSearchParameters(resourceRaw json }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_slot.go b/backend/pkg/models/database/fhir_slot.go index b5225cf1a..4edcec547 100644 --- a/backend/pkg/models/database/fhir_slot.go +++ b/backend/pkg/models/database/fhir_slot.go @@ -25,7 +25,7 @@ type FhirSlot struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Profiles this resource claims to conform to // https://hl7.org/fhir/r4/search.html#reference Profile datatypes.JSON `gorm:"column:profile;type:text;serializer:json" json:"profile,omitempty"` @@ -46,7 +46,7 @@ type FhirSlot struct { Specialty datatypes.JSON `gorm:"column:specialty;type:text;serializer:json" json:"specialty,omitempty"` // Appointment date/time. // https://hl7.org/fhir/r4/search.html#date - Start time.Time `gorm:"column:start;type:datetime" json:"start,omitempty"` + Start *time.Time `gorm:"column:start;type:datetime" json:"start,omitempty"` // The free/busy status of the appointment // https://hl7.org/fhir/r4/search.html#token Status datatypes.JSON `gorm:"column:status;type:text;serializer:json" json:"status,omitempty"` @@ -145,7 +145,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(AppointmentTypeProcessed) + if(AppointmentTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AppointmentTypeProcessed) + } `) if err == nil && appointmentTypeResult.String() != "undefined" { s.AppointmentType = []byte(appointmentTypeResult.String()) @@ -187,7 +192,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -229,7 +239,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -239,18 +254,21 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting Schedule scheduleResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Slot.schedule'))") if err == nil && scheduleResult.String() != "undefined" { - s.Schedule = []byte(scheduleResult.String()) } // extracting ServiceCategory serviceCategoryResult, err := vm.RunString(` @@ -289,7 +307,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(ServiceCategoryProcessed) + if(ServiceCategoryProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ServiceCategoryProcessed) + } `) if err == nil && serviceCategoryResult.String() != "undefined" { s.ServiceCategory = []byte(serviceCategoryResult.String()) @@ -331,7 +354,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(ServiceTypeProcessed) + if(ServiceTypeProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ServiceTypeProcessed) + } `) if err == nil && serviceTypeResult.String() != "undefined" { s.ServiceType = []byte(serviceTypeResult.String()) @@ -378,7 +406,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(SpecialtyProcessed) + if(SpecialtyProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(SpecialtyProcessed) + } `) if err == nil && specialtyResult.String() != "undefined" { s.Specialty = []byte(specialtyResult.String()) @@ -388,7 +421,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag if err == nil && startResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, startResult.String()) if err == nil { - s.Start = t + s.Start = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", startResult.String()) + if err == nil { + s.Start = &d + } } } // extracting Status @@ -428,7 +466,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -470,7 +513,12 @@ func (s *FhirSlot) PopulateAndExtractSearchParameters(resourceRaw json.RawMessag }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_specimen.go b/backend/pkg/models/database/fhir_specimen.go index e2cebc8da..f033f923e 100644 --- a/backend/pkg/models/database/fhir_specimen.go +++ b/backend/pkg/models/database/fhir_specimen.go @@ -22,7 +22,7 @@ type FhirSpecimen struct { Bodysite datatypes.JSON `gorm:"column:bodysite;type:text;serializer:json" json:"bodysite,omitempty"` // The date the specimen was collected // https://hl7.org/fhir/r4/search.html#date - Collected time.Time `gorm:"column:collected;type:datetime" json:"collected,omitempty"` + Collected *time.Time `gorm:"column:collected;type:datetime" json:"collected,omitempty"` // Who collected the specimen // https://hl7.org/fhir/r4/search.html#reference Collector datatypes.JSON `gorm:"column:collector;type:text;serializer:json" json:"collector,omitempty"` @@ -40,7 +40,7 @@ type FhirSpecimen struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The parent of the specimen // https://hl7.org/fhir/r4/search.html#reference Parent datatypes.JSON `gorm:"column:parent;type:text;serializer:json" json:"parent,omitempty"` @@ -153,7 +153,12 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(AccessionProcessed) + if(AccessionProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(AccessionProcessed) + } `) if err == nil && accessionResult.String() != "undefined" { s.Accession = []byte(accessionResult.String()) @@ -195,7 +200,12 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(BodysiteProcessed) + if(BodysiteProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(BodysiteProcessed) + } `) if err == nil && bodysiteResult.String() != "undefined" { s.Bodysite = []byte(bodysiteResult.String()) @@ -205,13 +215,17 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && collectedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, collectedResult.String()) if err == nil { - s.Collected = t + s.Collected = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", collectedResult.String()) + if err == nil { + s.Collected = &d + } } } // extracting Collector collectorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Specimen.collection.collector'))") if err == nil && collectorResult.String() != "undefined" { - s.Collector = []byte(collectorResult.String()) } // extracting Container containerResult, err := vm.RunString(` @@ -250,7 +264,12 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(ContainerProcessed) + if(ContainerProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ContainerProcessed) + } `) if err == nil && containerResult.String() != "undefined" { s.Container = []byte(containerResult.String()) @@ -292,7 +311,12 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(ContainerIdProcessed) + if(ContainerIdProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(ContainerIdProcessed) + } `) if err == nil && containerIdResult.String() != "undefined" { s.ContainerId = []byte(containerIdResult.String()) @@ -334,7 +358,12 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -376,7 +405,12 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -386,18 +420,21 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Parent parentResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Specimen.parent'))") if err == nil && parentResult.String() != "undefined" { - s.Parent = []byte(parentResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -441,7 +478,12 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -449,7 +491,6 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe // extracting Subject subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Specimen.subject'))") if err == nil && subjectResult.String() != "undefined" { - s.Subject = []byte(subjectResult.String()) } // extracting Tag tagResult, err := vm.RunString(` @@ -488,7 +529,12 @@ func (s *FhirSpecimen) PopulateAndExtractSearchParameters(resourceRaw json.RawMe }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/fhir_vision_prescription.go b/backend/pkg/models/database/fhir_vision_prescription.go index e3e1acc78..0bfdd6a5b 100644 --- a/backend/pkg/models/database/fhir_vision_prescription.go +++ b/backend/pkg/models/database/fhir_vision_prescription.go @@ -16,7 +16,7 @@ type FhirVisionPrescription struct { models.ResourceBase // Return prescriptions written on this date // https://hl7.org/fhir/r4/search.html#date - Datewritten time.Time `gorm:"column:datewritten;type:datetime" json:"datewritten,omitempty"` + Datewritten *time.Time `gorm:"column:datewritten;type:datetime" json:"datewritten,omitempty"` /* Multiple Resources: @@ -76,7 +76,7 @@ type FhirVisionPrescription struct { Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date - LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` + LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Who authorized the vision prescription // https://hl7.org/fhir/r4/search.html#reference Prescriber datatypes.JSON `gorm:"column:prescriber;type:text;serializer:json" json:"prescriber,omitempty"` @@ -149,13 +149,17 @@ func (s *FhirVisionPrescription) PopulateAndExtractSearchParameters(resourceRaw if err == nil && datewrittenResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, datewrittenResult.String()) if err == nil { - s.Datewritten = t + s.Datewritten = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", datewrittenResult.String()) + if err == nil { + s.Datewritten = &d + } } } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Composition.encounter | DeviceRequest.encounter | DiagnosticReport.encounter | DocumentReference.context.encounter.where(resolve() is Encounter) | Flag.encounter | List.encounter | NutritionOrder.encounter | Observation.encounter | Procedure.encounter | RiskAssessment.encounter | ServiceRequest.encounter | VisionPrescription.encounter'))") if err == nil && encounterResult.String() != "undefined" { - s.Encounter = []byte(encounterResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -194,7 +198,12 @@ func (s *FhirVisionPrescription) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(IdentifierProcessed) + if(IdentifierProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(IdentifierProcessed) + } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) @@ -236,7 +245,12 @@ func (s *FhirVisionPrescription) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(LanguageProcessed) + if(LanguageProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(LanguageProcessed) + } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) @@ -246,18 +260,21 @@ func (s *FhirVisionPrescription) PopulateAndExtractSearchParameters(resourceRaw if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { - s.LastUpdated = t + s.LastUpdated = &t + } else if err != nil { + d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) + if err == nil { + s.LastUpdated = &d + } } } // extracting Prescriber prescriberResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'VisionPrescription.prescriber'))") if err == nil && prescriberResult.String() != "undefined" { - s.Prescriber = []byte(prescriberResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") if err == nil && profileResult.String() != "undefined" { - s.Profile = []byte(profileResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -301,7 +318,12 @@ func (s *FhirVisionPrescription) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(StatusProcessed) + if(StatusProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(StatusProcessed) + } `) if err == nil && statusResult.String() != "undefined" { s.Status = []byte(statusResult.String()) @@ -343,7 +365,12 @@ func (s *FhirVisionPrescription) PopulateAndExtractSearchParameters(resourceRaw }, []) - JSON.stringify(TagProcessed) + if(TagProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(TagProcessed) + } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) diff --git a/backend/pkg/models/database/generate.go b/backend/pkg/models/database/generate.go index 859255551..84ae32c32 100644 --- a/backend/pkg/models/database/generate.go +++ b/backend/pkg/models/database/generate.go @@ -172,12 +172,26 @@ func main() { g.Comment(fieldInfo.Description) g.Comment(fmt.Sprintf("https://hl7.org/fhir/r4/search.html#%s", fieldInfo.FieldType)) golangFieldType := mapFieldType(fieldInfo.FieldType) + var isPointer bool + if strings.HasPrefix(golangFieldType, "*") { + golangFieldType = strings.TrimPrefix(golangFieldType, "*") + isPointer = true + } + var golangFieldStatement *jen.Statement if strings.Contains(golangFieldType, "#") { golangFieldTypeParts := strings.Split(golangFieldType, "#") - golangFieldStatement = g.Id(fieldName).Add(jen.Qual(golangFieldTypeParts[0], golangFieldTypeParts[1])) + if isPointer { + golangFieldStatement = g.Id(fieldName).Op("*").Add(jen.Qual(golangFieldTypeParts[0], golangFieldTypeParts[1])) + } else { + golangFieldStatement = g.Id(fieldName).Add(jen.Qual(golangFieldTypeParts[0], golangFieldTypeParts[1])) + } } else { - golangFieldStatement = g.Id(fieldName).Add(jen.Id(golangFieldType)) + if isPointer { + golangFieldStatement = g.Id(fieldName).Op("*").Id(golangFieldType) + } else { + golangFieldStatement = g.Id(fieldName).Id(golangFieldType) + } } golangFieldStatement.Tag(map[string]string{ "json": fmt.Sprintf("%s,omitempty", strcase.ToLowerCamel(fieldName)), @@ -320,9 +334,13 @@ func main() { return accumulator }, []) - - JSON.stringify(%sProcessed) - `, fieldName, script, fieldName, fieldName, fieldName)).Op("`") + if(%sProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(%sProcessed) + } + `, fieldName, script, fieldName, fieldName, fieldName, fieldName)).Op("`") } else if isSimpleFieldType(fieldInfo.FieldType) { //TODO: we may end up losing some information here, as we are only returning the first element of the array @@ -366,15 +384,20 @@ func main() { }, []) - JSON.stringify(%sProcessed) - `, fieldName, script, fieldName, fieldName, fieldName)).Op("`") + if(%sProcessed.length == 0) { + "undefined" + } + else { + JSON.stringify(%sProcessed) + } + `, fieldName, script, fieldName, fieldName, fieldName, fieldName)).Op("`") } else { r.Lit(fmt.Sprintf(`JSON.stringify(%s)`, script)) } }) g.If(jen.Err().Op("==").Nil().Op("&&").Id(fieldNameVar).Dot("String").Call().Op("!=").Lit("undefined")).BlockFunc(func(i *jen.Group) { switch fieldInfo.FieldType { - case "token", "reference", "special", "quantity", "string": + case "token", "special", "quantity", "string": i.Id("s").Dot(fieldName).Op("=").Index().Byte().Parens(jen.Id(fieldNameVar).Dot("String").Call()) break case "number": @@ -384,11 +407,20 @@ func main() { //parse RFC3339 date i.List(jen.Id("t"), jen.Id("err")).Op(":=").Qual("time", "Parse").Call(jen.Qual("time", "RFC3339"), jen.Id(fieldNameVar).Dot("String").Call()) i.If(jen.Err().Op("==").Nil()).BlockFunc(func(e *jen.Group) { - e.Id("s").Dot(fieldName).Op("=").Id("t") + e.Id("s").Dot(fieldName).Op("=").Op("&").Id("t") + }).Else().If(jen.Err().Op("!=").Nil()).BlockFunc(func(e *jen.Group) { + //parse date only + e.List(jen.Id("d"), jen.Id("err")).Op(":=").Qual("time", "Parse").Call(jen.Lit("2006-01-02"), jen.Id(fieldNameVar).Dot("String").Call()) + e.If(jen.Err().Op("==").Nil()).BlockFunc(func(f *jen.Group) { + f.Id("s").Dot(fieldName).Op("=").Op("&").Id("d") + }) }) case "uri": i.Id("s").Dot(fieldName).Op("=").Id(fieldNameVar).Dot("String").Call() break + case "reference": + //TODO: do nothing for reference types, not supported yet. + break default: i.Id("s").Dot(fieldName).Op("=").Id(fieldNameVar).Dot("String").Call() break @@ -588,7 +620,7 @@ func mapFieldType(fieldType string) string { case "reference": return "gorm.io/datatypes#JSON" case "date": - return "time#Time" + return "*time#Time" case "string": return "gorm.io/datatypes#JSON" case "uri": diff --git a/backend/pkg/models/database/interface.go b/backend/pkg/models/database/interface.go index 7a2e8bf6a..ad1407aae 100644 --- a/backend/pkg/models/database/interface.go +++ b/backend/pkg/models/database/interface.go @@ -4,12 +4,15 @@ import ( "encoding/json" "github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models" "gorm.io/datatypes" + "time" ) type IFhirResourceModel interface { models.OriginBaser SetOriginBase(originBase models.OriginBase) SetResourceRaw(resourceRaw datatypes.JSON) + SetSortTitle(sortTitle *string) + SetSortDate(sortDate *time.Time) GetSearchParameters() map[string]string PopulateAndExtractSearchParameters(rawResource json.RawMessage) error } diff --git a/backend/pkg/models/resource_base.go b/backend/pkg/models/resource_base.go index fcd0e5bf5..2009a51b8 100644 --- a/backend/pkg/models/resource_base.go +++ b/backend/pkg/models/resource_base.go @@ -21,6 +21,13 @@ type ResourceBase struct { func (s *ResourceBase) SetOriginBase(originBase OriginBase) { s.OriginBase = originBase } +func (s *ResourceBase) SetSortTitle(sortTitle *string) { + s.SortTitle = sortTitle +} + +func (s *ResourceBase) SetSortDate(sortDate *time.Time) { + s.SortDate = sortDate +} func (s *ResourceBase) SetResourceRaw(resourceRaw datatypes.JSON) { s.ResourceRaw = resourceRaw