Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
bd7c4ae
feat: :sparkles: Add typesense support to compose file, go server and…
alexszilagyi Jun 23, 2025
a0fdaad
feat: :sparkles: Fix search API call in server, add logs and type par…
alexszilagyi Jun 24, 2025
0096cc4
feat: :sparkles: Add pagination and hits per page support on request …
alexszilagyi Jun 24, 2025
ac1da8c
feat: :sparkles: Initial UI and route for resource search, integrate …
alexszilagyi Jun 25, 2025
ec161ad
chore: use the latest versions of typesense and typesense-go
alexszilagyi Jun 25, 2025
113804e
chore: revert fasten service
alexszilagyi Jun 25, 2025
4b967be
feat: :sparkles: Fix filtering by type
alexszilagyi Jun 26, 2025
9b94286
feat: :sparkles: Implement single record search, redirect to record p…
alexszilagyi Jun 26, 2025
98c0601
chore: fix the runtime bug
alexszilagyi Jun 26, 2025
f5ffed1
Merge branch 'feature/memory-bank' into feature/record-search
alexszilagyi Jun 26, 2025
300e083
chore: add embedding field in the resource collection
alexszilagyi Jun 27, 2025
2d2a131
chore: use docker volume
alexszilagyi Jun 30, 2025
eb703d6
chore: upgrade to typesense v29
alexszilagyi Jun 30, 2025
f6b7a71
refactor: :zap: Remove code text property, add date fallback and adju…
alexszilagyi Jun 30, 2025
993e788
Merge branch 'feature/record-search' into feature/conversation
alexszilagyi Jul 1, 2025
f45d675
chore: remove code_text from embeddings. use a different embeding lan…
alexszilagyi Jul 1, 2025
fd34a0b
chore: adjust sort_date field type
alexszilagyi Jul 1, 2025
d79018d
feat: chat page added
alexszilagyi Jul 1, 2025
1cdb5ac
feat: Implement initial Typesense conversational search and update de…
alexszilagyi Jul 1, 2025
5753dbc
chore: adjust yarn.lock
alexszilagyi Jul 1, 2025
5aa6251
chore: upgrade to angular v15
alexszilagyi Jul 1, 2025
70f03ff
chore: upgrade @angular/cdk to v15
alexszilagyi Jul 1, 2025
c9ec9ee
chore: upgrade to angular/cli 16
alexszilagyi Jul 1, 2025
dee7c01
chore: upgrade @angular/cdk to v16
alexszilagyi Jul 1, 2025
0b6c54d
chore: upgrade node version to v20
alexszilagyi Jul 1, 2025
5e6206b
chore: upgrade angular/cli version to v17
alexszilagyi Jul 1, 2025
2479503
chore: upgrade @angular/sdk to v17
alexszilagyi Jul 1, 2025
b58c434
chore: adjust yarn.lock
alexszilagyi Jul 1, 2025
71b303e
chore: upgrade some deps
alexszilagyi Jul 1, 2025
419b115
chore: hardcode the fhirpath package version
alexszilagyi Jul 1, 2025
6f6155e
chore: comment out the tree component with medical history
alexszilagyi Jul 10, 2025
b958a2a
chore: increase artefacts size limit
alexszilagyi Jul 10, 2025
c739277
chore: add missing mixins (bootstrap 4)
alexszilagyi Jul 10, 2025
d3963e8
chore: comment out ngx-datatable styling
alexszilagyi Jul 10, 2025
eccba1d
feat: :sparkles: WIP on table UI for Typesense records
alexszilagyi Jul 10, 2025
1d1c5d3
Merge branch 'feature/record-search' into feature/conversation
alexszilagyi Jul 10, 2025
3e0720d
fix: revert ResourceSearchTableComponent related changes
alexszilagyi Jul 10, 2025
4e00353
Merge branch 'feature/record-search' into feature/conversation
alexszilagyi Jul 10, 2025
a7c9309
chore: adjust flake.nix to include ng v17
alexszilagyi Jul 10, 2025
d08f7a6
chore: adjust startConversation method to return correct conversation…
alexszilagyi Jul 11, 2025
7128b99
chore: bump typesense-js version to @next
alexszilagyi Jul 11, 2025
7656b61
chore: bump typesensejs version
alexszilagyi Jul 15, 2025
f513948
chore: add startConversationStreaming
alexszilagyi Jul 15, 2025
3d07d61
docs: adjust memory bank with chat related context
alexszilagyi Jul 15, 2025
8a6ab1d
misc
alexszilagyi Jul 15, 2025
3b13037
chore: add conversations list
alexszilagyi Jul 15, 2025
3811eb2
chore: adjust chat screen design
alexszilagyi Jul 15, 2025
eb0e836
feat: :sparkles: Integrate table UI, separate resource type view and …
alexszilagyi Jul 15, 2025
851f2cd
chore: sort conversation messages
alexszilagyi Jul 15, 2025
cb2255a
adjust chat window styling
alexszilagyi Jul 15, 2025
5d97662
chore: add send message svg icon
alexszilagyi Jul 15, 2025
b6a8095
merge: from record-search
alexszilagyi Jul 15, 2025
44b31d7
chore: make conversation item looking minimalistic
alexszilagyi Jul 15, 2025
de8d7e1
chore: add delete conversation functionality
alexszilagyi Jul 15, 2025
1a782ce
chore: refactor some typesense service functions
alexszilagyi Jul 15, 2025
5cba078
feat: :sparkles: Add 'All' category to summary table
alexszilagyi Jul 15, 2025
86f50dc
chore: add specific field to the context
alexszilagyi Jul 15, 2025
b098996
Merge branch 'feature/record-search' into feature/conversation
alexszilagyi Jul 15, 2025
325cf67
chore: refactor the chat component and typesense service
alexszilagyi Jul 15, 2025
b07c345
docs: update memory bank
alexszilagyi Jul 16, 2025
495ab43
chore: move typesense env variables to config.yaml
alexszilagyi Jul 16, 2025
cb6d053
chore: create conversation collection on server init
alexszilagyi Jul 16, 2025
9c34f1a
chore: auto create typesense model on init
alexszilagyi Jul 16, 2025
7a7b72f
fix: :lipstick: Fix modal overlay
alexszilagyi Jul 16, 2025
d02cf64
fix: timeout on creation of resources collection
alexszilagyi Jul 16, 2025
60d1d89
feat: :lipstick: Update flow properties due to bootstrap package upgrade
alexszilagyi Jul 16, 2025
6bd50d8
chore: refactor typesense service
alexszilagyi Jul 16, 2025
1946758
fix: remove ReportMedicalHistoryEditorComponent component and tree-vi…
alexszilagyi Jul 17, 2025
ff34dc3
fix: modify datatable css import path
alexszilagyi Jul 17, 2025
9d02fe7
feat: :lipstick: Margin and padding changes
alexszilagyi Jul 17, 2025
60690ba
Merge branch 'bootstrap-styles-fix' into feature/conversation
alexszilagyi Jul 17, 2025
b290c02
fix: ng add localize
alexszilagyi Jul 17, 2025
0ae4520
chore: remove memory-bank
alexszilagyi Jul 17, 2025
606ec91
chore: remove .clineignore
alexszilagyi Jul 17, 2025
15e6ec9
Merge branch 'feature/memory-bank' into feature/record-search
alexszilagyi Jul 17, 2025
a072019
Merge branch 'feature/record-search' into feature/chat
alexszilagyi Jul 17, 2025
c6eb2ef
Merge branch 'feature/chat' into feature/chat-wo-memory-bank
alexszilagyi Jul 17, 2025
14094f0
feat: :lipstick: Update container styles on chat page
alexszilagyi Jul 17, 2025
aee7fed
chore: remove unnecessary dom element from timeline body
alexszilagyi Jul 17, 2025
f5a1bba
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 17, 2025
5b73b26
docs: add fhir resources related info
alexszilagyi Jul 17, 2025
c050389
chore: :construction: Cleanup initial search cards page and component
alexszilagyi Jul 18, 2025
60e1b59
merge from record-search
alexszilagyi Jul 18, 2025
b6d34e9
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
06b6b77
chore: remove TreeModule reference
alexszilagyi Jul 18, 2025
3ee1f86
chore: switch search/chat functions for desktop
alexszilagyi Jul 18, 2025
f1587e8
misc: remove logs decorations
alexszilagyi Jul 18, 2025
9cd984a
chore: refactor typesense config
alexszilagyi Jul 18, 2025
b44b0a2
chore: conditionally initialize typesense resources
alexszilagyi Jul 18, 2025
190eef3
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
2ab387d
feat: :sparkles: Default to All category on record search page
alexszilagyi Jul 18, 2025
0f48867
chore: adjust .gitignore
alexszilagyi Jul 18, 2025
6bbd273
fix: :bug: Fix pagination on search page
alexszilagyi Jul 18, 2025
a10bd93
chore: upgrade docker base image
alexszilagyi Jul 18, 2025
9be811b
Merge branch 'feature/chat' of github.com:TechStackApps/fasten-onprem…
alexszilagyi Jul 18, 2025
0a8b934
chore: increase angular style assets limits
alexszilagyi Jul 18, 2025
8341f93
chore: increase typesense service waiting time
alexszilagyi Jul 18, 2025
5408f1b
chore: adjust typesense service hostname
alexszilagyi Jul 18, 2025
591b178
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
3795dbe
chore: adjust .gitignore
alexszilagyi Jul 18, 2025
ccfdd43
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
284f871
chore: revert dockerfile step
alexszilagyi Jul 18, 2025
bfed8cc
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
2551342
chore: rever docker-compose env var
alexszilagyi Jul 18, 2025
71d4d36
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
61c8923
chore: revert docker-compose env
alexszilagyi Jul 18, 2025
3d88414
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
f5351b9
chore: revert docker-compose env
alexszilagyi Jul 18, 2025
f2c768a
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
091c6f6
chore: move typesense config to env
alexszilagyi Jul 18, 2025
b3b224e
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 18, 2025
ec4b47c
chore: adjust docker-compose-prod.yml to include typesense service
alexszilagyi Jul 19, 2025
2858be8
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 19, 2025
4500eb1
chore: forward typesense port
alexszilagyi Jul 19, 2025
e69e027
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 19, 2025
7604dd6
chore: add /env endpoint to backend
alexszilagyi Jul 19, 2025
c5f8cb1
chore: swith conditional logic enablic search functionality in the fr…
alexszilagyi Jul 19, 2025
47e79d9
chore: swith conditional logic enabling chat functionality in the fro…
alexszilagyi Jul 19, 2025
fb8bc72
chore: remove typesense/search/chat env from client environment
alexszilagyi Jul 19, 2025
c4ebe90
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 19, 2025
6228cb5
chore: revert some unused changes
alexszilagyi Jul 19, 2025
a99bf1c
chore: refresh memory bank
alexszilagyi Jul 19, 2025
5601c80
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 19, 2025
d7fd223
chore: revert previous version of ysconfig.spec.json
alexszilagyi Jul 21, 2025
0e07f75
fix: failed test because of zone.js initialization
alexszilagyi Jul 21, 2025
9f54e13
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 21, 2025
3d3c539
fix(frontend): correct test setup and dependencies
alexszilagyi Jul 21, 2025
6fcf995
Merge branch 'feature/chat' of github.com:TechStackApps/fasten-onprem…
alexszilagyi Jul 21, 2025
deed892
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 21, 2025
6c7383a
chore: upgrade frontend to storybook v8
alexszilagyi Jul 21, 2025
39974f5
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 21, 2025
50e25ca
chore: refactor search/chat config object to be more user-oriented
alexszilagyi Jul 21, 2025
7ff4392
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 21, 2025
fa8d5e2
feat: :sparkles: Implement index mechanism when loading Typesense
alexszilagyi Jul 22, 2025
5e5945d
chore: adjust docker-compose files
alexszilagyi Jul 22, 2025
5daf35b
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 22, 2025
60a44e9
test: :construction: Add new property to check on system settings entry
alexszilagyi Jul 22, 2025
68e72f9
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 22, 2025
27e66a9
feat: :sparkles: On resource summary/search add filter by user if ava…
alexszilagyi Jul 22, 2025
3ef6b68
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 22, 2025
7a02d3a
chore: merge from main
alexszilagyi Jul 25, 2025
a7593ad
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 25, 2025
95e8d32
test: Generate mock test for ListAllResources method
alexszilagyi Jul 25, 2025
8d968b2
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 28, 2025
72d56f7
Merge branch 'feature/memory-bank' into feature/chat
alexszilagyi Jul 28, 2025
93dae02
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 28, 2025
3dd08e4
Merge branch 'feature/memory-bank' into feature/chat
alexszilagyi Jul 31, 2025
1e09419
docs: add comments to docker-compose.yml regarding typesense service
alexszilagyi Jul 31, 2025
0e30438
chore: renave "env" related resources to "settings"
alexszilagyi Jul 31, 2025
dcd1711
chore: adjust indexer name
alexszilagyi Jul 31, 2025
0db03d9
misc: clean messages
alexszilagyi Jul 31, 2025
f358a88
chore: add extra check in IndexData
alexszilagyi Jul 31, 2025
83518e2
chore: revert CanActivate
alexszilagyi Jul 31, 2025
16983e9
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Jul 31, 2025
cd7a698
Merge branch 'feature/memory-bank' into feature/chat
alexszilagyi Aug 11, 2025
d8ff9a5
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Aug 11, 2025
3e6073f
refactor: Refactor search init and index function on server run
alexszilagyi Aug 19, 2025
af39140
test: Update tests suite to match latest change from migration file
alexszilagyi Aug 19, 2025
f342036
Revert "test: Update tests suite to match latest change from migratio…
alexszilagyi Aug 19, 2025
4519cd0
Revert "refactor: Refactor search init and index function on server run"
alexszilagyi Aug 19, 2025
5c7ddad
refactor: Refactor search init and index function on server run
alexszilagyi Aug 19, 2025
546c510
test: Update tests suite to match latest change from migration file
alexszilagyi Aug 19, 2025
c0c2129
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Aug 19, 2025
9ab25eb
refactor: Undo file format on resource_fhir_test file
alexszilagyi Aug 20, 2025
200d742
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Aug 20, 2025
330e02b
Merge branch 'main' into feature/chat
alexszilagyi Aug 25, 2025
ffc67fc
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Aug 25, 2025
d2a237b
feat: Add resource_id as property in schema and index function
alexszilagyi Aug 29, 2025
8dfd389
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Aug 29, 2025
41eaee0
feat: Adjust composite ID on Typsense records
alexszilagyi Aug 29, 2025
da7b8f0
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Aug 29, 2025
a8ca7e0
Merge branch 'main' into feature/chat
alexszilagyi Aug 29, 2025
faa2fca
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Aug 29, 2025
919627b
Merge branch 'main' into feature/chat
alexszilagyi Sep 3, 2025
16a21d4
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Sep 3, 2025
b9e7310
Merge branch 'main' into feature/chat
alexszilagyi Sep 18, 2025
8a174f1
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Sep 18, 2025
625e3e1
Merge branch 'main' into feature/chat
alexszilagyi Oct 14, 2025
84b95a8
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Oct 14, 2025
b957e0d
Fix chart configuration option types after update
alexszilagyi Oct 14, 2025
1a93e0a
Fix chart configuration option types after update
alexszilagyi Oct 14, 2025
bd65ae6
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Oct 14, 2025
9d88e48
Adjust test types on search enable test suite
alexszilagyi Oct 14, 2025
98e9593
Adjust test types on search enable test suite
alexszilagyi Oct 14, 2025
862cbec
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Oct 15, 2025
b451ea3
Merge branch 'main' into feature/chat
alexszilagyi Oct 22, 2025
6246955
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Oct 22, 2025
7c757d7
Merge branch 'main' into feature/chat
alexszilagyi Nov 5, 2025
3fec283
Merge branch 'feature/chat' into feature/chat-clean
alexszilagyi Nov 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN --mount=type=cache,target=/tmp/lock,sharing=locked \
#########################################################################################################
# Backend Build
#########################################################################################################
FROM golang:1.21 as backend-build
FROM golang:1.22 as backend-build

WORKDIR /go/src/github.com/fastenhealth/fasten-onprem
COPY . .
Expand Down
22 changes: 18 additions & 4 deletions backend/cmd/fasten/fasten.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ package main
import (
"encoding/json"
"fmt"
"io"
"log"
"os"
"time"

"github.com/analogj/go-util/utils"
"github.com/fastenhealth/fasten-onprem/backend/pkg/config"
"github.com/fastenhealth/fasten-onprem/backend/pkg/database"
"github.com/fastenhealth/fasten-onprem/backend/pkg/errors"
"github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus"
"github.com/fastenhealth/fasten-onprem/backend/pkg/search"
"github.com/fastenhealth/fasten-onprem/backend/pkg/version"
"github.com/fastenhealth/fasten-onprem/backend/pkg/web"
"github.com/fastenhealth/fasten-onprem/backend/resources"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"io"
"log"
"os"
"time"
)

var goos string
Expand Down Expand Up @@ -111,6 +113,18 @@ func main() {
}
}()

// Check if Typesense (search) is enabled and initialize it
if appconfig.IsSet("search") && appconfig.GetString("search.uri") != "" {
err = search.Init(appconfig, appLogger)
if err != nil {
appLogger.Error("failed to initialize Typesense: %w", err)
}

appLogger.Info("Typesense initialized successfully")
} else {
appLogger.Info("Search is disabled, skipping Typesense initialization.")
}

settingsData, err := json.Marshal(appconfig.AllSettings())
appLogger.Debug(string(settingsData), err)

Expand Down
41 changes: 41 additions & 0 deletions backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,46 @@ func (c *configuration) ValidateConfig() error {
return errors.ConfigValidationError("database.encryption.key must be at least 10 characters")
}
}

if c.IsSet("search") {
key := c.GetString("search.uri")
if key == "" {
return errors.ConfigValidationError("search.uri cannot be empty")
}
key = c.GetString("search.api_key")
if key == "" {
return errors.ConfigValidationError("search.api_key cannot be empty")
}
key = c.GetString("search.collection_name")
if key == "" {
return errors.ConfigValidationError("search.collection_name cannot be empty")
}
}

if c.IsSet("search.chat") {
key := c.GetString("search.chat.conversation_collection_name")
if key == "" {
return errors.ConfigValidationError("search.chat.conversation_collection_name cannot be empty")
}

key = c.GetString("search.chat.model.id")
if key == "" {
return errors.ConfigValidationError("search.chat.model.id cannot be empty")
}
key = c.GetString("search.chat.model.name")
if key == "" {
return errors.ConfigValidationError("search.chat.model.name cannot be empty")
}
key = c.GetString("search.chat.model.vllm_url")
if key == "" {
return errors.ConfigValidationError("search.chat.model.vllm_url cannot be empty")
}
key = c.GetString("search.chat.model.max_bytes")
if key == "" {
return errors.ConfigValidationError("search.chat.model.max_bytes cannot be empty")
}
}


return nil
}
83 changes: 82 additions & 1 deletion backend/pkg/database/gorm_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus"
"github.com/fastenhealth/fasten-onprem/backend/pkg/models"
databaseModel "github.com/fastenhealth/fasten-onprem/backend/pkg/models/database"
"github.com/fastenhealth/fasten-onprem/backend/pkg/search"
"github.com/fastenhealth/fasten-onprem/backend/pkg/utils"
sourceModel "github.com/fastenhealth/fasten-sources/clients/models"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -367,8 +368,44 @@ func (gr *GormRepository) UpsertRawResource(ctx context.Context, sourceCredentia
}
}

return gr.UpsertResource(ctx, wrappedResourceModel)
success, err := gr.UpsertResource(ctx, wrappedResourceModel)
if err != nil {
return false, err
}

// Add nil checks before launching goroutine
if wrappedResourceModel == nil {
gr.Logger.Warn("Cannot index nil resource in Typesense")
return success, nil
}

if search.Client == nil {
gr.Logger.Warn("Search client is nil, skipping indexing")
return success, nil
}

indexer := &search.IndexerService{Client: search.Client}

// Launch goroutine with proper error handling
go func(resource *models.ResourceBase) {
// Additional safety check inside goroutine
if resource == nil {
gr.Logger.Warn("Resource is nil in indexing goroutine")
return
}

if indexer == nil {
gr.Logger.Warn("IndexerService is nil in indexing goroutine")
return
}

err := indexer.IndexResource(resource)
if err != nil {
gr.Logger.Warnf("Failed to index resource: %v", err)
}
}(wrappedResourceModel)

return success, nil
}

func (gr *GormRepository) UpsertRawResourceAssociation(
Expand Down Expand Up @@ -526,6 +563,50 @@ func (gr *GormRepository) ListResources(ctx context.Context, queryOptions models
}
}

// Used to query all resources across all tables and use them for Typesense indexing
func (gr *GormRepository) ListAllResources(ctx context.Context, queryOptions models.ListResourceQueryOptions) ([]models.ResourceBase, error) {
queryParam := models.OriginBase{}

if len(queryOptions.SourceResourceType) > 0 {
queryParam.SourceResourceType = queryOptions.SourceResourceType
}
if len(queryOptions.SourceID) > 0 {
sourceUUID, err := uuid.Parse(queryOptions.SourceID)
if err != nil {
return nil, err
}
queryParam.SourceID = sourceUUID
}
if len(queryOptions.SourceResourceID) > 0 {
queryParam.SourceResourceID = queryOptions.SourceResourceID
}

queryBuilder := gr.GormClient.WithContext(ctx)
if len(queryOptions.SourceResourceType) > 0 {
tableName, err := databaseModel.GetTableNameByResourceType(queryOptions.SourceResourceType)
if err != nil {
return nil, err
}
queryBuilder = queryBuilder.
Where(queryParam).
Table(tableName)

if queryOptions.Limit > 0 {
queryBuilder = queryBuilder.Limit(queryOptions.Limit).Offset(queryOptions.Offset)
}

var wrappedResourceModels []models.ResourceBase
err = queryBuilder.Find(&wrappedResourceModels).Error
return wrappedResourceModels, err
}

// Query all resources across all tables
if queryOptions.Limit > 0 {
queryBuilder = queryBuilder.Limit(queryOptions.Limit).Offset(queryOptions.Offset)
}
return gr.getResourcesFromAllTables(queryBuilder, queryParam)
}

// TODO: should this be deprecated? (replaced by ListResources)
func (gr *GormRepository) GetResourceByResourceTypeAndId(ctx context.Context, sourceResourceType string, sourceResourceId string) (*models.ResourceBase, error) {
currentUser, currentUserErr := gr.GetCurrentUser(ctx)
Expand Down
11 changes: 7 additions & 4 deletions backend/pkg/database/gorm_repository_graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package database
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"testing"

"github.com/fastenhealth/fasten-onprem/backend/pkg"
mock_config "github.com/fastenhealth/fasten-onprem/backend/pkg/config/mock"
"github.com/fastenhealth/fasten-onprem/backend/pkg/event_bus"
Expand All @@ -14,10 +19,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"io/ioutil"
"log"
"os"
"testing"
)

// Define the suite, and absorb the built-in basic suite
Expand Down Expand Up @@ -61,6 +62,7 @@ func (suite *RepositoryGraphTestSuite) TestGetFlattenedResourceGraph() {
fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes()
fakeConfig.EXPECT().GetString("database.type").Return("sqlite").AnyTimes()
fakeConfig.EXPECT().IsSet("database.encryption.key").Return(false).AnyTimes()
fakeConfig.EXPECT().IsSet("search").Return(false).AnyTimes()
fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes()
fakeConfig.EXPECT().GetBool("database.validation_mode").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("database.encryption.enabled").Return(false).AnyTimes()
Expand Down Expand Up @@ -131,6 +133,7 @@ func (suite *RepositoryGraphTestSuite) TestGetFlattenedResourceGraph_NDJson() {
fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes()
fakeConfig.EXPECT().GetString("database.type").Return("sqlite").AnyTimes()
fakeConfig.EXPECT().IsSet("database.encryption.key").Return(false).AnyTimes()
fakeConfig.EXPECT().IsSet("search").Return(false).AnyTimes()
fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes()
fakeConfig.EXPECT().GetBool("database.validation_mode").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("database.encryption.enabled").Return(false).AnyTimes()
Expand Down
45 changes: 45 additions & 0 deletions backend/pkg/database/gorm_repository_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
_20250730100000 "github.com/fastenhealth/fasten-onprem/backend/pkg/database/migrations/20250730100000"
"github.com/fastenhealth/fasten-onprem/backend/pkg/models"
databaseModel "github.com/fastenhealth/fasten-onprem/backend/pkg/models/database"
"github.com/fastenhealth/fasten-onprem/backend/pkg/search"
sourceCatalog "github.com/fastenhealth/fasten-sources/catalog"
sourcePkg "github.com/fastenhealth/fasten-sources/pkg"
"github.com/go-gormigrate/gormigrate/v2"
Expand Down Expand Up @@ -267,6 +268,50 @@ func (gr *GormRepository) Migrate() error {
gr.Logger.Errorf("Final Database migration failed with error.\n Please open a github issue at https://github.com/fastenhealth/fasten-onprem. \n %v", err)
}

if gr.AppConfig.IsSet("search") && gr.AppConfig.GetString("search.uri") != "" {
indexer := &search.IndexerService{Client: search.Client}

// Index existing data if needed
ctx := context.Background()

systemSettings, err := gr.LoadSystemSettings(ctx)
if err != nil {
gr.Logger.Error("failed to load system settings: %w", err)
}

if systemSettings.TypesenseDataIndexed {
fmt.Print("Data already indexed, skipping...")
}

fmt.Print("Data not indexed. Indexing existing resources...")

if indexer.Client == nil {
gr.Logger.Error("Indexer client is nil!")
}

listResourceQueryOptions := models.ListResourceQueryOptions{}
resources, err := gr.ListAllResources(ctx, listResourceQueryOptions)
if err != nil {
gr.Logger.Error("failed to retrieve resources: %w", err)
}

for i := range resources {
if err := indexer.IndexResource(&resources[i]); err != nil {
gr.Logger.Error("Failed to index resource:", resources[i].ID, "-", err, "skipping...")
continue
}
}

systemSettings.TypesenseDataIndexed = true
if err := gr.SaveSystemSettings(ctx, systemSettings); err != nil {
gr.Logger.Error("failed to update system settings: %w", err)
}

gr.Logger.Print("Indexed %d resources", len(resources))
gr.Logger.Print("Indexing completed and flag updated.")
}

gr.Logger.Infoln("Database migration completed successfully")

return nil
}
1 change: 1 addition & 0 deletions backend/pkg/database/gorm_repository_query_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (suite *RepositorySqlTestSuite) BeforeTest(suiteName, testName string) {
fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes()
fakeConfig.EXPECT().GetString("database.type").Return("sqlite").AnyTimes()
fakeConfig.EXPECT().IsSet("database.encryption.key").Return(false).AnyTimes()
fakeConfig.EXPECT().IsSet("search").Return(false).AnyTimes()
fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes()
fakeConfig.EXPECT().GetBool("database.validation_mode").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("database.encryption.enabled").Return(false).AnyTimes()
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/database/gorm_repository_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (suite *RepositoryTestSuite) TestQueryResources_SQL() {
fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes()
fakeConfig.EXPECT().GetString("database.type").Return("sqlite").AnyTimes()
fakeConfig.EXPECT().IsSet("database.encryption.key").Return(false).AnyTimes()
fakeConfig.EXPECT().IsSet("search").Return(false).AnyTimes()
fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes()
fakeConfig.EXPECT().GetBool("database.validation_mode").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("database.encryption.enabled").Return(false).AnyTimes()
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/database/gorm_repository_related_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (suite *RepositoryRelatedTestSuite) SetupTest() {
fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes()
fakeConfig.EXPECT().GetString("database.type").Return("sqlite").AnyTimes()
fakeConfig.EXPECT().IsSet("database.encryption.key").Return(false).AnyTimes()
fakeConfig.EXPECT().IsSet("search").Return(false).AnyTimes()
fakeConfig.EXPECT().GetString("log.level").Return("DEBUG").AnyTimes()
fakeConfig.EXPECT().GetBool("database.validation_mode").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("database.encryption.enabled").Return(false).AnyTimes()
Expand Down
3 changes: 2 additions & 1 deletion backend/pkg/database/gorm_repository_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (suite *RepositorySummaryTestSuite) TestGetInternationalPatientSummaryBundl
fakeConfig.EXPECT().GetString("database.location").Return(suite.TestDatabase.Name()).AnyTimes()
fakeConfig.EXPECT().GetString("database.type").Return("sqlite").AnyTimes()
fakeConfig.EXPECT().IsSet("database.encryption.key").Return(false).AnyTimes()
fakeConfig.EXPECT().IsSet("search").Return(false).AnyTimes()
fakeConfig.EXPECT().GetString("log.level").Return("INFO").AnyTimes()
fakeConfig.EXPECT().GetBool("database.validation_mode").Return(false).AnyTimes()
fakeConfig.EXPECT().GetBool("database.encryption.enabled").Return(false).AnyTimes()
Expand Down Expand Up @@ -99,7 +100,7 @@ func (suite *RepositorySummaryTestSuite) TestGetInternationalPatientSummaryBundl

manualClient, err := sourceFactory.GetSourceClient(sourcePkg.FastenLighthouseEnvSandbox, authContext, testLogger, &testSourceCredential)
require.NoError(suite.T(), err)

summary, err := manualClient.SyncAllBundle(dbRepo, bundleFile, sourcePkg.FhirVersion401)
require.NoError(suite.T(), err)
require.Equal(suite.T(), 72, summary.TotalResources)
Expand Down
Loading