// THIS FILE IS GENERATED BY https://github.com/fastenhealth/fasten-onprem/blob/main/backend/pkg/models/database/generate.go // PLEASE DO NOT EDIT BY HAND package database import ( "encoding/json" "fmt" goja "github.com/dop251/goja" models "github.com/fastenhealth/fasten-onprem/backend/pkg/models" datatypes "gorm.io/datatypes" "time" ) type FhirOrganizationAffiliation struct { models.ResourceBase // Whether this organization affiliation record is 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 period during which the participatingOrganization is affiliated with the primary organization // https://hl7.org/fhir/r4/search.html#date Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` // A value in an email contact // https://hl7.org/fhir/r4/search.html#token Email datatypes.JSON `gorm:"column:email;type:text;serializer:json" json:"email,omitempty"` // Technical endpoints providing access to services operated for this role // https://hl7.org/fhir/r4/search.html#reference Endpoint datatypes.JSON `gorm:"column:endpoint;type:text;serializer:json" json:"endpoint,omitempty"` // An organization affiliation's Identifier // https://hl7.org/fhir/r4/search.html#token Identifier datatypes.JSON `gorm:"column:identifier;type:text;serializer:json" json:"identifier,omitempty"` // Language of the resource content // https://hl7.org/fhir/r4/search.html#token Language datatypes.JSON `gorm:"column:language;type:text;serializer:json" json:"language,omitempty"` // When the resource version last changed // https://hl7.org/fhir/r4/search.html#date LastUpdated *time.Time `gorm:"column:lastUpdated;type:datetime" json:"lastUpdated,omitempty"` // The location(s) at which the role occurs // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` // Health insurance provider network in which the participatingOrganization provides the role's services (if defined) at the indicated locations (if defined) // https://hl7.org/fhir/r4/search.html#reference Network datatypes.JSON `gorm:"column:network;type:text;serializer:json" json:"network,omitempty"` // The organization that provides services to the primary organization // https://hl7.org/fhir/r4/search.html#reference ParticipatingOrganization datatypes.JSON `gorm:"column:participatingOrganization;type:text;serializer:json" json:"participatingOrganization,omitempty"` // A value in a phone contact // https://hl7.org/fhir/r4/search.html#token Phone datatypes.JSON `gorm:"column:phone;type:text;serializer:json" json:"phone,omitempty"` // The organization that receives the services from the participating organization // https://hl7.org/fhir/r4/search.html#reference PrimaryOrganization datatypes.JSON `gorm:"column:primaryOrganization;type:text;serializer:json" json:"primaryOrganization,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"` // Definition of the role the participatingOrganization plays // https://hl7.org/fhir/r4/search.html#token Role datatypes.JSON `gorm:"column:role;type:text;serializer:json" json:"role,omitempty"` // Healthcare services provided through the role // https://hl7.org/fhir/r4/search.html#reference Service datatypes.JSON `gorm:"column:service;type:text;serializer:json" json:"service,omitempty"` // Specific specialty of the participatingOrganization in the context of the role // 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"` // The value in any kind of contact // https://hl7.org/fhir/r4/search.html#token Telecom datatypes.JSON `gorm:"column:telecom;type:text;serializer:json" json:"telecom,omitempty"` // Text search against the narrative // https://hl7.org/fhir/r4/search.html#string Text datatypes.JSON `gorm:"column:text;type:text;serializer:json" json:"text,omitempty"` // 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 *FhirOrganizationAffiliation) GetSearchParameters() map[string]string { searchParameters := map[string]string{ "active": "token", "date": "date", "email": "token", "endpoint": "reference", "id": "keyword", "identifier": "token", "language": "token", "lastUpdated": "date", "location": "reference", "network": "reference", "participatingOrganization": "reference", "phone": "token", "primaryOrganization": "reference", "profile": "reference", "role": "token", "service": "reference", "sort_date": "date", "source_id": "keyword", "source_resource_id": "keyword", "source_resource_type": "keyword", "source_uri": "keyword", "specialty": "token", "tag": "token", "telecom": "token", "text": "string", "type": "special", } return searchParameters } func (s *FhirOrganizationAffiliation) 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, 'OrganizationAffiliation.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 }, []) if(ActiveProcessed.length == 0) { "undefined" } else { JSON.stringify(ActiveProcessed) } `) if err == nil && activeResult.String() != "undefined" { s.Active = []byte(activeResult.String()) } // extracting Date dateResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.period')[0]") if err == nil && dateResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, dateResult.String()) if err == nil { s.Date = &t } else if err != nil { d, err := time.Parse("2006-01-02", dateResult.String()) if err == nil { s.Date = &d } } } // extracting Email emailResult, err := vm.RunString(` EmailResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.telecom.where(system='email')') EmailProcessed = EmailResult.reduce((accumulator, currentValue) => { if (currentValue.coding) { //CodeableConcept currentValue.coding.map((coding) => { accumulator.push({ "code": coding.code, "system": coding.system, "text": currentValue.text }) }) } else if (currentValue.value) { //ContactPoint, Identifier accumulator.push({ "code": currentValue.value, "system": currentValue.system, "text": currentValue.type?.text }) } else if (currentValue.code) { //Coding accumulator.push({ "code": currentValue.code, "system": currentValue.system, "text": currentValue.display }) } else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) { //string, boolean accumulator.push({ "code": currentValue, }) } return accumulator }, []) if(EmailProcessed.length == 0) { "undefined" } else { JSON.stringify(EmailProcessed) } `) if err == nil && emailResult.String() != "undefined" { s.Email = []byte(emailResult.String()) } // extracting Endpoint endpointResult, err := vm.RunString(` EndpointResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.endpoint') if(EndpointResult.length == 0) { "undefined" } else { JSON.stringify(EndpointResult) } `) if err == nil && endpointResult.String() != "undefined" { s.Endpoint = []byte(endpointResult.String()) } // extracting Identifier identifierResult, err := vm.RunString(` IdentifierResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.identifier') IdentifierProcessed = IdentifierResult.reduce((accumulator, currentValue) => { if (currentValue.coding) { //CodeableConcept currentValue.coding.map((coding) => { accumulator.push({ "code": coding.code, "system": coding.system, "text": currentValue.text }) }) } else if (currentValue.value) { //ContactPoint, Identifier accumulator.push({ "code": currentValue.value, "system": currentValue.system, "text": currentValue.type?.text }) } else if (currentValue.code) { //Coding accumulator.push({ "code": currentValue.code, "system": currentValue.system, "text": currentValue.display }) } else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) { //string, boolean accumulator.push({ "code": currentValue, }) } return accumulator }, []) if(IdentifierProcessed.length == 0) { "undefined" } else { JSON.stringify(IdentifierProcessed) } `) if err == nil && identifierResult.String() != "undefined" { s.Identifier = []byte(identifierResult.String()) } // extracting Language languageResult, err := vm.RunString(` LanguageResult = window.fhirpath.evaluate(fhirResource, 'language') LanguageProcessed = LanguageResult.reduce((accumulator, currentValue) => { if (currentValue.coding) { //CodeableConcept currentValue.coding.map((coding) => { accumulator.push({ "code": coding.code, "system": coding.system, "text": currentValue.text }) }) } else if (currentValue.value) { //ContactPoint, Identifier accumulator.push({ "code": currentValue.value, "system": currentValue.system, "text": currentValue.type?.text }) } else if (currentValue.code) { //Coding accumulator.push({ "code": currentValue.code, "system": currentValue.system, "text": currentValue.display }) } else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) { //string, boolean accumulator.push({ "code": currentValue, }) } return accumulator }, []) if(LanguageProcessed.length == 0) { "undefined" } else { JSON.stringify(LanguageProcessed) } `) if err == nil && languageResult.String() != "undefined" { s.Language = []byte(languageResult.String()) } // extracting LastUpdated lastUpdatedResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'meta.lastUpdated')[0]") if err == nil && lastUpdatedResult.String() != "undefined" { t, err := time.Parse(time.RFC3339, lastUpdatedResult.String()) if err == nil { s.LastUpdated = &t } else if err != nil { d, err := time.Parse("2006-01-02", lastUpdatedResult.String()) if err == nil { s.LastUpdated = &d } } } // extracting Location locationResult, err := vm.RunString(` LocationResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.location') if(LocationResult.length == 0) { "undefined" } else { JSON.stringify(LocationResult) } `) if err == nil && locationResult.String() != "undefined" { s.Location = []byte(locationResult.String()) } // extracting Network networkResult, err := vm.RunString(` NetworkResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.network') if(NetworkResult.length == 0) { "undefined" } else { JSON.stringify(NetworkResult) } `) if err == nil && networkResult.String() != "undefined" { s.Network = []byte(networkResult.String()) } // extracting ParticipatingOrganization participatingOrganizationResult, err := vm.RunString(` ParticipatingOrganizationResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.participatingOrganization') if(ParticipatingOrganizationResult.length == 0) { "undefined" } else { JSON.stringify(ParticipatingOrganizationResult) } `) if err == nil && participatingOrganizationResult.String() != "undefined" { s.ParticipatingOrganization = []byte(participatingOrganizationResult.String()) } // extracting Phone phoneResult, err := vm.RunString(` PhoneResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.telecom.where(system='phone')') PhoneProcessed = PhoneResult.reduce((accumulator, currentValue) => { if (currentValue.coding) { //CodeableConcept currentValue.coding.map((coding) => { accumulator.push({ "code": coding.code, "system": coding.system, "text": currentValue.text }) }) } else if (currentValue.value) { //ContactPoint, Identifier accumulator.push({ "code": currentValue.value, "system": currentValue.system, "text": currentValue.type?.text }) } else if (currentValue.code) { //Coding accumulator.push({ "code": currentValue.code, "system": currentValue.system, "text": currentValue.display }) } else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) { //string, boolean accumulator.push({ "code": currentValue, }) } return accumulator }, []) if(PhoneProcessed.length == 0) { "undefined" } else { JSON.stringify(PhoneProcessed) } `) if err == nil && phoneResult.String() != "undefined" { s.Phone = []byte(phoneResult.String()) } // extracting PrimaryOrganization primaryOrganizationResult, err := vm.RunString(` PrimaryOrganizationResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.organization') if(PrimaryOrganizationResult.length == 0) { "undefined" } else { JSON.stringify(PrimaryOrganizationResult) } `) if err == nil && primaryOrganizationResult.String() != "undefined" { s.PrimaryOrganization = []byte(primaryOrganizationResult.String()) } // extracting Profile profileResult, err := vm.RunString(` ProfileResult = window.fhirpath.evaluate(fhirResource, 'meta.profile') if(ProfileResult.length == 0) { "undefined" } else { JSON.stringify(ProfileResult) } `) if err == nil && profileResult.String() != "undefined" { s.Profile = []byte(profileResult.String()) } // extracting Role roleResult, err := vm.RunString(` RoleResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.code') RoleProcessed = RoleResult.reduce((accumulator, currentValue) => { if (currentValue.coding) { //CodeableConcept currentValue.coding.map((coding) => { accumulator.push({ "code": coding.code, "system": coding.system, "text": currentValue.text }) }) } else if (currentValue.value) { //ContactPoint, Identifier accumulator.push({ "code": currentValue.value, "system": currentValue.system, "text": currentValue.type?.text }) } else if (currentValue.code) { //Coding accumulator.push({ "code": currentValue.code, "system": currentValue.system, "text": currentValue.display }) } else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) { //string, boolean accumulator.push({ "code": currentValue, }) } return accumulator }, []) if(RoleProcessed.length == 0) { "undefined" } else { JSON.stringify(RoleProcessed) } `) if err == nil && roleResult.String() != "undefined" { s.Role = []byte(roleResult.String()) } // extracting Service serviceResult, err := vm.RunString(` ServiceResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.healthcareService') if(ServiceResult.length == 0) { "undefined" } else { JSON.stringify(ServiceResult) } `) if err == nil && serviceResult.String() != "undefined" { s.Service = []byte(serviceResult.String()) } // extracting Specialty specialtyResult, err := vm.RunString(` SpecialtyResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.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 }, []) if(SpecialtyProcessed.length == 0) { "undefined" } else { 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, 'meta.tag') TagProcessed = TagResult.reduce((accumulator, currentValue) => { if (currentValue.coding) { //CodeableConcept currentValue.coding.map((coding) => { accumulator.push({ "code": coding.code, "system": coding.system, "text": currentValue.text }) }) } else if (currentValue.value) { //ContactPoint, Identifier accumulator.push({ "code": currentValue.value, "system": currentValue.system, "text": currentValue.type?.text }) } else if (currentValue.code) { //Coding accumulator.push({ "code": currentValue.code, "system": currentValue.system, "text": currentValue.display }) } else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) { //string, boolean accumulator.push({ "code": currentValue, }) } return accumulator }, []) if(TagProcessed.length == 0) { "undefined" } else { JSON.stringify(TagProcessed) } `) if err == nil && tagResult.String() != "undefined" { s.Tag = []byte(tagResult.String()) } // extracting Telecom telecomResult, err := vm.RunString(` TelecomResult = window.fhirpath.evaluate(fhirResource, 'OrganizationAffiliation.telecom') TelecomProcessed = TelecomResult.reduce((accumulator, currentValue) => { if (currentValue.coding) { //CodeableConcept currentValue.coding.map((coding) => { accumulator.push({ "code": coding.code, "system": coding.system, "text": currentValue.text }) }) } else if (currentValue.value) { //ContactPoint, Identifier accumulator.push({ "code": currentValue.value, "system": currentValue.system, "text": currentValue.type?.text }) } else if (currentValue.code) { //Coding accumulator.push({ "code": currentValue.code, "system": currentValue.system, "text": currentValue.display }) } else if ((typeof currentValue === 'string') || (typeof currentValue === 'boolean')) { //string, boolean accumulator.push({ "code": currentValue, }) } return accumulator }, []) if(TelecomProcessed.length == 0) { "undefined" } else { JSON.stringify(TelecomProcessed) } `) if err == nil && telecomResult.String() != "undefined" { s.Telecom = []byte(telecomResult.String()) } return nil } // TableName overrides the table name from fhir_observations (pluralized) to `fhir_observation`. https://gorm.io/docs/conventions.html#TableName func (s *FhirOrganizationAffiliation) TableName() string { return "fhir_organization_affiliation" }