fasten-onprem/backend/pkg/models/database/fhir_questionnaire.go

930 lines
32 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/fasten-onprem/backend/pkg/models"
datatypes "gorm.io/datatypes"
"time"
)
type FhirQuestionnaire struct {
models.ResourceBase
// A code that corresponds to one of its items in the questionnaire
// https://hl7.org/fhir/r4/search.html#token
Code datatypes.JSON `gorm:"column:code;type:text;serializer:json" json:"code,omitempty"`
// A use context assigned to the questionnaire
// https://hl7.org/fhir/r4/search.html#token
Context datatypes.JSON `gorm:"column:context;type:text;serializer:json" json:"context,omitempty"`
// A quantity- or range-valued use context assigned to the questionnaire
// https://hl7.org/fhir/r4/search.html#quantity
ContextQuantity datatypes.JSON `gorm:"column:contextQuantity;type:text;serializer:json" json:"contextQuantity,omitempty"`
// A type of use context assigned to the questionnaire
// https://hl7.org/fhir/r4/search.html#token
ContextType datatypes.JSON `gorm:"column:contextType;type:text;serializer:json" json:"contextType,omitempty"`
// The questionnaire publication date
// https://hl7.org/fhir/r4/search.html#date
Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"`
// ElementDefinition - details for the item
// https://hl7.org/fhir/r4/search.html#uri
Definition string `gorm:"column:definition;type:text" json:"definition,omitempty"`
// The description of the questionnaire
// https://hl7.org/fhir/r4/search.html#string
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"`
// External identifier for the questionnaire
// https://hl7.org/fhir/r4/search.html#token
Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"`
// Intended jurisdiction for the questionnaire
// https://hl7.org/fhir/r4/search.html#token
Jurisdiction datatypes.JSON `gorm:"column:jurisdiction;type:text;serializer:json" json:"jurisdiction,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"`
// Computationally friendly name of the questionnaire
// https://hl7.org/fhir/r4/search.html#string
Name datatypes.JSON `gorm:"column:name;type:text;serializer:json" json:"name,omitempty"`
// 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 datatypes.JSON `gorm:"column:publisher;type:text;serializer:json" json:"publisher,omitempty"`
// The current status of the questionnaire
// https://hl7.org/fhir/r4/search.html#token
Status datatypes.JSON `gorm:"column:status;type:text;serializer:json" json:"status,omitempty"`
// Resource that can be subject of QuestionnaireResponse
// https://hl7.org/fhir/r4/search.html#token
SubjectType datatypes.JSON `gorm:"column:subjectType;type:text;serializer:json" json:"subjectType,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 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 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"`
// The uri that identifies the questionnaire
// https://hl7.org/fhir/r4/search.html#uri
Url string `gorm:"column:url;type:text" json:"url,omitempty"`
// The business version of the questionnaire
// https://hl7.org/fhir/r4/search.html#token
Version datatypes.JSON `gorm:"column:version;type:text;serializer:json" json:"version,omitempty"`
}
func (s *FhirQuestionnaire) GetSearchParameters() map[string]string {
searchParameters := map[string]string{
"code": "token",
"context": "token",
"contextQuantity": "quantity",
"contextType": "token",
"date": "date",
"definition": "uri",
"description": "string",
"effective": "date",
"id": "keyword",
"identifier": "token",
"jurisdiction": "token",
"language": "token",
"lastUpdated": "date",
"name": "string",
"profile": "reference",
"publisher": "string",
"sort_date": "date",
"source_id": "keyword",
"source_resource_id": "keyword",
"source_resource_type": "keyword",
"source_uri": "keyword",
"status": "token",
"subjectType": "token",
"tag": "token",
"text": "string",
"title": "string",
"type": "special",
"url": "uri",
"version": "token",
}
return searchParameters
}
func (s *FhirQuestionnaire) 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 Code
codeResult, err := vm.RunString(`
CodeResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.item.code')
CodeProcessed = CodeResult.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
}, [])
if(CodeProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(CodeProcessed)
}
`)
if err == nil && codeResult.String() != "undefined" {
s.Code = []byte(codeResult.String())
}
// extracting Context
contextResult, err := vm.RunString(`
ContextResult = window.fhirpath.evaluate(fhirResource, '(Questionnaire.useContext.valueCodeableConcept)')
ContextProcessed = ContextResult.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
}, [])
if(ContextProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(ContextProcessed)
}
`)
if err == nil && contextResult.String() != "undefined" {
s.Context = []byte(contextResult.String())
}
// extracting ContextQuantity
contextQuantityResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, '(Questionnaire.useContext.valueQuantity) | (Questionnaire.useContext.valueRange)'))")
if err == nil && contextQuantityResult.String() != "undefined" {
s.ContextQuantity = []byte(contextQuantityResult.String())
}
// extracting ContextType
contextTypeResult, err := vm.RunString(`
ContextTypeResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.useContext.code')
ContextTypeProcessed = ContextTypeResult.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
}, [])
if(ContextTypeProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(ContextTypeProcessed)
}
`)
if err == nil && contextTypeResult.String() != "undefined" {
s.ContextType = []byte(contextTypeResult.String())
}
// extracting Date
dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.date')[0]")
if err == nil && dateResult.String() != "undefined" {
t, err := time.Parse(time.RFC3339, dateResult.String())
if err == nil {
s.Date = &t
} else if err != nil {
d, err := time.Parse("2006-01-02", dateResult.String())
if err == nil {
s.Date = &d
}
}
}
// extracting Definition
definitionResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.item.definition')[0]")
if err == nil && definitionResult.String() != "undefined" {
s.Definition = definitionResult.String()
}
// extracting Description
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
}, [])
if(DescriptionProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(DescriptionProcessed)
}
`)
if err == nil && descriptionResult.String() != "undefined" {
s.Description = []byte(descriptionResult.String())
}
// extracting Effective
effectiveResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.effectivePeriod')[0]")
if err == nil && effectiveResult.String() != "undefined" {
t, err := time.Parse(time.RFC3339, effectiveResult.String())
if err == nil {
s.Effective = &t
} else if err != nil {
d, err := time.Parse("2006-01-02", effectiveResult.String())
if err == nil {
s.Effective = &d
}
}
}
// extracting Identifier
identifierResult, err := vm.RunString(`
IdentifierResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.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
}, [])
if(IdentifierProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(IdentifierProcessed)
}
`)
if err == nil && identifierResult.String() != "undefined" {
s.Identifier = []byte(identifierResult.String())
}
// extracting Jurisdiction
jurisdictionResult, err := vm.RunString(`
JurisdictionResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.jurisdiction')
JurisdictionProcessed = JurisdictionResult.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
}, [])
if(JurisdictionProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(JurisdictionProcessed)
}
`)
if err == nil && jurisdictionResult.String() != "undefined" {
s.Jurisdiction = []byte(jurisdictionResult.String())
}
// extracting Language
languageResult, err := vm.RunString(`
LanguageResult = window.fhirpath.evaluate(fhirResource, '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
}, [])
if(LanguageProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(LanguageProcessed)
}
`)
if err == nil && languageResult.String() != "undefined" {
s.Language = []byte(languageResult.String())
}
// extracting LastUpdated
lastUpdatedResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'meta.lastUpdated')[0]")
if err == nil && lastUpdatedResult.String() != "undefined" {
t, err := time.Parse(time.RFC3339, lastUpdatedResult.String())
if err == nil {
s.LastUpdated = &t
} else if err != nil {
d, err := time.Parse("2006-01-02", lastUpdatedResult.String())
if err == nil {
s.LastUpdated = &d
}
}
}
// extracting Name
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
}, [])
if(NameProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(NameProcessed)
}
`)
if err == nil && nameResult.String() != "undefined" {
s.Name = []byte(nameResult.String())
}
// extracting Profile
profileResult, err := vm.RunString(`
ProfileResult = window.fhirpath.evaluate(fhirResource, 'meta.profile')
if(ProfileResult.length == 0) {
"undefined"
}
else {
JSON.stringify(ProfileResult)
}
`)
if err == nil && profileResult.String() != "undefined" {
s.Profile = []byte(profileResult.String())
}
// extracting Publisher
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
}, [])
if(PublisherProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(PublisherProcessed)
}
`)
if err == nil && publisherResult.String() != "undefined" {
s.Publisher = []byte(publisherResult.String())
}
// extracting Status
statusResult, err := vm.RunString(`
StatusResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.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
}, [])
if(StatusProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(StatusProcessed)
}
`)
if err == nil && statusResult.String() != "undefined" {
s.Status = []byte(statusResult.String())
}
// extracting SubjectType
subjectTypeResult, err := vm.RunString(`
SubjectTypeResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.subjectType')
SubjectTypeProcessed = SubjectTypeResult.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
}, [])
if(SubjectTypeProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(SubjectTypeProcessed)
}
`)
if err == nil && subjectTypeResult.String() != "undefined" {
s.SubjectType = []byte(subjectTypeResult.String())
}
// extracting Tag
tagResult, err := vm.RunString(`
TagResult = window.fhirpath.evaluate(fhirResource, '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
}, [])
if(TagProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(TagProcessed)
}
`)
if err == nil && tagResult.String() != "undefined" {
s.Tag = []byte(tagResult.String())
}
// extracting Title
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
}, [])
if(TitleProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(TitleProcessed)
}
`)
if err == nil && titleResult.String() != "undefined" {
s.Title = []byte(titleResult.String())
}
// extracting Url
urlResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.url')[0]")
if err == nil && urlResult.String() != "undefined" {
s.Url = urlResult.String()
}
// extracting Version
versionResult, err := vm.RunString(`
VersionResult = window.fhirpath.evaluate(fhirResource, 'Questionnaire.version')
VersionProcessed = VersionResult.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
}, [])
if(VersionProcessed.length == 0) {
"undefined"
}
else {
JSON.stringify(VersionProcessed)
}
`)
if err == nil && versionResult.String() != "undefined" {
s.Version = []byte(versionResult.String())
}
return nil
}
// TableName overrides the table name from fhir_observations (pluralized) to `fhir_observation`. https://gorm.io/docs/conventions.html#TableName
func (s *FhirQuestionnaire) TableName() string {
return "fhir_questionnaire"
}