adding new fhir resources.
This commit is contained in:
parent
7ae0546cf0
commit
f0fa05c297
|
@ -0,0 +1,318 @@
|
|||
// 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 FhirAccount struct {
|
||||
models.ResourceBase
|
||||
// Account number
|
||||
// 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"`
|
||||
// Human-readable label
|
||||
// https://hl7.org/fhir/r4/search.html#string
|
||||
Name string `gorm:"column:name;type:text" 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"`
|
||||
// Transaction window
|
||||
// https://hl7.org/fhir/r4/search.html#date
|
||||
Period time.Time `gorm:"column:period;type:datetime" json:"period,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"`
|
||||
// active | inactive | entered-in-error | on-hold | unknown
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
Status datatypes.JSON `gorm:"column:status;type:text;serializer:json" json:"status,omitempty"`
|
||||
// The entity that caused the expenses
|
||||
// https://hl7.org/fhir/r4/search.html#reference
|
||||
Subject datatypes.JSON `gorm:"column:subject;type:text;serializer:json" json:"subject,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 *FhirAccount) GetSearchParameters() map[string]string {
|
||||
searchParameters := map[string]string{
|
||||
"identifier": "token",
|
||||
"language": "token",
|
||||
"lastUpdated": "date",
|
||||
"name": "string",
|
||||
"owner": "reference",
|
||||
"period": "date",
|
||||
"profile": "reference",
|
||||
"sourceUri": "uri",
|
||||
"status": "token",
|
||||
"subject": "reference",
|
||||
"tag": "token",
|
||||
"text": "string",
|
||||
"type": "special",
|
||||
}
|
||||
return searchParameters
|
||||
}
|
||||
func (s *FhirAccount) 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 Identifier
|
||||
identifierResult, err := vm.RunString(`
|
||||
IdentifierResult = window.fhirpath.evaluate(fhirResource, 'Account.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, 'Account.name')[0]")
|
||||
if err == nil && nameResult.String() != "undefined" {
|
||||
s.Name = nameResult.String()
|
||||
}
|
||||
// extracting Owner
|
||||
ownerResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Account.owner'))")
|
||||
if err == nil && ownerResult.String() != "undefined" {
|
||||
s.Owner = []byte(ownerResult.String())
|
||||
}
|
||||
// extracting Period
|
||||
periodResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Account.servicePeriod')[0]")
|
||||
if err == nil && periodResult.String() != "undefined" {
|
||||
t, err := time.Parse(time.RFC3339, periodResult.String())
|
||||
if err == nil {
|
||||
s.Period = t
|
||||
}
|
||||
}
|
||||
// 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, 'Account.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 Subject
|
||||
subjectResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Account.subject'))")
|
||||
if err == nil && subjectResult.String() != "undefined" {
|
||||
s.Subject = []byte(subjectResult.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 *FhirAccount) TableName() string {
|
||||
return "fhir_account"
|
||||
}
|
|
@ -0,0 +1,631 @@
|
|||
// 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 FhirConsent struct {
|
||||
models.ResourceBase
|
||||
// Actions controlled by this rule
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
Action datatypes.JSON `gorm:"column:action;type:text;serializer:json" json:"action,omitempty"`
|
||||
// Resource for the actor (or group, by role)
|
||||
// https://hl7.org/fhir/r4/search.html#reference
|
||||
Actor datatypes.JSON `gorm:"column:actor;type:text;serializer:json" json:"actor,omitempty"`
|
||||
// Classification of the consent statement - for indexing/retrieval
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
Category datatypes.JSON `gorm:"column:category;type:text;serializer:json" json:"category,omitempty"`
|
||||
// Who is agreeing to the policy and rules
|
||||
// https://hl7.org/fhir/r4/search.html#reference
|
||||
Consentor datatypes.JSON `gorm:"column:consentor;type:text;serializer:json" json:"consentor,omitempty"`
|
||||
// The actual data reference
|
||||
// https://hl7.org/fhir/r4/search.html#reference
|
||||
Data datatypes.JSON `gorm:"column:data;type:text;serializer:json" json:"data,omitempty"`
|
||||
/*
|
||||
Multiple Resources:
|
||||
|
||||
* [AllergyIntolerance](allergyintolerance.html): Date first version of the resource instance was recorded
|
||||
* [CarePlan](careplan.html): Time period plan covers
|
||||
* [CareTeam](careteam.html): Time period team covers
|
||||
* [ClinicalImpression](clinicalimpression.html): When the assessment was documented
|
||||
* [Composition](composition.html): Composition editing time
|
||||
* [Consent](consent.html): When this Consent was created or indexed
|
||||
* [DiagnosticReport](diagnosticreport.html): The clinically relevant time of the report
|
||||
* [Encounter](encounter.html): A date within the period the Encounter lasted
|
||||
* [EpisodeOfCare](episodeofcare.html): The provided date search value falls within the episode of care's period
|
||||
* [FamilyMemberHistory](familymemberhistory.html): When history was recorded or last updated
|
||||
* [Flag](flag.html): Time period when flag is active
|
||||
* [Immunization](immunization.html): Vaccination (non)-Administration Date
|
||||
* [List](list.html): When the list was prepared
|
||||
* [Observation](observation.html): Obtained date/time. If the obtained element is a period, a date that falls in the period
|
||||
* [Procedure](procedure.html): When the procedure was performed
|
||||
* [RiskAssessment](riskassessment.html): When was assessment made?
|
||||
* [SupplyRequest](supplyrequest.html): When the request was made
|
||||
*/
|
||||
// https://hl7.org/fhir/r4/search.html#date
|
||||
Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"`
|
||||
/*
|
||||
Multiple Resources:
|
||||
|
||||
* [AllergyIntolerance](allergyintolerance.html): External ids for this item
|
||||
* [CarePlan](careplan.html): External Ids for this plan
|
||||
* [CareTeam](careteam.html): External Ids for this team
|
||||
* [Composition](composition.html): Version-independent identifier for the Composition
|
||||
* [Condition](condition.html): A unique identifier of the condition record
|
||||
* [Consent](consent.html): Identifier for this record (external references)
|
||||
* [DetectedIssue](detectedissue.html): Unique id for the detected issue
|
||||
* [DeviceRequest](devicerequest.html): Business identifier for request/order
|
||||
* [DiagnosticReport](diagnosticreport.html): An identifier for the report
|
||||
* [DocumentManifest](documentmanifest.html): Unique Identifier for the set of documents
|
||||
* [DocumentReference](documentreference.html): Master Version Specific Identifier
|
||||
* [Encounter](encounter.html): Identifier(s) by which this encounter is known
|
||||
* [EpisodeOfCare](episodeofcare.html): Business Identifier(s) relevant for this EpisodeOfCare
|
||||
* [FamilyMemberHistory](familymemberhistory.html): A search by a record identifier
|
||||
* [Goal](goal.html): External Ids for this goal
|
||||
* [ImagingStudy](imagingstudy.html): Identifiers for the Study, such as DICOM Study Instance UID and Accession number
|
||||
* [Immunization](immunization.html): Business identifier
|
||||
* [List](list.html): Business identifier
|
||||
* [MedicationAdministration](medicationadministration.html): Return administrations with this external identifier
|
||||
* [MedicationDispense](medicationdispense.html): Returns dispenses with this external identifier
|
||||
* [MedicationRequest](medicationrequest.html): Return prescriptions with this external identifier
|
||||
* [MedicationStatement](medicationstatement.html): Return statements with this external identifier
|
||||
* [NutritionOrder](nutritionorder.html): Return nutrition orders with this external identifier
|
||||
* [Observation](observation.html): The unique id for a particular observation
|
||||
* [Procedure](procedure.html): A unique identifier for a procedure
|
||||
* [RiskAssessment](riskassessment.html): Unique identifier for the assessment
|
||||
* [ServiceRequest](servicerequest.html): Identifiers assigned to this order
|
||||
* [SupplyDelivery](supplydelivery.html): External identifier
|
||||
* [SupplyRequest](supplyrequest.html): Business Identifier for SupplyRequest
|
||||
* [VisionPrescription](visionprescription.html): Return prescriptions with this external 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"`
|
||||
// Custodian of the consent
|
||||
// https://hl7.org/fhir/r4/search.html#reference
|
||||
Organization datatypes.JSON `gorm:"column:organization;type:text;serializer:json" json:"organization,omitempty"`
|
||||
// Timeframe for this rule
|
||||
// https://hl7.org/fhir/r4/search.html#date
|
||||
Period time.Time `gorm:"column:period;type:datetime" json:"period,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"`
|
||||
// Context of activities covered by this rule
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
Purpose datatypes.JSON `gorm:"column:purpose;type:text;serializer:json" json:"purpose,omitempty"`
|
||||
// Which of the four areas this resource covers (extensible)
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
Scope datatypes.JSON `gorm:"column:scope;type:text;serializer:json" json:"scope,omitempty"`
|
||||
// Security Labels that define affected resources
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
SecurityLabel datatypes.JSON `gorm:"column:securityLabel;type:text;serializer:json" json:"securityLabel,omitempty"`
|
||||
// Search by reference to a Consent, DocumentReference, Contract or QuestionnaireResponse
|
||||
// https://hl7.org/fhir/r4/search.html#reference
|
||||
SourceReference datatypes.JSON `gorm:"column:sourceReference;type:text;serializer:json" json:"sourceReference,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"`
|
||||
// draft | proposed | active | rejected | inactive | entered-in-error
|
||||
// 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 *FhirConsent) GetSearchParameters() map[string]string {
|
||||
searchParameters := map[string]string{
|
||||
"action": "token",
|
||||
"actor": "reference",
|
||||
"category": "token",
|
||||
"consentor": "reference",
|
||||
"data": "reference",
|
||||
"date": "date",
|
||||
"identifier": "token",
|
||||
"language": "token",
|
||||
"lastUpdated": "date",
|
||||
"organization": "reference",
|
||||
"period": "date",
|
||||
"profile": "reference",
|
||||
"purpose": "token",
|
||||
"scope": "token",
|
||||
"securityLabel": "token",
|
||||
"sourceReference": "reference",
|
||||
"sourceUri": "uri",
|
||||
"status": "token",
|
||||
"tag": "token",
|
||||
"text": "string",
|
||||
"type": "special",
|
||||
}
|
||||
return searchParameters
|
||||
}
|
||||
func (s *FhirConsent) 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 Action
|
||||
actionResult, err := vm.RunString(`
|
||||
ActionResult = window.fhirpath.evaluate(fhirResource, 'Consent.provision.action')
|
||||
ActionProcessed = ActionResult.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(ActionProcessed)
|
||||
`)
|
||||
if err == nil && actionResult.String() != "undefined" {
|
||||
s.Action = []byte(actionResult.String())
|
||||
}
|
||||
// extracting Actor
|
||||
actorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.provision.actor.reference'))")
|
||||
if err == nil && actorResult.String() != "undefined" {
|
||||
s.Actor = []byte(actorResult.String())
|
||||
}
|
||||
// extracting Category
|
||||
categoryResult, err := vm.RunString(`
|
||||
CategoryResult = window.fhirpath.evaluate(fhirResource, 'Consent.category')
|
||||
CategoryProcessed = CategoryResult.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(CategoryProcessed)
|
||||
`)
|
||||
if err == nil && categoryResult.String() != "undefined" {
|
||||
s.Category = []byte(categoryResult.String())
|
||||
}
|
||||
// extracting Consentor
|
||||
consentorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.performer'))")
|
||||
if err == nil && consentorResult.String() != "undefined" {
|
||||
s.Consentor = []byte(consentorResult.String())
|
||||
}
|
||||
// extracting Data
|
||||
dataResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.provision.data.reference'))")
|
||||
if err == nil && dataResult.String() != "undefined" {
|
||||
s.Data = []byte(dataResult.String())
|
||||
}
|
||||
// extracting Date
|
||||
dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'AllergyIntolerance.recordedDate | CarePlan.period | CareTeam.period | ClinicalImpression.date | Composition.date | Consent.dateTime | DiagnosticReport.effective | Encounter.period | EpisodeOfCare.period | FamilyMemberHistory.date | Flag.period | (Immunization.occurrenceDateTime) | List.date | Observation.effective | Procedure.performed | (RiskAssessment.occurrenceDateTime) | SupplyRequest.authoredOn')[0]")
|
||||
if err == nil && dateResult.String() != "undefined" {
|
||||
t, err := time.Parse(time.RFC3339, dateResult.String())
|
||||
if err == nil {
|
||||
s.Date = t
|
||||
}
|
||||
}
|
||||
// extracting Identifier
|
||||
identifierResult, err := vm.RunString(`
|
||||
IdentifierResult = window.fhirpath.evaluate(fhirResource, 'AllergyIntolerance.identifier | CarePlan.identifier | CareTeam.identifier | Composition.identifier | Condition.identifier | Consent.identifier | DetectedIssue.identifier | DeviceRequest.identifier | DiagnosticReport.identifier | DocumentManifest.masterIdentifier | DocumentManifest.identifier | DocumentReference.masterIdentifier | DocumentReference.identifier | Encounter.identifier | EpisodeOfCare.identifier | FamilyMemberHistory.identifier | Goal.identifier | ImagingStudy.identifier | Immunization.identifier | List.identifier | MedicationAdministration.identifier | MedicationDispense.identifier | MedicationRequest.identifier | MedicationStatement.identifier | NutritionOrder.identifier | Observation.identifier | Procedure.identifier | RiskAssessment.identifier | ServiceRequest.identifier | SupplyDelivery.identifier | SupplyRequest.identifier | VisionPrescription.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 Organization
|
||||
organizationResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.organization'))")
|
||||
if err == nil && organizationResult.String() != "undefined" {
|
||||
s.Organization = []byte(organizationResult.String())
|
||||
}
|
||||
// extracting Period
|
||||
periodResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Consent.provision.period')[0]")
|
||||
if err == nil && periodResult.String() != "undefined" {
|
||||
t, err := time.Parse(time.RFC3339, periodResult.String())
|
||||
if err == nil {
|
||||
s.Period = t
|
||||
}
|
||||
}
|
||||
// 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 Purpose
|
||||
purposeResult, err := vm.RunString(`
|
||||
PurposeResult = window.fhirpath.evaluate(fhirResource, 'Consent.provision.purpose')
|
||||
PurposeProcessed = PurposeResult.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(PurposeProcessed)
|
||||
`)
|
||||
if err == nil && purposeResult.String() != "undefined" {
|
||||
s.Purpose = []byte(purposeResult.String())
|
||||
}
|
||||
// extracting Scope
|
||||
scopeResult, err := vm.RunString(`
|
||||
ScopeResult = window.fhirpath.evaluate(fhirResource, 'Consent.scope')
|
||||
ScopeProcessed = ScopeResult.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(ScopeProcessed)
|
||||
`)
|
||||
if err == nil && scopeResult.String() != "undefined" {
|
||||
s.Scope = []byte(scopeResult.String())
|
||||
}
|
||||
// extracting SecurityLabel
|
||||
securityLabelResult, err := vm.RunString(`
|
||||
SecurityLabelResult = window.fhirpath.evaluate(fhirResource, 'Consent.provision.securityLabel')
|
||||
SecurityLabelProcessed = SecurityLabelResult.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(SecurityLabelProcessed)
|
||||
`)
|
||||
if err == nil && securityLabelResult.String() != "undefined" {
|
||||
s.SecurityLabel = []byte(securityLabelResult.String())
|
||||
}
|
||||
// extracting SourceReference
|
||||
sourceReferenceResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Consent.source'))")
|
||||
if err == nil && sourceReferenceResult.String() != "undefined" {
|
||||
s.SourceReference = []byte(sourceReferenceResult.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, 'Consent.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 *FhirConsent) TableName() string {
|
||||
return "fhir_consent"
|
||||
}
|
|
@ -0,0 +1,438 @@
|
|||
// 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 FhirSchedule struct {
|
||||
models.ResourceBase
|
||||
// Is the schedule in active use
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
Active datatypes.JSON `gorm:"column:active;type:text;serializer:json" json:"active,omitempty"`
|
||||
// The individual(HealthcareService, Practitioner, Location, ...) to find a Schedule for
|
||||
// https://hl7.org/fhir/r4/search.html#reference
|
||||
Actor datatypes.JSON `gorm:"column:actor;type:text;serializer:json" json:"actor,omitempty"`
|
||||
// Search for Schedule resources that have a period that contains this date specified
|
||||
// https://hl7.org/fhir/r4/search.html#date
|
||||
Date time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"`
|
||||
// A Schedule 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"`
|
||||
// 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"`
|
||||
// High-level category
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
ServiceCategory datatypes.JSON `gorm:"column:serviceCategory;type:text;serializer:json" json:"serviceCategory,omitempty"`
|
||||
// The type of appointments that can be booked into associated slot(s)
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
ServiceType datatypes.JSON `gorm:"column:serviceType;type:text;serializer:json" json:"serviceType,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"`
|
||||
// Type of specialty needed
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
Specialty datatypes.JSON `gorm:"column:specialty;type:text;serializer:json" json:"specialty,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 *FhirSchedule) GetSearchParameters() map[string]string {
|
||||
searchParameters := map[string]string{
|
||||
"active": "token",
|
||||
"actor": "reference",
|
||||
"date": "date",
|
||||
"identifier": "token",
|
||||
"language": "token",
|
||||
"lastUpdated": "date",
|
||||
"profile": "reference",
|
||||
"serviceCategory": "token",
|
||||
"serviceType": "token",
|
||||
"sourceUri": "uri",
|
||||
"specialty": "token",
|
||||
"tag": "token",
|
||||
"text": "string",
|
||||
"type": "special",
|
||||
}
|
||||
return searchParameters
|
||||
}
|
||||
func (s *FhirSchedule) 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 Active
|
||||
activeResult, err := vm.RunString(`
|
||||
ActiveResult = window.fhirpath.evaluate(fhirResource, 'Schedule.active')
|
||||
ActiveProcessed = ActiveResult.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(ActiveProcessed)
|
||||
`)
|
||||
if err == nil && activeResult.String() != "undefined" {
|
||||
s.Active = []byte(activeResult.String())
|
||||
}
|
||||
// extracting Actor
|
||||
actorResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Schedule.actor'))")
|
||||
if err == nil && actorResult.String() != "undefined" {
|
||||
s.Actor = []byte(actorResult.String())
|
||||
}
|
||||
// extracting Date
|
||||
dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Schedule.planningHorizon')[0]")
|
||||
if err == nil && dateResult.String() != "undefined" {
|
||||
t, err := time.Parse(time.RFC3339, dateResult.String())
|
||||
if err == nil {
|
||||
s.Date = t
|
||||
}
|
||||
}
|
||||
// extracting Identifier
|
||||
identifierResult, err := vm.RunString(`
|
||||
IdentifierResult = window.fhirpath.evaluate(fhirResource, 'Schedule.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 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 ServiceCategory
|
||||
serviceCategoryResult, err := vm.RunString(`
|
||||
ServiceCategoryResult = window.fhirpath.evaluate(fhirResource, 'Schedule.serviceCategory')
|
||||
ServiceCategoryProcessed = ServiceCategoryResult.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(ServiceCategoryProcessed)
|
||||
`)
|
||||
if err == nil && serviceCategoryResult.String() != "undefined" {
|
||||
s.ServiceCategory = []byte(serviceCategoryResult.String())
|
||||
}
|
||||
// extracting ServiceType
|
||||
serviceTypeResult, err := vm.RunString(`
|
||||
ServiceTypeResult = window.fhirpath.evaluate(fhirResource, 'Schedule.serviceType')
|
||||
ServiceTypeProcessed = ServiceTypeResult.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(ServiceTypeProcessed)
|
||||
`)
|
||||
if err == nil && serviceTypeResult.String() != "undefined" {
|
||||
s.ServiceType = []byte(serviceTypeResult.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 Specialty
|
||||
specialtyResult, err := vm.RunString(`
|
||||
SpecialtyResult = window.fhirpath.evaluate(fhirResource, 'Schedule.specialty')
|
||||
SpecialtyProcessed = SpecialtyResult.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(SpecialtyProcessed)
|
||||
`)
|
||||
if err == nil && specialtyResult.String() != "undefined" {
|
||||
s.Specialty = []byte(specialtyResult.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 *FhirSchedule) TableName() string {
|
||||
return "fhir_schedule"
|
||||
}
|
|
@ -0,0 +1,484 @@
|
|||
// 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 FhirSlot struct {
|
||||
models.ResourceBase
|
||||
// The style of appointment or patient that may be booked in the slot (not service type)
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
AppointmentType datatypes.JSON `gorm:"column:appointmentType;type:text;serializer:json" json:"appointmentType,omitempty"`
|
||||
// A Slot 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"`
|
||||
// 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"`
|
||||
// The Schedule Resource that we are seeking a slot within
|
||||
// https://hl7.org/fhir/r4/search.html#reference
|
||||
Schedule datatypes.JSON `gorm:"column:schedule;type:text;serializer:json" json:"schedule,omitempty"`
|
||||
// A broad categorization of the service that is to be performed during this appointment
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
ServiceCategory datatypes.JSON `gorm:"column:serviceCategory;type:text;serializer:json" json:"serviceCategory,omitempty"`
|
||||
// The type of appointments that can be booked into the slot
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
ServiceType datatypes.JSON `gorm:"column:serviceType;type:text;serializer:json" json:"serviceType,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 specialty of a practitioner that would be required to perform the service requested in this appointment
|
||||
// https://hl7.org/fhir/r4/search.html#token
|
||||
Specialty datatypes.JSON `gorm:"column:specialty;type:text;serializer:json" json:"specialty,omitempty"`
|
||||
// Appointment date/time.
|
||||
// https://hl7.org/fhir/r4/search.html#date
|
||||
Start time.Time `gorm:"column:start;type:datetime" json:"start,omitempty"`
|
||||
// The free/busy status of the appointment
|
||||
// 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 *FhirSlot) GetSearchParameters() map[string]string {
|
||||
searchParameters := map[string]string{
|
||||
"appointmentType": "token",
|
||||
"identifier": "token",
|
||||
"language": "token",
|
||||
"lastUpdated": "date",
|
||||
"profile": "reference",
|
||||
"schedule": "reference",
|
||||
"serviceCategory": "token",
|
||||
"serviceType": "token",
|
||||
"sourceUri": "uri",
|
||||
"specialty": "token",
|
||||
"start": "date",
|
||||
"status": "token",
|
||||
"tag": "token",
|
||||
"text": "string",
|
||||
"type": "special",
|
||||
}
|
||||
return searchParameters
|
||||
}
|
||||
func (s *FhirSlot) 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 AppointmentType
|
||||
appointmentTypeResult, err := vm.RunString(`
|
||||
AppointmentTypeResult = window.fhirpath.evaluate(fhirResource, 'Slot.appointmentType')
|
||||
AppointmentTypeProcessed = AppointmentTypeResult.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(AppointmentTypeProcessed)
|
||||
`)
|
||||
if err == nil && appointmentTypeResult.String() != "undefined" {
|
||||
s.AppointmentType = []byte(appointmentTypeResult.String())
|
||||
}
|
||||
// extracting Identifier
|
||||
identifierResult, err := vm.RunString(`
|
||||
IdentifierResult = window.fhirpath.evaluate(fhirResource, 'Slot.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 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 Schedule
|
||||
scheduleResult, err := vm.RunString("JSON.stringify(window.fhirpath.evaluate(fhirResource, 'Slot.schedule'))")
|
||||
if err == nil && scheduleResult.String() != "undefined" {
|
||||
s.Schedule = []byte(scheduleResult.String())
|
||||
}
|
||||
// extracting ServiceCategory
|
||||
serviceCategoryResult, err := vm.RunString(`
|
||||
ServiceCategoryResult = window.fhirpath.evaluate(fhirResource, 'Slot.serviceCategory')
|
||||
ServiceCategoryProcessed = ServiceCategoryResult.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(ServiceCategoryProcessed)
|
||||
`)
|
||||
if err == nil && serviceCategoryResult.String() != "undefined" {
|
||||
s.ServiceCategory = []byte(serviceCategoryResult.String())
|
||||
}
|
||||
// extracting ServiceType
|
||||
serviceTypeResult, err := vm.RunString(`
|
||||
ServiceTypeResult = window.fhirpath.evaluate(fhirResource, 'Slot.serviceType')
|
||||
ServiceTypeProcessed = ServiceTypeResult.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(ServiceTypeProcessed)
|
||||
`)
|
||||
if err == nil && serviceTypeResult.String() != "undefined" {
|
||||
s.ServiceType = []byte(serviceTypeResult.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 Specialty
|
||||
specialtyResult, err := vm.RunString(`
|
||||
SpecialtyResult = window.fhirpath.evaluate(fhirResource, 'Slot.specialty')
|
||||
SpecialtyProcessed = SpecialtyResult.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(SpecialtyProcessed)
|
||||
`)
|
||||
if err == nil && specialtyResult.String() != "undefined" {
|
||||
s.Specialty = []byte(specialtyResult.String())
|
||||
}
|
||||
// extracting Start
|
||||
startResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'Slot.start')[0]")
|
||||
if err == nil && startResult.String() != "undefined" {
|
||||
t, err := time.Parse(time.RFC3339, startResult.String())
|
||||
if err == nil {
|
||||
s.Start = t
|
||||
}
|
||||
}
|
||||
// extracting Status
|
||||
statusResult, err := vm.RunString(`
|
||||
StatusResult = window.fhirpath.evaluate(fhirResource, 'Slot.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 *FhirSlot) TableName() string {
|
||||
return "fhir_slot"
|
||||
}
|
|
@ -450,6 +450,7 @@ func main() {
|
|||
//TODO: should we do this, or allow all resources instead of just USCore?
|
||||
//The dataabase would be full of empty data, but we'd be more flexible & future-proof.. supporting other countries, etc.
|
||||
var AllowedResources = []string{
|
||||
"Account",
|
||||
"AdverseEvent",
|
||||
"AllergyIntolerance",
|
||||
"Appointment",
|
||||
|
@ -460,6 +461,7 @@ var AllowedResources = []string{
|
|||
"ClaimResponse",
|
||||
"Composition",
|
||||
"Condition",
|
||||
"Consent",
|
||||
"Coverage",
|
||||
"CoverageEligibilityRequest",
|
||||
"CoverageEligibilityResponse",
|
||||
|
@ -491,14 +493,16 @@ var AllowedResources = []string{
|
|||
"OrganizationAffiliation",
|
||||
"Patient",
|
||||
"Person",
|
||||
"PractitionerRole",
|
||||
"Practitioner",
|
||||
"PractitionerRole",
|
||||
"Procedure",
|
||||
"Provenance",
|
||||
"Questionnaire",
|
||||
"QuestionnaireResponse",
|
||||
"RelatedPerson",
|
||||
"Schedule",
|
||||
"ServiceRequest",
|
||||
"Slot",
|
||||
"Specimen",
|
||||
"VisionPrescription",
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ var fhirPathJs string
|
|||
|
||||
// Generates all tables in the database associated with these models
|
||||
func Migrate(gormClient *gorm.DB) error {
|
||||
err := gormClient.AutoMigrate(&FhirAdverseEvent{}, &FhirAllergyIntolerance{}, &FhirAppointment{}, &FhirBinary{}, &FhirCarePlan{}, &FhirCareTeam{}, &FhirClaim{}, &FhirClaimResponse{}, &FhirComposition{}, &FhirCondition{}, &FhirCoverage{}, &FhirCoverageEligibilityRequest{}, &FhirCoverageEligibilityResponse{}, &FhirDevice{}, &FhirDeviceRequest{}, &FhirDiagnosticReport{}, &FhirDocumentManifest{}, &FhirDocumentReference{}, &FhirEncounter{}, &FhirEndpoint{}, &FhirEnrollmentRequest{}, &FhirEnrollmentResponse{}, &FhirExplanationOfBenefit{}, &FhirFamilyMemberHistory{}, &FhirGoal{}, &FhirImagingStudy{}, &FhirImmunization{}, &FhirInsurancePlan{}, &FhirLocation{}, &FhirMedia{}, &FhirMedication{}, &FhirMedicationAdministration{}, &FhirMedicationDispense{}, &FhirMedicationRequest{}, &FhirMedicationStatement{}, &FhirNutritionOrder{}, &FhirObservation{}, &FhirOrganization{}, &FhirOrganizationAffiliation{}, &FhirPatient{}, &FhirPerson{}, &FhirPractitionerRole{}, &FhirPractitioner{}, &FhirProcedure{}, &FhirProvenance{}, &FhirQuestionnaire{}, &FhirQuestionnaireResponse{}, &FhirRelatedPerson{}, &FhirServiceRequest{}, &FhirSpecimen{}, &FhirVisionPrescription{})
|
||||
err := gormClient.AutoMigrate(&FhirAccount{}, &FhirAdverseEvent{}, &FhirAllergyIntolerance{}, &FhirAppointment{}, &FhirBinary{}, &FhirCarePlan{}, &FhirCareTeam{}, &FhirClaim{}, &FhirClaimResponse{}, &FhirComposition{}, &FhirCondition{}, &FhirConsent{}, &FhirCoverage{}, &FhirCoverageEligibilityRequest{}, &FhirCoverageEligibilityResponse{}, &FhirDevice{}, &FhirDeviceRequest{}, &FhirDiagnosticReport{}, &FhirDocumentManifest{}, &FhirDocumentReference{}, &FhirEncounter{}, &FhirEndpoint{}, &FhirEnrollmentRequest{}, &FhirEnrollmentResponse{}, &FhirExplanationOfBenefit{}, &FhirFamilyMemberHistory{}, &FhirGoal{}, &FhirImagingStudy{}, &FhirImmunization{}, &FhirInsurancePlan{}, &FhirLocation{}, &FhirMedia{}, &FhirMedication{}, &FhirMedicationAdministration{}, &FhirMedicationDispense{}, &FhirMedicationRequest{}, &FhirMedicationStatement{}, &FhirNutritionOrder{}, &FhirObservation{}, &FhirOrganization{}, &FhirOrganizationAffiliation{}, &FhirPatient{}, &FhirPerson{}, &FhirPractitioner{}, &FhirPractitionerRole{}, &FhirProcedure{}, &FhirProvenance{}, &FhirQuestionnaire{}, &FhirQuestionnaireResponse{}, &FhirRelatedPerson{}, &FhirSchedule{}, &FhirServiceRequest{}, &FhirSlot{}, &FhirSpecimen{}, &FhirVisionPrescription{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ func Migrate(gormClient *gorm.DB) error {
|
|||
// Returns a map of all the resource names to their corresponding go struct
|
||||
func NewFhirResourceModelByType(resourceType string) (IFhirResourceModel, error) {
|
||||
switch resourceType {
|
||||
case "Account":
|
||||
return &FhirAccount{}, nil
|
||||
case "AdverseEvent":
|
||||
return &FhirAdverseEvent{}, nil
|
||||
case "AllergyIntolerance":
|
||||
|
@ -41,6 +43,8 @@ func NewFhirResourceModelByType(resourceType string) (IFhirResourceModel, error)
|
|||
return &FhirComposition{}, nil
|
||||
case "Condition":
|
||||
return &FhirCondition{}, nil
|
||||
case "Consent":
|
||||
return &FhirConsent{}, nil
|
||||
case "Coverage":
|
||||
return &FhirCoverage{}, nil
|
||||
case "CoverageEligibilityRequest":
|
||||
|
@ -103,10 +107,10 @@ func NewFhirResourceModelByType(resourceType string) (IFhirResourceModel, error)
|
|||
return &FhirPatient{}, nil
|
||||
case "Person":
|
||||
return &FhirPerson{}, nil
|
||||
case "PractitionerRole":
|
||||
return &FhirPractitionerRole{}, nil
|
||||
case "Practitioner":
|
||||
return &FhirPractitioner{}, nil
|
||||
case "PractitionerRole":
|
||||
return &FhirPractitionerRole{}, nil
|
||||
case "Procedure":
|
||||
return &FhirProcedure{}, nil
|
||||
case "Provenance":
|
||||
|
@ -117,8 +121,12 @@ func NewFhirResourceModelByType(resourceType string) (IFhirResourceModel, error)
|
|||
return &FhirQuestionnaireResponse{}, nil
|
||||
case "RelatedPerson":
|
||||
return &FhirRelatedPerson{}, nil
|
||||
case "Schedule":
|
||||
return &FhirSchedule{}, nil
|
||||
case "ServiceRequest":
|
||||
return &FhirServiceRequest{}, nil
|
||||
case "Slot":
|
||||
return &FhirSlot{}, nil
|
||||
case "Specimen":
|
||||
return &FhirSpecimen{}, nil
|
||||
case "VisionPrescription":
|
||||
|
@ -131,6 +139,8 @@ func NewFhirResourceModelByType(resourceType string) (IFhirResourceModel, error)
|
|||
// Returns the GORM table name for a FHIRResource when provided the FhirResource type string
|
||||
func GetTableNameByResourceType(resourceType string) (string, error) {
|
||||
switch resourceType {
|
||||
case "Account":
|
||||
return "fhir_account", nil
|
||||
case "AdverseEvent":
|
||||
return "fhir_adverse_event", nil
|
||||
case "AllergyIntolerance":
|
||||
|
@ -151,6 +161,8 @@ func GetTableNameByResourceType(resourceType string) (string, error) {
|
|||
return "fhir_composition", nil
|
||||
case "Condition":
|
||||
return "fhir_condition", nil
|
||||
case "Consent":
|
||||
return "fhir_consent", nil
|
||||
case "Coverage":
|
||||
return "fhir_coverage", nil
|
||||
case "CoverageEligibilityRequest":
|
||||
|
@ -213,10 +225,10 @@ func GetTableNameByResourceType(resourceType string) (string, error) {
|
|||
return "fhir_patient", nil
|
||||
case "Person":
|
||||
return "fhir_person", nil
|
||||
case "PractitionerRole":
|
||||
return "fhir_practitioner_role", nil
|
||||
case "Practitioner":
|
||||
return "fhir_practitioner", nil
|
||||
case "PractitionerRole":
|
||||
return "fhir_practitioner_role", nil
|
||||
case "Procedure":
|
||||
return "fhir_procedure", nil
|
||||
case "Provenance":
|
||||
|
@ -227,8 +239,12 @@ func GetTableNameByResourceType(resourceType string) (string, error) {
|
|||
return "fhir_questionnaire_response", nil
|
||||
case "RelatedPerson":
|
||||
return "fhir_related_person", nil
|
||||
case "Schedule":
|
||||
return "fhir_schedule", nil
|
||||
case "ServiceRequest":
|
||||
return "fhir_service_request", nil
|
||||
case "Slot":
|
||||
return "fhir_slot", nil
|
||||
case "Specimen":
|
||||
return "fhir_specimen", nil
|
||||
case "VisionPrescription":
|
||||
|
@ -240,5 +256,5 @@ func GetTableNameByResourceType(resourceType string) (string, error) {
|
|||
|
||||
// Returns a slice of all allowed resource types
|
||||
func GetAllowedResourceTypes() []string {
|
||||
return []string{"AdverseEvent", "AllergyIntolerance", "Appointment", "Binary", "CarePlan", "CareTeam", "Claim", "ClaimResponse", "Composition", "Condition", "Coverage", "CoverageEligibilityRequest", "CoverageEligibilityResponse", "Device", "DeviceRequest", "DiagnosticReport", "DocumentManifest", "DocumentReference", "Encounter", "Endpoint", "EnrollmentRequest", "EnrollmentResponse", "ExplanationOfBenefit", "FamilyMemberHistory", "Goal", "ImagingStudy", "Immunization", "InsurancePlan", "Location", "Media", "Medication", "MedicationAdministration", "MedicationDispense", "MedicationRequest", "MedicationStatement", "NutritionOrder", "Observation", "Organization", "OrganizationAffiliation", "Patient", "Person", "PractitionerRole", "Practitioner", "Procedure", "Provenance", "Questionnaire", "QuestionnaireResponse", "RelatedPerson", "ServiceRequest", "Specimen", "VisionPrescription"}
|
||||
return []string{"Account", "AdverseEvent", "AllergyIntolerance", "Appointment", "Binary", "CarePlan", "CareTeam", "Claim", "ClaimResponse", "Composition", "Condition", "Consent", "Coverage", "CoverageEligibilityRequest", "CoverageEligibilityResponse", "Device", "DeviceRequest", "DiagnosticReport", "DocumentManifest", "DocumentReference", "Encounter", "Endpoint", "EnrollmentRequest", "EnrollmentResponse", "ExplanationOfBenefit", "FamilyMemberHistory", "Goal", "ImagingStudy", "Immunization", "InsurancePlan", "Location", "Media", "Medication", "MedicationAdministration", "MedicationDispense", "MedicationRequest", "MedicationStatement", "NutritionOrder", "Observation", "Organization", "OrganizationAffiliation", "Patient", "Person", "Practitioner", "PractitionerRole", "Procedure", "Provenance", "Questionnaire", "QuestionnaireResponse", "RelatedPerson", "Schedule", "ServiceRequest", "Slot", "Specimen", "VisionPrescription"}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue