From 0517f9b3503838a0e82f70cd025652e4dc802c3b Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Sun, 30 Jul 2023 21:40:25 -0700 Subject: [PATCH] make sure we can handle HumanName and Address type objects (convert to string). --- backend/pkg/models/database/fhir_account.go | 58 +- .../pkg/models/database/fhir_adverse_event.go | 2 +- .../database/fhir_allergy_intolerance.go | 2 +- .../pkg/models/database/fhir_appointment.go | 2 +- backend/pkg/models/database/fhir_binary.go | 2 +- backend/pkg/models/database/fhir_care_plan.go | 2 +- backend/pkg/models/database/fhir_care_team.go | 2 +- backend/pkg/models/database/fhir_claim.go | 2 +- .../models/database/fhir_claim_response.go | 58 +- .../pkg/models/database/fhir_composition.go | 58 +- backend/pkg/models/database/fhir_condition.go | 114 +++- backend/pkg/models/database/fhir_consent.go | 2 +- backend/pkg/models/database/fhir_coverage.go | 114 +++- .../fhir_coverage_eligibility_request.go | 2 +- .../fhir_coverage_eligibility_response.go | 58 +- backend/pkg/models/database/fhir_device.go | 282 +++++++++- .../models/database/fhir_device_request.go | 2 +- .../models/database/fhir_diagnostic_report.go | 2 +- .../models/database/fhir_document_manifest.go | 58 +- .../database/fhir_document_reference.go | 58 +- backend/pkg/models/database/fhir_encounter.go | 2 +- backend/pkg/models/database/fhir_endpoint.go | 58 +- .../database/fhir_enrollment_request.go | 2 +- .../database/fhir_enrollment_response.go | 2 +- .../database/fhir_explanation_of_benefit.go | 58 +- .../database/fhir_family_member_history.go | 2 +- backend/pkg/models/database/fhir_goal.go | 2 +- .../pkg/models/database/fhir_imaging_study.go | 2 +- .../pkg/models/database/fhir_immunization.go | 114 +++- .../models/database/fhir_insurance_plan.go | 394 +++++++++++++- backend/pkg/models/database/fhir_location.go | 338 +++++++++++- backend/pkg/models/database/fhir_media.go | 2 +- .../pkg/models/database/fhir_medication.go | 2 +- .../fhir_medication_administration.go | 2 +- .../database/fhir_medication_dispense.go | 2 +- .../database/fhir_medication_request.go | 2 +- .../database/fhir_medication_statement.go | 2 +- .../models/database/fhir_nutrition_order.go | 2 +- .../pkg/models/database/fhir_observation.go | 58 +- .../pkg/models/database/fhir_organization.go | 394 +++++++++++++- .../database/fhir_organization_affiliation.go | 2 +- backend/pkg/models/database/fhir_patient.go | 506 +++++++++++++++++- .../pkg/models/database/fhir_patient_test.go | 50 ++ backend/pkg/models/database/fhir_person.go | 394 +++++++++++++- .../pkg/models/database/fhir_practitioner.go | 506 +++++++++++++++++- .../models/database/fhir_practitioner_role.go | 2 +- backend/pkg/models/database/fhir_procedure.go | 2 +- .../pkg/models/database/fhir_provenance.go | 2 +- .../pkg/models/database/fhir_questionnaire.go | 226 +++++++- .../database/fhir_questionnaire_response.go | 2 +- .../models/database/fhir_related_person.go | 394 +++++++++++++- backend/pkg/models/database/fhir_schedule.go | 2 +- .../models/database/fhir_service_request.go | 2 +- backend/pkg/models/database/fhir_slot.go | 2 +- backend/pkg/models/database/fhir_specimen.go | 2 +- .../database/fhir_vision_prescription.go | 2 +- 56 files changed, 4133 insertions(+), 283 deletions(-) create mode 100644 backend/pkg/models/database/fhir_patient_test.go diff --git a/backend/pkg/models/database/fhir_account.go b/backend/pkg/models/database/fhir_account.go index 051c88d78..8cf7efff7 100644 --- a/backend/pkg/models/database/fhir_account.go +++ b/backend/pkg/models/database/fhir_account.go @@ -25,7 +25,7 @@ type FhirAccount struct { LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // Human-readable label // https://hl7.org/fhir/r4/search.html#string - Name string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` // Entity managing the Account // https://hl7.org/fhir/r4/search.html#reference Owner datatypes.JSON `gorm:"column:owner;type:text;serializer:json" json:"owner,omitempty"` @@ -49,7 +49,7 @@ type FhirAccount struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -193,9 +193,59 @@ func (s *FhirAccount) PopulateAndExtractSearchParameters(resourceRaw json.RawMes } } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Account.name')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'Account.name') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting Owner ownerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Account.owner'))") diff --git a/backend/pkg/models/database/fhir_adverse_event.go b/backend/pkg/models/database/fhir_adverse_event.go index 1899e0d30..f810565bf 100644 --- a/backend/pkg/models/database/fhir_adverse_event.go +++ b/backend/pkg/models/database/fhir_adverse_event.go @@ -67,7 +67,7 @@ type FhirAdverseEvent struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_allergy_intolerance.go b/backend/pkg/models/database/fhir_allergy_intolerance.go index cb0b50f0c..e3e5d1577 100644 --- a/backend/pkg/models/database/fhir_allergy_intolerance.go +++ b/backend/pkg/models/database/fhir_allergy_intolerance.go @@ -140,7 +140,7 @@ type FhirAllergyIntolerance struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_appointment.go b/backend/pkg/models/database/fhir_appointment.go index 77403f3fa..f4ff7fbea 100644 --- a/backend/pkg/models/database/fhir_appointment.go +++ b/backend/pkg/models/database/fhir_appointment.go @@ -79,7 +79,7 @@ type FhirAppointment struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_binary.go b/backend/pkg/models/database/fhir_binary.go index eb5b96cef..da98cc9ef 100644 --- a/backend/pkg/models/database/fhir_binary.go +++ b/backend/pkg/models/database/fhir_binary.go @@ -31,7 +31,7 @@ type FhirBinary struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_care_plan.go b/backend/pkg/models/database/fhir_care_plan.go index c15851862..6d181be23 100644 --- a/backend/pkg/models/database/fhir_care_plan.go +++ b/backend/pkg/models/database/fhir_care_plan.go @@ -141,7 +141,7 @@ type FhirCarePlan struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_care_team.go b/backend/pkg/models/database/fhir_care_team.go index 484d7821d..fa233eee6 100644 --- a/backend/pkg/models/database/fhir_care_team.go +++ b/backend/pkg/models/database/fhir_care_team.go @@ -105,7 +105,7 @@ type FhirCareTeam struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_claim.go b/backend/pkg/models/database/fhir_claim.go index 997b3e998..fb63f1f4d 100644 --- a/backend/pkg/models/database/fhir_claim.go +++ b/backend/pkg/models/database/fhir_claim.go @@ -76,7 +76,7 @@ type FhirClaim struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_claim_response.go b/backend/pkg/models/database/fhir_claim_response.go index 1cbe13249..ae3dca7cd 100644 --- a/backend/pkg/models/database/fhir_claim_response.go +++ b/backend/pkg/models/database/fhir_claim_response.go @@ -19,7 +19,7 @@ type FhirClaimResponse struct { 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 string `gorm:"column:disposition;type:text" json:"disposition,omitempty"` + Disposition datatypes.JSON `gorm:"column:disposition;type:text;serializer:json" json:"disposition,omitempty"` // The identity of the ClaimResponse // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -58,7 +58,7 @@ type FhirClaimResponse struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -125,9 +125,59 @@ func (s *FhirClaimResponse) PopulateAndExtractSearchParameters(resourceRaw json. } } // extracting Disposition - dispositionResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'ClaimResponse.disposition')[0]") + dispositionResult, err := vm.RunString(` + DispositionResult = window.fhirpath.evaluate(fhirResource, 'ClaimResponse.disposition') + DispositionProcessed = DispositionResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(DispositionProcessed) + `) if err == nil && dispositionResult.String() != "undefined" { - s.Disposition = dispositionResult.String() + s.Disposition = []byte(dispositionResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` diff --git a/backend/pkg/models/database/fhir_composition.go b/backend/pkg/models/database/fhir_composition.go index 17ea89e26..32a6fa519 100644 --- a/backend/pkg/models/database/fhir_composition.go +++ b/backend/pkg/models/database/fhir_composition.go @@ -144,10 +144,10 @@ type FhirComposition struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // Human Readable name/title // https://hl7.org/fhir/r4/search.html#string - Title string `gorm:"column:title;type:text" json:"title,omitempty"` + Title datatypes.JSON `gorm:"column:title;type:text;serializer:json" json:"title,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -651,9 +651,59 @@ func (s *FhirComposition) PopulateAndExtractSearchParameters(resourceRaw json.Ra s.Tag = []byte(tagResult.String()) } // extracting Title - titleResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Composition.title')[0]") + titleResult, err := vm.RunString(` + TitleResult = window.fhirpath.evaluate(fhirResource, 'Composition.title') + TitleProcessed = TitleResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(TitleProcessed) + `) if err == nil && titleResult.String() != "undefined" { - s.Title = titleResult.String() + s.Title = []byte(titleResult.String()) } return nil } diff --git a/backend/pkg/models/database/fhir_condition.go b/backend/pkg/models/database/fhir_condition.go index 76626f992..754872db9 100644 --- a/backend/pkg/models/database/fhir_condition.go +++ b/backend/pkg/models/database/fhir_condition.go @@ -22,7 +22,7 @@ type FhirCondition struct { AbatementDate time.Time `gorm:"column:abatementDate;type:datetime" json:"abatementDate,omitempty"` // Abatement as a string // https://hl7.org/fhir/r4/search.html#string - AbatementString string `gorm:"column:abatementString;type:text" json:"abatementString,omitempty"` + AbatementString datatypes.JSON `gorm:"column:abatementString;type:text;serializer:json" json:"abatementString,omitempty"` // Person who asserts this condition // https://hl7.org/fhir/r4/search.html#reference Asserter datatypes.JSON `gorm:"column:asserter;type:text;serializer:json" json:"asserter,omitempty"` @@ -114,7 +114,7 @@ type FhirCondition struct { OnsetDate time.Time `gorm:"column:onsetDate;type:datetime" json:"onsetDate,omitempty"` // Onsets as a string // https://hl7.org/fhir/r4/search.html#string - OnsetInfo string `gorm:"column:onsetInfo;type:text" json:"onsetInfo,omitempty"` + OnsetInfo datatypes.JSON `gorm:"column:onsetInfo;type:text;serializer:json" json:"onsetInfo,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"` @@ -138,7 +138,7 @@ type FhirCondition struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -220,9 +220,59 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM } } // extracting AbatementString - abatementStringResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Condition.abatement.as(string)')[0]") + abatementStringResult, err := vm.RunString(` + AbatementStringResult = window.fhirpath.evaluate(fhirResource, 'Condition.abatement.as(string)') + AbatementStringProcessed = AbatementStringResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AbatementStringProcessed) + `) if err == nil && abatementStringResult.String() != "undefined" { - s.AbatementString = abatementStringResult.String() + s.AbatementString = []byte(abatementStringResult.String()) } // extracting Asserter asserterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Condition.asserter'))") @@ -555,9 +605,59 @@ func (s *FhirCondition) PopulateAndExtractSearchParameters(resourceRaw json.RawM } } // extracting OnsetInfo - onsetInfoResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Condition.onset.as(string)')[0]") + onsetInfoResult, err := vm.RunString(` + OnsetInfoResult = window.fhirpath.evaluate(fhirResource, 'Condition.onset.as(string)') + OnsetInfoProcessed = OnsetInfoResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(OnsetInfoProcessed) + `) if err == nil && onsetInfoResult.String() != "undefined" { - s.OnsetInfo = onsetInfoResult.String() + s.OnsetInfo = []byte(onsetInfoResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") diff --git a/backend/pkg/models/database/fhir_consent.go b/backend/pkg/models/database/fhir_consent.go index 825255c6f..d7f6b9dd2 100644 --- a/backend/pkg/models/database/fhir_consent.go +++ b/backend/pkg/models/database/fhir_consent.go @@ -126,7 +126,7 @@ type FhirConsent struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_coverage.go b/backend/pkg/models/database/fhir_coverage.go index fa14c6ce4..2278031b3 100644 --- a/backend/pkg/models/database/fhir_coverage.go +++ b/backend/pkg/models/database/fhir_coverage.go @@ -22,10 +22,10 @@ type FhirCoverage struct { ClassType datatypes.JSON `gorm:"column:classType;type:text;serializer:json" json:"classType,omitempty"` // Value of the class (eg. Plan number, group number) // https://hl7.org/fhir/r4/search.html#string - ClassValue string `gorm:"column:classValue;type:text" json:"classValue,omitempty"` + ClassValue datatypes.JSON `gorm:"column:classValue;type:text;serializer:json" json:"classValue,omitempty"` // Dependent number // https://hl7.org/fhir/r4/search.html#string - Dependent string `gorm:"column:dependent;type:text" json:"dependent,omitempty"` + Dependent datatypes.JSON `gorm:"column:dependent;type:text;serializer:json" json:"dependent,omitempty"` // The primary identifier of the insured and the coverage // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -58,7 +58,7 @@ type FhirCoverage struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -160,14 +160,114 @@ func (s *FhirCoverage) PopulateAndExtractSearchParameters(resourceRaw json.RawMe s.ClassType = []byte(classTypeResult.String()) } // extracting ClassValue - classValueResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Coverage.class.value')[0]") + classValueResult, err := vm.RunString(` + ClassValueResult = window.fhirpath.evaluate(fhirResource, 'Coverage.class.value') + ClassValueProcessed = ClassValueResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(ClassValueProcessed) + `) if err == nil && classValueResult.String() != "undefined" { - s.ClassValue = classValueResult.String() + s.ClassValue = []byte(classValueResult.String()) } // extracting Dependent - dependentResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Coverage.dependent')[0]") + dependentResult, err := vm.RunString(` + DependentResult = window.fhirpath.evaluate(fhirResource, 'Coverage.dependent') + DependentProcessed = DependentResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(DependentProcessed) + `) if err == nil && dependentResult.String() != "undefined" { - s.Dependent = dependentResult.String() + s.Dependent = []byte(dependentResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` diff --git a/backend/pkg/models/database/fhir_coverage_eligibility_request.go b/backend/pkg/models/database/fhir_coverage_eligibility_request.go index b7ef0ea3c..485508a2c 100644 --- a/backend/pkg/models/database/fhir_coverage_eligibility_request.go +++ b/backend/pkg/models/database/fhir_coverage_eligibility_request.go @@ -49,7 +49,7 @@ type FhirCoverageEligibilityRequest struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_coverage_eligibility_response.go b/backend/pkg/models/database/fhir_coverage_eligibility_response.go index 0b44de1a0..8a5e45dfa 100644 --- a/backend/pkg/models/database/fhir_coverage_eligibility_response.go +++ b/backend/pkg/models/database/fhir_coverage_eligibility_response.go @@ -19,7 +19,7 @@ type FhirCoverageEligibilityResponse struct { 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 string `gorm:"column:disposition;type:text" json:"disposition,omitempty"` + Disposition datatypes.JSON `gorm:"column:disposition;type:text;serializer:json" json:"disposition,omitempty"` // The business identifier // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -55,7 +55,7 @@ type FhirCoverageEligibilityResponse struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -117,9 +117,59 @@ func (s *FhirCoverageEligibilityResponse) PopulateAndExtractSearchParameters(res } } // extracting Disposition - dispositionResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'CoverageEligibilityResponse.disposition')[0]") + dispositionResult, err := vm.RunString(` + DispositionResult = window.fhirpath.evaluate(fhirResource, 'CoverageEligibilityResponse.disposition') + DispositionProcessed = DispositionResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(DispositionProcessed) + `) if err == nil && dispositionResult.String() != "undefined" { - s.Disposition = dispositionResult.String() + s.Disposition = []byte(dispositionResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` diff --git a/backend/pkg/models/database/fhir_device.go b/backend/pkg/models/database/fhir_device.go index 9137bfdd8..4e30b5d7f 100644 --- a/backend/pkg/models/database/fhir_device.go +++ b/backend/pkg/models/database/fhir_device.go @@ -16,7 +16,7 @@ type FhirDevice struct { models.ResourceBase // A server defined search that may match any of the string fields in Device.deviceName or Device.type. // https://hl7.org/fhir/r4/search.html#string - DeviceName string `gorm:"column:deviceName;type:text" json:"deviceName,omitempty"` + DeviceName datatypes.JSON `gorm:"column:deviceName;type:text;serializer:json" json:"deviceName,omitempty"` // Instance id from manufacturer, owner, and others // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -31,10 +31,10 @@ type FhirDevice struct { Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` // The manufacturer of the device // https://hl7.org/fhir/r4/search.html#string - Manufacturer string `gorm:"column:manufacturer;type:text" json:"manufacturer,omitempty"` + Manufacturer datatypes.JSON `gorm:"column:manufacturer;type:text;serializer:json" json:"manufacturer,omitempty"` // The model of the device // https://hl7.org/fhir/r4/search.html#string - Model string `gorm:"column:model;type:text" json:"model,omitempty"` + Model datatypes.JSON `gorm:"column:model;type:text;serializer:json" json:"model,omitempty"` // The organization responsible for the device // https://hl7.org/fhir/r4/search.html#reference Organization datatypes.JSON `gorm:"column:organization;type:text;serializer:json" json:"organization,omitempty"` @@ -52,16 +52,16 @@ type FhirDevice struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` // UDI Barcode (RFID or other technology) string in *HRF* format. // https://hl7.org/fhir/r4/search.html#string - UdiCarrier string `gorm:"column:udiCarrier;type:text" json:"udiCarrier,omitempty"` + UdiCarrier datatypes.JSON `gorm:"column:udiCarrier;type:text;serializer:json" json:"udiCarrier,omitempty"` // The udi Device Identifier (DI) // https://hl7.org/fhir/r4/search.html#string - UdiDi string `gorm:"column:udiDi;type:text" json:"udiDi,omitempty"` + UdiDi datatypes.JSON `gorm:"column:udiDi;type:text;serializer:json" json:"udiDi,omitempty"` // Network address to contact device // https://hl7.org/fhir/r4/search.html#uri Url string `gorm:"column:url;type:text" json:"url,omitempty"` @@ -117,9 +117,59 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess } // execute the fhirpath expression for each search parameter // extracting DeviceName - deviceNameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Device.deviceName.name | Device.type.coding.display | Device.type.text')[0]") + deviceNameResult, err := vm.RunString(` + DeviceNameResult = window.fhirpath.evaluate(fhirResource, 'Device.deviceName.name | Device.type.coding.display | Device.type.text') + DeviceNameProcessed = DeviceNameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(DeviceNameProcessed) + `) if err == nil && deviceNameResult.String() != "undefined" { - s.DeviceName = deviceNameResult.String() + s.DeviceName = []byte(deviceNameResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -219,14 +269,114 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess s.Location = []byte(locationResult.String()) } // extracting Manufacturer - manufacturerResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Device.manufacturer')[0]") + manufacturerResult, err := vm.RunString(` + ManufacturerResult = window.fhirpath.evaluate(fhirResource, 'Device.manufacturer') + ManufacturerProcessed = ManufacturerResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(ManufacturerProcessed) + `) if err == nil && manufacturerResult.String() != "undefined" { - s.Manufacturer = manufacturerResult.String() + s.Manufacturer = []byte(manufacturerResult.String()) } // extracting Model - modelResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Device.modelNumber')[0]") + modelResult, err := vm.RunString(` + ModelResult = window.fhirpath.evaluate(fhirResource, 'Device.modelNumber') + ModelProcessed = ModelResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(ModelProcessed) + `) if err == nil && modelResult.String() != "undefined" { - s.Model = modelResult.String() + s.Model = []byte(modelResult.String()) } // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Device.owner'))") @@ -328,14 +478,114 @@ func (s *FhirDevice) PopulateAndExtractSearchParameters(resourceRaw json.RawMess s.Tag = []byte(tagResult.String()) } // extracting UdiCarrier - udiCarrierResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Device.udiCarrier.carrierHRF')[0]") + udiCarrierResult, err := vm.RunString(` + UdiCarrierResult = window.fhirpath.evaluate(fhirResource, 'Device.udiCarrier.carrierHRF') + UdiCarrierProcessed = UdiCarrierResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(UdiCarrierProcessed) + `) if err == nil && udiCarrierResult.String() != "undefined" { - s.UdiCarrier = udiCarrierResult.String() + s.UdiCarrier = []byte(udiCarrierResult.String()) } // extracting UdiDi - udiDiResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Device.udiCarrier.deviceIdentifier')[0]") + udiDiResult, err := vm.RunString(` + UdiDiResult = window.fhirpath.evaluate(fhirResource, 'Device.udiCarrier.deviceIdentifier') + UdiDiProcessed = UdiDiResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(UdiDiProcessed) + `) if err == nil && udiDiResult.String() != "undefined" { - s.UdiDi = udiDiResult.String() + s.UdiDi = []byte(udiDiResult.String()) } // extracting Url urlResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Device.url')[0]") diff --git a/backend/pkg/models/database/fhir_device_request.go b/backend/pkg/models/database/fhir_device_request.go index 7dd42bfae..6560e7808 100644 --- a/backend/pkg/models/database/fhir_device_request.go +++ b/backend/pkg/models/database/fhir_device_request.go @@ -147,7 +147,7 @@ type FhirDeviceRequest struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_diagnostic_report.go b/backend/pkg/models/database/fhir_diagnostic_report.go index 4e726526c..29a68e892 100644 --- a/backend/pkg/models/database/fhir_diagnostic_report.go +++ b/backend/pkg/models/database/fhir_diagnostic_report.go @@ -161,7 +161,7 @@ type FhirDiagnosticReport struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_document_manifest.go b/backend/pkg/models/database/fhir_document_manifest.go index ee70d1ce6..089d13ee0 100644 --- a/backend/pkg/models/database/fhir_document_manifest.go +++ b/backend/pkg/models/database/fhir_document_manifest.go @@ -22,7 +22,7 @@ type FhirDocumentManifest struct { Created time.Time `gorm:"column:created;type:datetime" json:"created,omitempty"` // Human-readable description (title) // https://hl7.org/fhir/r4/search.html#string - Description string `gorm:"column:description;type:text" json:"description,omitempty"` + Description datatypes.JSON `gorm:"column:description;type:text;serializer:json" json:"description,omitempty"` /* Multiple Resources: @@ -97,7 +97,7 @@ type FhirDocumentManifest struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -167,9 +167,59 @@ func (s *FhirDocumentManifest) PopulateAndExtractSearchParameters(resourceRaw js } } // extracting Description - descriptionResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'DocumentManifest.description')[0]") + descriptionResult, err := vm.RunString(` + DescriptionResult = window.fhirpath.evaluate(fhirResource, 'DocumentManifest.description') + DescriptionProcessed = DescriptionResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(DescriptionProcessed) + `) if err == nil && descriptionResult.String() != "undefined" { - s.Description = descriptionResult.String() + s.Description = []byte(descriptionResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` diff --git a/backend/pkg/models/database/fhir_document_reference.go b/backend/pkg/models/database/fhir_document_reference.go index ba4d79f6c..09a084654 100644 --- a/backend/pkg/models/database/fhir_document_reference.go +++ b/backend/pkg/models/database/fhir_document_reference.go @@ -34,7 +34,7 @@ type FhirDocumentReference struct { Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // Human-readable description // https://hl7.org/fhir/r4/search.html#string - Description string `gorm:"column:description;type:text" json:"description,omitempty"` + Description datatypes.JSON `gorm:"column:description;type:text;serializer:json" json:"description,omitempty"` /* Multiple Resources: @@ -142,7 +142,7 @@ type FhirDocumentReference struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -316,9 +316,59 @@ func (s *FhirDocumentReference) PopulateAndExtractSearchParameters(resourceRaw j } } // extracting Description - descriptionResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'DocumentReference.description')[0]") + descriptionResult, err := vm.RunString(` + DescriptionResult = window.fhirpath.evaluate(fhirResource, 'DocumentReference.description') + DescriptionProcessed = DescriptionResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(DescriptionProcessed) + `) if err == nil && descriptionResult.String() != "undefined" { - s.Description = descriptionResult.String() + s.Description = []byte(descriptionResult.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'))") diff --git a/backend/pkg/models/database/fhir_encounter.go b/backend/pkg/models/database/fhir_encounter.go index db2b82db4..3918b45f9 100644 --- a/backend/pkg/models/database/fhir_encounter.go +++ b/backend/pkg/models/database/fhir_encounter.go @@ -147,7 +147,7 @@ type FhirEncounter struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_endpoint.go b/backend/pkg/models/database/fhir_endpoint.go index d0d14edec..616a3ac5a 100644 --- a/backend/pkg/models/database/fhir_endpoint.go +++ b/backend/pkg/models/database/fhir_endpoint.go @@ -28,7 +28,7 @@ type FhirEndpoint struct { 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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` // The organization that is managing the endpoint // https://hl7.org/fhir/r4/search.html#reference Organization datatypes.JSON `gorm:"column:organization;type:text;serializer:json" json:"organization,omitempty"` @@ -49,7 +49,7 @@ type FhirEndpoint struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -235,9 +235,59 @@ func (s *FhirEndpoint) PopulateAndExtractSearchParameters(resourceRaw json.RawMe } } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Endpoint.name')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'Endpoint.name') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Endpoint.managingOrganization'))") diff --git a/backend/pkg/models/database/fhir_enrollment_request.go b/backend/pkg/models/database/fhir_enrollment_request.go index 6b28ab167..b9dbc3505 100644 --- a/backend/pkg/models/database/fhir_enrollment_request.go +++ b/backend/pkg/models/database/fhir_enrollment_request.go @@ -40,7 +40,7 @@ type FhirEnrollmentRequest struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_enrollment_response.go b/backend/pkg/models/database/fhir_enrollment_response.go index 855b8404d..bf568e17d 100644 --- a/backend/pkg/models/database/fhir_enrollment_response.go +++ b/backend/pkg/models/database/fhir_enrollment_response.go @@ -40,7 +40,7 @@ type FhirEnrollmentResponse struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_explanation_of_benefit.go b/backend/pkg/models/database/fhir_explanation_of_benefit.go index b19ac4636..9184ab82a 100644 --- a/backend/pkg/models/database/fhir_explanation_of_benefit.go +++ b/backend/pkg/models/database/fhir_explanation_of_benefit.go @@ -31,7 +31,7 @@ type FhirExplanationOfBenefit struct { DetailUdi datatypes.JSON `gorm:"column:detailUdi;type:text;serializer:json" json:"detailUdi,omitempty"` // The contents of the disposition message // https://hl7.org/fhir/r4/search.html#string - Disposition string `gorm:"column:disposition;type:text" json:"disposition,omitempty"` + Disposition datatypes.JSON `gorm:"column:disposition;type:text;serializer:json" json:"disposition,omitempty"` // Encounters associated with a billed line item // https://hl7.org/fhir/r4/search.html#reference Encounter datatypes.JSON `gorm:"column:encounter;type:text;serializer:json" json:"encounter,omitempty"` @@ -79,7 +79,7 @@ type FhirExplanationOfBenefit struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -169,9 +169,59 @@ func (s *FhirExplanationOfBenefit) PopulateAndExtractSearchParameters(resourceRa s.DetailUdi = []byte(detailUdiResult.String()) } // extracting Disposition - dispositionResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.disposition')[0]") + dispositionResult, err := vm.RunString(` + DispositionResult = window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.disposition') + DispositionProcessed = DispositionResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(DispositionProcessed) + `) if err == nil && dispositionResult.String() != "undefined" { - s.Disposition = dispositionResult.String() + s.Disposition = []byte(dispositionResult.String()) } // extracting Encounter encounterResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'ExplanationOfBenefit.item.encounter'))") diff --git a/backend/pkg/models/database/fhir_family_member_history.go b/backend/pkg/models/database/fhir_family_member_history.go index e729ef39c..62cd46ab6 100644 --- a/backend/pkg/models/database/fhir_family_member_history.go +++ b/backend/pkg/models/database/fhir_family_member_history.go @@ -125,7 +125,7 @@ type FhirFamilyMemberHistory struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_goal.go b/backend/pkg/models/database/fhir_goal.go index 7a873c87b..48e76004f 100644 --- a/backend/pkg/models/database/fhir_goal.go +++ b/backend/pkg/models/database/fhir_goal.go @@ -85,7 +85,7 @@ type FhirGoal struct { 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 string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_imaging_study.go b/backend/pkg/models/database/fhir_imaging_study.go index 06c37cf17..46e1e5dad 100644 --- a/backend/pkg/models/database/fhir_imaging_study.go +++ b/backend/pkg/models/database/fhir_imaging_study.go @@ -112,7 +112,7 @@ type FhirImagingStudy struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_immunization.go b/backend/pkg/models/database/fhir_immunization.go index 1ebf84687..10c75f2ce 100644 --- a/backend/pkg/models/database/fhir_immunization.go +++ b/backend/pkg/models/database/fhir_immunization.go @@ -84,7 +84,7 @@ type FhirImmunization struct { Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` // Vaccine Lot Number // https://hl7.org/fhir/r4/search.html#string - LotNumber string `gorm:"column:lotNumber;type:text" json:"lotNumber,omitempty"` + LotNumber datatypes.JSON `gorm:"column:lotNumber;type:text;serializer:json" json:"lotNumber,omitempty"` // Vaccine Manufacturer // https://hl7.org/fhir/r4/search.html#reference Manufacturer datatypes.JSON `gorm:"column:manufacturer;type:text;serializer:json" json:"manufacturer,omitempty"` @@ -108,7 +108,7 @@ type FhirImmunization struct { ReasonReference datatypes.JSON `gorm:"column:reasonReference;type:text;serializer:json" json:"reasonReference,omitempty"` // The series being followed by the provider // https://hl7.org/fhir/r4/search.html#string - Series string `gorm:"column:series;type:text" json:"series,omitempty"` + Series datatypes.JSON `gorm:"column:series;type:text;serializer:json" json:"series,omitempty"` // Identifies where the resource comes from // https://hl7.org/fhir/r4/search.html#uri SourceUri string `gorm:"column:sourceUri;type:text" json:"sourceUri,omitempty"` @@ -126,7 +126,7 @@ type FhirImmunization struct { TargetDisease datatypes.JSON `gorm:"column:targetDisease;type:text;serializer:json" json:"targetDisease,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -295,9 +295,59 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R s.Location = []byte(locationResult.String()) } // extracting LotNumber - lotNumberResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Immunization.lotNumber')[0]") + lotNumberResult, err := vm.RunString(` + LotNumberResult = window.fhirpath.evaluate(fhirResource, 'Immunization.lotNumber') + LotNumberProcessed = LotNumberResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(LotNumberProcessed) + `) if err == nil && lotNumberResult.String() != "undefined" { - s.LotNumber = lotNumberResult.String() + s.LotNumber = []byte(lotNumberResult.String()) } // extracting Manufacturer manufacturerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Immunization.manufacturer'))") @@ -375,9 +425,59 @@ func (s *FhirImmunization) PopulateAndExtractSearchParameters(resourceRaw json.R s.ReasonReference = []byte(reasonReferenceResult.String()) } // extracting Series - seriesResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Immunization.protocolApplied.series')[0]") + seriesResult, err := vm.RunString(` + SeriesResult = window.fhirpath.evaluate(fhirResource, 'Immunization.protocolApplied.series') + SeriesProcessed = SeriesResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(SeriesProcessed) + `) if err == nil && seriesResult.String() != "undefined" { - s.Series = seriesResult.String() + s.Series = []byte(seriesResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") diff --git a/backend/pkg/models/database/fhir_insurance_plan.go b/backend/pkg/models/database/fhir_insurance_plan.go index 6f9b17856..97b07ea9c 100644 --- a/backend/pkg/models/database/fhir_insurance_plan.go +++ b/backend/pkg/models/database/fhir_insurance_plan.go @@ -16,19 +16,19 @@ type FhirInsurancePlan struct { models.ResourceBase // A server defined search that may match any of the string fields in the Address, including line, city, district, state, country, postalCode, and/or text // https://hl7.org/fhir/r4/search.html#string - Address string `gorm:"column:address;type:text" json:"address,omitempty"` + Address datatypes.JSON `gorm:"column:address;type:text;serializer:json" json:"address,omitempty"` // A city specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressCity string `gorm:"column:addressCity;type:text" json:"addressCity,omitempty"` + AddressCity datatypes.JSON `gorm:"column:addressCity;type:text;serializer:json" json:"addressCity,omitempty"` // A country specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressCountry string `gorm:"column:addressCountry;type:text" json:"addressCountry,omitempty"` + AddressCountry datatypes.JSON `gorm:"column:addressCountry;type:text;serializer:json" json:"addressCountry,omitempty"` // A postal code specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressPostalcode string `gorm:"column:addressPostalcode;type:text" json:"addressPostalcode,omitempty"` + AddressPostalcode datatypes.JSON `gorm:"column:addressPostalcode;type:text;serializer:json" json:"addressPostalcode,omitempty"` // A state specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressState string `gorm:"column:addressState;type:text" json:"addressState,omitempty"` + AddressState datatypes.JSON `gorm:"column:addressState;type:text;serializer:json" json:"addressState,omitempty"` // A use code specified in an address // https://hl7.org/fhir/r4/search.html#token AddressUse datatypes.JSON `gorm:"column:addressUse;type:text;serializer:json" json:"addressUse,omitempty"` @@ -49,13 +49,13 @@ type FhirInsurancePlan struct { 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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` // An organization of which this organization forms a part // https://hl7.org/fhir/r4/search.html#reference OwnedBy datatypes.JSON `gorm:"column:ownedBy;type:text;serializer:json" json:"ownedBy,omitempty"` // A portion of the organization's name using some kind of phonetic matching algorithm // https://hl7.org/fhir/r4/search.html#string - Phonetic string `gorm:"column:phonetic;type:text" json:"phonetic,omitempty"` + Phonetic datatypes.JSON `gorm:"column:phonetic;type:text;serializer:json" json:"phonetic,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"` @@ -70,7 +70,7 @@ type FhirInsurancePlan struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -129,29 +129,279 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. } // execute the fhirpath expression for each search parameter // extracting Address - addressResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address')[0]") + addressResult, err := vm.RunString(` + AddressResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address') + AddressProcessed = AddressResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressProcessed) + `) if err == nil && addressResult.String() != "undefined" { - s.Address = addressResult.String() + s.Address = []byte(addressResult.String()) } // extracting AddressCity - addressCityResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.city')[0]") + addressCityResult, err := vm.RunString(` + AddressCityResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.city') + AddressCityProcessed = AddressCityResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCityProcessed) + `) if err == nil && addressCityResult.String() != "undefined" { - s.AddressCity = addressCityResult.String() + s.AddressCity = []byte(addressCityResult.String()) } // extracting AddressCountry - addressCountryResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.country')[0]") + addressCountryResult, err := vm.RunString(` + AddressCountryResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.country') + AddressCountryProcessed = AddressCountryResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCountryProcessed) + `) if err == nil && addressCountryResult.String() != "undefined" { - s.AddressCountry = addressCountryResult.String() + s.AddressCountry = []byte(addressCountryResult.String()) } // extracting AddressPostalcode - addressPostalcodeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.postalCode')[0]") + addressPostalcodeResult, err := vm.RunString(` + AddressPostalcodeResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.postalCode') + AddressPostalcodeProcessed = AddressPostalcodeResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressPostalcodeProcessed) + `) if err == nil && addressPostalcodeResult.String() != "undefined" { - s.AddressPostalcode = addressPostalcodeResult.String() + s.AddressPostalcode = []byte(addressPostalcodeResult.String()) } // extracting AddressState - addressStateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.state')[0]") + addressStateResult, err := vm.RunString(` + AddressStateResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.state') + AddressStateProcessed = AddressStateResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressStateProcessed) + `) if err == nil && addressStateResult.String() != "undefined" { - s.AddressState = addressStateResult.String() + s.AddressState = []byte(addressStateResult.String()) } // extracting AddressUse addressUseResult, err := vm.RunString(` @@ -298,9 +548,59 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. } } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'name | alias')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'name | alias') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting OwnedBy ownedByResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'InsurancePlan.ownedBy'))") @@ -308,9 +608,59 @@ func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json. s.OwnedBy = []byte(ownedByResult.String()) } // extracting Phonetic - phoneticResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.name')[0]") + phoneticResult, err := vm.RunString(` + PhoneticResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.name') + PhoneticProcessed = PhoneticResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(PhoneticProcessed) + `) if err == nil && phoneticResult.String() != "undefined" { - s.Phonetic = phoneticResult.String() + s.Phonetic = []byte(phoneticResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") diff --git a/backend/pkg/models/database/fhir_location.go b/backend/pkg/models/database/fhir_location.go index 44f7d0b8d..c92d9686e 100644 --- a/backend/pkg/models/database/fhir_location.go +++ b/backend/pkg/models/database/fhir_location.go @@ -16,19 +16,19 @@ type FhirLocation struct { models.ResourceBase // A (part of the) address of the location // https://hl7.org/fhir/r4/search.html#string - Address string `gorm:"column:address;type:text" json:"address,omitempty"` + Address datatypes.JSON `gorm:"column:address;type:text;serializer:json" json:"address,omitempty"` // A city specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressCity string `gorm:"column:addressCity;type:text" json:"addressCity,omitempty"` + AddressCity datatypes.JSON `gorm:"column:addressCity;type:text;serializer:json" json:"addressCity,omitempty"` // A country specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressCountry string `gorm:"column:addressCountry;type:text" json:"addressCountry,omitempty"` + AddressCountry datatypes.JSON `gorm:"column:addressCountry;type:text;serializer:json" json:"addressCountry,omitempty"` // A postal code specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressPostalcode string `gorm:"column:addressPostalcode;type:text" json:"addressPostalcode,omitempty"` + AddressPostalcode datatypes.JSON `gorm:"column:addressPostalcode;type:text;serializer:json" json:"addressPostalcode,omitempty"` // A state specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressState string `gorm:"column:addressState;type:text" json:"addressState,omitempty"` + AddressState datatypes.JSON `gorm:"column:addressState;type:text;serializer:json" json:"addressState,omitempty"` // A use code specified in an address // https://hl7.org/fhir/r4/search.html#token AddressUse datatypes.JSON `gorm:"column:addressUse;type:text;serializer:json" json:"addressUse,omitempty"` @@ -46,7 +46,7 @@ type FhirLocation struct { 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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` // Searches for locations (typically bed/room) that have an operational status (e.g. contaminated, housekeeping) // https://hl7.org/fhir/r4/search.html#token OperationalStatus datatypes.JSON `gorm:"column:operationalStatus;type:text;serializer:json" json:"operationalStatus,omitempty"` @@ -70,7 +70,7 @@ type FhirLocation struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -129,29 +129,279 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe } // execute the fhirpath expression for each search parameter // extracting Address - addressResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Location.address')[0]") + addressResult, err := vm.RunString(` + AddressResult = window.fhirpath.evaluate(fhirResource, 'Location.address') + AddressProcessed = AddressResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressProcessed) + `) if err == nil && addressResult.String() != "undefined" { - s.Address = addressResult.String() + s.Address = []byte(addressResult.String()) } // extracting AddressCity - addressCityResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Location.address.city')[0]") + addressCityResult, err := vm.RunString(` + AddressCityResult = window.fhirpath.evaluate(fhirResource, 'Location.address.city') + AddressCityProcessed = AddressCityResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCityProcessed) + `) if err == nil && addressCityResult.String() != "undefined" { - s.AddressCity = addressCityResult.String() + s.AddressCity = []byte(addressCityResult.String()) } // extracting AddressCountry - addressCountryResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Location.address.country')[0]") + addressCountryResult, err := vm.RunString(` + AddressCountryResult = window.fhirpath.evaluate(fhirResource, 'Location.address.country') + AddressCountryProcessed = AddressCountryResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCountryProcessed) + `) if err == nil && addressCountryResult.String() != "undefined" { - s.AddressCountry = addressCountryResult.String() + s.AddressCountry = []byte(addressCountryResult.String()) } // extracting AddressPostalcode - addressPostalcodeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Location.address.postalCode')[0]") + addressPostalcodeResult, err := vm.RunString(` + AddressPostalcodeResult = window.fhirpath.evaluate(fhirResource, 'Location.address.postalCode') + AddressPostalcodeProcessed = AddressPostalcodeResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressPostalcodeProcessed) + `) if err == nil && addressPostalcodeResult.String() != "undefined" { - s.AddressPostalcode = addressPostalcodeResult.String() + s.AddressPostalcode = []byte(addressPostalcodeResult.String()) } // extracting AddressState - addressStateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Location.address.state')[0]") + addressStateResult, err := vm.RunString(` + AddressStateResult = window.fhirpath.evaluate(fhirResource, 'Location.address.state') + AddressStateProcessed = AddressStateResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressStateProcessed) + `) if err == nil && addressStateResult.String() != "undefined" { - s.AddressState = addressStateResult.String() + s.AddressState = []byte(addressStateResult.String()) } // extracting AddressUse addressUseResult, err := vm.RunString(` @@ -293,9 +543,59 @@ func (s *FhirLocation) PopulateAndExtractSearchParameters(resourceRaw json.RawMe } } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Location.name | Location.alias')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'Location.name | Location.alias') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting OperationalStatus operationalStatusResult, err := vm.RunString(` diff --git a/backend/pkg/models/database/fhir_media.go b/backend/pkg/models/database/fhir_media.go index 702fc8b04..889f497ee 100644 --- a/backend/pkg/models/database/fhir_media.go +++ b/backend/pkg/models/database/fhir_media.go @@ -61,7 +61,7 @@ type FhirMedia struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_medication.go b/backend/pkg/models/database/fhir_medication.go index 8b8619cfe..8a4fd67db 100644 --- a/backend/pkg/models/database/fhir_medication.go +++ b/backend/pkg/models/database/fhir_medication.go @@ -75,7 +75,7 @@ type FhirMedication struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_medication_administration.go b/backend/pkg/models/database/fhir_medication_administration.go index ee5c0a8a1..676097226 100644 --- a/backend/pkg/models/database/fhir_medication_administration.go +++ b/backend/pkg/models/database/fhir_medication_administration.go @@ -131,7 +131,7 @@ type FhirMedicationAdministration struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_medication_dispense.go b/backend/pkg/models/database/fhir_medication_dispense.go index 15d97f06f..8628d7970 100644 --- a/backend/pkg/models/database/fhir_medication_dispense.go +++ b/backend/pkg/models/database/fhir_medication_dispense.go @@ -132,7 +132,7 @@ type FhirMedicationDispense struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_medication_request.go b/backend/pkg/models/database/fhir_medication_request.go index 971722cb3..0463811ff 100644 --- a/backend/pkg/models/database/fhir_medication_request.go +++ b/backend/pkg/models/database/fhir_medication_request.go @@ -148,7 +148,7 @@ type FhirMedicationRequest struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_medication_statement.go b/backend/pkg/models/database/fhir_medication_statement.go index b35b4eec1..e18ff8bd1 100644 --- a/backend/pkg/models/database/fhir_medication_statement.go +++ b/backend/pkg/models/database/fhir_medication_statement.go @@ -125,7 +125,7 @@ type FhirMedicationStatement struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_nutrition_order.go b/backend/pkg/models/database/fhir_nutrition_order.go index ec3b75b7a..d1119c76e 100644 --- a/backend/pkg/models/database/fhir_nutrition_order.go +++ b/backend/pkg/models/database/fhir_nutrition_order.go @@ -112,7 +112,7 @@ type FhirNutritionOrder struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_observation.go b/backend/pkg/models/database/fhir_observation.go index 7e18bded8..450cd2aad 100644 --- a/backend/pkg/models/database/fhir_observation.go +++ b/backend/pkg/models/database/fhir_observation.go @@ -191,7 +191,7 @@ type FhirObservation struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -206,7 +206,7 @@ type FhirObservation struct { ValueQuantity datatypes.JSON `gorm:"column:valueQuantity;type:text;serializer:json" json:"valueQuantity,omitempty"` // The value of the observation, if the value is a string, and also searches in CodeableConcept.text // https://hl7.org/fhir/r4/search.html#string - ValueString string `gorm:"column:valueString;type:text" json:"valueString,omitempty"` + ValueString datatypes.JSON `gorm:"column:valueString;type:text;serializer:json" json:"valueString,omitempty"` } func (s *FhirObservation) GetSearchParameters() map[string]string { @@ -1007,9 +1007,59 @@ func (s *FhirObservation) PopulateAndExtractSearchParameters(resourceRaw json.Ra s.ValueQuantity = []byte(valueQuantityResult.String()) } // extracting ValueString - valueStringResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, '(Observation.valueString) | (Observation.valueCodeableConcept).text')[0]") + valueStringResult, err := vm.RunString(` + ValueStringResult = window.fhirpath.evaluate(fhirResource, '(Observation.valueString) | (Observation.valueCodeableConcept).text') + ValueStringProcessed = ValueStringResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(ValueStringProcessed) + `) if err == nil && valueStringResult.String() != "undefined" { - s.ValueString = valueStringResult.String() + s.ValueString = []byte(valueStringResult.String()) } return nil } diff --git a/backend/pkg/models/database/fhir_organization.go b/backend/pkg/models/database/fhir_organization.go index 95812dd20..875d8d601 100644 --- a/backend/pkg/models/database/fhir_organization.go +++ b/backend/pkg/models/database/fhir_organization.go @@ -19,19 +19,19 @@ type FhirOrganization struct { Active datatypes.JSON `gorm:"column:active;type:text;serializer:json" json:"active,omitempty"` // A server defined search that may match any of the string fields in the Address, including line, city, district, state, country, postalCode, and/or text // https://hl7.org/fhir/r4/search.html#string - Address string `gorm:"column:address;type:text" json:"address,omitempty"` + Address datatypes.JSON `gorm:"column:address;type:text;serializer:json" json:"address,omitempty"` // A city specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressCity string `gorm:"column:addressCity;type:text" json:"addressCity,omitempty"` + AddressCity datatypes.JSON `gorm:"column:addressCity;type:text;serializer:json" json:"addressCity,omitempty"` // A country specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressCountry string `gorm:"column:addressCountry;type:text" json:"addressCountry,omitempty"` + AddressCountry datatypes.JSON `gorm:"column:addressCountry;type:text;serializer:json" json:"addressCountry,omitempty"` // A postal code specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressPostalcode string `gorm:"column:addressPostalcode;type:text" json:"addressPostalcode,omitempty"` + AddressPostalcode datatypes.JSON `gorm:"column:addressPostalcode;type:text;serializer:json" json:"addressPostalcode,omitempty"` // A state specified in an address // https://hl7.org/fhir/r4/search.html#string - AddressState string `gorm:"column:addressState;type:text" json:"addressState,omitempty"` + AddressState datatypes.JSON `gorm:"column:addressState;type:text;serializer:json" json:"addressState,omitempty"` // A use code specified in an address // https://hl7.org/fhir/r4/search.html#token AddressUse datatypes.JSON `gorm:"column:addressUse;type:text;serializer:json" json:"addressUse,omitempty"` @@ -49,13 +49,13 @@ type FhirOrganization struct { 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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` // An organization of which this organization forms a part // https://hl7.org/fhir/r4/search.html#reference Partof datatypes.JSON `gorm:"column:partof;type:text;serializer:json" json:"partof,omitempty"` // A portion of the organization's name using some kind of phonetic matching algorithm // https://hl7.org/fhir/r4/search.html#string - Phonetic string `gorm:"column:phonetic;type:text" json:"phonetic,omitempty"` + Phonetic datatypes.JSON `gorm:"column:phonetic;type:text;serializer:json" json:"phonetic,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"` @@ -67,7 +67,7 @@ type FhirOrganization struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -167,29 +167,279 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R s.Active = []byte(activeResult.String()) } // extracting Address - addressResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Organization.address')[0]") + addressResult, err := vm.RunString(` + AddressResult = window.fhirpath.evaluate(fhirResource, 'Organization.address') + AddressProcessed = AddressResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressProcessed) + `) if err == nil && addressResult.String() != "undefined" { - s.Address = addressResult.String() + s.Address = []byte(addressResult.String()) } // extracting AddressCity - addressCityResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Organization.address.city')[0]") + addressCityResult, err := vm.RunString(` + AddressCityResult = window.fhirpath.evaluate(fhirResource, 'Organization.address.city') + AddressCityProcessed = AddressCityResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCityProcessed) + `) if err == nil && addressCityResult.String() != "undefined" { - s.AddressCity = addressCityResult.String() + s.AddressCity = []byte(addressCityResult.String()) } // extracting AddressCountry - addressCountryResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Organization.address.country')[0]") + addressCountryResult, err := vm.RunString(` + AddressCountryResult = window.fhirpath.evaluate(fhirResource, 'Organization.address.country') + AddressCountryProcessed = AddressCountryResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCountryProcessed) + `) if err == nil && addressCountryResult.String() != "undefined" { - s.AddressCountry = addressCountryResult.String() + s.AddressCountry = []byte(addressCountryResult.String()) } // extracting AddressPostalcode - addressPostalcodeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Organization.address.postalCode')[0]") + addressPostalcodeResult, err := vm.RunString(` + AddressPostalcodeResult = window.fhirpath.evaluate(fhirResource, 'Organization.address.postalCode') + AddressPostalcodeProcessed = AddressPostalcodeResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressPostalcodeProcessed) + `) if err == nil && addressPostalcodeResult.String() != "undefined" { - s.AddressPostalcode = addressPostalcodeResult.String() + s.AddressPostalcode = []byte(addressPostalcodeResult.String()) } // extracting AddressState - addressStateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Organization.address.state')[0]") + addressStateResult, err := vm.RunString(` + AddressStateResult = window.fhirpath.evaluate(fhirResource, 'Organization.address.state') + AddressStateProcessed = AddressStateResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressStateProcessed) + `) if err == nil && addressStateResult.String() != "undefined" { - s.AddressState = addressStateResult.String() + s.AddressState = []byte(addressStateResult.String()) } // extracting AddressUse addressUseResult, err := vm.RunString(` @@ -331,9 +581,59 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R } } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Organization.name | Organization.alias')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'Organization.name | Organization.alias') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting Partof partofResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Organization.partOf'))") @@ -341,9 +641,59 @@ func (s *FhirOrganization) PopulateAndExtractSearchParameters(resourceRaw json.R s.Partof = []byte(partofResult.String()) } // extracting Phonetic - phoneticResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Organization.name')[0]") + phoneticResult, err := vm.RunString(` + PhoneticResult = window.fhirpath.evaluate(fhirResource, 'Organization.name') + PhoneticProcessed = PhoneticResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(PhoneticProcessed) + `) if err == nil && phoneticResult.String() != "undefined" { - s.Phonetic = phoneticResult.String() + s.Phonetic = []byte(phoneticResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") diff --git a/backend/pkg/models/database/fhir_organization_affiliation.go b/backend/pkg/models/database/fhir_organization_affiliation.go index 4ebeade8e..4cf302626 100644 --- a/backend/pkg/models/database/fhir_organization_affiliation.go +++ b/backend/pkg/models/database/fhir_organization_affiliation.go @@ -73,7 +73,7 @@ type FhirOrganizationAffiliation struct { Telecom datatypes.JSON `gorm:"column:telecom;type:text;serializer:json" json:"telecom,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_patient.go b/backend/pkg/models/database/fhir_patient.go index 4106d8e7e..13e086e64 100644 --- a/backend/pkg/models/database/fhir_patient.go +++ b/backend/pkg/models/database/fhir_patient.go @@ -26,7 +26,7 @@ type FhirPatient struct { * [RelatedPerson](relatedperson.html): A server defined search that may match any of the string fields in the Address, including line, city, district, state, country, postalCode, and/or text */ // https://hl7.org/fhir/r4/search.html#string - Address string `gorm:"column:address;type:text" json:"address,omitempty"` + Address datatypes.JSON `gorm:"column:address;type:text;serializer:json" json:"address,omitempty"` /* Multiple Resources: @@ -36,7 +36,7 @@ type FhirPatient struct { * [RelatedPerson](relatedperson.html): A city specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressCity string `gorm:"column:addressCity;type:text" json:"addressCity,omitempty"` + AddressCity datatypes.JSON `gorm:"column:addressCity;type:text;serializer:json" json:"addressCity,omitempty"` /* Multiple Resources: @@ -46,7 +46,7 @@ type FhirPatient struct { * [RelatedPerson](relatedperson.html): A country specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressCountry string `gorm:"column:addressCountry;type:text" json:"addressCountry,omitempty"` + AddressCountry datatypes.JSON `gorm:"column:addressCountry;type:text;serializer:json" json:"addressCountry,omitempty"` /* Multiple Resources: @@ -56,7 +56,7 @@ type FhirPatient struct { * [RelatedPerson](relatedperson.html): A postal code specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressPostalcode string `gorm:"column:addressPostalcode;type:text" json:"addressPostalcode,omitempty"` + AddressPostalcode datatypes.JSON `gorm:"column:addressPostalcode;type:text;serializer:json" json:"addressPostalcode,omitempty"` /* Multiple Resources: @@ -66,7 +66,7 @@ type FhirPatient struct { * [RelatedPerson](relatedperson.html): A state specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressState string `gorm:"column:addressState;type:text" json:"addressState,omitempty"` + AddressState datatypes.JSON `gorm:"column:addressState;type:text;serializer:json" json:"addressState,omitempty"` /* Multiple Resources: @@ -110,7 +110,7 @@ type FhirPatient struct { * [Practitioner](practitioner.html): A portion of the family name */ // https://hl7.org/fhir/r4/search.html#string - Family string `gorm:"column:family;type:text" json:"family,omitempty"` + Family datatypes.JSON `gorm:"column:family;type:text;serializer:json" json:"family,omitempty"` /* Multiple Resources: @@ -131,7 +131,7 @@ type FhirPatient struct { * [Practitioner](practitioner.html): A portion of the given name */ // https://hl7.org/fhir/r4/search.html#string - Given string `gorm:"column:given;type:text" json:"given,omitempty"` + Given datatypes.JSON `gorm:"column:given;type:text;serializer:json" json:"given,omitempty"` // A patient identifier // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -146,7 +146,7 @@ type FhirPatient struct { Link datatypes.JSON `gorm:"column:link;type:text;serializer:json" json:"link,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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` // The organization that is the custodian of the patient record // https://hl7.org/fhir/r4/search.html#reference Organization datatypes.JSON `gorm:"column:organization;type:text;serializer:json" json:"organization,omitempty"` @@ -170,7 +170,7 @@ type FhirPatient struct { * [RelatedPerson](relatedperson.html): A portion of name using some kind of phonetic matching algorithm */ // https://hl7.org/fhir/r4/search.html#string - Phonetic string `gorm:"column:phonetic;type:text" json:"phonetic,omitempty"` + Phonetic datatypes.JSON `gorm:"column:phonetic;type:text;serializer:json" json:"phonetic,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"` @@ -193,7 +193,7 @@ type FhirPatient struct { Telecom datatypes.JSON `gorm:"column:telecom;type:text;serializer:json" json:"telecom,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -303,29 +303,279 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes s.Active = []byte(activeResult.String()) } // extracting Address - addressResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address | Person.address | Practitioner.address | RelatedPerson.address')[0]") + addressResult, err := vm.RunString(` + AddressResult = window.fhirpath.evaluate(fhirResource, 'Patient.address | Person.address | Practitioner.address | RelatedPerson.address') + AddressProcessed = AddressResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressProcessed) + `) if err == nil && addressResult.String() != "undefined" { - s.Address = addressResult.String() + s.Address = []byte(addressResult.String()) } // extracting AddressCity - addressCityResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.city | Person.address.city | Practitioner.address.city | RelatedPerson.address.city')[0]") + addressCityResult, err := vm.RunString(` + AddressCityResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.city | Person.address.city | Practitioner.address.city | RelatedPerson.address.city') + AddressCityProcessed = AddressCityResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCityProcessed) + `) if err == nil && addressCityResult.String() != "undefined" { - s.AddressCity = addressCityResult.String() + s.AddressCity = []byte(addressCityResult.String()) } // extracting AddressCountry - addressCountryResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.country | Person.address.country | Practitioner.address.country | RelatedPerson.address.country')[0]") + addressCountryResult, err := vm.RunString(` + AddressCountryResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.country | Person.address.country | Practitioner.address.country | RelatedPerson.address.country') + AddressCountryProcessed = AddressCountryResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCountryProcessed) + `) if err == nil && addressCountryResult.String() != "undefined" { - s.AddressCountry = addressCountryResult.String() + s.AddressCountry = []byte(addressCountryResult.String()) } // extracting AddressPostalcode - addressPostalcodeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.postalCode | Person.address.postalCode | Practitioner.address.postalCode | RelatedPerson.address.postalCode')[0]") + addressPostalcodeResult, err := vm.RunString(` + AddressPostalcodeResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.postalCode | Person.address.postalCode | Practitioner.address.postalCode | RelatedPerson.address.postalCode') + AddressPostalcodeProcessed = AddressPostalcodeResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressPostalcodeProcessed) + `) if err == nil && addressPostalcodeResult.String() != "undefined" { - s.AddressPostalcode = addressPostalcodeResult.String() + s.AddressPostalcode = []byte(addressPostalcodeResult.String()) } // extracting AddressState - addressStateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.state | Person.address.state | Practitioner.address.state | RelatedPerson.address.state')[0]") + addressStateResult, err := vm.RunString(` + AddressStateResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.state | Person.address.state | Practitioner.address.state | RelatedPerson.address.state') + AddressStateProcessed = AddressStateResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressStateProcessed) + `) if err == nil && addressStateResult.String() != "undefined" { - s.AddressState = addressStateResult.String() + s.AddressState = []byte(addressStateResult.String()) } // extracting AddressUse addressUseResult, err := vm.RunString(` @@ -470,9 +720,59 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes s.Email = []byte(emailResult.String()) } // extracting Family - familyResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name.family | Practitioner.name.family')[0]") + familyResult, err := vm.RunString(` + FamilyResult = window.fhirpath.evaluate(fhirResource, 'Patient.name.family | Practitioner.name.family') + FamilyProcessed = FamilyResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(FamilyProcessed) + `) if err == nil && familyResult.String() != "undefined" { - s.Family = familyResult.String() + s.Family = []byte(familyResult.String()) } // extracting Gender genderResult, err := vm.RunString(` @@ -522,9 +822,59 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes s.GeneralPractitioner = []byte(generalPractitionerResult.String()) } // extracting Given - givenResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name.given | Practitioner.name.given')[0]") + givenResult, err := vm.RunString(` + GivenResult = window.fhirpath.evaluate(fhirResource, 'Patient.name.given | Practitioner.name.given') + GivenProcessed = GivenResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(GivenProcessed) + `) if err == nil && givenResult.String() != "undefined" { - s.Given = givenResult.String() + s.Given = []byte(givenResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -624,9 +974,59 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes s.Link = []byte(linkResult.String()) } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'Patient.name') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Patient.managingOrganization'))") @@ -676,9 +1076,59 @@ func (s *FhirPatient) PopulateAndExtractSearchParameters(resourceRaw json.RawMes s.Phone = []byte(phoneResult.String()) } // extracting Phonetic - phoneticResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name | Person.name | Practitioner.name | RelatedPerson.name')[0]") + phoneticResult, err := vm.RunString(` + PhoneticResult = window.fhirpath.evaluate(fhirResource, 'Patient.name | Person.name | Practitioner.name | RelatedPerson.name') + PhoneticProcessed = PhoneticResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(PhoneticProcessed) + `) if err == nil && phoneticResult.String() != "undefined" { - s.Phonetic = phoneticResult.String() + s.Phonetic = []byte(phoneticResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") diff --git a/backend/pkg/models/database/fhir_patient_test.go b/backend/pkg/models/database/fhir_patient_test.go new file mode 100644 index 000000000..ca1c047d4 --- /dev/null +++ b/backend/pkg/models/database/fhir_patient_test.go @@ -0,0 +1,50 @@ +package database + +import ( + "encoding/json" + "github.com/stretchr/testify/require" + "os" + "testing" +) + +func TestFhirPatient_ExtractSearchParameters(t *testing.T) { + t.Parallel() + //setup + //var observationJson map[string]interface{} + patientBytes, err := os.ReadFile("../../../../frontend/src/lib/fixtures/r4/resources/patient/example1.json") + require.NoError(t, err) + //err = json.Unmarshal(patientBytes, &observationJson) + //require.NoError(t, err) + + //test + patientModel := FhirPatient{} + err = patientModel.PopulateAndExtractSearchParameters(patientBytes) + + //assert + type CodeType struct { + Code bool `json:"code"` + } + var testCode []CodeType + require.NoError(t, err) + err = json.Unmarshal(json.RawMessage(patientModel.Active), &testCode) + require.NoError(t, err) + require.Equal(t, []CodeType{ + { + Code: true, + }, + }, testCode) + + var testName []string + err = json.Unmarshal(json.RawMessage(patientModel.Name), &testName) + require.NoError(t, err) + require.Equal(t, []string{ + "Peter James Chalmers", "Jim", "Peter James Windsor", + }, testName) + + var testAddress []string + err = json.Unmarshal(json.RawMessage(patientModel.Address), &testAddress) + require.NoError(t, err) + require.Equal(t, []string{ + "534 Erewhon St PleasantVille Vic 3999", + }, testAddress) +} diff --git a/backend/pkg/models/database/fhir_person.go b/backend/pkg/models/database/fhir_person.go index 3774259e2..483c732c5 100644 --- a/backend/pkg/models/database/fhir_person.go +++ b/backend/pkg/models/database/fhir_person.go @@ -23,7 +23,7 @@ type FhirPerson struct { * [RelatedPerson](relatedperson.html): A server defined search that may match any of the string fields in the Address, including line, city, district, state, country, postalCode, and/or text */ // https://hl7.org/fhir/r4/search.html#string - Address string `gorm:"column:address;type:text" json:"address,omitempty"` + Address datatypes.JSON `gorm:"column:address;type:text;serializer:json" json:"address,omitempty"` /* Multiple Resources: @@ -33,7 +33,7 @@ type FhirPerson struct { * [RelatedPerson](relatedperson.html): A city specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressCity string `gorm:"column:addressCity;type:text" json:"addressCity,omitempty"` + AddressCity datatypes.JSON `gorm:"column:addressCity;type:text;serializer:json" json:"addressCity,omitempty"` /* Multiple Resources: @@ -43,7 +43,7 @@ type FhirPerson struct { * [RelatedPerson](relatedperson.html): A country specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressCountry string `gorm:"column:addressCountry;type:text" json:"addressCountry,omitempty"` + AddressCountry datatypes.JSON `gorm:"column:addressCountry;type:text;serializer:json" json:"addressCountry,omitempty"` /* Multiple Resources: @@ -53,7 +53,7 @@ type FhirPerson struct { * [RelatedPerson](relatedperson.html): A postal code specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressPostalcode string `gorm:"column:addressPostalcode;type:text" json:"addressPostalcode,omitempty"` + AddressPostalcode datatypes.JSON `gorm:"column:addressPostalcode;type:text;serializer:json" json:"addressPostalcode,omitempty"` /* Multiple Resources: @@ -63,7 +63,7 @@ type FhirPerson struct { * [RelatedPerson](relatedperson.html): A state specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressState string `gorm:"column:addressState;type:text" json:"addressState,omitempty"` + AddressState datatypes.JSON `gorm:"column:addressState;type:text;serializer:json" json:"addressState,omitempty"` /* Multiple Resources: @@ -118,7 +118,7 @@ type FhirPerson struct { Link datatypes.JSON `gorm:"column:link;type:text;serializer:json" json:"link,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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` // The organization at which this person record is being managed // https://hl7.org/fhir/r4/search.html#reference Organization datatypes.JSON `gorm:"column:organization;type:text;serializer:json" json:"organization,omitempty"` @@ -142,7 +142,7 @@ type FhirPerson struct { * [RelatedPerson](relatedperson.html): A portion of name using some kind of phonetic matching algorithm */ // https://hl7.org/fhir/r4/search.html#string - Phonetic string `gorm:"column:phonetic;type:text" json:"phonetic,omitempty"` + Phonetic datatypes.JSON `gorm:"column:phonetic;type:text;serializer:json" json:"phonetic,omitempty"` // The Person links to this Practitioner // https://hl7.org/fhir/r4/search.html#reference Practitioner datatypes.JSON `gorm:"column:practitioner;type:text;serializer:json" json:"practitioner,omitempty"` @@ -171,7 +171,7 @@ type FhirPerson struct { Telecom datatypes.JSON `gorm:"column:telecom;type:text;serializer:json" json:"telecom,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -235,29 +235,279 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess } // execute the fhirpath expression for each search parameter // extracting Address - addressResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address | Person.address | Practitioner.address | RelatedPerson.address')[0]") + addressResult, err := vm.RunString(` + AddressResult = window.fhirpath.evaluate(fhirResource, 'Patient.address | Person.address | Practitioner.address | RelatedPerson.address') + AddressProcessed = AddressResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressProcessed) + `) if err == nil && addressResult.String() != "undefined" { - s.Address = addressResult.String() + s.Address = []byte(addressResult.String()) } // extracting AddressCity - addressCityResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.city | Person.address.city | Practitioner.address.city | RelatedPerson.address.city')[0]") + addressCityResult, err := vm.RunString(` + AddressCityResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.city | Person.address.city | Practitioner.address.city | RelatedPerson.address.city') + AddressCityProcessed = AddressCityResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCityProcessed) + `) if err == nil && addressCityResult.String() != "undefined" { - s.AddressCity = addressCityResult.String() + s.AddressCity = []byte(addressCityResult.String()) } // extracting AddressCountry - addressCountryResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.country | Person.address.country | Practitioner.address.country | RelatedPerson.address.country')[0]") + addressCountryResult, err := vm.RunString(` + AddressCountryResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.country | Person.address.country | Practitioner.address.country | RelatedPerson.address.country') + AddressCountryProcessed = AddressCountryResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCountryProcessed) + `) if err == nil && addressCountryResult.String() != "undefined" { - s.AddressCountry = addressCountryResult.String() + s.AddressCountry = []byte(addressCountryResult.String()) } // extracting AddressPostalcode - addressPostalcodeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.postalCode | Person.address.postalCode | Practitioner.address.postalCode | RelatedPerson.address.postalCode')[0]") + addressPostalcodeResult, err := vm.RunString(` + AddressPostalcodeResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.postalCode | Person.address.postalCode | Practitioner.address.postalCode | RelatedPerson.address.postalCode') + AddressPostalcodeProcessed = AddressPostalcodeResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressPostalcodeProcessed) + `) if err == nil && addressPostalcodeResult.String() != "undefined" { - s.AddressPostalcode = addressPostalcodeResult.String() + s.AddressPostalcode = []byte(addressPostalcodeResult.String()) } // extracting AddressState - addressStateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.state | Person.address.state | Practitioner.address.state | RelatedPerson.address.state')[0]") + addressStateResult, err := vm.RunString(` + AddressStateResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.state | Person.address.state | Practitioner.address.state | RelatedPerson.address.state') + AddressStateProcessed = AddressStateResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressStateProcessed) + `) if err == nil && addressStateResult.String() != "undefined" { - s.AddressState = addressStateResult.String() + s.AddressState = []byte(addressStateResult.String()) } // extracting AddressUse addressUseResult, err := vm.RunString(` @@ -491,9 +741,59 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess s.Link = []byte(linkResult.String()) } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Person.name')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'Person.name') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting Organization organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Person.managingOrganization'))") @@ -543,9 +843,59 @@ func (s *FhirPerson) PopulateAndExtractSearchParameters(resourceRaw json.RawMess s.Phone = []byte(phoneResult.String()) } // extracting Phonetic - phoneticResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name | Person.name | Practitioner.name | RelatedPerson.name')[0]") + phoneticResult, err := vm.RunString(` + PhoneticResult = window.fhirpath.evaluate(fhirResource, 'Patient.name | Person.name | Practitioner.name | RelatedPerson.name') + PhoneticProcessed = PhoneticResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(PhoneticProcessed) + `) if err == nil && phoneticResult.String() != "undefined" { - s.Phonetic = phoneticResult.String() + s.Phonetic = []byte(phoneticResult.String()) } // extracting Practitioner practitionerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Person.link.target.where(resolve() is Practitioner)'))") diff --git a/backend/pkg/models/database/fhir_practitioner.go b/backend/pkg/models/database/fhir_practitioner.go index a22b04340..db184bbdd 100644 --- a/backend/pkg/models/database/fhir_practitioner.go +++ b/backend/pkg/models/database/fhir_practitioner.go @@ -26,7 +26,7 @@ type FhirPractitioner struct { * [RelatedPerson](relatedperson.html): A server defined search that may match any of the string fields in the Address, including line, city, district, state, country, postalCode, and/or text */ // https://hl7.org/fhir/r4/search.html#string - Address string `gorm:"column:address;type:text" json:"address,omitempty"` + Address datatypes.JSON `gorm:"column:address;type:text;serializer:json" json:"address,omitempty"` /* Multiple Resources: @@ -36,7 +36,7 @@ type FhirPractitioner struct { * [RelatedPerson](relatedperson.html): A city specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressCity string `gorm:"column:addressCity;type:text" json:"addressCity,omitempty"` + AddressCity datatypes.JSON `gorm:"column:addressCity;type:text;serializer:json" json:"addressCity,omitempty"` /* Multiple Resources: @@ -46,7 +46,7 @@ type FhirPractitioner struct { * [RelatedPerson](relatedperson.html): A country specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressCountry string `gorm:"column:addressCountry;type:text" json:"addressCountry,omitempty"` + AddressCountry datatypes.JSON `gorm:"column:addressCountry;type:text;serializer:json" json:"addressCountry,omitempty"` /* Multiple Resources: @@ -56,7 +56,7 @@ type FhirPractitioner struct { * [RelatedPerson](relatedperson.html): A postal code specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressPostalcode string `gorm:"column:addressPostalcode;type:text" json:"addressPostalcode,omitempty"` + AddressPostalcode datatypes.JSON `gorm:"column:addressPostalcode;type:text;serializer:json" json:"addressPostalcode,omitempty"` /* Multiple Resources: @@ -66,7 +66,7 @@ type FhirPractitioner struct { * [RelatedPerson](relatedperson.html): A state specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressState string `gorm:"column:addressState;type:text" json:"addressState,omitempty"` + AddressState datatypes.JSON `gorm:"column:addressState;type:text;serializer:json" json:"addressState,omitempty"` /* Multiple Resources: @@ -98,7 +98,7 @@ type FhirPractitioner struct { * [Practitioner](practitioner.html): A portion of the family name */ // https://hl7.org/fhir/r4/search.html#string - Family string `gorm:"column:family;type:text" json:"family,omitempty"` + Family datatypes.JSON `gorm:"column:family;type:text;serializer:json" json:"family,omitempty"` /* Multiple Resources: @@ -116,7 +116,7 @@ type FhirPractitioner struct { * [Practitioner](practitioner.html): A portion of the given name */ // https://hl7.org/fhir/r4/search.html#string - Given string `gorm:"column:given;type:text" json:"given,omitempty"` + Given datatypes.JSON `gorm:"column:given;type:text;serializer:json" json:"given,omitempty"` // A practitioner's Identifier // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` @@ -128,7 +128,7 @@ type FhirPractitioner struct { 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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` /* Multiple Resources: @@ -149,7 +149,7 @@ type FhirPractitioner struct { * [RelatedPerson](relatedperson.html): A portion of name using some kind of phonetic matching algorithm */ // https://hl7.org/fhir/r4/search.html#string - Phonetic string `gorm:"column:phonetic;type:text" json:"phonetic,omitempty"` + Phonetic datatypes.JSON `gorm:"column:phonetic;type:text;serializer:json" json:"phonetic,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"` @@ -172,7 +172,7 @@ type FhirPractitioner struct { Telecom datatypes.JSON `gorm:"column:telecom;type:text;serializer:json" json:"telecom,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -277,29 +277,279 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R s.Active = []byte(activeResult.String()) } // extracting Address - addressResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address | Person.address | Practitioner.address | RelatedPerson.address')[0]") + addressResult, err := vm.RunString(` + AddressResult = window.fhirpath.evaluate(fhirResource, 'Patient.address | Person.address | Practitioner.address | RelatedPerson.address') + AddressProcessed = AddressResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressProcessed) + `) if err == nil && addressResult.String() != "undefined" { - s.Address = addressResult.String() + s.Address = []byte(addressResult.String()) } // extracting AddressCity - addressCityResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.city | Person.address.city | Practitioner.address.city | RelatedPerson.address.city')[0]") + addressCityResult, err := vm.RunString(` + AddressCityResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.city | Person.address.city | Practitioner.address.city | RelatedPerson.address.city') + AddressCityProcessed = AddressCityResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCityProcessed) + `) if err == nil && addressCityResult.String() != "undefined" { - s.AddressCity = addressCityResult.String() + s.AddressCity = []byte(addressCityResult.String()) } // extracting AddressCountry - addressCountryResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.country | Person.address.country | Practitioner.address.country | RelatedPerson.address.country')[0]") + addressCountryResult, err := vm.RunString(` + AddressCountryResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.country | Person.address.country | Practitioner.address.country | RelatedPerson.address.country') + AddressCountryProcessed = AddressCountryResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCountryProcessed) + `) if err == nil && addressCountryResult.String() != "undefined" { - s.AddressCountry = addressCountryResult.String() + s.AddressCountry = []byte(addressCountryResult.String()) } // extracting AddressPostalcode - addressPostalcodeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.postalCode | Person.address.postalCode | Practitioner.address.postalCode | RelatedPerson.address.postalCode')[0]") + addressPostalcodeResult, err := vm.RunString(` + AddressPostalcodeResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.postalCode | Person.address.postalCode | Practitioner.address.postalCode | RelatedPerson.address.postalCode') + AddressPostalcodeProcessed = AddressPostalcodeResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressPostalcodeProcessed) + `) if err == nil && addressPostalcodeResult.String() != "undefined" { - s.AddressPostalcode = addressPostalcodeResult.String() + s.AddressPostalcode = []byte(addressPostalcodeResult.String()) } // extracting AddressState - addressStateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.state | Person.address.state | Practitioner.address.state | RelatedPerson.address.state')[0]") + addressStateResult, err := vm.RunString(` + AddressStateResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.state | Person.address.state | Practitioner.address.state | RelatedPerson.address.state') + AddressStateProcessed = AddressStateResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressStateProcessed) + `) if err == nil && addressStateResult.String() != "undefined" { - s.AddressState = addressStateResult.String() + s.AddressState = []byte(addressStateResult.String()) } // extracting AddressUse addressUseResult, err := vm.RunString(` @@ -428,9 +678,59 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R s.Email = []byte(emailResult.String()) } // extracting Family - familyResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name.family | Practitioner.name.family')[0]") + familyResult, err := vm.RunString(` + FamilyResult = window.fhirpath.evaluate(fhirResource, 'Patient.name.family | Practitioner.name.family') + FamilyProcessed = FamilyResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(FamilyProcessed) + `) if err == nil && familyResult.String() != "undefined" { - s.Family = familyResult.String() + s.Family = []byte(familyResult.String()) } // extracting Gender genderResult, err := vm.RunString(` @@ -475,9 +775,59 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R s.Gender = []byte(genderResult.String()) } // extracting Given - givenResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name.given | Practitioner.name.given')[0]") + givenResult, err := vm.RunString(` + GivenResult = window.fhirpath.evaluate(fhirResource, 'Patient.name.given | Practitioner.name.given') + GivenProcessed = GivenResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(GivenProcessed) + `) if err == nil && givenResult.String() != "undefined" { - s.Given = givenResult.String() + s.Given = []byte(givenResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` @@ -572,9 +922,59 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R } } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Practitioner.name')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'Practitioner.name') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting Phone phoneResult, err := vm.RunString(` @@ -619,9 +1019,59 @@ func (s *FhirPractitioner) PopulateAndExtractSearchParameters(resourceRaw json.R s.Phone = []byte(phoneResult.String()) } // extracting Phonetic - phoneticResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name | Person.name | Practitioner.name | RelatedPerson.name')[0]") + phoneticResult, err := vm.RunString(` + PhoneticResult = window.fhirpath.evaluate(fhirResource, 'Patient.name | Person.name | Practitioner.name | RelatedPerson.name') + PhoneticProcessed = PhoneticResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(PhoneticProcessed) + `) if err == nil && phoneticResult.String() != "undefined" { - s.Phonetic = phoneticResult.String() + s.Phonetic = []byte(phoneticResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") diff --git a/backend/pkg/models/database/fhir_practitioner_role.go b/backend/pkg/models/database/fhir_practitioner_role.go index 41282c604..bbe42d233 100644 --- a/backend/pkg/models/database/fhir_practitioner_role.go +++ b/backend/pkg/models/database/fhir_practitioner_role.go @@ -94,7 +94,7 @@ type FhirPractitionerRole struct { Telecom datatypes.JSON `gorm:"column:telecom;type:text;serializer:json" json:"telecom,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_procedure.go b/backend/pkg/models/database/fhir_procedure.go index 7f99f2eb2..acd431f1a 100644 --- a/backend/pkg/models/database/fhir_procedure.go +++ b/backend/pkg/models/database/fhir_procedure.go @@ -161,7 +161,7 @@ type FhirProcedure struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_provenance.go b/backend/pkg/models/database/fhir_provenance.go index 050bd7fdb..5ecf93177 100644 --- a/backend/pkg/models/database/fhir_provenance.go +++ b/backend/pkg/models/database/fhir_provenance.go @@ -55,7 +55,7 @@ type FhirProvenance struct { Target datatypes.JSON `gorm:"column:target;type:text;serializer:json" json:"target,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_questionnaire.go b/backend/pkg/models/database/fhir_questionnaire.go index 26a38a987..a620d9181 100644 --- a/backend/pkg/models/database/fhir_questionnaire.go +++ b/backend/pkg/models/database/fhir_questionnaire.go @@ -34,7 +34,7 @@ type FhirQuestionnaire struct { Definition string `gorm:"column:definition;type:text" json:"definition,omitempty"` // The description of the questionnaire // https://hl7.org/fhir/r4/search.html#string - Description string `gorm:"column:description;type:text" json:"description,omitempty"` + 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"` @@ -52,13 +52,13 @@ type FhirQuestionnaire struct { 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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,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"` // Name of the publisher of the questionnaire // https://hl7.org/fhir/r4/search.html#string - Publisher string `gorm:"column:publisher;type:text" json:"publisher,omitempty"` + Publisher datatypes.JSON `gorm:"column:publisher;type:text;serializer:json" json:"publisher,omitempty"` // Identifies where the resource comes from // https://hl7.org/fhir/r4/search.html#uri SourceUri string `gorm:"column:sourceUri;type:text" json:"sourceUri,omitempty"` @@ -73,10 +73,10 @@ type FhirQuestionnaire struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // The human-friendly name of the questionnaire // https://hl7.org/fhir/r4/search.html#string - Title string `gorm:"column:title;type:text" json:"title,omitempty"` + Title datatypes.JSON `gorm:"column:title;type:text;serializer:json" json:"title,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -289,9 +289,59 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. s.Definition = definitionResult.String() } // extracting Description - descriptionResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.description')[0]") + descriptionResult, err := vm.RunString(` + DescriptionResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.description') + DescriptionProcessed = DescriptionResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(DescriptionProcessed) + `) if err == nil && descriptionResult.String() != "undefined" { - s.Description = descriptionResult.String() + s.Description = []byte(descriptionResult.String()) } // extracting Effective effectiveResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.effectivePeriod')[0]") @@ -436,9 +486,59 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. } } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.name')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.name') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") @@ -446,9 +546,59 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. s.Profile = []byte(profileResult.String()) } // extracting Publisher - publisherResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.publisher')[0]") + publisherResult, err := vm.RunString(` + PublisherResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.publisher') + PublisherProcessed = PublisherResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(PublisherProcessed) + `) if err == nil && publisherResult.String() != "undefined" { - s.Publisher = publisherResult.String() + s.Publisher = []byte(publisherResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]") @@ -582,9 +732,59 @@ func (s *FhirQuestionnaire) PopulateAndExtractSearchParameters(resourceRaw json. s.Tag = []byte(tagResult.String()) } // extracting Title - titleResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.title')[0]") + titleResult, err := vm.RunString(` + TitleResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.title') + TitleProcessed = TitleResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(TitleProcessed) + `) if err == nil && titleResult.String() != "undefined" { - s.Title = titleResult.String() + s.Title = []byte(titleResult.String()) } // extracting Url urlResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.url')[0]") diff --git a/backend/pkg/models/database/fhir_questionnaire_response.go b/backend/pkg/models/database/fhir_questionnaire_response.go index 327310ef6..c993e5840 100644 --- a/backend/pkg/models/database/fhir_questionnaire_response.go +++ b/backend/pkg/models/database/fhir_questionnaire_response.go @@ -61,7 +61,7 @@ type FhirQuestionnaireResponse struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_related_person.go b/backend/pkg/models/database/fhir_related_person.go index 6bfe9bbf8..037fd756f 100644 --- a/backend/pkg/models/database/fhir_related_person.go +++ b/backend/pkg/models/database/fhir_related_person.go @@ -26,7 +26,7 @@ type FhirRelatedPerson struct { * [RelatedPerson](relatedperson.html): A server defined search that may match any of the string fields in the Address, including line, city, district, state, country, postalCode, and/or text */ // https://hl7.org/fhir/r4/search.html#string - Address string `gorm:"column:address;type:text" json:"address,omitempty"` + Address datatypes.JSON `gorm:"column:address;type:text;serializer:json" json:"address,omitempty"` /* Multiple Resources: @@ -36,7 +36,7 @@ type FhirRelatedPerson struct { * [RelatedPerson](relatedperson.html): A city specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressCity string `gorm:"column:addressCity;type:text" json:"addressCity,omitempty"` + AddressCity datatypes.JSON `gorm:"column:addressCity;type:text;serializer:json" json:"addressCity,omitempty"` /* Multiple Resources: @@ -46,7 +46,7 @@ type FhirRelatedPerson struct { * [RelatedPerson](relatedperson.html): A country specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressCountry string `gorm:"column:addressCountry;type:text" json:"addressCountry,omitempty"` + AddressCountry datatypes.JSON `gorm:"column:addressCountry;type:text;serializer:json" json:"addressCountry,omitempty"` /* Multiple Resources: @@ -56,7 +56,7 @@ type FhirRelatedPerson struct { * [RelatedPerson](relatedperson.html): A postal code specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressPostalcode string `gorm:"column:addressPostalcode;type:text" json:"addressPostalcode,omitempty"` + AddressPostalcode datatypes.JSON `gorm:"column:addressPostalcode;type:text;serializer:json" json:"addressPostalcode,omitempty"` /* Multiple Resources: @@ -66,7 +66,7 @@ type FhirRelatedPerson struct { * [RelatedPerson](relatedperson.html): A state specified in an address */ // https://hl7.org/fhir/r4/search.html#string - AddressState string `gorm:"column:addressState;type:text" json:"addressState,omitempty"` + AddressState datatypes.JSON `gorm:"column:addressState;type:text;serializer:json" json:"addressState,omitempty"` /* Multiple Resources: @@ -118,7 +118,7 @@ type FhirRelatedPerson struct { 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 string `gorm:"column:name;type:text" json:"name,omitempty"` + Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"` /* Multiple Resources: @@ -139,7 +139,7 @@ type FhirRelatedPerson struct { * [RelatedPerson](relatedperson.html): A portion of name using some kind of phonetic matching algorithm */ // https://hl7.org/fhir/r4/search.html#string - Phonetic string `gorm:"column:phonetic;type:text" json:"phonetic,omitempty"` + Phonetic datatypes.JSON `gorm:"column:phonetic;type:text;serializer:json" json:"phonetic,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"` @@ -165,7 +165,7 @@ type FhirRelatedPerson struct { Telecom datatypes.JSON `gorm:"column:telecom;type:text;serializer:json" json:"telecom,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` @@ -269,29 +269,279 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. s.Active = []byte(activeResult.String()) } // extracting Address - addressResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address | Person.address | Practitioner.address | RelatedPerson.address')[0]") + addressResult, err := vm.RunString(` + AddressResult = window.fhirpath.evaluate(fhirResource, 'Patient.address | Person.address | Practitioner.address | RelatedPerson.address') + AddressProcessed = AddressResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressProcessed) + `) if err == nil && addressResult.String() != "undefined" { - s.Address = addressResult.String() + s.Address = []byte(addressResult.String()) } // extracting AddressCity - addressCityResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.city | Person.address.city | Practitioner.address.city | RelatedPerson.address.city')[0]") + addressCityResult, err := vm.RunString(` + AddressCityResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.city | Person.address.city | Practitioner.address.city | RelatedPerson.address.city') + AddressCityProcessed = AddressCityResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCityProcessed) + `) if err == nil && addressCityResult.String() != "undefined" { - s.AddressCity = addressCityResult.String() + s.AddressCity = []byte(addressCityResult.String()) } // extracting AddressCountry - addressCountryResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.country | Person.address.country | Practitioner.address.country | RelatedPerson.address.country')[0]") + addressCountryResult, err := vm.RunString(` + AddressCountryResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.country | Person.address.country | Practitioner.address.country | RelatedPerson.address.country') + AddressCountryProcessed = AddressCountryResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressCountryProcessed) + `) if err == nil && addressCountryResult.String() != "undefined" { - s.AddressCountry = addressCountryResult.String() + s.AddressCountry = []byte(addressCountryResult.String()) } // extracting AddressPostalcode - addressPostalcodeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.postalCode | Person.address.postalCode | Practitioner.address.postalCode | RelatedPerson.address.postalCode')[0]") + addressPostalcodeResult, err := vm.RunString(` + AddressPostalcodeResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.postalCode | Person.address.postalCode | Practitioner.address.postalCode | RelatedPerson.address.postalCode') + AddressPostalcodeProcessed = AddressPostalcodeResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressPostalcodeProcessed) + `) if err == nil && addressPostalcodeResult.String() != "undefined" { - s.AddressPostalcode = addressPostalcodeResult.String() + s.AddressPostalcode = []byte(addressPostalcodeResult.String()) } // extracting AddressState - addressStateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.address.state | Person.address.state | Practitioner.address.state | RelatedPerson.address.state')[0]") + addressStateResult, err := vm.RunString(` + AddressStateResult = window.fhirpath.evaluate(fhirResource, 'Patient.address.state | Person.address.state | Practitioner.address.state | RelatedPerson.address.state') + AddressStateProcessed = AddressStateResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(AddressStateProcessed) + `) if err == nil && addressStateResult.String() != "undefined" { - s.AddressState = addressStateResult.String() + s.AddressState = []byte(addressStateResult.String()) } // extracting AddressUse addressUseResult, err := vm.RunString(` @@ -520,9 +770,59 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. } } // extracting Name - nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'RelatedPerson.name')[0]") + nameResult, err := vm.RunString(` + NameResult = window.fhirpath.evaluate(fhirResource, 'RelatedPerson.name') + NameProcessed = NameResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(NameProcessed) + `) if err == nil && nameResult.String() != "undefined" { - s.Name = nameResult.String() + s.Name = []byte(nameResult.String()) } // extracting Phone phoneResult, err := vm.RunString(` @@ -567,9 +867,59 @@ func (s *FhirRelatedPerson) PopulateAndExtractSearchParameters(resourceRaw json. s.Phone = []byte(phoneResult.String()) } // extracting Phonetic - phoneticResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Patient.name | Person.name | Practitioner.name | RelatedPerson.name')[0]") + phoneticResult, err := vm.RunString(` + PhoneticResult = window.fhirpath.evaluate(fhirResource, 'Patient.name | Person.name | Practitioner.name | RelatedPerson.name') + PhoneticProcessed = PhoneticResult.reduce((accumulator, currentValue) => { + if (typeof currentValue === 'string') { + //basic string + accumulator.push(currentValue) + } else if (currentValue.family || currentValue.given) { + //HumanName http://hl7.org/fhir/R4/datatypes.html#HumanName + var humanNameParts = [] + if (currentValue.prefix) { + humanNameParts = humanNameParts.concat(currentValue.prefix) + } + if (currentValue.given) { + humanNameParts = humanNameParts.concat(currentValue.given) + } + if (currentValue.family) { + humanNameParts.push(currentValue.family) + } + if (currentValue.suffix) { + humanNameParts = humanNameParts.concat(currentValue.suffix) + } + accumulator.push(humanNameParts.join(" ")) + } else if (currentValue.city || currentValue.state || currentValue.country || currentValue.postalCode) { + //Address http://hl7.org/fhir/R4/datatypes.html#Address + var addressParts = [] + if (currentValue.line) { + addressParts = addressParts.concat(currentValue.line) + } + if (currentValue.city) { + addressParts.push(currentValue.city) + } + if (currentValue.state) { + addressParts.push(currentValue.state) + } + if (currentValue.postalCode) { + addressParts.push(currentValue.postalCode) + } + if (currentValue.country) { + addressParts.push(currentValue.country) + } + accumulator.push(addressParts.join(" ")) + } else { + //string, boolean + accumulator.push(currentValue) + } + return accumulator + }, []) + + + JSON.stringify(PhoneticProcessed) + `) if err == nil && phoneticResult.String() != "undefined" { - s.Phonetic = phoneticResult.String() + s.Phonetic = []byte(phoneticResult.String()) } // extracting Profile profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))") diff --git a/backend/pkg/models/database/fhir_schedule.go b/backend/pkg/models/database/fhir_schedule.go index 2cfcdf451..c03b2014b 100644 --- a/backend/pkg/models/database/fhir_schedule.go +++ b/backend/pkg/models/database/fhir_schedule.go @@ -52,7 +52,7 @@ type FhirSchedule struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_service_request.go b/backend/pkg/models/database/fhir_service_request.go index e40a1c3b4..82db645cb 100644 --- a/backend/pkg/models/database/fhir_service_request.go +++ b/backend/pkg/models/database/fhir_service_request.go @@ -156,7 +156,7 @@ type FhirServiceRequest struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_slot.go b/backend/pkg/models/database/fhir_slot.go index 3ce506d3c..b5225cf1a 100644 --- a/backend/pkg/models/database/fhir_slot.go +++ b/backend/pkg/models/database/fhir_slot.go @@ -55,7 +55,7 @@ type FhirSlot struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_specimen.go b/backend/pkg/models/database/fhir_specimen.go index 5ba41eb57..e2cebc8da 100644 --- a/backend/pkg/models/database/fhir_specimen.go +++ b/backend/pkg/models/database/fhir_specimen.go @@ -61,7 +61,7 @@ type FhirSpecimen struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"` diff --git a/backend/pkg/models/database/fhir_vision_prescription.go b/backend/pkg/models/database/fhir_vision_prescription.go index 62a001d3e..e3e1acc78 100644 --- a/backend/pkg/models/database/fhir_vision_prescription.go +++ b/backend/pkg/models/database/fhir_vision_prescription.go @@ -94,7 +94,7 @@ type FhirVisionPrescription struct { Tag datatypes.JSON `gorm:"column:tag;type:text;serializer:json" json:"tag,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string - Text string `gorm:"column:text;type:text" json:"text,omitempty"` + Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // A resource type filter // https://hl7.org/fhir/r4/search.html#special Type datatypes.JSON `gorm:"column:type;type:text;serializer:json" json:"type,omitempty"`