// 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 FhirPractitionerRole struct { models.ResourceBase // Whether this practitioner role 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 practitioner is authorized to perform in these role(s) // https://hl7.org/fhir/r4/search.html#date Date *time.Time `gorm:"column:date;type:datetime" json:"date,omitempty"` /* Multiple Resources: * [Patient](patient.html): A value in an email contact * [Person](person.html): A value in an email contact * [Practitioner](practitioner.html): A value in an email contact * [PractitionerRole](practitionerrole.html): A value in an email contact * [RelatedPerson](relatedperson.html): 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 the practitioner with this role // https://hl7.org/fhir/r4/search.html#reference Endpoint datatypes.JSON `gorm:"column:endpoint;type:text;serializer:json" json:"endpoint,omitempty"` // A practitioner'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"` // One of the locations at which this practitioner provides care // https://hl7.org/fhir/r4/search.html#reference Location datatypes.JSON `gorm:"column:location;type:text;serializer:json" json:"location,omitempty"` // The identity of the organization the practitioner represents / acts on behalf of // https://hl7.org/fhir/r4/search.html#reference Organization datatypes.JSON `gorm:"column:organization;type:text;serializer:json" json:"organization,omitempty"` /* Multiple Resources: * [Patient](patient.html): A value in a phone contact * [Person](person.html): A value in a phone contact * [Practitioner](practitioner.html): A value in a phone contact * [PractitionerRole](practitionerrole.html): A value in a phone contact * [RelatedPerson](relatedperson.html): 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"` // Practitioner that is able to provide the defined services for the organization // https://hl7.org/fhir/r4/search.html#reference Practitioner datatypes.JSON `gorm:"column:practitioner;type:text;serializer:json" json:"practitioner,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 practitioner can perform this role at for the organization // https://hl7.org/fhir/r4/search.html#token Role datatypes.JSON `gorm:"column:role;type:text;serializer:json" json:"role,omitempty"` // The list of healthcare services that this worker provides for this role's Organization/Location(s) // https://hl7.org/fhir/r4/search.html#reference Service datatypes.JSON `gorm:"column:service;type:text;serializer:json" json:"service,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 practitioner has this specialty at an organization // 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"` /* Multiple Resources: * [Patient](patient.html): The value in any kind of telecom details of the patient * [Person](person.html): The value in any kind of contact * [Practitioner](practitioner.html): The value in any kind of contact * [PractitionerRole](practitionerrole.html): The value in any kind of contact * [RelatedPerson](relatedperson.html): 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 *FhirPractitionerRole) GetSearchParameters() map[string]string { searchParameters := map[string]string{ "active": "token", "date": "date", "email": "token", "endpoint": "reference", "identifier": "token", "language": "token", "lastUpdated": "date", "location": "reference", "organization": "reference", "phone": "token", "practitioner": "reference", "profile": "reference", "role": "token", "service": "reference", "sourceUri": "uri", "specialty": "token", "tag": "token", "telecom": "token", "text": "string", "type": "special", } return searchParameters } func (s *FhirPractitionerRole) 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, 'PractitionerRole.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, 'PractitionerRole.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, 'Patient.telecom.where(system='email') | Person.telecom.where(system='email') | Practitioner.telecom.where(system='email') | PractitionerRole.telecom.where(system='email') | RelatedPerson.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, 'PractitionerRole.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, 'PractitionerRole.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, 'PractitionerRole.location') if(LocationResult.length == 0) { "undefined" } else { JSON.stringify(LocationResult) } `) if err == nil && locationResult.String() != "undefined" { s.Location = []byte(locationResult.String()) } // extracting Organization organizationResult, err := vm.RunString(` OrganizationResult = window.fhirpath.evaluate(fhirResource, 'PractitionerRole.organization') if(OrganizationResult.length == 0) { "undefined" } else { JSON.stringify(OrganizationResult) } `) if err == nil && organizationResult.String() != "undefined" { s.Organization = []byte(organizationResult.String()) } // extracting Phone phoneResult, err := vm.RunString(` PhoneResult = window.fhirpath.evaluate(fhirResource, 'Patient.telecom.where(system='phone') | Person.telecom.where(system='phone') | Practitioner.telecom.where(system='phone') | PractitionerRole.telecom.where(system='phone') | RelatedPerson.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 Practitioner practitionerResult, err := vm.RunString(` PractitionerResult = window.fhirpath.evaluate(fhirResource, 'PractitionerRole.practitioner') if(PractitionerResult.length == 0) { "undefined" } else { JSON.stringify(PractitionerResult) } `) if err == nil && practitionerResult.String() != "undefined" { s.Practitioner = []byte(practitionerResult.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, 'PractitionerRole.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, 'PractitionerRole.healthcareService') if(ServiceResult.length == 0) { "undefined" } else { JSON.stringify(ServiceResult) } `) if err == nil && serviceResult.String() != "undefined" { s.Service = []byte(serviceResult.String()) } // extracting SourceUri sourceUriResult, err := vm.RunString("window.fhirpath.evaluate(fhirResource, 'meta.source')[0]") if err == nil && sourceUriResult.String() != "undefined" { s.SourceUri = sourceUriResult.String() } // extracting Specialty specialtyResult, err := vm.RunString(` SpecialtyResult = window.fhirpath.evaluate(fhirResource, 'PractitionerRole.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, 'Patient.telecom | Person.telecom | Practitioner.telecom | PractitionerRole.telecom | RelatedPerson.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 *FhirPractitionerRole) TableName() string { return "fhir_practitioner_role" }