643 lines
23 KiB
Go
643 lines
23 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 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 string `gorm:"column:description;type:text" 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 string `gorm:"column:name;type:text" 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"`
|
|
// Identifies where the resource comes from
|
|
// https://hl7.org/fhir/r4/search.html#uri
|
|
SourceUri string `gorm:"column:sourceUri;type:text" json:"sourceUri,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 string `gorm:"column:text;type:text" 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"`
|
|
// 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",
|
|
"identifier": "token",
|
|
"jurisdiction": "token",
|
|
"language": "token",
|
|
"lastUpdated": "date",
|
|
"name": "string",
|
|
"profile": "reference",
|
|
"publisher": "string",
|
|
"sourceUri": "uri",
|
|
"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
|
|
}, [])
|
|
|
|
|
|
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
|
|
}, [])
|
|
|
|
|
|
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
|
|
}, [])
|
|
|
|
|
|
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
|
|
}
|
|
}
|
|
// 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("window.fhirpath.evaluate(fhirResource, 'Questionnaire.description')[0]")
|
|
if err == nil && descriptionResult.String() != "undefined" {
|
|
s.Description = 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
|
|
}
|
|
}
|
|
// 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
|
|
}, [])
|
|
|
|
|
|
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
|
|
}, [])
|
|
|
|
|
|
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, '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, 'Questionnaire.name')[0]")
|
|
if err == nil && nameResult.String() != "undefined" {
|
|
s.Name = nameResult.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 Publisher
|
|
publisherResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.publisher')[0]")
|
|
if err == nil && publisherResult.String() != "undefined" {
|
|
s.Publisher = publisherResult.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, '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
|
|
}, [])
|
|
|
|
|
|
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
|
|
}, [])
|
|
|
|
|
|
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, '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())
|
|
}
|
|
// extracting Title
|
|
titleResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Questionnaire.title')[0]")
|
|
if err == nil && titleResult.String() != "undefined" {
|
|
s.Title = 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
|
|
}, [])
|
|
|
|
|
|
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"
|
|
}
|