# aqlbetter **Repository Path**: mirrors_crs4/aqlbetter ## Basic Information - **Project Name**: aqlbetter - **Description**: Angular UI written by Better and adapted to EHRBase by sasurfer - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-12 - **Last Updated**: 2026-03-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AQL BUILDER WRITTEN BY BETTER AND ADAPTED BY SASURFER (@GITHUB) _WARNING: for EHRBase versions < 2.5.0 use release 1.0.0. Use latest version for EHRBase version >= 2.14.0 . No version available for 2.5.0<= EHRBase version<2.14.0__ This sofware helps in building openEHR aql queries. It needs a running instance of EHRBase in order to work. Its main capabilities are: creating the query with autocompletion and template visualization, saving queries on the running instance of EHRBase (called views) or locally (called snippets), performing queries, retrieving and showing the results, importing (writing into EHRBase) templates. More info at [aql builder site]( https://docs.better.care/studio/aql-builder/overview ). At login are asked: Username, Password, Platform URL. If oauth2 is configured (see below on how to do it) then the client_secret is also requested. The platform URL has the form http://{yourehrbaseservername}:{yourehrbaseserverport}/ehrbase NOTE: It is necessary to login with the EHRBase admin credentials to let all template and views methods work as intended. Example of values for the default credentials: - Username: ehrbase-admin - Password: EvenMoreSecretPassword - Platform URL: http://localhost:8080/ehrbase ## INSTALL LOCALLY Conda is optional. You can install with or without it. Clone the repository: ``` git clone https://github.com/sasurfer/aqlbetter.git ``` creates, optionally, a conda environment and install nodejs and run install and build scripts: ``` cd aqlbetter conda create --name aqlbetter conda activate aqlbetter conda install -c conda-forge nodejs npm install -g @angular/cli@10.1.0 cd projects/aql-builder/ npm install --save-dev @angular-devkit/build-angular --force export NODE_OPTIONS=--openssl-legacy-provider ng build aql-builder --prod ``` ## COMMON CONFIGURATION Modify 'localhost:8080' in projects/aql-builder/src/proxy.conf.json with {youehrbaseservername}:{yourehrbaseserverport}. This step, though optional, ensures that the app uses the EHRBase nodename, e.g., local.ehrbase.org, to create the full name for the queries. If the server in proxy is not recognized a default nodename will be used instead. ## RUN WITH BASIC AUTH ### EHRBASE CONFIGURATION In the EHRBase directory creates two files: .env.ehrbase and docker-compose.yml This is an example of .env.ehrbase (read by docker-compose.yaml): ``` SERVER_NODENAME=local.ehrbase.org SECURITY_AUTHTYPE=BASIC SECURITY_AUTHUSER=ehrbase-user SECURITY_AUTHPASSWORD=SuperSecretPassword SECURITY_AUTHADMINUSER=ehrbase-admin SECURITY_AUTHADMINPASSWORD=EvenMoreSecretPassword SECURITY_OAUTH2USERROLE=USER SECURITY_OAUTH2ADMINROLE=ADMIN SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUERURI= MANAGEMENT_ENDPOINTS_WEB_EXPOSURE=env,health,info,metrics,prometheus MANAGEMENT_ENDPOINTS_WEB_BASEPATH=/management MANAGEMENT_ENDPOINT_ENV_ENABLED=true MANAGEMENT_ENDPOINT_HEALTH_ENABLED=true MANAGEMENT_ENDPOINT_HEALTH_DATASOURCE_ENABLED=true MANAGEMENT_ENDPOINT_INFO_ENABLED=true MANAGEMENT_ENDPOINT_METRICS_ENABLED=true MANAGEMENT_ENDPOINT_PROMETHEUS_ENABLED=FALSE MANAGEMENT_ENDPOINT_HEALTH_PROBES_ENABLED=true MANAGEMENT_ENDPOINT_ENV_SHOWVALUES=ALWAYS SYSTEM_ALLOW_TEMPLATE_OVERWRITE=true EHRBASE_TEMPLATE_ALLOW_OVERWRITE=true ADMIN_API_ACTIVE=true CACHE_ENABLED=true ADMINAPI_ALLOWDELETEALL=true WEB_CORS_ALLOWEDORIGINS=http://localhost:4201 WEB_CORS_ALLOWEDORIGINPATTERNS=http://*.localhost:4201 WEB_CORS_ALLOWEDMETHODS=GET,PUT,DELETE,POST,OPTIONS,HEAD WEB_CORS_ALLOWCREDENTIALS=true WEB_CORS_ALLOWEDHEADERS=* ``` and the related docker-compose.yml: ``` version: '3' # # Minimal setup for a running EHRbase. Contains the server component as well as the required postgres instance. # services: # # EHRBase container. see `.env.ehrbase` for configuration details. # ehrbase: image: ${EHRBASE_IMAGE:-ehrbase/ehrbase:2.15.0} env_file: - .env.ehrbase environment: DB_URL: jdbc:postgresql://ehrdb:5432/ehrbase DB_USER_ADMIN: ehrbase DB_PASS_ADMIN: ehrbase DB_USER: ehrbase_restricted DB_PASS: ehrbase_restricted links: - ehrdb depends_on: ehrdb: condition: service_healthy ports: - "8080:8080" networks: - ehrbase-net # # Pre-configured ehrbase postgres. # ehrdb: image: ${EHRBASE_POSTGRES_IMAGE:-ehrbase/ehrbase-v2-postgres:16.2} environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres EHRBASE_USER_ADMIN: ehrbase EHRBASE_PASSWORD_ADMIN: ehrbase EHRBASE_USER: ehrbase_restricted EHRBASE_PASSWORD: ehrbase_restricted healthcheck: test: [ "CMD-SHELL", "pg_isready -U postgres" ] interval: 5s timeout: 5s retries: 12 ports: - "5432:5432" networks: - ehrbase-net volumes: - ./.pgdata:/var/lib/postgresql/data networks: ehrbase-net: { } ``` Start the services: ``` docker compose up ``` ### AQLBETTER CONFIGURATION Make sure to use {aqlbetter_dir}/projects/aql-builder/src/environments/environment.prod.ts.BASICAUTH From the dir {aqlbetter_dir}/projects/aql-builder: ``` cp ./src/environments/environment.prod.ts.BASICAUTH ./src/environments/environment.prod.ts ``` Remember to rerun the build step: ``` ng build aql-builder --prod ``` ### RUN Run with: ``` ng serve aql-builder --port 4201 ``` Open a browser tab to localhost:4201, fill the credentials and click "Start querying data". ## OAUTH2 ### EHRBASE CONFIGURATION Create a directory for EHRBase and copy the following two example files. This is an example of .env.ehrbase (read by docker compose yaml): ``` SERVER_NODENAME=local.ehrbase.org SECURITY_AUTHTYPE=OAUTH SECURITY_AUTHUSER=ehrbase-user SECURITY_AUTHPASSWORD=SuperSecretPassword SECURITY_AUTHADMINUSER=ehrbase-admin SECURITY_AUTHADMINPASSWORD=EvenMoreSecretPassword SECURITY_OAUTH2USERROLE=USER SECURITY_OAUTH2ADMINROLE=ADMIN SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUERURI=http://172.31.0.2:8080/auth/realms/ehrbase MANAGEMENT_ENDPOINTS_WEB_EXPOSURE=env,health,info,metrics,prometheus MANAGEMENT_ENDPOINTS_WEB_BASEPATH=/management MANAGEMENT_ENDPOINT_ENV_ENABLED=true MANAGEMENT_ENDPOINT_HEALTH_ENABLED=true MANAGEMENT_ENDPOINT_HEALTH_DATASOURCE_ENABLED=true MANAGEMENT_ENDPOINT_INFO_ENABLED=true MANAGEMENT_ENDPOINT_METRICS_ENABLED=true MANAGEMENT_ENDPOINT_PROMETHEUS_ENABLED=FALSE MANAGEMENT_ENDPOINT_HEALTH_PROBES_ENABLED=true MANAGEMENT_ENDPOINT_ENV_SHOWVALUES=ALWAYS SYSTEM_ALLOW_TEMPLATE_OVERWRITE=true ADMIN_API_ACTIVE=true CACHE_ENABLED=true ADMINAPI_ALLOWDELETEALL=true WEB_CORS_ALLOWEDORIGINS=http://localhost:4201 WEB_CORS_ALLOWEDORIGINPATTERNS=http://*.localhost:4201 WEB_CORS_ALLOWEDMETHODS=GET,PUT,DELETE,POST,OPTIONS,HEAD WEB_CORS_ALLOWCREDENTIALS=true WEB_CORS_ALLOWEDHEADERS=* ``` and the docker-compose.yml: ``` version: '3' # # Minimal setup for a running EHRbase. Contains the server component as well as the required postgres instance. # services: # # EHRBase container. see `.env.ehrbase` for configuration details. # ehrbase: image: ${EHRBASE_IMAGE:-ehrbase/ehrbase:2.6.0} env_file: - .env.ehrbase environment: DB_URL: jdbc:postgresql://ehrdb:5432/ehrbase DB_USER_ADMIN: ehrbase DB_PASS_ADMIN: ehrbase DB_USER: ehrbase_restricted DB_PASS: ehrbase_restricted links: - ehrdb - keycloak3 depends_on: ehrdb: condition: service_healthy keycloak3: condition: service_started ports: - "8080:8080" networks: - ehrbase-net # # Pre-configured ehrbase postgres. # ehrdb: image: ${EHRBASE_POSTGRES_IMAGE:-ehrbase/ehrbase-v2-postgres:16.2} environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres EHRBASE_USER_ADMIN: ehrbase EHRBASE_PASSWORD_ADMIN: ehrbase EHRBASE_USER: ehrbase_restricted EHRBASE_PASSWORD: ehrbase_restricted healthcheck: test: [ "CMD-SHELL", "pg_isready -U postgres" ] interval: 5s timeout: 5s retries: 12 ports: - "5432:5432" networks: - ehrbase-net volumes: - ./.pgdata:/var/lib/postgresql/data keycloak3: image: quay.io/keycloak/keycloak:24.0.3 #image: registry.vitasystems.dev/docker-registry/keycloak-x:0.9.9 container_name: keycloak3 command: "start-dev --import-realm" ports: - "8081:8080" environment: KEYCLOAK_ADMIN: admin KEYCLOAK_ADMIN_PASSWORD: admin KC_HTTP_RELATIVE_PATH: /auth KC_HTTP_PORT: 8080 volumes: - ./tests/keycloak/import:/opt/keycloak/data/import networks: - ehrbase-net networks: ehrbase-net: { } ``` from the latest https://github.com/ehrbase/ehrbase.git copy the path to the file (included) tests/keycloak/import/ehrbase-realm-exported.json to this directory. Modify the SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUERURI server and port with your keycloak ip and port. Start the services: ``` docker compose up ``` ### AQLBETTER CONFIGURATION Use {aqlbetter_dir}/projects/aql-builder/src/environments/environment.prod.ts.OAUTH2 and modify the authorizationUrl according to your installation of keycloak. Remember that the address (server:port) must be the same as the one given in SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUERURI in the EHRBase settings (172.31.0.2:8080 in the example). Rerun the build step: ``` ng build aql-builder --prod ``` ### KEYCLOAK Open a browser tab to localhost:8081/auth/admin and login to keycloak (admin/admin). Create, inside the ehrbase realm, a client named aqlbetter with client_id=aqlbetter, the urls set to http://localhost:4201 and Authentication and OAuth 2.0 Device Authorization Grant flagged on, choose client_id and client_secret as credentials and copy the newly created client_secret. Reset the ehrbase-admin password and copy it. client_secret and password for ehrbase-admin will be needed for the login form. ### RUN Run with: ``` ng serve aql-builder --port 4201 --prod ``` Open a browser tab to localhost:4201, fill the credentials and click "Start querying data". ## Acknowledgments This work has been partially funded by the following sources: