-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
382 lines (329 loc) · 12.2 KB
/
Taskfile.yml
File metadata and controls
382 lines (329 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# https://taskfile.dev
# Task runner for OpenEMR CLI Import Codes development
#
# SEPARATION OF CONCERNS:
# Taskfile: Infrastructure operations (Docker, database, CLI execution)
# Composer: Code quality checks (phpcs, phpstan, rector)
#
# WHY BOTH?
# - Composer scripts work in ANY environment (local, Docker, CI)
# - Taskfile provides convenience wrappers and Docker orchestration
# - Prevents bloated composer.json with Docker-specific commands
# - Taskfile can call Composer scripts (see check: tasks below)
#
# Installation: https://taskfile.dev/installation/
# macOS: brew install go-task
# Linux: sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
#
# Usage:
# task --list # Show all available tasks
# task dev:start # Start Docker environment
# task cli:run -- [args] # Run CLI import command
# task check # Run code quality checks (calls pre-commit/composer)
version: '3'
vars:
CLI_PATH: /var/www/localhost/htdocs/openemr/oce-cli-import-codes
OPENEMR_PATH: /var/www/localhost/htdocs/openemr
DB_USER: root
DB_PASS: root
DB_NAME: openemr
tasks:
default:
desc: Show available tasks
cmds:
- task --list
# === Docker Environment ===
dev:start:
desc: Start Docker development environment
cmds:
- docker compose up -d --wait
- echo "OpenEMR started. Get port with 'task dev:port'"
dev:stop:
desc: Stop Docker environment (keeps data)
cmds:
- docker compose down
- echo "Docker environment stopped"
dev:restart:
desc: Restart Docker environment
cmds:
- docker compose restart
- echo "Docker environment restarted"
dev:reset:
desc: Stop and remove all data (fresh start)
prompt: This will delete ALL data. Continue?
cmds:
- docker compose down -v
- echo "All data removed. Run 'task dev:start' to start fresh"
dev:purge:
desc: Stop and remove all containers, volumes, and orphans
prompt: This will DELETE all Docker containers, volumes, and orphans. Continue?
cmds:
- docker compose down -v --remove-orphans
- echo "Docker environment purged"
dev:has-volumes:
desc: Check if Docker volumes exist (returns 0 if exist, 1 if not)
internal: true
cmds:
- test -n "$(docker volume ls -q --filter name=oce-cli-import-codes)"
dev:logs:
desc: View OpenEMR logs (follow mode)
cmds:
- docker compose logs -f openemr
dev:logs:errors:
desc: View OpenEMR error logs only
cmds:
- docker compose logs -f openemr | grep -i error
dev:port:
desc: Get assigned port for OpenEMR
cmds:
- echo "OpenEMR HTTP port:"
- docker compose port openemr 80
- echo ""
- echo "Access OpenEMR at http://localhost:[PORT]"
- echo "Login - admin / pass"
dev:browse:
desc: Open OpenEMR in your default browser
cmds:
- |
HTTPS_PORT=$(docker compose port openemr 443 | cut -d: -f2)
if [ -z "$HTTPS_PORT" ]; then
echo "Could not detect HTTPS port. Is Docker running?"
exit 1
fi
URL="https://localhost:$HTTPS_PORT"
echo "Opening OpenEMR at $URL"
echo "Login credentials: admin / pass"
if command -v open > /dev/null 2>&1; then
open "$URL"
elif command -v xdg-open > /dev/null 2>&1; then
xdg-open "$URL"
else
echo "Could not find 'open' or 'xdg-open' command"
echo "Please open this URL manually: $URL"
fi
dev:shell:
desc: Access OpenEMR container shell
cmds:
- docker compose exec openemr bash
dev:status:
desc: Check Docker container status
cmds:
- docker compose ps
# === CLI Tool Execution ===
cli:run:
desc: 'Run the import codes CLI (usage: task cli:run -- /path/to/file.zip)'
cmds:
- docker compose exec openemr php {{.CLI_PATH}}/bin/oce-import-codes --openemr-path={{.OPENEMR_PATH}} {{.CLI_ARGS}}
cli:help:
desc: Show CLI help
cmds:
- docker compose exec openemr php {{.CLI_PATH}}/bin/oce-import-codes --help
cli:dry-run:
desc: 'Run CLI in dry-run mode (usage: task cli:dry-run -- /path/to/file.zip)'
cmds:
- docker compose exec openemr php {{.CLI_PATH}}/bin/oce-import-codes --openemr-path={{.OPENEMR_PATH}} --dry-run {{.CLI_ARGS}}
# === Database Access ===
db:shell:
desc: Access MariaDB database shell
cmds:
- docker compose exec mysql mariadb -u{{.DB_USER}} -p{{.DB_PASS}} {{.DB_NAME}}
db:export:
desc: Export database to backup.sql
cmds:
- docker compose exec mysql mariadb-dump -u{{.DB_USER}} -p{{.DB_PASS}} {{.DB_NAME}} > backup.sql
- echo "Database exported to backup.sql"
db:import:
desc: Import database from backup.sql
prompt: This will overwrite the current database. Continue?
cmds:
- docker compose exec -T mysql mariadb -u{{.DB_USER}} -p{{.DB_PASS}} {{.DB_NAME}} < backup.sql
- echo "Database imported from backup.sql"
db:query:
desc: 'Run a SQL query (usage: task db:query -- "SELECT * FROM users LIMIT 5")'
cmds:
- docker compose exec mysql mariadb -u{{.DB_USER}} -p{{.DB_PASS}} -e "{{.CLI_ARGS}}" {{.DB_NAME}} 2>&1 | grep -v "Using a password"
db:show-codes:
desc: Show loaded code types and counts
cmds:
- |
echo "code_type count"
echo "--------- -----"
for pair in "RXNORM:rxnconso" "SNOMED:sct_descriptions" "ICD10:icd10_dx_order_code" "ICD9:icd9_dx_code" "CQM_VALUESET:valueset"; do
name="${pair%%:*}"
table="${pair##*:}"
count=$(docker compose exec -T mysql mariadb -u{{.DB_USER}} -p{{.DB_PASS}} -N -e "SELECT COUNT(*) FROM $table" {{.DB_NAME}} 2>/dev/null | grep -v "Using a password" || echo "0")
echo "$name $count"
done
db:tracking:
desc: Show standardized tables tracking info
cmds:
- |
result=$(docker compose exec -T mysql mariadb -u{{.DB_USER}} -p{{.DB_PASS}} -e "SELECT * FROM standardized_tables_track ORDER BY imported_date DESC" {{.DB_NAME}} 2>&1 | { grep -v "Using a password" || true; })
if [ -z "$result" ]; then
echo "No vocabularies tracked yet."
else
echo "$result"
fi
db:clean-vocabs:
desc: 'Clean vocabulary tables and staging dirs (usage: task db:clean-vocabs -- ICD10 or task db:clean-vocabs for all)'
cmds:
- |
VOCAB="{{.CLI_ARGS}}"
# OpenEMR's temporary_files_dir is /tmp by default (check globals table)
TEMP_DIR="/tmp"
truncate_tables() {
local tables="$1"
for t in $tables; do
docker compose exec -T mysql mariadb -u{{.DB_USER}} -p{{.DB_PASS}} -e "TRUNCATE TABLE $t" {{.DB_NAME}} 2>/dev/null || true
done
}
clean_tracking() {
local name="$1"
docker compose exec -T mysql mariadb -u{{.DB_USER}} -p{{.DB_PASS}} -e "DELETE FROM standardized_tables_track WHERE name = '$name'" {{.DB_NAME}} 2>/dev/null
}
clean_staging() {
local dir="$1"
docker compose exec -T openemr rm -rf "$TEMP_DIR/$dir" 2>/dev/null || true
}
if [ -z "$VOCAB" ] || [ "$VOCAB" = "RXNORM" ]; then
echo "Cleaning RXNORM..."
truncate_tables "rxnconso rxnrel rxnatomarchive rxncui rxnsat rxnsty"
clean_tracking "RXNORM"
clean_staging "RXNORM"
fi
if [ -z "$VOCAB" ] || [ "$VOCAB" = "SNOMED" ]; then
echo "Cleaning SNOMED..."
truncate_tables "sct_descriptions sct_concepts sct_relationships"
clean_tracking "SNOMED"
clean_staging "SNOMED"
fi
if [ -z "$VOCAB" ] || [ "$VOCAB" = "ICD10" ]; then
echo "Cleaning ICD10..."
truncate_tables "icd10_dx_order_code icd10_pcs_order_code icd10_gem_dx_10_9 icd10_gem_dx_9_10 icd10_gem_pcs_10_9 icd10_gem_pcs_9_10 icd10_reimbr_dx_9_10 icd10_reimbr_pcs_9_10"
clean_tracking "ICD10"
clean_staging "ICD10"
fi
if [ -z "$VOCAB" ] || [ "$VOCAB" = "ICD9" ]; then
echo "Cleaning ICD9..."
truncate_tables "icd9_dx_code icd9_dx_long_code icd9_sg_code icd9_sg_long_code"
clean_tracking "ICD9"
clean_staging "ICD9"
fi
if [ -z "$VOCAB" ] || [ "$VOCAB" = "CQM_VALUESET" ]; then
echo "Cleaning CQM_VALUESET..."
truncate_tables "valueset"
clean_tracking "CQM_VALUESET"
clean_staging "CQM_VALUESET"
fi
echo "Done."
# === Code Quality (delegates to Composer scripts) ===
# These tasks call Composer scripts directly on the host (no Docker needed).
# You can also run `composer phpcs`, `composer phpstan`, etc. directly.
check:
desc: Run all code quality checks (calls pre-commit run -a)
cmds:
- pre-commit run -a
check:phpcs:
desc: Run PHP CodeSniffer (calls composer phpcs)
cmds:
- composer phpcs
check:phpstan:
desc: Run PHPStan (calls composer phpstan)
cmds:
- composer phpstan
check:fix:
desc: Auto-fix code style (calls composer phpcbf)
cmds:
- composer phpcbf
# === Testing ===
test:
desc: Run PHPUnit tests (unit tests only, runs locally)
cmds:
- composer test:unit
test:unit:
desc: Run unit tests only (no Docker required)
cmds:
- composer test:unit
test:integration:
desc: Run integration tests inside Docker (requires dev:start)
cmds:
- docker compose exec -w {{.CLI_PATH}} openemr php vendor/bin/phpunit -c phpunit-integration.xml --testsuite integration --testdox
test:e2e:
desc: Run e2e tests that load vocabs and verify DB state (requires dev:start)
cmds:
- docker compose exec -w {{.CLI_PATH}} openemr php vendor/bin/phpunit -c phpunit-integration.xml --testsuite e2e --testdox
test:all:
desc: Run all tests (unit locally, integration and e2e in Docker)
cmds:
- task: test:unit
- task: test:integration
- task: test:e2e
test:coverage:
desc: Run PHPUnit with coverage report
cmds:
- docker compose run --rm phpunit-coverage
test:docker:
desc: Run PHPUnit tests in Docker
cmds:
- docker compose run --rm phpunit
# === Development Helpers ===
composer:install:
desc: Install composer dependencies
cmds:
- composer install
- echo "Composer dependencies installed"
composer:update:
desc: Update composer dependencies
cmds:
- composer update
- echo "Composer dependencies updated"
openemr:prebuild:
desc: Pre-build OpenEMR dependencies (speeds up first Docker start)
cmds:
- echo "Building OpenEMR dependencies..."
- cd vendor/openemr/openemr && composer install --no-dev
- cd vendor/openemr/openemr && npm install --legacy-peer-deps
- cd vendor/openemr/openemr && npm run build
- echo "OpenEMR dependencies built"
git:clean:
desc: Run git clean (remove untracked files, preserves .local/)
prompt: This will delete untracked files (except .local/). Continue?
cmds:
- git clean -fd -e .local
- echo "Untracked files removed (preserved .local/)"
vendor:clean:
desc: Remove vendor directory (forces complete reinstall of dependencies)
prompt: This will DELETE the entire vendor directory. Continue?
preconditions:
- sh: test -z "$(docker volume ls -q --filter name=oce-cli-import-codes 2>/dev/null)"
msg: |
Docker volumes still exist. You must run 'task dev:purge' first.
Reason: OpenEMR stores crypto keys in both the database (volume) and filesystem (vendor).
Removing vendor without removing volumes will break encryption and make the database unusable.
Run: task workflow:nuke (to remove both) or task dev:purge (then task vendor:clean)
cmds:
- git clean -ffdx vendor/
- echo "Vendor directory removed"
# === Quick Workflows ===
setup:
desc: Complete setup (install deps, prebuild OpenEMR, start Docker)
cmds:
- task: composer:install
- task: openemr:prebuild
- task: dev:start
- task: dev:port
workflow:reset:
desc: Complete reset (stop, clean data, restart)
cmds:
- task: dev:reset
- task: dev:start
- echo ""
- echo "Environment reset complete"
- task: dev:port
workflow:nuke:
desc: Nuclear reset (removes vendor + database volumes, forces complete reinstall)
cmds:
- task: dev:purge
- task: vendor:clean
- echo "Complete reset done. Vendor removed, Docker volumes deleted."
- echo " Run 'task setup' to rebuild from scratch."