Skip to content

Commit

Permalink
make sure we can handle HumanName and Address type objects (convert t…
Browse files Browse the repository at this point in the history
…o string).
  • Loading branch information
AnalogJ committed Aug 1, 2023
1 parent 6433de8 commit 0517f9b
Show file tree
Hide file tree
Showing 56 changed files with 4,133 additions and 283 deletions.
58 changes: 54 additions & 4 deletions backend/pkg/models/database/fhir_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down Expand Up @@ -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'))")
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/models/database/fhir_adverse_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/models/database/fhir_allergy_intolerance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/models/database/fhir_appointment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/models/database/fhir_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/models/database/fhir_care_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/models/database/fhir_care_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/models/database/fhir_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
58 changes: 54 additions & 4 deletions backend/pkg/models/database/fhir_claim_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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(`
Expand Down
58 changes: 54 additions & 4 deletions backend/pkg/models/database/fhir_composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 0517f9b

Please sign in to comment.