416 lines
16 KiB
Go
416 lines
16 KiB
Go
// THIS FILE IS GENERATED BY https://github.com/fastenhealth/fasten-onprem/blob/main/backend/pkg/models/database/generate.go
|
|
// PLEASE DO NOT EDIT BY HAND
|
|
|
|
package database
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
goja "github.com/dop251/goja"
|
|
models "github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
|
datatypes "gorm.io/datatypes"
|
|
"time"
|
|
)
|
|
|
|
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"`
|
|
// A city specified in an address
|
|
// https://hl7.org/fhir/r4/search.html#string
|
|
AddressCity string `gorm:"column:addressCity;type:text" 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"`
|
|
// 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"`
|
|
// A state specified in an address
|
|
// https://hl7.org/fhir/r4/search.html#string
|
|
AddressState string `gorm:"column:addressState;type:text" 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"`
|
|
// Product administrator
|
|
// https://hl7.org/fhir/r4/search.html#reference
|
|
AdministeredBy datatypes.JSON `gorm:"column:administeredBy;type:text;serializer:json" json:"administeredBy,omitempty"`
|
|
// Technical endpoint
|
|
// https://hl7.org/fhir/r4/search.html#reference
|
|
Endpoint datatypes.JSON `gorm:"column:endpoint;type:text;serializer:json" json:"endpoint,omitempty"`
|
|
// Any identifier for the organization (not the accreditation issuer's identifier)
|
|
// https://hl7.org/fhir/r4/search.html#token
|
|
Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"`
|
|
// Language of the resource content
|
|
// https://hl7.org/fhir/r4/search.html#token
|
|
Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"`
|
|
// When the resource version last changed
|
|
// https://hl7.org/fhir/r4/search.html#date
|
|
LastUpdated time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"`
|
|
// 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"`
|
|
// 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"`
|
|
// 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"`
|
|
// Identifies where the resource comes from
|
|
// https://hl7.org/fhir/r4/search.html#uri
|
|
SourceUri string `gorm:"column:sourceUri;type:text" json:"sourceUri,omitempty"`
|
|
// Is the Organization record active
|
|
// https://hl7.org/fhir/r4/search.html#token
|
|
Status datatypes.JSON `gorm:"column:status;type:text;serializer:json" json:"status,omitempty"`
|
|
// Tags applied to this resource
|
|
// https://hl7.org/fhir/r4/search.html#token
|
|
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"`
|
|
// 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"`
|
|
}
|
|
|
|
func (s *FhirInsurancePlan) GetSearchParameters() map[string]string {
|
|
searchParameters := map[string]string{
|
|
"address": "string",
|
|
"addressCity": "string",
|
|
"addressCountry": "string",
|
|
"addressPostalcode": "string",
|
|
"addressState": "string",
|
|
"addressUse": "token",
|
|
"administeredBy": "reference",
|
|
"endpoint": "reference",
|
|
"identifier": "token",
|
|
"language": "token",
|
|
"lastUpdated": "date",
|
|
"name": "string",
|
|
"ownedBy": "reference",
|
|
"phonetic": "string",
|
|
"profile": "reference",
|
|
"sourceUri": "uri",
|
|
"status": "token",
|
|
"tag": "token",
|
|
"text": "string",
|
|
"type": "special",
|
|
}
|
|
return searchParameters
|
|
}
|
|
func (s *FhirInsurancePlan) PopulateAndExtractSearchParameters(resourceRaw json.RawMessage) error {
|
|
s.ResourceRaw = datatypes.JSON(resourceRaw)
|
|
// unmarshal the raw resource (bytes) into a map
|
|
var resourceRawMap map[string]interface{}
|
|
err := json.Unmarshal(resourceRaw, &resourceRawMap)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(fhirPathJs) == 0 {
|
|
return fmt.Errorf("fhirPathJs script is empty")
|
|
}
|
|
vm := goja.New()
|
|
// setup the global window object
|
|
vm.Set("window", vm.NewObject())
|
|
// set the global FHIR Resource object
|
|
vm.Set("fhirResource", resourceRawMap)
|
|
// compile the fhirpath library
|
|
fhirPathJsProgram, err := goja.Compile("fhirpath.min.js", fhirPathJs, true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// add the fhirpath library in the goja vm
|
|
_, err = vm.RunProgram(fhirPathJsProgram)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// execute the fhirpath expression for each search parameter
|
|
// extracting Address
|
|
addressResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address')[0]")
|
|
if err == nil && addressResult.String() != "undefined" {
|
|
s.Address = addressResult.String()
|
|
}
|
|
// extracting AddressCity
|
|
addressCityResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.city')[0]")
|
|
if err == nil && addressCityResult.String() != "undefined" {
|
|
s.AddressCity = addressCityResult.String()
|
|
}
|
|
// extracting AddressCountry
|
|
addressCountryResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.country')[0]")
|
|
if err == nil && addressCountryResult.String() != "undefined" {
|
|
s.AddressCountry = addressCountryResult.String()
|
|
}
|
|
// extracting AddressPostalcode
|
|
addressPostalcodeResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.postalCode')[0]")
|
|
if err == nil && addressPostalcodeResult.String() != "undefined" {
|
|
s.AddressPostalcode = addressPostalcodeResult.String()
|
|
}
|
|
// extracting AddressState
|
|
addressStateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.state')[0]")
|
|
if err == nil && addressStateResult.String() != "undefined" {
|
|
s.AddressState = addressStateResult.String()
|
|
}
|
|
// extracting AddressUse
|
|
addressUseResult, err := vm.RunString(`
|
|
AddressUseResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.contact.address.use')
|
|
AddressUseProcessed = AddressUseResult.reduce((accumulator, currentValue) => {
|
|
if (currentValue.coding) {
|
|
//CodeableConcept
|
|
currentValue.coding.map((coding) => {
|
|
accumulator.push({
|
|
"code": coding.code,
|
|
"system": coding.system,
|
|
"text": currentValue.text
|
|
})
|
|
})
|
|
} else if (currentValue.value) {
|
|
//ContactPoint, Identifier
|
|
accumulator.push({
|
|
"code": currentValue.value,
|
|
"system": currentValue.system,
|
|
"text": currentValue.type?.text
|
|
})
|
|
} else if (currentValue.code) {
|
|
//Coding
|
|
accumulator.push({
|
|
"code": currentValue.code,
|
|
"system": currentValue.system,
|
|
"text": currentValue.display
|
|
})
|
|
} else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) {
|
|
//string, boolean
|
|
accumulator.push({
|
|
"code": currentValue,
|
|
})
|
|
}
|
|
return accumulator
|
|
}, [])
|
|
|
|
|
|
JSON.stringify(AddressUseProcessed)
|
|
`)
|
|
if err == nil && addressUseResult.String() != "undefined" {
|
|
s.AddressUse = []byte(addressUseResult.String())
|
|
}
|
|
// extracting AdministeredBy
|
|
administeredByResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'InsurancePlan.administeredBy'))")
|
|
if err == nil && administeredByResult.String() != "undefined" {
|
|
s.AdministeredBy = []byte(administeredByResult.String())
|
|
}
|
|
// extracting Endpoint
|
|
endpointResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'InsurancePlan.endpoint'))")
|
|
if err == nil && endpointResult.String() != "undefined" {
|
|
s.Endpoint = []byte(endpointResult.String())
|
|
}
|
|
// extracting Identifier
|
|
identifierResult, err := vm.RunString(`
|
|
IdentifierResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.identifier')
|
|
IdentifierProcessed = IdentifierResult.reduce((accumulator, currentValue) => {
|
|
if (currentValue.coding) {
|
|
//CodeableConcept
|
|
currentValue.coding.map((coding) => {
|
|
accumulator.push({
|
|
"code": coding.code,
|
|
"system": coding.system,
|
|
"text": currentValue.text
|
|
})
|
|
})
|
|
} else if (currentValue.value) {
|
|
//ContactPoint, Identifier
|
|
accumulator.push({
|
|
"code": currentValue.value,
|
|
"system": currentValue.system,
|
|
"text": currentValue.type?.text
|
|
})
|
|
} else if (currentValue.code) {
|
|
//Coding
|
|
accumulator.push({
|
|
"code": currentValue.code,
|
|
"system": currentValue.system,
|
|
"text": currentValue.display
|
|
})
|
|
} else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) {
|
|
//string, boolean
|
|
accumulator.push({
|
|
"code": currentValue,
|
|
})
|
|
}
|
|
return accumulator
|
|
}, [])
|
|
|
|
|
|
JSON.stringify(IdentifierProcessed)
|
|
`)
|
|
if err == nil && identifierResult.String() != "undefined" {
|
|
s.Identifier = []byte(identifierResult.String())
|
|
}
|
|
// extracting Language
|
|
languageResult, err := vm.RunString(`
|
|
LanguageResult = window.fhirpath.evaluate(fhirResource, 'Resource.language')
|
|
LanguageProcessed = LanguageResult.reduce((accumulator, currentValue) => {
|
|
if (currentValue.coding) {
|
|
//CodeableConcept
|
|
currentValue.coding.map((coding) => {
|
|
accumulator.push({
|
|
"code": coding.code,
|
|
"system": coding.system,
|
|
"text": currentValue.text
|
|
})
|
|
})
|
|
} else if (currentValue.value) {
|
|
//ContactPoint, Identifier
|
|
accumulator.push({
|
|
"code": currentValue.value,
|
|
"system": currentValue.system,
|
|
"text": currentValue.type?.text
|
|
})
|
|
} else if (currentValue.code) {
|
|
//Coding
|
|
accumulator.push({
|
|
"code": currentValue.code,
|
|
"system": currentValue.system,
|
|
"text": currentValue.display
|
|
})
|
|
} else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) {
|
|
//string, boolean
|
|
accumulator.push({
|
|
"code": currentValue,
|
|
})
|
|
}
|
|
return accumulator
|
|
}, [])
|
|
|
|
|
|
JSON.stringify(LanguageProcessed)
|
|
`)
|
|
if err == nil && languageResult.String() != "undefined" {
|
|
s.Language = []byte(languageResult.String())
|
|
}
|
|
// extracting LastUpdated
|
|
lastUpdatedResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.lastUpdated')[0]")
|
|
if err == nil && lastUpdatedResult.String() != "undefined" {
|
|
t, err := time.Parse(time.RFC3339, lastUpdatedResult.String())
|
|
if err == nil {
|
|
s.LastUpdated = t
|
|
}
|
|
}
|
|
// extracting Name
|
|
nameResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'name | alias')[0]")
|
|
if err == nil && nameResult.String() != "undefined" {
|
|
s.Name = nameResult.String()
|
|
}
|
|
// extracting OwnedBy
|
|
ownedByResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'InsurancePlan.ownedBy'))")
|
|
if err == nil && ownedByResult.String() != "undefined" {
|
|
s.OwnedBy = []byte(ownedByResult.String())
|
|
}
|
|
// extracting Phonetic
|
|
phoneticResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'InsurancePlan.name')[0]")
|
|
if err == nil && phoneticResult.String() != "undefined" {
|
|
s.Phonetic = phoneticResult.String()
|
|
}
|
|
// extracting Profile
|
|
profileResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Resource.meta.profile'))")
|
|
if err == nil && profileResult.String() != "undefined" {
|
|
s.Profile = []byte(profileResult.String())
|
|
}
|
|
// extracting SourceUri
|
|
sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Resource.meta.source')[0]")
|
|
if err == nil && sourceUriResult.String() != "undefined" {
|
|
s.SourceUri = sourceUriResult.String()
|
|
}
|
|
// extracting Status
|
|
statusResult, err := vm.RunString(`
|
|
StatusResult = window.fhirpath.evaluate(fhirResource, 'InsurancePlan.status')
|
|
StatusProcessed = StatusResult.reduce((accumulator, currentValue) => {
|
|
if (currentValue.coding) {
|
|
//CodeableConcept
|
|
currentValue.coding.map((coding) => {
|
|
accumulator.push({
|
|
"code": coding.code,
|
|
"system": coding.system,
|
|
"text": currentValue.text
|
|
})
|
|
})
|
|
} else if (currentValue.value) {
|
|
//ContactPoint, Identifier
|
|
accumulator.push({
|
|
"code": currentValue.value,
|
|
"system": currentValue.system,
|
|
"text": currentValue.type?.text
|
|
})
|
|
} else if (currentValue.code) {
|
|
//Coding
|
|
accumulator.push({
|
|
"code": currentValue.code,
|
|
"system": currentValue.system,
|
|
"text": currentValue.display
|
|
})
|
|
} else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) {
|
|
//string, boolean
|
|
accumulator.push({
|
|
"code": currentValue,
|
|
})
|
|
}
|
|
return accumulator
|
|
}, [])
|
|
|
|
|
|
JSON.stringify(StatusProcessed)
|
|
`)
|
|
if err == nil && statusResult.String() != "undefined" {
|
|
s.Status = []byte(statusResult.String())
|
|
}
|
|
// extracting Tag
|
|
tagResult, err := vm.RunString(`
|
|
TagResult = window.fhirpath.evaluate(fhirResource, 'Resource.meta.tag')
|
|
TagProcessed = TagResult.reduce((accumulator, currentValue) => {
|
|
if (currentValue.coding) {
|
|
//CodeableConcept
|
|
currentValue.coding.map((coding) => {
|
|
accumulator.push({
|
|
"code": coding.code,
|
|
"system": coding.system,
|
|
"text": currentValue.text
|
|
})
|
|
})
|
|
} else if (currentValue.value) {
|
|
//ContactPoint, Identifier
|
|
accumulator.push({
|
|
"code": currentValue.value,
|
|
"system": currentValue.system,
|
|
"text": currentValue.type?.text
|
|
})
|
|
} else if (currentValue.code) {
|
|
//Coding
|
|
accumulator.push({
|
|
"code": currentValue.code,
|
|
"system": currentValue.system,
|
|
"text": currentValue.display
|
|
})
|
|
} else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) {
|
|
//string, boolean
|
|
accumulator.push({
|
|
"code": currentValue,
|
|
})
|
|
}
|
|
return accumulator
|
|
}, [])
|
|
|
|
|
|
JSON.stringify(TagProcessed)
|
|
`)
|
|
if err == nil && tagResult.String() != "undefined" {
|
|
s.Tag = []byte(tagResult.String())
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// TableName overrides the table name from fhir_observations (pluralized) to `fhir_observation`. https://gorm.io/docs/conventions.html#TableName
|
|
func (s *FhirInsurancePlan) TableName() string {
|
|
return "fhir_insurance_plan"
|
|
}
|