520 Commits

Author SHA1 Message Date
70d5b78ca8 wip 2025-09-28 07:26:46 +03:00
e4fcafa57c feat(MED-97): add dev key for medusa benefits payment 2025-09-26 17:23:23 +03:00
f794a66147 feat(MED-97): fix new OpenAI() throws error when key is missing in env 2025-09-26 17:01:56 +03:00
6bdf5fbf12 feat(MED-97): fix duplicate element 2025-09-26 17:01:35 +03:00
c6a1400dc7 Merge branch 'develop' into MED-97 2025-09-26 17:01:24 +03:00
danelkungla
aef772c6b1 MED-102: improve tto orders view
MED-102
2025-09-26 16:39:29 +03:00
2d9e6f8df3 feat(MED-97): display accounts count, usage total 2025-09-26 16:34:10 +03:00
Danel Kungla
c99beea46a add openai validation 2025-09-26 16:18:50 +03:00
Danel Kungla
bfdd1ec62a add tto order 2025-09-26 15:58:25 +03:00
27689dbbff feat(MED-97): hide company logo upload if it doesn't work 2025-09-26 15:46:52 +03:00
a68f7c7ab5 feat(MED-97): save benefit_distribution_schedule_id to account_balance_entries 2025-09-26 15:46:32 +03:00
92dd792121 feat(MED-97): update translations in each language 2025-09-26 15:46:01 +03:00
eb6ef2abe1 feat(MED-97): show benefits amount for each member 2025-09-26 15:39:33 +03:00
428cbd9477 feat(MED-97): small fixes 2025-09-26 15:37:47 +03:00
0aa16c457a feat(MED-97): make sure new company employee accounts get benefits balance 2025-09-26 13:50:33 +03:00
1aeee0bc30 feat(MED-97): update benefit stats view in dashboards 2025-09-26 13:50:14 +03:00
fdc2e3e064 feat(MED-97): show person name instead of keycloak email in company invite form 2025-09-26 13:26:58 +03:00
beeea33842 feat(MED-97): use spinner in order confirmed view and wait for payment to be captured in webhook 2025-09-26 13:25:23 +03:00
4ed3924907 feat(MED-97): update orders page to load more than 10 orders 2025-09-26 13:24:36 +03:00
db38e602aa feat(MED-97): update cart flow for using benefits 2025-09-26 13:24:09 +03:00
56f84a003c feat(MED-97): move shared order placing logic to cart-actions 2025-09-26 09:47:28 +03:00
579ec7547e feat(MED-97): fix client type 2025-09-26 09:45:35 +03:00
f091ed5b49 feat(MED-97): update team account navigation links 2025-09-26 09:45:18 +03:00
fc63b9e7b7 feat(MED-97): move order status updating to user-analyses feature pkg 2025-09-26 09:43:49 +03:00
Danel Kungla
0a61371271 refactor env 2025-09-25 18:07:10 +03:00
Danel Kungla
1acde486f2 add dynamic export 2025-09-25 17:42:53 +03:00
Danel Kungla
0f2bfb74b4 disable revalidatePath for home/cart 2025-09-25 17:24:44 +03:00
Danel Kungla
2188b73f54 recreated montonio env 2025-09-25 17:11:00 +03:00
Danel Kungla
85c6621b7a use env 2025-09-25 16:11:08 +03:00
Danel Kungla
c69a1af094 added CONNECTED_ONLINE_URL env 2025-09-25 16:06:34 +03:00
danelkungla
1e02cd99bc MED-103: create connected api job
MED-103: create job
2025-09-25 15:52:28 +03:00
Danel Kungla
5d88121e78 refactor demo clinic condition 2025-09-25 15:51:43 +03:00
Danel Kungla
2e2498577f MED-103: create job 2025-09-25 15:40:37 +03:00
Danel Kungla
6c3ae1eda6 MED-102: clean order page for tto orders 2025-09-25 15:30:07 +03:00
danelkungla
5dc625c903 MED-129 + MED-103: add shopping cart functionality for TTO services
MED-129 + MED-103: add shopping cart functionality for TTO services
2025-09-24 18:49:10 +03:00
Danel Kungla
6c6e7a6847 fix conflict duplicates 2025-09-24 18:45:29 +03:00
Danel Kungla
c7298d2b7e refactor 2025-09-24 16:54:36 +03:00
b4cdc08532 fix circular dependency due to index.ts import/export all same files 2025-09-24 16:48:55 +03:00
cf9a51e64f rerun pipeline for updated aws parameters 2025-09-24 15:27:31 +03:00
Danel Kungla
41593be44a fix types 2025-09-24 15:14:13 +03:00
Danel Kungla
1275f23bb1 Merge branch 'develop' into feature/MED-129 2025-09-24 15:00:57 +03:00
Danel Kungla
7817ae0448 Merge branch 'develop' into feature/MED-129 2025-09-24 15:00:27 +03:00
a520c04a02 feat(MED-97): clean up 2025-09-24 14:58:07 +03:00
07237dece6 feat(MED-97): clean up 2025-09-24 14:57:52 +03:00
dc35c3d43e Merge pull request #106 from MR-medreport/MED-97
feat(MED-97): migrations fix timestamps
2025-09-24 14:55:43 +03:00
7830b92571 feat(MED-97): migrations fix timestamps 2025-09-24 14:54:53 +03:00
4c003b3cb5 Merge pull request #105 from MR-medreport/MED-97
feat(MED-97): create company benefits tables; company, superadmin view fixes
2025-09-24 12:57:42 +03:00
ddd1728e4e feat(MED-97): allow different card heading sizes 2025-09-24 12:44:47 +03:00
4b44ead3ff feat(MED-97): create company benefits tables 2025-09-24 12:43:54 +03:00
f1eb0e1ebf feat(MED-97): fix missing breadcrumbs, consistent layouts 2025-09-23 20:27:20 +03:00
fb03d548af feat(MED-97): fix occurance->occurrence in components, add missing translations 2025-09-23 20:03:36 +03:00
8af2c8710f feat(MED-97): fix display account name instead of slug 2025-09-23 19:52:49 +03:00
3212b52b02 feat(MED-97): fix /home/[account] and /admin* routes layout consistencies 2025-09-23 19:22:40 +03:00
f0853409c8 fix monitoring dependency missing 2025-09-23 17:30:07 +03:00
e92120654b fix db function 2025-09-23 17:29:50 +03:00
Danel Kungla
2f22b6c88f fix sql 2025-09-23 17:18:49 +03:00
Danel Kungla
40b7a98c57 dont render if env is missing 2025-09-23 16:48:23 +03:00
cd3d2586f7 fix constraint 2025-09-23 16:24:59 +03:00
Danel Kungla
8794bf998c add try catch for openai responses api 2025-09-23 16:08:07 +03:00
edba074b38 fix medipost_actions constraint 2025-09-23 16:05:11 +03:00
Danel Kungla
6492421c0d add prompt id to env 2025-09-23 15:34:41 +03:00
danelkungla
e6ccb85c34 MED-157: openai analyses recomendations
MED-157: openai analyses recomendations
2025-09-23 15:14:24 +03:00
Danel Kungla
df850cf1b2 update skeleton 2025-09-23 15:13:48 +03:00
Danel Kungla
4afc498cd7 feedback fix 2025-09-23 14:33:48 +03:00
Danel Kungla
4962ba8ec2 add real data to ai 2025-09-23 14:27:41 +03:00
4b4a7097ae rerun pipeline for updated aws medipost values 2025-09-23 13:32:10 +03:00
Danel Kungla
258e18e6a6 Merge branch 'develop' into MED-157 2025-09-23 11:03:54 +03:00
danelkungla
e3adae69bd Use eslint config for whole project
Add eslint
2025-09-23 10:58:09 +03:00
Danel Kungla
1fdbaf1bd5 run prettier fix 2025-09-23 10:57:28 +03:00
Danel Kungla
63ede85668 Merge branch 'develop' into add-eslint 2025-09-23 10:56:41 +03:00
Danel Kungla
3dd82902fe log recommendations 2025-09-23 10:50:20 +03:00
Karli
f47a9e75e2 update types matching in test responses 2025-09-22 15:55:15 +03:00
Karli
428a1dfb87 don't upsert if audit log doesn't have medipost_private_message_id, improve logging 2025-09-22 15:31:06 +03:00
Danel Kungla
fee8534fcc Merge branch 'develop' into MED-157 2025-09-20 18:44:10 +03:00
Danel Kungla
643e67e2a1 update type 2025-09-20 18:42:18 +03:00
Danel Kungla
5f0ca6bdae add ai_tables 2025-09-20 18:12:34 +03:00
Danel Kungla
a52a9bec06 add api 2025-09-20 18:12:15 +03:00
Danel Kungla
9ed52dcf02 add readme
delete unrequired configs
2025-09-19 18:07:31 +03:00
Helena
249611886b remove unused import 2025-09-19 17:30:32 +03:00
Helena
961f726520 translations, remove random empty lines, refactor 2025-09-19 17:28:45 +03:00
Danel Kungla
0c2cfe6d18 prettier fix 2025-09-19 17:22:36 +03:00
Danel Kungla
efa94b3322 Merge branch 'develop' into add-eslint 2025-09-19 17:00:44 +03:00
Danel Kungla
c6c0fe0a09 Merge branch 'develop' into add-eslint 2025-09-19 17:00:18 +03:00
Danel Kungla
78221c4267 eslint refactor 2025-09-19 16:59:52 +03:00
Danel Kungla
addd3a5dae send analyses to ai 2025-09-19 16:54:21 +03:00
Helena
c50b75ce9b merge 2025-09-19 16:27:40 +03:00
Helena
b59148630a add cart functionality for tto services 2025-09-19 16:23:19 +03:00
d86495d7f7 Merge pull request #100 from MR-medreport/MED-168-fixes
feat(MED-168): analysis results view improvements / fixes
2025-09-19 15:30:30 +03:00
ffd8cc1b3f feat(MED-168): mark order as completed if more than expected response elements come from post 2025-09-19 15:29:23 +03:00
71a9ff75c4 feat(MED-168): improve styles 2025-09-19 15:29:07 +03:00
afdaebc804 feat(MED-168): clean up types 2025-09-19 15:29:04 +03:00
47bbeeb155 feat(MED-168): remove unused field 2025-09-19 15:29:01 +03:00
091144d942 feat(MED-168): clean up types, show nested elements 2025-09-19 15:28:56 +03:00
e7b484e1d4 feat(MED-168): move analysis result element mapping to shared 2025-09-19 15:28:41 +03:00
81f7a03388 feat(MED-168): disable useless console logs on browserside, too many logs 2025-09-19 15:28:37 +03:00
c37706f6a9 feat(MED-168): separate user analysis results building 2025-09-19 15:28:34 +03:00
08b27b022f feat(MED-168): move toArray to shared utils 2025-09-19 15:28:23 +03:00
Helena
3c272505d6 various minor changes 2025-09-19 10:18:18 +03:00
2bdd54e649 Merge pull request #98 from MR-medreport/MED-168
feat(MED-168): keep medipost response data unique, no need for duplicate rows
2025-09-18 16:59:07 +03:00
54209553ec feat(MED-168): update analysis results display 2025-09-18 16:42:12 +03:00
d99016aa5e feat(MED-168): keep medipost response data unique, no need for duplicate rows 2025-09-18 16:41:05 +03:00
Helena
f0fbca832d use cn 2025-09-18 16:40:25 +03:00
Helena
2f470d3531 revert some whitespace changes for better readability 2025-09-18 10:24:47 +03:00
Helena
71f3aed875 move booking calendar to separate file 2025-09-18 10:17:24 +03:00
Helena
3f3fbad556 mobile improvements 2025-09-18 10:17:07 +03:00
Helena
d85b028bda fix broken import 2025-09-18 09:48:26 +03:00
Helena
db2ccd0f57 log page views 2025-09-18 09:45:09 +03:00
Helena
4bd88f1b4e clean up 2025-09-17 18:23:25 +03:00
Helena
cd55ddf3f8 Merge branch 'develop' of https://github.com/MR-medreport/MRB2B into MED-103 2025-09-17 18:17:01 +03:00
Helena
22f7fa134b MED-103: add booking functionality 2025-09-17 18:11:13 +03:00
Danel Kungla
1b634f9736 add analysis recommendation 2025-09-17 17:35:04 +03:00
Danel Kungla
b96ef47b2d Merge branch 'develop' into MED-157 2025-09-17 11:52:35 +03:00
Danel Kungla
cb32ee5339 Merge branch 'develop' into MED-157 2025-09-17 11:52:04 +03:00
Danel Kungla
f7f0e5e48f add openai package 2025-09-17 11:51:39 +03:00
a243bd4769 improve nested elements null filtering 2025-09-17 11:48:49 +03:00
924e89c714 remove console log 2025-09-17 11:47:51 +03:00
be6e3b6960 Merge pull request #97 from MR-medreport/improvements-1709
feat: improvements for medipost service xml building, analysis results view, add jest
2025-09-17 08:29:14 +00:00
8a7d88d645 feat(MED-161): no need for default value as it's only used in one place 2025-09-17 11:28:32 +03:00
5c4831c5af feat(MED-161): add extra log 2025-09-17 11:19:27 +03:00
4302ddb90e feat(MED-161): add jest for service tests 2025-09-17 11:17:50 +03:00
64acdfcbbb feat(MED-161): add test analysis results page for different cases 2025-09-17 11:17:43 +03:00
bfadf56173 feat(MED-161): update analysis results view 2025-09-17 11:17:36 +03:00
2019c2c1fc feat(MED-161): update sync private message 2025-09-17 11:17:30 +03:00
ecc8c2b982 feat(MED-161): update results sync validations 2025-09-17 11:17:23 +03:00
b729ad9ffa feat(MED-161): add feature flag for delete private messages 2025-09-17 11:17:15 +03:00
4560d2df1d feat(MED-161): use shared types 2025-09-17 11:17:08 +03:00
4ac261fd0d feat(MED-161): move analyses logic to separate package from kit/accounts 2025-09-17 11:16:59 +03:00
e7650e3c32 feat(MED-161): move type to types file 2025-09-17 11:16:50 +03:00
afac628bcf feat(MED-161): move analysis types separately from accounts types 2025-09-17 11:16:42 +03:00
20a497938e feat(MED-161): delete unused loader 2025-09-17 11:16:35 +03:00
7870b8840a feat(MED-161): allow syncing new analyses for existing groups 2025-09-17 11:16:27 +03:00
e5822fd55d feat(MED-161): improve query 2025-09-17 11:16:18 +03:00
c51808d899 feat(MED-161): separate doctor analysis view 2025-09-17 11:16:09 +03:00
46774b286e feat(MED-161): return with type in getAnalysisOrder 2025-09-17 11:16:00 +03:00
7af6aa438e feat(MED-161): store more fields about medipost analysis response 2025-09-17 11:15:55 +03:00
cee37178df feat(MED-161): create analysis-order service 2025-09-17 11:15:44 +03:00
000cad7f05 feat(MED-161): move medipost services to medipost package 2025-09-17 11:15:26 +03:00
0d08592a9a feat(MED-161): move medipost publicmessage logic to separate service 2025-09-17 11:15:16 +03:00
19631fb2db feat(MED-161): delete unused functions 2025-09-17 11:15:08 +03:00
a788e8b587 feat(MED-161): move medipost privatemessage logic to separate service 2025-09-17 11:14:54 +03:00
33a6c92841 feat(MED-161): create medipost common service 2025-09-17 11:14:45 +03:00
a229ab4d31 feat(MED-161): move medipost xml validate to separate service 2025-09-17 11:14:33 +03:00
eda21b8a99 Merge pull request #96 from MR-medreport/analysis-xml-fix-1109
small fixes for dev
2025-09-16 11:32:54 +00:00
16b4589330 fix BO account check in case account id refers to deleted BO account 2025-09-16 14:32:04 +03:00
7e9e1ce3a0 improve styles 2025-09-16 14:31:11 +03:00
Danel Kungla
14252c3efd MED-159: add profile icon to mobile menu 2025-09-16 13:52:24 +03:00
Danel Kungla
cbdcc061d5 fix visual bugs with udate-account-form 2025-09-16 11:21:13 +03:00
Danel Kungla
0b7829be8b weight and height default values to null 2025-09-15 19:03:59 +03:00
Danel Kungla
74edc6c679 add user consent url 2025-09-12 18:34:45 +03:00
3525a5ccd2 fix analysis package button alignment with short subtitle text 2025-09-12 15:33:13 +03:00
781a21aef4 Merge pull request #93 from MR-medreport/analysis-xml-fix-1109
fix sending multiple analysis elements for same material group with different <Proov> data
2025-09-12 10:55:04 +00:00
74c176912b fix sending multiple analysis elements for same material group with different <Proov> data 2025-09-12 12:46:46 +03:00
Helena
7c92b787ce Merge branch 'develop' of https://github.com/MR-medreport/MRB2B into MED-103 2025-09-11 10:09:37 +03:00
Helena
99e62b91a5 use analysis order id as valis tellimuse id (#92)
* use order analysis id as valis tellimuse id

* send analysis order id in xml
2025-09-10 16:54:12 +03:00
Helena
b31de91daf Merge branch 'develop' of https://github.com/MR-medreport/MRB2B into develop 2025-09-10 12:40:23 +03:00
Helena
0e7e0b0ed6 fix translation 2025-09-10 12:37:39 +03:00
Danel Kungla
da6acd8756 change design for analysis-package button 2025-09-10 12:21:43 +03:00
745ba874b6 Merge pull request #89 from MR-medreport/updates-for-live-0909
fix package analyses count should include variant count
2025-09-10 07:13:03 +00:00
e324d6c5d1 fix package analyses count should include variant count 2025-09-10 10:11:14 +03:00
6b1f93c317 Merge pull request #87 from MR-medreport/updates-for-live-0909
updates for live; auth provider changes, smaller fixes for styles/etc
2025-09-10 04:14:40 +00:00
96f82444a7 show 2fa secret as text also (example: adding to bitwarden) 2025-09-10 07:12:05 +03:00
0328e518b6 improve some texts + styles 2025-09-10 07:11:18 +03:00
0c764f82e5 add missing i18n schema for page 2025-09-10 07:10:06 +03:00
4f99e32009 fix error boundary flashing on signout action 2025-09-10 06:42:39 +03:00
e0adc2fb68 remove temp data with TODO 2025-09-10 06:42:14 +03:00
76433684e7 improve cart mobile styles 2025-09-10 06:34:34 +03:00
8b3e58e833 improve signup container 2025-09-10 06:34:27 +03:00
b8a8eab87c update order details view, translations 2025-09-10 06:34:18 +03:00
fa0bbe64fb update account form for email login 2025-09-10 06:34:05 +03:00
e3cdba6a7c show less update-account fields on email login 2025-09-10 06:33:56 +03:00
312027b9ed avoid too many duplicate requireUserInServerComponent requests for each page+layout 2025-09-10 06:33:44 +03:00
2aad0329f3 update cart discount for prod build, add loading toast 2025-09-10 06:32:55 +03:00
229b3d7c27 fix warnings on cart page refresh 2025-09-10 06:32:48 +03:00
cb11244d79 improve order analyses cards 2025-09-10 06:32:41 +03:00
fa9895637d add env to turn off automatic medipost sending on montonio callback 2025-09-10 06:32:25 +03:00
0aea6b80d4 sent time in medipost xml can be different from order creation time 2025-09-10 06:31:49 +03:00
be33b892f5 only show checks for analysis elements explicitly in current package 2025-09-10 06:31:39 +03:00
7bc89f7c22 no need to show "select-package" page after onboading if it has nothing 2025-09-10 06:31:32 +03:00
95452de88b prefer using providers conf from supabase instead of env 2025-09-10 06:31:23 +03:00
9f9508233d Merge pull request #86 from MR-medreport/keycloak-improvements-0909
fix case when variant has no metadata and no package elements are displayed
2025-09-09 12:50:16 +00:00
danelkungla
478eef3681 MED-154: redirect homepage to website in production. support lang param
MED-154: redirect homepage to website in production. support lang param
2025-09-09 15:49:16 +03:00
831e60c3c1 fix case when variant has no metadata and no package elements are displayed 2025-09-09 15:48:02 +03:00
Danel Kungla
86a5931b66 update condition for production redirect 2025-09-09 15:25:31 +03:00
0f16c6552f Merge pull request #84 from MR-medreport/keycloak-improvements-0909
improve namings; improve logging for orders without analysis packages
2025-09-09 11:55:43 +00:00
165d44b13f prepare montonio callback logic to send email for individual analysis order
- skip confusing error log for orders without analysis packages
2025-09-09 14:02:34 +03:00
7d208b41f2 update naming to be clearer 2025-09-09 14:01:19 +03:00
Danel Kungla
ebab0556ba change else to else if 2025-09-09 12:39:00 +03:00
Danel Kungla
514cb3bf7b redirect homepage to website in production. support lang param 2025-09-09 12:36:19 +03:00
0281298b0c Merge pull request #82 from MR-medreport/keycloak-improvements-0909
add missing translations
2025-09-09 09:36:05 +00:00
85c72e777b add missing translations 2025-09-09 12:05:03 +03:00
Danel Kungla
1283094a91 newer pino-pretty@13.1.1 has new strip-json-comments version that conflicts with others and causes error 2025-09-09 11:56:52 +03:00
Helena
ca13e9e30a MED-82: add patient notification emails (#74)
* MED-82: add patient notification emails

* remove console.log

* clean up

* remove extra paragraph from email
2025-09-09 10:37:22 +03:00
d00449da29 Merge pull request #80 from MR-medreport/keycloak-improvements-0909
some small fixes/improvements for update-account-form, medipost-xml, analysis packages
2025-09-09 07:00:48 +00:00
c0e9cf5e25 fix value with new types 2025-09-09 09:57:01 +03:00
fd94320295 use analysisElementMedusaProductIds from order product selected variant if it exists 2025-09-09 09:56:57 +03:00
596d0e9eee fix missing month for DoB in medipost xml 2025-09-09 09:56:47 +03:00
1d641211b6 update for new type 2025-09-09 09:56:44 +03:00
06154f24bf fix: deduplicate specimen elements in medipost XML generation
- Fix duplicate <Proov> elements when multiple analysis elements use same material type
- Ensure analysis elements reference correct specimen order numbers
- Move XML composition logic to separate service for better separation of concerns
2025-09-09 09:56:39 +03:00
f00899c456 move medipost xml to separate service to be unit tested 2025-09-09 09:56:34 +03:00
c2896d77b0 prefill phone field in update-account form 2025-09-09 09:56:31 +03:00
353e5c3c4b update types 2025-09-09 09:56:23 +03:00
3bdc1cfefc update personal code util 2025-09-09 09:56:19 +03:00
5b91ece1ec sort compare packages modal analyses by title 2025-09-09 09:56:16 +03:00
0e063cd5dc 'medreport.update_account' should also update email 2025-09-09 09:56:12 +03:00
2c63875806 fix typo 2025-09-09 09:56:09 +03:00
0081e8948b move most isikukood.js usage to utils 2025-09-09 09:56:03 +03:00
ccdfd5872b retry pipeline 2025-09-08 13:37:47 +03:00
321c85bc9c Merge pull request #79 from MR-medreport/keycloak-updates-v2
update login/signup/update-account for keycloak
2025-09-08 08:25:19 +00:00
Helena
422b0d5856 Merge branch 'develop' of https://github.com/MR-medreport/MRB2B into MED-103 2025-09-08 09:36:46 +03:00
aa441d4055 update medreport.accounts with keycloak data when supabase auth.user is created 2025-09-08 01:05:02 +03:00
c882a24415 update envs for keycloak 2025-09-08 01:04:37 +03:00
077aaee181 handle keycloak user prefills in update-account form 2025-09-08 01:03:17 +03:00
57a998d215 fix NaN for bmi when divide-by-zero 2025-09-08 01:02:42 +03:00
f01829de96 update keycloak signup / login 2025-09-08 01:02:10 +03:00
7815a1c011 add phone number validation to update account form 2025-09-08 00:59:17 +03:00
96eea95fb9 fix password signup not redirecting to update-account view 2025-09-08 00:58:34 +03:00
6495d1c4a3 fix toTitleCase 2025-09-08 00:58:02 +03:00
a9612ad992 remove useless await 2025-09-08 00:57:38 +03:00
ab2176bc69 fix analyses loading 2025-09-08 00:57:28 +03:00
a89d8d3153 fix whitespace 2025-09-08 00:57:18 +03:00
1b29cb222b prefer pathsConfig urls 2025-09-08 00:56:55 +03:00
dfcfdb8f97 Merge pull request #76 from MR-medreport/improvements-0609
update order xml for live, allow adding discounts in cart
2025-09-06 19:58:59 +00:00
d87d08aaea Merge pull request #75 from MR-medreport/main
main <-> develop
2025-09-06 19:57:59 +00:00
c83694222d allow adding discounts in cart 2025-09-06 22:56:54 +03:00
c08fe26b36 remove comments from order xml 2025-09-05 15:13:14 +03:00
d3202a2cb2 remove comments from order xml 2025-09-05 15:12:58 +03:00
2435e6f113 update medipost order xml for live 2025-09-05 15:09:27 +03:00
54856b0e45 update medipost order xml for live 2025-09-05 15:09:11 +03:00
95e72bb3f8 log out of medusa and reset cart on supabase logout 2025-09-05 14:15:03 +03:00
3d268b6061 retry initial dockerfile 2025-09-05 14:09:02 +03:00
5c6280ec42 retry updated dockerfile 2025-09-05 14:01:22 +03:00
0de9dcf7e3 retry 2025-09-05 13:49:52 +03:00
f3a6fb627c react compiler uses too much memory 2025-09-05 13:39:04 +03:00
c1746c6c20 retry 2025-09-05 13:20:17 +03:00
c6f56f6e11 retry pipeline with updated parameters 2025-09-05 12:54:58 +03:00
a6b246cdf3 improve dockerfile 2025-09-05 12:52:06 +03:00
a705dea9cf retry 2025-09-05 12:19:00 +03:00
8485d2e9a3 retry 2025-09-05 12:11:34 +03:00
c356f69656 retry 2025-09-05 12:03:26 +03:00
cacd23be40 layer cache before envs 2025-09-05 11:53:39 +03:00
f8765dce49 update dockerfile 2025-09-05 11:44:25 +03:00
42bebb6d93 all needed variables in buildtime 2025-09-05 11:39:12 +03:00
354a0c04ee prefer to use env from parameter store 2025-09-05 01:44:05 +03:00
72bb9a33ef Merge branch 'develop' 2025-09-05 01:39:25 +03:00
771c28f8ef rerun codepipeline 2025-09-04 17:07:52 +03:00
Danel Kungla
e9497c3d52 update staging env 2025-09-04 14:26:21 +03:00
70188f297f Merge pull request #73 from MR-medreport/develop
develop -> main
2025-09-04 10:42:33 +00:00
e0940a1600 allow transferCart to fail on register 2025-09-04 13:41:21 +03:00
65eb6c780d allow transferCart to fail on login/register 2025-09-04 13:20:12 +03:00
6e9cde6b95 medusa product can have either analysiselement or analysis originalId 2025-09-04 13:20:09 +03:00
3a062eaa9c hide dashboard recommendations block 2025-09-04 13:20:05 +03:00
c07acb85a2 fix tooltip should wrap long text 2025-09-04 13:20:02 +03:00
5c8f8b73d7 try to display price before adding to cart 2025-09-04 12:39:24 +03:00
5b52da0a62 fix adding to cart loading 2025-09-04 12:39:21 +03:00
Helena
21375cf55f MED-149: add more estonian translations (#72) 2025-09-04 12:38:46 +03:00
Helena
9122acc89f MED-151: add profile view and working smoking dashboard card (#71)
* MED-151: add profile view and working smoking dashboard card

* update zod

* move some components to shared

* move some components to shared

* remove console.logs

* remove unused password form components

* only check null for variant

* use pathsconfig
2025-09-04 12:17:54 +03:00
Danel Kungla
152ec5f36b fix query response cant be undefined 2025-09-04 10:59:34 +03:00
Danel Kungla
5176ecdddc hide search and wallet 2025-09-04 10:56:24 +03:00
1de564b917 rerun codepipeline 2025-09-03 15:15:02 +03:00
a2c080914a Merge branch 'develop' 2025-09-03 13:32:15 +03:00
40ffbf29a5 improve analyses sync error logging 2025-09-03 13:31:43 +03:00
b046b6ab16 use recipient from env as it's different in live 2025-09-03 13:31:41 +03:00
Danel Kungla
8cb9d7552c add Supabase configuration to staging environment and update Dockerfile to include .env.staging 2025-09-03 12:46:39 +03:00
Danel Kungla
cdb638f046 remove Supabase configuration from production environment variables 2025-09-03 10:04:56 +03:00
Danel Kungla
f7514c698e feat: implement booking feature with service and time slot selection 2025-09-03 10:04:00 +03:00
Danel Kungla
a587b222b9 updated supabase parameters for test 2025-09-02 17:52:47 +03:00
Danel Kungla
612673ddf9 add redirect for authenticated users to home page in middleware 2025-09-02 16:25:27 +03:00
Danel Kungla
3230dd7608 updated medusa publishable key env 2025-09-02 14:01:19 +03:00
Danel Kungla
e4d7c874cc updated medusa publishable key env 2025-09-02 13:13:21 +03:00
Helena
b7926f79a9 MED-89: add analysis view with doctor summary (#68)
* add analysis view with doctor summary

* remove console.log, also return null if analysis data missing

* replace orders table eye with button
2025-09-02 12:18:18 +03:00
Helena
9d62a2d86f MED-140: ui fixes (#69)
* MED-140: ui fixes

* make accountid optional in hook
2025-09-02 12:14:24 +03:00
Helena
3498406a0c MED-88: add doctor email notifications (#65)
* MED-88: add doctor email notifications

* add logging, send open jobs notification on partial analysis response

* update permissions

* fix import, permissions

* casing, let email be null

* unused import
2025-09-02 12:14:01 +03:00
Helena
56a832b96b MED-75: add russian translations (#70) 2025-09-02 11:53:30 +03:00
Danel Kungla
568104eaff updated test envs in aws 2025-09-01 23:25:24 +03:00
Danel Kungla
2eac3a6836 updated test envs in aws 2025-09-01 18:07:54 +03:00
2df366c14a feat(MED-121): fix variant age range check 2025-09-01 14:29:14 +03:00
Danel Kungla
6ce60eacc7 Add data.sql to .gitignore 2025-08-29 18:05:51 +03:00
Danel Kungla
94dd00b9ca Add data.sql to .gitignore 2025-08-29 18:05:29 +03:00
danelkungla
6e76e75e85 Merge pull request #66 from MR-medreport/main
Main
2025-08-29 16:17:54 +03:00
71c3e2ef1e Merge pull request #64 from MR-medreport/MED-85
feat(MED-85-105-123): some testing feedback, other improvements
2025-08-29 11:52:55 +03:00
d83319a094 Merge branch 'main' into MED-85 2025-08-29 11:45:36 +03:00
Helena
505ef0d91b Merge branch 'main' of https://github.com/MR-medreport/MRB2B 2025-08-29 10:28:15 +03:00
Helena
fce4355be8 Merge branch 'main' of https://github.com/MR-medreport/MRB2B 2025-08-29 10:27:46 +03:00
Helena
da9658ad7a fix email button 2025-08-29 10:27:12 +03:00
danelkungla
e023d54a2a Merge pull request #63 from MR-medreport/main
update develop
2025-08-29 09:50:32 +03:00
danelkungla
bdaacbe78a MED-104: booking page
MED-104
2025-08-29 09:48:26 +03:00
Danel Kungla
5479f310d7 Merge branch 'main' into MED-104 2025-08-29 09:46:04 +03:00
Helena
5cf29447b3 add email sender 2025-08-28 18:03:28 +03:00
Helena
7d1400fba6 log email result and subject 2025-08-28 17:30:32 +03:00
Helena
5ee161f482 remove html length limit from emails 2025-08-28 16:47:27 +03:00
815b877b5b Merge branch 'main' into MED-85 2025-08-28 16:12:46 +03:00
4588d11d5a feat(MED-86): don't prettify results sync log since aws will split it up 2025-08-28 15:49:30 +03:00
e0688eb539 feat(MED-86): fix status check for fake responses 2025-08-28 15:49:12 +03:00
0c28f9681b feat(MED-86): fix status check for fake responses 2025-08-28 15:49:03 +03:00
70b85dc967 feat(MED-86): don't prettify results sync log since aws will split it up 2025-08-28 15:37:29 +03:00
71f5a25632 Merge branch 'main' into MED-85 2025-08-28 14:57:09 +03:00
d072226a5c feat(MED-105): organize env specific required migrations 2025-08-28 14:54:51 +03:00
da7f574234 feat(MED-86): user can see in Medusa BO if sending order to medipost succeeded 2025-08-28 14:42:07 +03:00
b3505c1627 feat(MED-100): show cart line item quantities total instead of items total count 2025-08-28 14:41:59 +03:00
Danel Kungla
ad28352fc8 MED-104: create booking view with categories 2025-08-28 14:11:54 +03:00
b931035c3b feat(MED-86): add db fn to show medipost dispatch error for order in Medusa 2025-08-28 13:36:07 +03:00
f723633646 feat(MED-123): don't redirect to cart on single analysis select 2025-08-28 13:31:29 +03:00
6e6ad13b52 feat(MED-123): show toast on adding analysis package to cart 2025-08-28 13:30:25 +03:00
Danel Kungla
31bc4b6cff initial commit 2025-08-28 13:15:39 +03:00
Helena
86dc221cc6 MED-145: send notification to patient when summary completed (#61)
* MED-145: send notification to patient when summary completed

* MED-145: send notification to patient when summary completed

* use aliased imports where possible, revert cart service urls

* save language preference to local db

* remove unnecessary optional chaning
2025-08-28 13:05:07 +03:00
3ddc0a2716 feat(MED-123): show toast on adding analysis to cart 2025-08-28 12:44:07 +03:00
49eeaa1876 feat(MED-123): update translations 2025-08-28 12:40:33 +03:00
2ffad84100 feat(MED-105): log opening analysis results from orders view 2025-08-28 12:35:30 +03:00
b4985afdf0 feat(MED-85): add logging for medipost response error xml 2025-08-28 12:25:18 +03:00
a37c4cad9c feat(MED-85): add logging for medipost actions with xml and related order id 2025-08-28 11:56:07 +03:00
47ab39172e feat(MED-85): run sending fake medipost results in dev from Medusa BO 2025-08-28 10:30:43 +03:00
d760f86632 feat(MED-85): run force medipost results sync from Medusa BO 2025-08-28 09:54:32 +03:00
Helena
5159325e6d fix missing id 2025-08-27 09:11:21 +03:00
794d5b7079 Merge pull request #60 from MR-medreport/MED-85
feat(MED-85): testing feedback updates, some fixes+improvements
2025-08-27 08:40:25 +03:00
a547503887 Merge branch 'main' into MED-85 2025-08-27 08:31:26 +03:00
94439432fd feat(MED-85): improve naming 2025-08-27 08:29:36 +03:00
a03db16092 feat(MED-85): add get_order_possible_actions function for backoffice 2025-08-27 08:27:44 +03:00
Helena
8c6ce29c23 MED-147: add doctor actions logging (#59)
* MED-147: add doctor actions logging

* enum casing
2025-08-27 08:11:13 +03:00
380363922c feat(MED-85): improve results sync logs 2025-08-27 08:07:18 +03:00
68e5101885 feat(MED-85): update order status translations 2025-08-27 08:06:30 +03:00
7087c9a6da feat(MED-85): fix missing async 2025-08-27 08:06:00 +03:00
2b2a0b8bc4 feat(MED-85): update dispatch order to medipost retry 2025-08-27 08:05:52 +03:00
Danel Kungla
f33f2b6db4 feat: update AppLogo component to use pathsConfig for home navigation 2025-08-26 16:36:06 +03:00
Danel Kungla
db6d29c208 feat: update audit logging function for tracking changes in database 2025-08-26 16:13:17 +03:00
Helena
5d92c34259 MED-56: show specific error when job taken, other small improvements (#58)
* show specific error when job taken, other small improvements

* enum name case

* enum value case, actually
2025-08-26 11:43:31 +03:00
danelkungla
f5abf2d21e Merge pull request #56 from MR-medreport/MED-57
MED-57: update dashboard with real data
2025-08-26 11:31:25 +03:00
Danel Kungla
dedb42f15b Merge branch 'main' into MED-57 2025-08-26 11:30:34 +03:00
Danel Kungla
54df7aae69 fix: update translation key for date selection in Estonian locale 2025-08-26 11:28:10 +03:00
Helena
5663f41f22 switch weight and height parameters in analysis view 2025-08-25 19:48:37 +03:00
Helena
38d8ca9cfb add isBefore check to previous analysis find 2025-08-25 19:34:47 +03:00
Helena
d017834b8c MED-90: improve doctor analysis detail view (#57)
* add doctor jobs view

* change translation

* another translation change

* clean up

* add analaysis detail view to paths config

* translation

* merge fix

* fix path

* MED-90: improve doctor analysis detail view

* add key
2025-08-25 16:49:04 +03:00
Danel Kungla
4b7d5ff7bb fix(sign-up): move emailRedirectTo option into signUp options 2025-08-25 16:16:56 +03:00
Danel Kungla
2ac2e517f2 Merge branch 'main' into MED-57 2025-08-25 15:24:30 +03:00
Danel Kungla
a088da28d8 refactor: reorder import statements for improved clarity and consistency 2025-08-25 15:22:13 +03:00
Danel Kungla
d57c691a71 update pnpm-lock 2025-08-25 12:57:39 +03:00
Helena
7ac31991c0 fix import paths 2025-08-25 12:52:28 +03:00
Danel Kungla
81a32199e8 refactor: reorganize imports in various components for consistency 2025-08-25 12:46:24 +03:00
Danel Kungla
63c5caca3d fix(page): remove unused imports from TeamAccountHomePage component 2025-08-25 12:25:27 +03:00
Danel Kungla
e0a8173368 Merge branch 'main' into MED-57 2025-08-25 12:25:18 +03:00
Danel Kungla
56ffd7591e feat(team-accounts): enhance team account statistics and health details components with new data and improved calculations 2025-08-25 12:24:27 +03:00
da8b5aa59f feat(MED-85): create logs of sending order to medipost success/error 2025-08-25 12:22:29 +03:00
828f32ee81 feat(MED-85): create audit log on orders view + export csv 2025-08-25 11:51:43 +03:00
eb1eeb690b feat(MED-85): create audit logs for medusa admin actions 2025-08-25 11:51:35 +03:00
811e860965 feat(MED-85): fix delete company account error 2025-08-25 11:51:27 +03:00
89d6035151 feat(MED-85): create customer group for company account in Medusa 2025-08-25 11:51:12 +03:00
5108087cc5 feat(MED-100): improve translation for status 2025-08-25 11:51:04 +03:00
4e6f12a9a0 feat(MED-100): add partner locations list for cart 2025-08-25 11:50:55 +03:00
1d1b10d094 feat(MED-100): show analysis packages and analyses in separate block from tto services 2025-08-25 11:50:47 +03:00
e8e762e7ee feat(MED-100): update analysis level bars 2025-08-25 11:50:32 +03:00
b6a0940506 feat(MED-87): don't show 'waiting for results' text if order is cancelled 2025-08-25 11:50:22 +03:00
38d73e27ad feat(MED-121): use age+sex specific analysis package variants 2025-08-25 11:50:03 +03:00
Helena
195af1db3d MED-137: add doctor other jobs view (#55)
* add doctor jobs view

* change translation

* another translation change

* clean up

* add analaysis detail view to paths config

* translation

* merge fix

* fix path

* move components to shared

* refactor

* imports

* clean up
2025-08-25 11:12:57 +03:00
Danel Kungla
ee86bb8829 fix(sign-up): remove unused emailRedirectTo option from signUp function 2025-08-25 10:34:43 +03:00
Danel Kungla
d8c617eb34 fix(utils): round BMI calculation to return a valid number or NaN 2025-08-22 09:16:06 +03:00
Danel Kungla
9a5cf3ea84 refactor(accounts): remove translation for create company account button 2025-08-21 23:04:41 +03:00
Danel Kungla
1fb8df7c89 feat(dashboard, api): integrate BMI thresholds and enhance dashboard with health metrics 2025-08-21 22:09:17 +03:00
Danel Kungla
b1b0846234 feat(dashboard, api): enhance dashboard card calculations and add team membership check 2025-08-21 21:32:22 +03:00
Danel Kungla
492327c5c7 feat(account): add team membership check and refactor user account loading in HomeLayout 2025-08-21 21:32:17 +03:00
Danel Kungla
cdf1491e53 refactor(auth): remove personal code from sign-up flow and update related components
feat(i18n): update translations for company account creation and get started
2025-08-21 21:32:03 +03:00
Danel Kungla
6f67a21cc1 refactor(footer, header): remove unused components and clean up code 2025-08-21 21:30:29 +03:00
danelkungla
8dfa0e5f4a Merge pull request #54 from MR-medreport/MED-57
MED-57: Team account dashboard
2025-08-18 17:57:42 +03:00
Danel Kungla
2b79a9e401 Refactor team account statistics and health details
- Simplified the TeamAccountStatistics component by removing unused code and integrating translation for health details.
- Updated the load-team-account-health-details to calculate average BMI based on member parameters.
- Adjusted the billing page to correctly reference the number of team members.
- Enhanced the main account page to pass member parameters to the Dashboard component.
- Modified the admin account page to destructure member data from the API response.
- Updated the TeamAccountsApi to return member parameters alongside member data.
- Added new translations for health details in Estonian locale.
2025-08-18 16:50:26 +03:00
Danel Kungla
937f3e4a71 feat(account): refactor team account retrieval and update SQL function for workspace 2025-08-18 15:59:59 +03:00
Danel Kungla
1427bcd5a9 Merge branch 'main' into MED-57 2025-08-18 15:15:27 +03:00
64f8c44c74 Merge pull request #53 from MR-medreport/MED-105-v3
feat(MED-123): fix medreport.notifications.body only allows 5000 chars, cannot log longer emails
2025-08-18 15:11:20 +03:00
Karli
9995c7d170 feat(MED-123): fix medreport.notifications.body only allows 5000 chars, cannot log longer emails 2025-08-18 15:10:25 +03:00
Danel Kungla
c48a4b482f feat(dashboard): add dynamic loading for dashboard component
feat(team-account-benefit-statistics): implement benefit statistics card with budget and booking details

feat(team-account-health-details): create health details component displaying account health metrics

feat(team-account-statistics): develop team account statistics page with charts and customer table

feat(load-team-account-health-details): add server-side function to retrieve account health details

chore(migrations): create trigger for logging changes in account memberships
2025-08-18 14:54:46 +03:00
07ffd6814e Merge pull request #52 from MR-medreport/MED-105-v3
feat(MED-123): update "order analysis" page
2025-08-18 14:14:45 +03:00
Karli
2f732b254f feat(MED-123): log order analysis page view 2025-08-18 14:11:27 +03:00
Karli
abf455117d feat(MED-123): analysis to order can be not-available 2025-08-18 14:11:19 +03:00
Karli
9b50b0f92a feat(MED-123): update dashboard cards for "order analysis" 2025-08-18 13:58:42 +03:00
8a6e805afc Merge pull request #51 from MR-medreport/MED-105-v3
feat(MED-101): disable cart timer, create audit log on "remove item from cart"
2025-08-18 13:28:22 +03:00
Karli
ec866c7f29 feat(MED-101): add audit log to cart item delete 2025-08-18 13:27:13 +03:00
Karli
43117985dd feat(MED-101): disable timer until TTO products are used 2025-08-18 13:21:56 +03:00
e6d768d6ed Merge pull request #50 from MR-medreport/MED-105-v3
feat(MED-105): update sending test analysis results
2025-08-18 13:20:54 +03:00
Karli
d65a6e8a4a feat(MED-105): update sending test analysis results 2025-08-18 13:20:06 +03:00
44670965ae feat(MED-105): update email 2025-08-16 14:59:46 +03:00
bf61763452 Merge pull request #49 from MR-medreport/MED-105-v3
feat(MED-105): update analysis results view to be by analysis order, create notifications entry on email
2025-08-14 13:00:30 +03:00
4c5ec1cfac feat(MED-105): update orders table to be by each separate order 2025-08-14 12:59:42 +03:00
465d2e0a00 feat(MED-48): update email title 2025-08-14 12:28:41 +03:00
5ff0500a9a Merge branch 'main' into MED-105-v3 2025-08-14 12:21:46 +03:00
1285b02f9c feat(MED-105): update analysis results view to be by analysis order 2025-08-14 12:10:12 +03:00
Helena
b4b75438d2 Fix: add application_role to account-related fields (#48)
* Fix: fix accounts view, menu

* add migration

* add application_role to account-related fields
2025-08-14 11:40:53 +03:00
Danel Kungla
bbb5e83ed9 feat(audit): implement page view logging for membership confirmation and analysis results 2025-08-14 09:37:03 +03:00
Danel Kungla
536f915c69 fix: ensure form resets and button state reflects dirty status 2025-08-14 09:24:20 +03:00
d3b393156a feat(MED-105): create update_analysis_order_status for cancelling 2025-08-14 01:21:22 +03:00
87751e10b4 feat(MED-105): allow sending partial results in test 2025-08-14 01:20:45 +03:00
8e9da80e5c Merge branch 'main' into MED-105-v3 2025-08-14 01:19:48 +03:00
Helena
c22667dab4 Fix: add missing paths to dropdown (#47) 2025-08-13 14:42:26 +03:00
5bd1483aa8 Run test sync with curl 2025-08-13 13:01:56 +03:00
Helena
3c6c86c7c8 MED-109: add doctor role and basic view (#45)
* MED-109: add doctor role and basic view

* add role to accounts

* remove old super admin and doctor sql
2025-08-13 12:28:50 +03:00
5d6aa96324 feat(MED-105): create notifications entry on email 2025-08-13 11:45:04 +03:00
Danel Kungla
ce7b04fda8 feat(mailer): add CONTACT_EMAIL environment variable for email sending 2025-08-13 09:51:20 +03:00
Danel Kungla
00bfb3574e refactor: remove next-transpile-modules and update related configurations 2025-08-12 16:49:33 +03:00
Danel Kungla
e085a69442 feat(billing): remove unused BillingErrorPage component 2025-08-12 16:23:04 +03:00
Danel Kungla
b4a811e781 feat(migrations): add missing fields and triggers for auditing changes in accounts and company_params 2025-08-12 16:07:56 +03:00
danelkungla
b3620fbb19 Merge pull request #46 from MR-medreport/MED-91
Med 91
2025-08-12 15:51:06 +03:00
Danel Kungla
4d1cf6a84a Merge branch 'main' into MED-91 2025-08-12 15:50:40 +03:00
Danel Kungla
4c38da445c Merge branch 'main' into MED-91 2025-08-12 15:50:14 +03:00
Danel Kungla
3295ce7d04 feat(auth): refactor account submission data structure and remove unused billing error component 2025-08-12 15:47:01 +03:00
7094523d7e feat(MED-105): reset instrumentation.ts 2025-08-12 12:12:11 +03:00
Danel Kungla
801f5f45e2 Implement code changes to enhance functionality and improve performance 2025-08-11 17:58:36 +03:00
Danel Kungla
c3cab7c06d feat: update README for payment process clarity and enhance success notification button behavior 2025-08-11 17:51:35 +03:00
Danel Kungla
99ba14bab2 Refactor code structure and remove redundant sections for improved readability and maintainability 2025-08-11 17:51:12 +03:00
Danel Kungla
9298abe354 feat(billing): enhance health benefit form and yearly expenses overview with employee count and loading state 2025-08-11 15:04:16 +03:00
2c78b921b9 Merge pull request #43 from MR-medreport/MED-105-1108
feat(MED-105): small fixes
2025-08-11 14:06:52 +03:00
91e0987831 feat(MED-105): tooltip content too wide 2025-08-11 14:06:05 +03:00
4d76dd83ad feat(MED-105): disable scheduler 2025-08-11 14:05:54 +03:00
6e63646944 Merge pull request #42 from MR-medreport/MED-105-1108
feat(MED-105): update analysis results page, analysis order new statuses
2025-08-11 10:45:32 +03:00
5264455793 feat(MED-87): improve naming 2025-08-11 10:44:53 +03:00
63b86c0abb feat(MED-87): update status on results 2025-08-11 10:41:01 +03:00
d582e222ce feat(MED-105): update order details redirect and shown page 2025-08-11 09:21:40 +03:00
556d7bd321 feat(MED-105): show analysis date in tooltip for now 2025-08-11 09:21:33 +03:00
37f233e363 feat(MED-105): show empty text on no ordered analyses 2025-08-11 09:21:27 +03:00
c8621c4453 feat(MED-105): sort analysis result elements by date 2025-08-11 09:21:20 +03:00
83fff1ffe7 feat(MED-105): create audit entry on analysis results view 2025-08-11 09:21:13 +03:00
49fc75b17b feat(MED-105): update analysis results page 2025-08-11 09:21:06 +03:00
Danel Kungla
aba4596edd fix: update email recipient logic in renderCompanyOfferEmail function 2025-08-07 18:04:44 +03:00
Danel Kungla
2850478443 feat: enable TLS for email and improve loading state handling in CompanyOfferForm 2025-08-07 15:10:59 +03:00
09155ae110 feat(MED-131): revert to use server action for montonio token for revalidateTag 2025-08-05 10:59:44 +03:00
d9b619d560 feat(MED-131): rerun 2025-08-05 10:33:59 +03:00
7f1596b141 feat(MED-131): keep unused app/store pages for now but don't build them since its unstable 2025-08-05 10:29:37 +03:00
e375f22b57 feat(MED-131): route sometimes redirects back to login instead 2025-08-05 10:07:59 +03:00
4617c483fa feat(MED-131): env fix v2 2025-08-04 19:03:18 +03:00
d68ed20ca9 feat(MED-131): temp fix for env 2025-08-04 18:42:28 +03:00
danelkungla
90e0049d65 Merge pull request #41 from MR-medreport/MED-111
feat(MED-111): update navigation links and adjust invitation handling
2025-08-04 18:35:08 +03:00
47675252ed feat(MED-131): conditional env 2025-08-04 18:31:17 +03:00
bd78b28f3c feat(MED-131): move dev envs to .env.development 2025-08-04 18:23:52 +03:00
e0064b9d55 feat(MED-131): fix migration date 2025-08-04 18:16:47 +03:00
Danel Kungla
cb7f4f7ba5 feat(MED-111): update navigation links and adjust invitation handling 2025-08-04 18:15:22 +03:00
edfc9776d3 feat(MED-131): remove fake url 2025-08-04 17:56:04 +03:00
77d58ef5b1 feat(MED-131): fix analysis element ids 2025-08-04 17:41:32 +03:00
0ba23b6c8e feat(MED-131): show other (non analysis-package) orders 2025-08-04 17:32:54 +03:00
74ccbfd4d7 feat(MED-131): update default region 2025-08-04 17:20:23 +03:00
9854a65484 Revert "feat(MED-131): check permissions for 'audit' schema"
This reverts commit ff3335d331.
2025-08-04 17:16:09 +03:00
ff3335d331 feat(MED-131): check permissions for 'audit' schema 2025-08-04 16:51:52 +03:00
4b198cd10c Merge pull request #40 from MR-medreport/MED-131-v2
feat(MED-131): update analysis/package -> cart -> medipost flow, many fixes/improvements
2025-08-04 16:32:30 +03:00
e8dae56d7e feat(MED-131): update type 2025-08-04 16:30:42 +03:00
0c6bda607d feat(MED-131): support multiple elements under same group for creating fake medipost responses 2025-08-04 16:30:17 +03:00
84b629ab0b feat(MED-131): remove private messages with unknown order ID from queue 2025-08-04 16:29:50 +03:00
0a4be89fc9 feat(MED-131): initial fix for analysis results table so result elements are shown correctly 2025-08-04 16:28:57 +03:00
30c7d192fa feat(MED-131): fix validation 2025-08-04 16:28:24 +03:00
8790b515d5 feat(MED-131): fix medusa vs medipost vs b2b product ids mixed 2025-08-04 16:27:54 +03:00
36816cfcd5 feat(MED-131): improve logging, error validation 2025-08-04 16:26:26 +03:00
58e2b8dc81 feat(MED-131): send to medipost on montonio callback 2025-08-04 16:24:28 +03:00
b2003ad30d feat(MED-131): move medipost xml logic to service 2025-08-04 12:49:03 +03:00
853bd75119 feat(MED-131): analysis package has list of medusa product IDs, not medipost IDs 2025-08-04 12:44:36 +03:00
0d1e255fe2 feat(MED-131): redirect to /home in case of no redirect path 2025-08-04 11:55:27 +03:00
7c3aa45ec7 feat(MED-131): update analyses on package logic 2025-08-04 11:55:23 +03:00
c02cb046a5 feat(MED-131): update readme for medipost and jobs 2025-08-04 11:55:13 +03:00
f4dcc44428 feat(MED-131): reset loading on error, show spinner 2025-08-04 11:53:33 +03:00
606fd55a42 feat(MED-131): use constants 2025-08-04 11:53:27 +03:00
0e9d9a212a feat(MED-131): sync analysis results in job handler 2025-08-04 11:53:18 +03:00
69f41430e2 feat(MED-131): send fake test response for an order 2025-08-04 11:53:12 +03:00
91f6dd11be feat(MED-131): handle analysis order 2025-08-04 11:53:04 +03:00
08950896e5 feat(MED-131): improve xml response code validation 2025-08-04 11:52:57 +03:00
dfce4047cd feat(MED-131): change all jobs apis to POST 2025-08-04 11:52:48 +03:00
5966fb2a77 feat(MED-131): store medusa_store_id along with analysis_order 2025-08-04 11:52:39 +03:00
c681063e8d feat(MED-131): show separate text in case of no existing analysis results 2025-08-04 11:52:31 +03:00
12cd61840c feat(MED-131): update location in action so cart is always reloaded properly 2025-08-04 11:52:22 +03:00
959646a319 feat(MED-131): direct imports 2025-08-04 11:52:14 +03:00
ee60a78335 feat(MED-131): update analyses sync to medusa store 2025-08-04 11:52:09 +03:00
b665678dbb feat(MED-131): display analyses options and add to cart 2025-08-04 11:51:49 +03:00
8c4df731aa feat(MED-131): show package analysis elements in comparison modal 2025-08-04 11:51:38 +03:00
d7d089c11d feat(MED-131): use existing supabase server admin client conf 2025-08-04 11:51:28 +03:00
12465e18fb feat(MED-131): update translations 2025-08-04 11:51:21 +03:00
43493c261c feat(MED-131): move jobs to /api/job/* secured with key 2025-08-04 11:51:11 +03:00
danelkungla
5746e1b087 Merge pull request #39 from MR-medreport/MED-111
MED-111: fix company creation for admin and inviting of new employees
2025-08-04 11:33:08 +03:00
Danel Kungla
0254805743 use isikukood library to validate in zod 2025-08-04 11:32:41 +03:00
Danel Kungla
6ba33a99b2 clean 2025-07-31 12:31:58 +03:00
Danel Kungla
7031bc1176 Merge branch 'main' into MED-111 2025-07-31 12:30:25 +03:00
Danel Kungla
a39c21e4e7 fix company creation for admin and inviting of new employees 2025-07-31 12:27:30 +03:00
2caf847296 feat(MED-85): update webhook url to have public path in test env 2025-07-31 12:02:01 +03:00
23a07658c9 feat(MED-85): redirect to dashboard after MFA is done 2025-07-31 12:00:51 +03:00
c91adc7521 feat(MED-85): fix wrong env variable name 2025-07-31 12:00:13 +03:00
Danel Kungla
87363051cd feat: implement loadCurrentUserAccounts for user account management in SiteLayout 2025-07-24 16:13:32 +03:00
Danel Kungla
a85f26d55b feat: refactor SiteLayout to use Supabase client for user authentication 2025-07-24 12:07:53 +03:00
1d746e8e6d feat(MED-48): local docker mailer to readme 2025-07-24 12:02:17 +03:00
6374bfb602 feat(MED-48): retry 2025-07-24 10:42:43 +03:00
790103a55f Merge pull request #38 from MR-medreport/MED-48
feat(MED-48 MED-100): update products -> cart -> montonio -> orders flow, send email
2025-07-24 10:26:34 +03:00
Danel Kungla
f0e956a7e8 fix: remove redundant build step in Dockerfile 2025-07-24 09:43:04 +03:00
danelkungla
65f0114ae4 Merge pull request #37 from MR-medreport/MED-91
add health benefit form, fix super admin
2025-07-24 09:26:06 +03:00
894cf1b454 feat(MED-100): partner location metadata stored on order line instead of order 2025-07-24 09:23:44 +03:00
3341dbd306 feat(MED-48): improvements 2025-07-24 08:52:59 +03:00
d7499fbc13 feat(MED-50): update default env 2025-07-24 08:40:27 +03:00
6dcb9ae4db feat(MED-50): apply medusa middleware for cache id 2025-07-24 08:40:01 +03:00
f26085e362 feat(MED-50): add placeholder pages 2025-07-24 08:38:30 +03:00
349e3e3143 feat(MED-50): use account_params in dashboard 2025-07-24 08:38:12 +03:00
66760adc06 feat(MED-50): initial analysis package orders table 2025-07-24 08:06:33 +03:00
57e30911e9 feat(MED-100): show cart in mobile menu 2025-07-24 08:06:01 +03:00
b9f40d6a2d feat(MED-100): analysis location select in cart 2025-07-24 08:05:10 +03:00
23f656ccc9 feat(MED-100): analysis package products by product type 2025-07-24 08:04:04 +03:00
e59ad6af00 feat(MED-100): update montonio redirect 2025-07-24 08:03:55 +03:00
8633ac4bce feat(MED-48): add synlab analysis package email 2025-07-24 07:59:17 +03:00
Danel Kungla
0bd67ec4e8 refactor: move role creation and permissions to super_admin_fix.sql 2025-07-23 17:01:13 +03:00
Danel Kungla
86b86c6752 add health benefit form
fix super admin
2025-07-23 16:33:24 +03:00
Danel Kungla
2db67b7f20 fix: ensure environment variables are loaded before building 2025-07-22 15:19:17 +03:00
Danel Kungla
c8be061ddc remove git for /health 2025-07-22 10:55:40 +03:00
Danel Kungla
aa62aa69f3 need git in dockerfile for /health page 2025-07-22 10:42:37 +03:00
Danel Kungla
8ee9271c2e feat: add commit hash to environment variables and create HealthPage component to display it 2025-07-21 14:59:29 +03:00
Danel Kungla
8e4d634a7d fix build 2025-07-21 13:56:52 +03:00
93e44cda83 Merge pull request #36 from MR-medreport/feature/MED-100
feat(MED-100): update cart with montonio
2025-07-21 09:05:00 +00:00
185a8a8293 feat(MED-100): update env 2025-07-21 11:54:27 +03:00
5d53e53ba8 feat(MED-100): small improvements 2025-07-21 11:54:07 +03:00
15ed539283 Merge branch 'main' into feature/MED-100 2025-07-21 11:38:47 +03:00
Danel Kungla
eec8a12db2 feat: fix lucide-react renders
feat: fix mobile designs
feat: remove conflicting react-hook-form
feat: change update-account-form path
2025-07-18 17:19:12 +03:00
8c090f9d68 Merge pull request #34 from MR-medreport/MED-122
feat(MED-122): update analysis packages page, pageheader usage
2025-07-18 13:12:23 +00:00
c8e5d8835b Merge branch 'main' into MED-122 2025-07-18 16:11:50 +03:00
danelkungla
2cb378a88a Merge pull request #35 from MR-medreport/MED-105
MED-105: create analysis results page
2025-07-18 15:40:58 +03:00
Danel Kungla
3a5058fc44 Merge branch 'main' into MED-105 2025-07-18 15:35:44 +03:00
Danel Kungla
dca5f04739 add env logging 2025-07-17 12:39:21 +03:00
Danel Kungla
79b6652748 Add missing .env file copy in Dockerfile for build stage 2025-07-16 16:07:27 +03:00
Danel Kungla
2689b87977 add logs 2025-07-16 14:48:18 +03:00
Danel Kungla
6232ffc50d Remove unused Stripe publishable key from development and production environment files 2025-07-16 13:35:01 +03:00
Danel Kungla
b028aae1ba Fix environment variable copying in Dockerfile for runtime stage 2025-07-16 13:29:29 +03:00
Danel Kungla
d572ba52a8 Refactor Dockerfile for improved build and runtime stages 2025-07-16 12:09:14 +03:00
Danel Kungla
4e0ef7b9de Fix environment variable configuration in .env and .env.production files 2025-07-16 11:21:08 +03:00
Danel Kungla
571637f96a Add .env.production copy to Dockerfile for environment configuration 2025-07-16 10:16:47 +03:00
Danel Kungla
53e9349f37 Update Supabase configuration in development and production environment files 2025-07-15 17:13:12 +03:00
Danel Kungla
87dfcf55e6 MED-105: create analysis results page 2025-07-15 17:12:52 +03:00
939 changed files with 52813 additions and 16152 deletions

28
.env
View File

@@ -5,7 +5,6 @@
# TO OVERRIDE THESE VARIABLES IN A SPECIFIC ENVIRONMENT, PLEASE ADD THEM TO THE SPECIFIC ENVIRONMENT FILE (e.g. .env.development, .env.production)
# SITE
NEXT_PUBLIC_SITE_URL=https://localhost:3000
NEXT_PUBLIC_PRODUCT_NAME=MedReport
NEXT_PUBLIC_SITE_TITLE="MedReport"
NEXT_PUBLIC_SITE_DESCRIPTION="MedReport."
@@ -14,12 +13,12 @@ NEXT_PUBLIC_THEME_COLOR="#ffffff"
NEXT_PUBLIC_THEME_COLOR_DARK="#0a0a0a"
# AUTH
NEXT_PUBLIC_AUTH_PASSWORD=true
NEXT_PUBLIC_AUTH_PASSWORD=false
NEXT_PUBLIC_AUTH_MAGIC_LINK=false
NEXT_PUBLIC_CAPTCHA_SITE_KEY=
# BILLING
NEXT_PUBLIC_BILLING_PROVIDER=stripe
NEXT_PUBLIC_BILLING_PROVIDER=montonio
# CMS
CMS_CLIENT=keystatic
@@ -34,14 +33,26 @@ NEXT_PUBLIC_LOCALES_PATH=apps/web/public/locales
NEXT_PUBLIC_ENABLE_THEME_TOGGLE=true
NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_DELETION=true
NEXT_PUBLIC_ENABLE_PERSONAL_ACCOUNT_BILLING=false
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_DELETION=false
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_BILLING=false
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_DELETION=true
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_BILLING=true
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS=true
NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_CREATION=true
NEXT_PUBLIC_LANGUAGE_PRIORITY=application
NEXT_PUBLIC_ENABLE_NOTIFICATIONS=true
NEXT_PUBLIC_REALTIME_NOTIFICATIONS=true
WEBHOOK_SENDER_PROVIDER=postgres
# MAILER DEV
CONTACT_EMAIL=info@medreport.ee
MAILER_PROVIDER=nodemailer
EMAIL_SENDER=info@medreport.ee
EMAIL_USER= # refer to your email provider's documentation
EMAIL_PASSWORD= # refer to your email provider's documentation
EMAIL_HOST=localhost # refer to your email provider's documentation
EMAIL_PORT=1025 # or 465 for SSL
EMAIL_TLS=true
NODE_TLS_REJECT_UNAUTHORIZED=0
# NEXTJS
NEXT_TELEMETRY_DISABLED=1
@@ -53,5 +64,10 @@ NEXT_PUBLIC_DEFAULT_LOCALE=et
NEXT_PUBLIC_TEAM_NAVIGATION_STYLE=custom
NEXT_PUBLIC_USER_NAVIGATION_STYLE=custom
# MEDUSA
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=
# Configure Medusa password secret for Keycloak users
MEDUSA_PASSWORD_SECRET=ODEwMGNiMmUtOGMxYS0xMWYwLWJlZDYtYTM3YzYyMWY0NGEzCg==
# False by default
MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK=false

View File

@@ -1,10 +1,11 @@
# This file is used to define environment variables for the development environment.
# These values are only used when running the app in development mode.
# SUPABASE
NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
# SITE
NEXT_PUBLIC_SITE_URL=http://localhost:3000
NEXT_PUBLIC_AUTH_PASSWORD=true
# SUPABASE DEVELOPMENT
## THIS IS FOR DEVELOPMENT ONLY - DO NOT USE IN PRODUCTION
SUPABASE_DB_WEBHOOK_SECRET=WEBHOOKSECRET
@@ -14,14 +15,80 @@ SUPABASE_DB_WEBHOOK_SECRET=WEBHOOKSECRET
# CONTACT FORM
CONTACT_EMAIL=test@makerkit.dev
# STRIPE
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=
# MAILER
MAILER_PROVIDER=nodemailer
# EMAIL_SENDER=
# EMAIL_USER= # refer to your email provider's documentation
# EMAIL_PASSWORD= # refer to your email provider's documentation
# EMAIL_HOST= # refer to your email provider's documentation
# EMAIL_PORT= # or 465 for SSL
# EMAIL_TLS= # or false for SSL (see provider documentation)
EMAIL_SENDER=info@medreport.ee
EMAIL_USER= # refer to your email provider's documentation
EMAIL_PASSWORD= # refer to your email provider's documentation
EMAIL_HOST=localhost # refer to your email provider's documentation
EMAIL_PORT=1025 # or 465 for SSL
EMAIL_TLS=false
NODE_TLS_REJECT_UNAUTHORIZED=0
# MEDIPOST
MEDIPOST_URL=https://meditest.medisoft.ee:7443/Medipost/MedipostServlet
MEDIPOST_USER=trvurgtst
MEDIPOST_PASSWORD=SRB48HZMV
MEDIPOST_RECIPIENT=syndev
MEDIPOST_RECIPIENT=trvurgtst
MEDIPOST_MESSAGE_SENDER=trvurgtst
MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK=true
#MEDIPOST_URL=https://medipost2.medisoft.ee:8443/Medipost/MedipostServlet
#MEDIPOST_USER=medreport
#MEDIPOST_PASSWORD=85MXFFDB7
#MEDIPOST_RECIPIENT=HTI
#MEDIPOST_MESSAGE_SENDER=medreport
#MEDIPOST_ENABLE_DISPATCH_ON_MONTONIO_CALLBACK=false
# MEDUSA
COMPANY_BENEFITS_PAYMENT_SECRET_KEY=NzcwMzE2NmEtOThiMS0xMWYwLWI4NjYtMDMwZDQzMjFhMjExCg==
MEDUSA_BACKEND_URL=http://localhost:9000
MEDUSA_BACKEND_PUBLIC_URL=http://localhost:9000
MEDUSA_SECRET_API_KEY=sk_b332d525212ab4078ef73fb2b8232c3beebccc4a460e2c7abf6e187a458d60cf
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_e23a820689a07d55aa0a0ad187268559f5d6288ecb0768ff4520516285bdef84
#MEDUSA_BACKEND_URL=https://backoffice-test.medreport.ee
#MEDUSA_BACKEND_PUBLIC_URL=https://backoffice-test.medreport.ee
#MEDUSA_SECRET_API_KEY=sk_5ac1c1c12c144cd744b6c881050d459e339ddf6a3d14eda271a0cc4f9d3812cb
#NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_e740b9ca22b31c4b44862044f001dbcf8f46d47d40f430733d0c75bef14d2d6a
#MEDUSA_BACKEND_URL=https://backoffice.medreport.ee
#MEDUSA_BACKEND_PUBLIC_URL=https://backoffice.medreport.ee
#NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_068d930c33fea53608a410d84a51935f6ce2ccec5bef8e0ecf75eaee602ac486
#MEDUSA_SECRET_API_KEY=sk_fdb1808fbabf62979cc46316aa997378ffbb87882883e8f5c3ee47cee39dcac5
#MEDUSA_BACKEND_URL=http://5.181.51.38:9000
#MEDUSA_BACKEND_PUBLIC_URL=http://5.181.51.38:9000
#NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_0ec86252438b38ce18d5601f7877e4395d7e0a6afa8687dfea8d37af33015633
# MONTONIO
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo
MONTONIO_API_URL=https://sandbox-stargate.montonio.com
#NEXT_PUBLIC_MONTONIO_ACCESS_KEY=13e3686a-e7ad-41f6-998b-3f7d7de17654
#MONTONIO_SECRET_KEY=wTd4BZ01h80KZLMPL4mjt0RCFxKaYRSu9mMB1PQZCxnw
#MONTONIO_API_URL=https://stargate.montonio.com
# JOBS
JOBS_API_TOKEN=73ce073c-6dd4-11f0-8e75-8fee89786197
# SUPABASE
NEXT_PUBLIC_SUPABASE_URL=https://klocrucggryikaxzvxgc.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imtsb2NydWNnZ3J5aWtheHp2eGdjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTY5ODQ2MjgsImV4cCI6MjA3MjU2MDYyOH0.2XOQngowcymiSUZO_XEEWAWzco2uRIjwG7TAeRRLIdU
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imtsb2NydWNnZ3J5aWtheHp2eGdjIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc1Njk4NDYyOCwiZXhwIjoyMDcyNTYwNjI4fQ.1UZR7AqSD9bOy1gtZRGhOCNoESsw2W-DoFDDsNNMwoE
#NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co
#NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0
#SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0NjUyODEyMywiZXhwIjoyMDYyMTA0MTIzfQ.KVcnkZ21Pd0XkJho23dZqFHawVTLQqfvF7l2RxsELLk
NEXT_PUBLIC_SUPABASE_URL=http://5.181.51.38:54321
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU
### TEST.MEDREPORT.ee ###
DB_PASSWORD=imCTUreSnazWKT3u#

View File

@@ -2,7 +2,7 @@
# https://app.supabase.com/project/_/settings/api
NEXT_PUBLIC_SUPABASE_URL=your-project-url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
MEDIPOST_URL=your-medipost-url
MEDIPOST_USER=your-medipost-user
@@ -23,3 +23,5 @@ NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead
MONTONIO_SECRET_KEY=rNZkzwxOiH93mzkdV53AvhSsbGidrgO2Kl5lE/IT7cvo
MONTONIO_API_URL=https://sandbox-stargate.montonio.com
JOBS_API_TOKEN=73ce073c-6dd4-11f0-8e75-8fee89786197

View File

@@ -6,7 +6,10 @@
## PUBLIC KEYS OR CONFIGURATION ARE OKAY TO BE PLACED HERE.
# SUPABASE
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_URL=https://oqsdacktkhmbylmzstjq.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9xc2RhY2t0a2htYnlsbXpzdGpxIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY1MjgxMjMsImV4cCI6MjA2MjEwNDEyM30.LdHCTWxijFmhXdnT9KVuLRAVbtSwY7OO-oLtpd8GmO0
# STRIPE
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=
NEXT_PUBLIC_SITE_URL=https://test.medreport.ee
# # MONTONIO
NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead

15
.env.staging Normal file
View File

@@ -0,0 +1,15 @@
# PRODUCTION ENVIRONMENT VARIABLES
## DO NOT ADD VARS HERE UNLESS THEY ARE PUBLIC OR NOT SENSITIVE
## THIS ENV IS USED FOR PRODUCTION AND IS COMMITED TO THE REPO
## AVOID PLACING SENSITIVE DATA IN THIS FILE.
## PUBLIC KEYS OR CONFIGURATION ARE OKAY TO BE PLACED HERE.
# SUPABASE
# NEXT_PUBLIC_SUPABASE_URL=https://klocrucggryikaxzvxgc.supabase.co
# NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Imtsb2NydWNnZ3J5aWtheHp2eGdjIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTY5ODQ2MjgsImV4cCI6MjA3MjU2MDYyOH0.2XOQngowcymiSUZO_XEEWAWzco2uRIjwG7TAeRRLIdU
# NEXT_PUBLIC_SITE_URL=https://test.medreport.ee
# # MONTONIO
# NEXT_PUBLIC_MONTONIO_ACCESS_KEY=7da5d7fa-3383-4997-9435-46aa818f4ead

1
.gitignore vendored
View File

@@ -43,3 +43,4 @@ yarn-error.log*
next-env.d.ts
dump.sql
data.sql

1
.npmrc
View File

@@ -3,6 +3,7 @@ dedupe-peer-dependents=true
use-lockfile-v6=true
resolution-mode=highest
package-manager-strict=true
ignore-workspace-root-check=true
public-hoist-pattern[]=*i18next*
public-hoist-pattern[]=*eslint*
public-hoist-pattern[]=*prettier*

View File

@@ -1,17 +1,55 @@
# --- Stage 1: Build ---
FROM node:20-alpine as builder
WORKDIR /app
RUN npm install -g pnpm@9
RUN npm install -g dotenv-cli
# Copy necessary files for workspace resolution
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages packages
COPY tooling tooling
COPY .env .env
COPY .env.production .env.production
COPY .env.staging .env.staging
# Install all dependencies
# Load env file and echo a specific variable
# RUN dotenv -e .env -- printenv | grep 'SUPABASE' || true
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
ENV NODE_ENV=production
RUN set -a \
&& . .env \
&& . .env.production \
&& . .env.staging \
&& set +a \
&& node check-env.js \
&& pnpm build
# --- Stage 2: Runtime ---
FROM node:20-alpine
ARG APP_ENV=production
WORKDIR /app
COPY --from=builder /app ./
RUN cp ".env.${APP_ENV}" .env.local
RUN npm install -g pnpm@9 \
&& pnpm install --prod --frozen-lockfile
ENV NODE_ENV=production
# 🔍 Optional: Log key envs for debug
RUN echo "📄 .env contents:" && cat .env.local \
&& echo "🔧 Current ENV available to Next.js build:" && printenv | grep -E 'SUPABASE|STRIPE|NEXT|NODE_ENV' || true
EXPOSE 3000
CMD ["pnpm", "start"]

View File

@@ -47,6 +47,18 @@ if you get missing dependency error do `pnpm i --force`
pnpm add <pacakge-name> -w
```
## Eslint and prettier
To clean code run
```bash
npm run lint:fix
```
```bash
npm run prettier:fix
```
## Supabase
Start supabase in docker
@@ -85,5 +97,58 @@ To access admin pages follow these steps:
- Register new user
- Go to Profile and add Multi-Factor Authentication
- Sign out and Sign in
- Authenticate with mfa (at current time profile page prompts it again)
- update your role. look at `supabase/sql/super-admin.sql`
- Sign out and Sign in
## Company User
- With admin account go to `http://localhost:3000/admin/accounts`
- For Create Company Account to work you need to have rows in `medreport.roles` table. For that you can sql in `supabase/sql/super-admin.sql`
## Start email server
`docker run -p 1080:1080 -p 1025:1025 maildev/maildev`
- [View emails](http://localhost:1080/#/)
- Mail server is running on `localhost:1025` without password
## Medipost flow
1. Customer adds analysis to cart in **B2B** storefront
2. Customer checks out from cart and is redirected to **Montonio**
3. Customer pays and is redirected back to **B2B** `GET B2B/home/cart/montonio-callback?order-token=$JWT`
- **Medusa** order is created and cart is emptied
- email is sent to customer
- B2B sends order XML as private message to Medipost.
When **Montonio** has confirmed payment, it will call **Medusa** webhook endpoint and **Medusa** will mark order payment as captured.
In background a job will call `POST B2B/api/job/sync-analysis-results` every n minutes and sync private messages with responses from **Medipost**.
In local dev environment, you can create a private message with analysis responses in **Medipost** system for a submitted order:
`POST B2B/api/order/medipost-test-response body={medusaOrderId:'input here'}`
After that run `POST /api/job/sync-analysis-results` and analysis results should be synced.
In local dev environment, you can import products from B2B to Medusa with this API:
- `POST /api/job/sync-analysis-groups-store`
- Syncs required data of `analyses`, `analysis_elements` data from **B2B** to **Medusa** and creates relevant products and categories.
If product or category already exists, then it is not recreated. Old entries are not deleted either currently.
## Jobs
Required headers:
- `x-jobs-api-key` in UUID format
Endpoints:
- `POST /api/job/sync-analysis-groups`
- Queries **Medipost** for public messages list and takes analysis info from the latest event.
Updates `analyses` and `analysis_elements` lists in **B2B**.
- `POST /api/job/sync-analysis-results`
- Queries **Medipost** for latest private message that has a response and updates order analysis results from lab results data.
- `POST /api/job/sync-connected-online`
- TODO

44
__mocks__/isikukood.ts Normal file
View File

@@ -0,0 +1,44 @@
// Mock for isikukood library to avoid ES module issues in tests
export enum Gender {
MALE = 'male',
FEMALE = 'female',
}
export default class Isikukood {
private code: string;
constructor(code: string) {
this.code = code;
}
static validate(code: string): boolean {
return true; // Mock always returns true for tests
}
static generate(options?: { gender?: Gender; century?: number }): string {
return '39001010002'; // Mock Estonian ID code
}
isValid(): boolean {
return true;
}
getGender(): Gender {
return Gender.MALE;
}
getBirthDate(): Date {
return new Date('1990-01-01');
}
getAge(): number {
return 30;
}
getCentury(): number {
return 3;
}
}
export { Isikukood };

3
__mocks__/server-only.ts Normal file
View File

@@ -0,0 +1,3 @@
// Mock for server-only to avoid Next.js server component issues in tests
// This module does nothing in tests - it's just a marker for Next.js
export {};

View File

@@ -1,14 +1,13 @@
import { AppLogo } from '@kit/shared/components/app-logo';
import { appConfig } from '@kit/shared/config';
import { Footer } from '@kit/ui/marketing';
import { Trans } from '@kit/ui/trans';
import { AppLogo } from '~/components/app-logo';
import appConfig from '~/config/app.config';
export function SiteFooter() {
return (
<Footer
logo={<AppLogo className="w-[85px] md:w-[95px]" />}
description={<Trans i18nKey="marketing:footerDescription" />}
description=""
copyright={
<Trans
i18nKey="marketing:copyright"
@@ -19,22 +18,6 @@ export function SiteFooter() {
/>
}
sections={[
{
heading: <Trans i18nKey="marketing:about" />,
links: [
{ href: '/blog', label: <Trans i18nKey="marketing:blog" /> },
{ href: '/contact', label: <Trans i18nKey="marketing:contact" /> },
],
},
{
heading: <Trans i18nKey="marketing:product" />,
links: [
{
href: '/docs',
label: <Trans i18nKey="marketing:documentation" />,
},
],
},
{
heading: <Trans i18nKey="marketing:legal" />,
links: [

View File

@@ -3,18 +3,18 @@
import dynamic from 'next/dynamic';
import Link from 'next/link';
import { UserWorkspace } from '@/app/home/(user)/_lib/server/load-user-workspace';
import { useQuery } from '@tanstack/react-query';
import { PersonalAccountDropdown } from '@kit/accounts/personal-account-dropdown';
import { featureFlagsConfig, pathsConfig } from '@kit/shared/config';
import { useAuthConfig } from '@kit/shared/hooks';
import { useSignOut } from '@kit/supabase/hooks/use-sign-out';
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
import { Button } from '@kit/ui/button';
import { If } from '@kit/ui/if';
import { Trans } from '@kit/ui/trans';
import featuresFlagConfig from '~/config/feature-flags.config';
import pathsConfig from '~/config/paths.config';
const ModeToggle = dynamic(() =>
import('@kit/ui/mode-toggle').then((mod) => ({
default: mod.ModeToggle,
@@ -23,13 +23,20 @@ const ModeToggle = dynamic(() =>
const paths = {
home: pathsConfig.app.home,
admin: pathsConfig.app.admin,
doctor: pathsConfig.app.doctor,
personalAccountSettings: pathsConfig.app.personalAccountSettings,
};
const features = {
enableThemeToggle: featuresFlagConfig.enableThemeToggle,
enableThemeToggle: featureFlagsConfig.enableThemeToggle,
};
export function SiteHeaderAccountSection() {
export function SiteHeaderAccountSection({
accounts,
}: {
accounts: UserWorkspace['accounts'];
}) {
const session = useSession();
const signOut = useSignOut();
@@ -41,6 +48,7 @@ export function SiteHeaderAccountSection() {
features={features}
user={session.data.user}
signOutRequested={() => signOut.mutateAsync()}
accounts={accounts}
/>
);
}
@@ -49,6 +57,8 @@ export function SiteHeaderAccountSection() {
}
function AuthButtons() {
const { config } = useAuthConfig();
return (
<div className={'animate-in fade-in flex gap-x-2.5 duration-500'}>
<div className={'hidden md:flex'}>
@@ -57,19 +67,25 @@ function AuthButtons() {
</If>
</div>
{config && (
<div className={'flex gap-x-2.5'}>
<Button className={'hidden md:block'} asChild variant={'ghost'}>
{(config.providers.password || config.providers.oAuth.length > 0) && (
<Button className={'block'} asChild variant={'ghost'}>
<Link href={pathsConfig.auth.signIn}>
<Trans i18nKey={'auth:signIn'} />
</Link>
</Button>
)}
{config.providers.password && (
<Button asChild className="text-xs md:text-sm" variant={'default'}>
<Link href={pathsConfig.auth.signUp}>
<Trans i18nKey={'auth:signUp'} />
</Link>
</Button>
)}
</div>
)}
</div>
);
}

View File

@@ -1,16 +1,19 @@
import { UserWorkspace } from '@/app/home/(user)/_lib/server/load-user-workspace';
import { AppLogo } from '@kit/shared/components/app-logo';
import { Header } from '@kit/ui/marketing';
import { AppLogo } from '~/components/app-logo';
import { SiteHeaderAccountSection } from './site-header-account-section';
import { SiteNavigation } from './site-navigation';
export function SiteHeader() {
export function SiteHeader({
accounts,
}: {
accounts: UserWorkspace['accounts'];
}) {
return (
<Header
logo={<AppLogo />}
navigation={<SiteNavigation />}
actions={<SiteHeaderAccountSection />}
actions={<SiteHeaderAccountSection accounts={accounts} />}
/>
);
}

View File

@@ -22,10 +22,6 @@ const links = {
label: 'marketing:documentation',
path: '/docs',
},
Pricing: {
label: 'marketing:pricing',
path: '/pricing',
},
FAQ: {
label: 'marketing:faq',
path: '/faq',

View File

@@ -9,18 +9,18 @@ import { ContactEmailSchema } from '../contact-email.schema';
const contactEmail = z
.string({
description: `The email where you want to receive the contact form submissions.`,
required_error:
error:
'Contact email is required. Please use the environment variable CONTACT_EMAIL.',
})
.describe(`The email where you want to receive the contact form submissions.`)
.parse(process.env.CONTACT_EMAIL);
const emailFrom = z
.string({
description: `The email sending address.`,
required_error:
error:
'Sender email is required. Please use the environment variable EMAIL_SENDER.',
})
.describe(`The email sending address.`)
.parse(process.env.EMAIL_SENDER);
export const sendContactEmail = enhanceAction(

View File

@@ -1,11 +1,15 @@
import { use } from 'react';
import { SiteFooter } from '~/(marketing)/_components/site-footer';
import { SiteHeader } from '~/(marketing)/_components/site-header';
import { loadCurrentUserAccounts } from '~/home/(user)/_lib/server/load-accounts';
import { withI18n } from '~/lib/i18n/with-i18n';
function SiteLayout(props: React.PropsWithChildren) {
const accounts = use(loadCurrentUserAccounts());
return (
<div className={'flex min-h-[100vh] flex-col'}>
<SiteHeader />
<SiteHeader accounts={accounts} />
{props.children}

View File

@@ -1,8 +1,9 @@
import Link from 'next/link';
import { MedReportLogo } from '@/components/med-report-logo';
import { ArrowRightIcon } from 'lucide-react';
import { MedReportLogo } from '@kit/shared/components/med-report-logo';
import { pathsConfig } from '@kit/shared/config';
import { CtaButton, Hero } from '@kit/ui/marketing';
import { Trans } from '@kit/ui/trans';
@@ -32,7 +33,7 @@ function MainCallToActionButton() {
return (
<div className={'flex space-x-4'}>
<CtaButton>
<Link href={'/auth/sign-up'}>
<Link href={pathsConfig.auth.signUp}>
<span className={'flex items-center space-x-0.5'}>
<span>
<Trans i18nKey={'common:getStarted'} />
@@ -49,8 +50,8 @@ function MainCallToActionButton() {
</CtaButton>
<CtaButton variant={'link'}>
<Link href={'/company-offer'}>
<Trans i18nKey={'account:createCompanyAccount'} />
<Link href="/company-offer">
<Trans i18nKey="account:createCompanyAccount" />
</Link>
</CtaButton>
</div>

View File

@@ -1,21 +1,26 @@
'use client';
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { SubmitButton } from '@/components/ui/submit-button';
import { sendCompanyOfferEmail } from '@/lib/services/mailer.service';
import { sendEmailFromTemplate } from '@/lib/services/mailer.service';
import { CompanySubmitData } from '@/lib/types/company';
import { companyOfferSchema } from '@/lib/validations/company-offer.schema';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { renderCompanyOfferEmail } from '@kit/email-templates';
import { SubmitButton } from '@kit/shared/components/ui/submit-button';
import { FormItem } from '@kit/ui/form';
import { Input } from '@kit/ui/input';
import { Label } from '@kit/ui/label';
import { Spinner } from '@kit/ui/spinner';
import { Trans } from '@kit/ui/trans';
const CompanyOfferForm = () => {
const [isLoading, setIsLoading] = useState(false);
const router = useRouter();
const language = useTranslation().i18n.language;
const {
@@ -28,16 +33,29 @@ const CompanyOfferForm = () => {
});
const onSubmit = async (data: CompanySubmitData) => {
setIsLoading(true);
const formData = new FormData();
Object.entries(data).forEach(([key, value]) => {
if (value !== undefined) formData.append(key, value);
});
try {
sendCompanyOfferEmail(data, language)
sendEmailFromTemplate(
renderCompanyOfferEmail,
{
companyData: data,
language,
},
process.env.CONTACT_EMAIL!,
)
.then(() => router.push('/company-offer/success'))
.catch((error) => alert('error: ' + error));
.catch((error) => {
setIsLoading(false);
alert('Could not send email at this time');
console.warn('error: ' + error);
});
} catch (err: unknown) {
setIsLoading(false);
if (err instanceof Error) {
console.warn('Server validation error: ' + err.message);
}
@@ -76,11 +94,15 @@ const CompanyOfferForm = () => {
<Input type="tel" {...register('phone')} />
</FormItem>
<SubmitButton
disabled={!isValid || isSubmitting}
disabled={isLoading || !isValid || isSubmitting}
pendingText="Saatmine..."
type="submit"
>
{isLoading ? (
<Spinner />
) : (
<Trans i18nKey={'account:requestCompanyAccount:button'} />
)}
</SubmitButton>
</form>
);

View File

@@ -1,16 +1,16 @@
import React from 'react';
import { MedReportLogo } from '@/components/med-report-logo';
import { withI18n } from '@/lib/i18n/with-i18n';
import { MedReportLogo } from '@kit/shared/components/med-report-logo';
import { Trans } from '@kit/ui/trans';
import { withI18n } from '~/lib/i18n/with-i18n';
import CompanyOfferForm from './_components/company-offer-form';
function CompanyOffer() {
return (
<div className="border-border flex max-w-5xl flex-row overflow-hidden rounded-3xl border">
<div className="flex w-1/2 flex-col px-12 py-14 text-center">
<div className="flex flex-col px-12 py-14 text-center md:w-1/2">
<MedReportLogo />
<h1 className="pt-8">
<Trans i18nKey={'account:requestCompanyAccount:title'} />
@@ -20,7 +20,7 @@ function CompanyOffer() {
</p>
<CompanyOfferForm />
</div>
<div className="w-1/2 min-w-[460px] bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat"></div>
<div className="hidden w-1/2 min-w-[460px] bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat md:block"></div>
</div>
);
}

View File

@@ -2,7 +2,7 @@ import { withI18n } from '~/lib/i18n/with-i18n';
function SiteLayout(props: React.PropsWithChildren) {
return (
<div className={'flex min-h-[100vh] flex-col justify-center items-center'}>
<div className={'flex min-h-[100vh] flex-col items-center justify-center'}>
{props.children}
</div>
);

View File

@@ -0,0 +1,24 @@
import { SIDEBAR_WIDTH_PROPERTY } from '@/packages/ui/src/shadcn/constants';
import { AppLogo } from '@kit/shared/components/app-logo';
import { ProfileAccountDropdownContainer } from '@kit/shared/components/personal-account-dropdown-container';
import type { UserWorkspace } from '../../home/(user)/_lib/server/load-user-workspace';
export function AdminMenuNavigation(props: { workspace: UserWorkspace }) {
const { accounts } = props.workspace;
return (
<div className={'flex w-full flex-1 items-center justify-between gap-3'}>
<div className={`flex items-center ${SIDEBAR_WIDTH_PROPERTY}`}>
<AppLogo href={'/admin'} />
</div>
<div className="flex items-center justify-end gap-3">
<div>
<ProfileAccountDropdownContainer accounts={accounts} />
</div>
</div>
</div>
);
}

View File

@@ -1,69 +1,25 @@
'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { LayoutDashboard, Users } from 'lucide-react';
import { adminNavigationConfig } from '@kit/shared/config';
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
useSidebar,
SidebarNavigation,
} from '@kit/ui/shadcn-sidebar';
import { AppLogo } from '~/components/app-logo';
import { ProfileAccountDropdownContainer } from '~/components/personal-account-dropdown-container';
export function AdminSidebar() {
const path = usePathname();
const { open } = useSidebar();
const collapsible = adminNavigationConfig.sidebarCollapsedStyle;
return (
<Sidebar collapsible="icon">
<SidebarHeader className={'m-2'}>
<AppLogo href={'/admin'} className="max-w-full" compact={!open} />
<Sidebar collapsible={collapsible}>
<SidebarHeader className="h-24 justify-center">
<div className="mt-24 flex items-center">
<h5>Superadmin</h5>
</div>
</SidebarHeader>
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>Super Admin</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuButton isActive={path === '/admin'} asChild>
<Link className={'flex gap-2.5'} href={'/admin'}>
<LayoutDashboard className={'h-4'} />
<span>Dashboard</span>
</Link>
</SidebarMenuButton>
<SidebarMenuButton
isActive={path.includes('/admin/accounts')}
asChild
>
<Link
className={'flex size-full gap-2.5'}
href={'/admin/accounts'}
>
<Users className={'h-4'} />
<span>Accounts</span>
</Link>
</SidebarMenuButton>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
<SidebarNavigation config={adminNavigationConfig} />
</SidebarContent>
<SidebarFooter>
<ProfileAccountDropdownContainer />
</SidebarFooter>
</Sidebar>
);
}

View File

@@ -2,7 +2,9 @@ import { cache } from 'react';
import { AdminAccountPage } from '@kit/admin/components/admin-account-page';
import { AdminGuard } from '@kit/admin/components/admin-guard';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { withI18n } from '~/lib/i18n/with-i18n';
import { getAccount } from '~/lib/services/account.service';
interface Params {
params: Promise<{
@@ -26,23 +28,6 @@ async function AccountPage(props: Params) {
return <AdminAccountPage account={account} />;
}
export default AdminGuard(AccountPage);
export default withI18n(AdminGuard(AccountPage));
const loadAccount = cache(accountLoader);
async function accountLoader(id: string) {
const client = getSupabaseServerClient();
const { data, error } = await client
.schema('medreport')
.from('accounts')
.select('*, memberships: accounts_memberships (*)')
.eq('id', id)
.single();
if (error) {
throw error;
}
return data;
}
const loadAccount = cache(getAccount);

View File

@@ -1,14 +1,16 @@
import { ServerDataLoader } from '@makerkit/data-loader-supabase-nextjs';
import { AdminAccountsTable } from '@kit/admin/components/admin-accounts-table';
import { AdminCreateUserDialog } from '@kit/admin/components/admin-create-user-dialog';
import { AdminCreateCompanyDialog } from '@kit/admin/components/admin-create-company-dialog';
import { AdminCreateUserDialog } from '@kit/admin/components/admin-create-user-dialog';
import { AdminGuard } from '@kit/admin/components/admin-guard';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { AppBreadcrumbs } from '@kit/ui/app-breadcrumbs';
import { Button } from '@kit/ui/button';
import { PageBody, PageHeader } from '@kit/ui/page';
import { withI18n } from '~/lib/i18n/with-i18n';
interface SearchParams {
page?: string;
account_type?: 'all' | 'team' | 'personal';
@@ -24,27 +26,28 @@ export const metadata = {
};
async function AccountsPage(props: AdminAccountsPageProps) {
const client = getSupabaseServerClient();
const client = getSupabaseServerClient().schema('medreport');
const searchParams = await props.searchParams;
const page = searchParams.page ? parseInt(searchParams.page) : 1;
return (
<>
<PageHeader description={<AppBreadcrumbs />}>
<PageHeader description={<AppBreadcrumbs />} title="Accounts">
<div className="flex justify-end gap-2">
<AdminCreateUserDialog>
<Button data-test="admin-create-user-button">Create Personal Account</Button>
<Button data-test="admin-create-user-button">
Create Personal Account
</Button>
</AdminCreateUserDialog>
<AdminCreateCompanyDialog>
<Button>Create Company Account</Button>
</AdminCreateCompanyDialog>
</div>
</PageHeader>
<PageBody>
<ServerDataLoader
table={'accounts'}
table="accounts"
client={client}
page={page}
where={(queryBuilder) => {
@@ -55,7 +58,9 @@ async function AccountsPage(props: AdminAccountsPageProps) {
}
if (query) {
queryBuilder.or(`name.ilike.%${query}%,email.ilike.%${query}%,personal_code.ilike.%${query}%`);
queryBuilder.or(
`name.ilike.%${query}%,email.ilike.%${query}%,personal_code.ilike.%${query}%`,
);
}
return queryBuilder;
@@ -81,4 +86,4 @@ async function AccountsPage(props: AdminAccountsPageProps) {
);
}
export default AdminGuard(AccountsPage);
export default withI18n(AdminGuard(AccountsPage));

View File

@@ -5,9 +5,12 @@ import { cookies } from 'next/headers';
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
import { AdminMenuNavigation } from '~/admin/_components/admin-menu-navigation';
import { AdminSidebar } from '~/admin/_components/admin-sidebar';
import { AdminMobileNavigation } from '~/admin/_components/mobile-navigation';
import { loadUserWorkspace } from '../home/(user)/_lib/server/load-user-workspace';
export const metadata = {
title: `Super Admin`,
};
@@ -16,21 +19,27 @@ export const dynamic = 'force-dynamic';
export default function AdminLayout(props: React.PropsWithChildren) {
const state = use(getLayoutState());
const workspace = use(loadUserWorkspace());
return (
<SidebarProvider defaultOpen={state.open}>
<Page style={'sidebar'}>
<Page style={'header'}>
<PageNavigation>
<AdminSidebar />
<AdminMenuNavigation workspace={workspace} />
</PageNavigation>
<PageMobileNavigation>
<AdminMobileNavigation />
</PageMobileNavigation>
<SidebarProvider defaultOpen={state.open}>
<Page style={'sidebar'}>
<PageNavigation>
<AdminSidebar />
</PageNavigation>
{props.children}
</Page>
</SidebarProvider>
</Page>
);
}

View File

@@ -2,10 +2,12 @@ import { AdminDashboard } from '@kit/admin/components/admin-dashboard';
import { AdminGuard } from '@kit/admin/components/admin-guard';
import { PageBody, PageHeader } from '@kit/ui/page';
import { withI18n } from '~/lib/i18n/with-i18n';
function AdminPage() {
return (
<>
<PageHeader description={`Super Admin`} />
<PageHeader title={`Super Admin`} />
<PageBody>
<AdminDashboard />
@@ -14,4 +16,4 @@ function AdminPage() {
);
}
export default AdminGuard(AdminPage);
export default withI18n(AdminGuard(AdminPage));

View File

@@ -1,11 +1,10 @@
import { getPlanTypesMap } from '@kit/billing';
import { getBillingEventHandlerService } from '@kit/billing-gateway';
import { enhanceRouteHandler } from '@kit/next/routes';
import { billingConfig } from '@kit/shared/config';
import { getLogger } from '@kit/shared/logger';
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
import billingConfig from '~/config/billing.config';
/**
* @description Handle the webhooks from Stripe related to checkouts
*/

View File

@@ -0,0 +1,12 @@
import { config } from 'dotenv';
export default function loadEnv() {
config({ path: `.env` });
if (
['local', 'test', 'development', 'production'].includes(
process.env.NODE_ENV!,
)
) {
config({ path: `.env.${process.env.NODE_ENV}` });
}
}

View File

@@ -0,0 +1,23 @@
import { renderNewJobsAvailableEmail } from '@kit/email-templates';
import { getDoctorAccounts } from '~/lib/services/account.service';
import { getOpenJobAnalysisResponseIds } from '~/lib/services/doctor-jobs.service';
import { sendEmailFromTemplate } from '~/lib/services/mailer.service';
export default async function sendOpenJobsEmails() {
const analysisResponseIds = await getOpenJobAnalysisResponseIds();
const doctorAccounts = await getDoctorAccounts();
const doctorEmails: string[] = doctorAccounts
.map(({ email }) => email)
.filter((email): email is string => !!email);
await sendEmailFromTemplate(
renderNewJobsAvailableEmail,
{
language: 'et',
analysisResponseIds,
},
doctorEmails,
);
}

View File

@@ -0,0 +1,250 @@
import { listProductTypes } from '@lib/data/products';
import Medusa from '@medusajs/js-sdk';
import type { AdminProductCategory } from '@medusajs/types';
import {
createMedusaSyncFailEntry,
createMedusaSyncSuccessEntry,
} from '~/lib/services/analyses.service';
import { getAnalysisElements } from '~/lib/services/analysis-element.service';
import { getAnalysisGroups } from '~/lib/services/analysis-group.service';
const SYNLAB_SERVICES_CATEGORY_HANDLE = 'synlab-services';
const SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE = 'synlab-analysis';
const BASE_ANALYSIS_PRODUCT_HANDLE = 'analysis-base';
const getAdminSdk = () => {
const medusaBackendUrl = process.env.MEDUSA_BACKEND_PUBLIC_URL!;
const medusaPublishableApiKey =
process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY!;
const key = process.env.MEDUSA_SECRET_API_KEY!;
if (!medusaBackendUrl || !medusaPublishableApiKey) {
throw new Error('Medusa environment variables not set');
}
return new Medusa({
baseUrl: medusaBackendUrl,
debug: process.env.NODE_ENV === 'development',
apiKey: key,
});
};
async function createProductCategories({ medusa }: { medusa: Medusa }) {
const { product_categories: existingProductCategories } =
await medusa.admin.productCategory.list();
const parentCategory = existingProductCategories.find(
({ handle }) => handle === SYNLAB_SERVICES_CATEGORY_HANDLE,
);
if (!parentCategory) {
throw new Error('Parent category not found');
}
const analysisGroups = await getAnalysisGroups();
if (!analysisGroups) {
throw new Error('Analysis groups not found');
}
const createdCategories: AdminProductCategory[] = [];
for (const analysisGroup of analysisGroups) {
console.info(`Processing analysis group '${analysisGroup.name}'`);
const isExisting = existingProductCategories.find(
({ name }) => name === analysisGroup.name,
);
const isNewlyCreated = createdCategories.find(
({ name }) => name === analysisGroup.name,
);
if (isExisting || isNewlyCreated) {
console.info(`Analysis group '${analysisGroup.name}' already exists`);
continue;
}
const createResponse = await medusa.admin.productCategory.create({
name: analysisGroup.name,
handle: analysisGroup.name,
parent_category_id: parentCategory.id,
is_active: true,
metadata: {
analysisGroupOriginalId: analysisGroup.original_id,
analysisGroupId: analysisGroup.id,
},
});
console.info(
`Successfully created category, id=${createResponse.product_category.id}`,
);
createdCategories.push(createResponse.product_category);
}
}
async function getChildProductCategories({ medusa }: { medusa: Medusa }) {
const { product_categories: allCategories } =
await medusa.admin.productCategory.list();
const childCategories = allCategories.filter(
({ parent_category_id }) => parent_category_id !== null,
);
return childCategories;
}
async function deleteProductCategories({
medusa,
categories,
}: {
medusa: Medusa;
categories: AdminProductCategory[];
}) {
for (const category of categories) {
await medusa.admin.productCategory.delete(category.id);
}
}
/**
* In case a reset is needed
*/
async function deleteProducts({ medusa }: { medusa: Medusa }) {
const { products: existingProducts } = await medusa.admin.product.list({
fields: 'id,collection_id',
limit: 1000,
});
await Promise.all(
existingProducts
.filter((a) => !a.collection_id)
.map(({ id }) => medusa.admin.product.delete(id)),
);
}
async function getAnalysisPackagesType() {
const { productTypes } = await listProductTypes();
const analysisPackagesType = productTypes.find(
({ metadata }) => metadata?.handle === SYNLAB_ANALYSIS_PRODUCT_TYPE_HANDLE,
);
if (!analysisPackagesType) {
throw new Error('Synlab analysis packages type not found');
}
return analysisPackagesType;
}
async function getProductDefaultFields({ medusa }: { medusa: Medusa }) {
const baseProductsResponse = await medusa.admin.product.list({
handle: BASE_ANALYSIS_PRODUCT_HANDLE,
});
const baseProduct = baseProductsResponse.products[0];
if (!baseProduct) {
throw new Error('Base product not found');
}
const defaultSalesChannels = baseProduct.sales_channels;
if (!Array.isArray(defaultSalesChannels)) {
throw new Error('Base analysis product has no required sales channels');
}
const defaultProductOption = baseProduct.options;
if (!Array.isArray(defaultProductOption)) {
throw new Error('Base analysis product has no required options');
}
const defaultProductVariant = baseProduct.variants?.[0];
if (!defaultProductVariant) {
throw new Error('Base analysis product has no required variant');
}
return {
defaultSalesChannels,
defaultProductOption,
defaultProductVariant,
};
}
async function createProducts({ medusa }: { medusa: Medusa }) {
const { product_categories: allCategories } =
await medusa.admin.productCategory.list();
const [
{ products: existingProducts },
analysisElements,
analysisPackagesType,
{ defaultSalesChannels, defaultProductOption, defaultProductVariant },
] = await Promise.all([
medusa.admin.product.list({
category_id: allCategories.map(({ id }) => id),
}),
getAnalysisElements({ getAll: true }),
getAnalysisPackagesType(),
getProductDefaultFields({ medusa }),
]);
for (const analysisElement of analysisElements) {
const { analysis_id_original: originalId } = analysisElement;
const isExisting = existingProducts.find(
({ metadata }) => metadata?.analysisIdOriginal === originalId,
);
if (isExisting) {
console.info(
`Analysis element '${analysisElement.analysis_name_lab}' already exists`,
);
continue;
}
const { analysis_name_lab: name } = analysisElement;
if (!name) {
console.error(`Analysis element '${originalId}' has no name`);
continue;
}
const category = allCategories.find(
({ metadata }) =>
metadata?.analysisGroupId === analysisElement.parent_analysis_group_id,
);
if (!category) {
console.error(`Category not found for analysis element '${name}'`);
continue;
}
await medusa.admin.product.create({
title: name,
handle: `analysis-element-${analysisElement.id}`,
categories: [{ id: category.id }],
options: defaultProductOption.map(({ id, title, values }) => ({
id,
title,
values: values?.map(({ value }) => value) ?? [],
})),
metadata: {
analysisIdOriginal: originalId,
},
is_giftcard: false,
discountable: false,
status: 'published',
sales_channels: defaultSalesChannels.map(({ id }) => ({ id })),
variants: [
{
title: defaultProductVariant.title!,
prices: defaultProductVariant.prices!,
manage_inventory: false,
},
],
type_id: analysisPackagesType.id,
});
}
}
export default async function syncAnalysisGroupsStore() {
const medusa = getAdminSdk();
try {
await createProductCategories({ medusa });
// const categories = await getChildProductCategories({ medusa });
// await deleteProductCategories({ medusa, categories });
// await deleteProducts({ medusa });
// return;
await createProducts({ medusa });
await createMedusaSyncSuccessEntry();
} catch (e) {
await createMedusaSyncFailEntry(JSON.stringify(e));
console.error(e);
throw new Error(
`Failed to sync analyses to Medusa, error: ${JSON.stringify(e)}`,
);
}
}

View File

@@ -0,0 +1,241 @@
import axios from 'axios';
import { XMLParser } from 'fast-xml-parser';
import fs from 'fs';
import { toArray } from '@kit/shared/utils';
import {
createAnalysis,
createNoDataReceivedEntry,
createNoNewDataReceivedEntry,
createSyncFailEntry,
createSyncSuccessEntry,
getAnalyses,
} from '~/lib/services/analyses.service';
import {
AnalysisElement,
createAnalysisElement,
getAnalysisElements,
} from '~/lib/services/analysis-element.service';
import {
createAnalysisGroup,
getAnalysisGroups,
} from '~/lib/services/analysis-group.service';
import { createCodes } from '~/lib/services/codes.service';
import { IMedipostPublicMessageDataParsed } from '~/lib/services/medipost/medipost.types';
import { getLatestPublicMessageListItem } from '~/lib/services/medipost/medipostPublicMessage.service';
import { getLastCheckedDate } from '~/lib/services/sync-entries.service';
import type { ICode } from '~/lib/types/code';
const WRITE_XML_TO_FILE = false as boolean;
export default async function syncAnalysisGroups() {
const baseUrl = process.env.MEDIPOST_URL;
const user = process.env.MEDIPOST_USER;
const password = process.env.MEDIPOST_PASSWORD;
const sender = process.env.MEDIPOST_MESSAGE_SENDER;
if (!baseUrl || !user || !password || !sender) {
throw new Error('Could not access all necessary environment variables');
}
try {
console.info('Getting latest public message id');
const lastCheckedDate = await getLastCheckedDate();
const latestMessage = await getLatestPublicMessageListItem();
if (!latestMessage) {
console.info('No new data received');
await createNoNewDataReceivedEntry();
return;
}
console.info('Getting public message with id: ', latestMessage.messageId);
const { data: publicMessageData } = await axios.get(baseUrl, {
params: {
Action: 'GetPublicMessage',
User: user,
Password: password,
MessageId: latestMessage.messageId,
},
headers: {
Accept: 'application/xml',
},
});
if (WRITE_XML_TO_FILE) {
fs.writeFileSync('public-messages-list-response.xml', publicMessageData);
}
const parser = new XMLParser({ ignoreAttributes: false });
const parsed: IMedipostPublicMessageDataParsed =
parser.parse(publicMessageData);
if (parsed.ANSWER?.CODE && parsed.ANSWER?.CODE !== 0) {
throw new Error(
`Failed to get public message (id: ${latestMessage.messageId})`,
);
}
const existingAnalysisGroups = await getAnalysisGroups();
// SAVE PUBLIC MESSAGE DATA
const providers = toArray(parsed?.Saadetis?.Teenused.Teostaja);
const analysisGroups = providers.flatMap((provider) =>
toArray(provider.UuringuGrupp),
);
if (!parsed || !analysisGroups.length) {
console.info('No analysis groups data received');
await createNoDataReceivedEntry();
return;
}
const codes: ICode[] = [];
for (const analysisGroup of analysisGroups) {
const existingAnalysisGroup = existingAnalysisGroups?.find(
({ original_id }) => original_id === analysisGroup.UuringuGruppId,
);
let groupExistingAnalysisElements: AnalysisElement[] = [];
let analysisGroupId: number;
if (existingAnalysisGroup) {
console.info(
`Analysis group '${analysisGroup.UuringuGruppNimi}' already exists, only creating new analysis elements`,
);
groupExistingAnalysisElements = await getAnalysisElements({
analysisGroupId: existingAnalysisGroup.id,
});
analysisGroupId = existingAnalysisGroup.id;
} else {
analysisGroupId = await createAnalysisGroup({
id: analysisGroup.UuringuGruppId,
name: analysisGroup.UuringuGruppNimi,
order: analysisGroup.UuringuGruppJarjekord,
});
const analysisGroupCodes = toArray(analysisGroup.Kood);
codes.push(
...analysisGroupCodes.map((kood) => ({
hk_code: kood.HkKood,
hk_code_multiplier: kood.HkKoodiKordaja,
coefficient: kood.Koefitsient,
price: kood.Hind,
analysis_group_id: analysisGroupId,
analysis_element_id: null,
analysis_id: null,
})),
);
}
const analysisGroupItems = toArray(analysisGroup.Uuring);
for (const item of analysisGroupItems) {
const analysisElement = item.UuringuElement!;
const isExistingAnalysisElement = groupExistingAnalysisElements.find(
({ analysis_id_original }) =>
analysis_id_original === analysisElement.UuringId,
);
if (isExistingAnalysisElement) {
console.info(
`Analysis element '${analysisElement.UuringNimi}' already exists`,
);
continue;
}
const insertedAnalysisElementId = await createAnalysisElement({
analysisElement: analysisElement!,
analysisGroupId,
materialGroups: toArray(item.MaterjalideGrupp),
});
if (Array.isArray(analysisElement.UuringuElement)) {
for (const nestedAnalysisElement of analysisElement.UuringuElement) {
await createAnalysisElement({
analysisElement: nestedAnalysisElement,
analysisGroupId,
materialGroups: toArray(item.MaterjalideGrupp),
});
}
}
if (analysisElement.Kood) {
const analysisElementCodes = toArray(analysisElement.Kood);
codes.push(
...analysisElementCodes.map((kood) => ({
hk_code: kood.HkKood,
hk_code_multiplier: kood.HkKoodiKordaja,
coefficient: kood.Koefitsient,
price: kood.Hind,
analysis_group_id: null,
analysis_element_id: insertedAnalysisElementId,
analysis_id: null,
})),
);
}
const analyses = analysisElement.UuringuElement;
if (analyses?.length) {
const existingAnalyses = await getAnalyses({
originalIds: analyses.map(({ UuringId }) => UuringId),
});
for (const analysis of analyses) {
const isExistingAnalysis = existingAnalyses.find(
({ analysis_id_original }) =>
analysis_id_original === analysis.UuringId,
);
if (isExistingAnalysis) {
console.info(`Analysis '${analysis.UuringNimi}' already exists`);
continue;
}
const insertedAnalysisId = await createAnalysis(
analysis,
analysisGroupId,
);
if (analysis.Kood) {
const analysisCodes = toArray(analysis.Kood);
codes.push(
...analysisCodes.map((kood) => ({
hk_code: kood.HkKood,
hk_code_multiplier: kood.HkKoodiKordaja,
coefficient: kood.Koefitsient,
price: kood.Hind,
analysis_group_id: null,
analysis_element_id: null,
analysis_id: insertedAnalysisId,
})),
);
}
}
}
}
}
console.info('Inserting codes');
await createCodes(codes);
console.info('Inserting sync entry');
await createSyncSuccessEntry();
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e);
await createSyncFailEntry(
JSON.stringify(
{
message: errorMessage,
stack: e instanceof Error ? e.stack : undefined,
name: e instanceof Error ? e.name : 'Unknown',
},
null,
2,
),
);
console.error('Sync failed:', e);
throw new Error(
`Failed to sync public message data, error: ${errorMessage}`,
);
}
}

View File

@@ -0,0 +1,65 @@
import { readPrivateMessageResponse } from '~/lib/services/medipost/medipostPrivateMessage.service';
type ProcessedMessage = {
messageId: string;
hasAnalysisResponse: boolean;
hasPartialAnalysisResponse: boolean;
hasFullAnalysisResponse: boolean;
medusaOrderId: string | undefined;
analysisOrderId: number | undefined;
};
type GroupedResults = {
processed: Pick<ProcessedMessage, 'messageId' | 'analysisOrderId'>[];
waitingForResults: Pick<ProcessedMessage, 'messageId' | 'analysisOrderId'>[];
};
export default async function syncAnalysisResults() {
console.info('Syncing analysis results');
const processedMessages: ProcessedMessage[] = [];
const excludedMessageIds: string[] = [];
while (true) {
const result = await readPrivateMessageResponse({ excludedMessageIds });
if (result.messageId) {
processedMessages.push(result as ProcessedMessage);
}
if (!result.messageId) {
console.info('No more messages to process');
break;
}
if (!excludedMessageIds.includes(result.messageId)) {
excludedMessageIds.push(result.messageId);
} else {
break;
}
}
const groupedResults = processedMessages.reduce((acc, result) => {
if (result.analysisOrderId) {
if (result.hasAnalysisResponse) {
if (!acc.processed) {
acc.processed = [];
}
acc.processed.push({
messageId: result.messageId,
analysisOrderId: result.analysisOrderId,
});
} else {
if (!acc.waitingForResults) {
acc.waitingForResults = [];
}
acc.waitingForResults.push({
messageId: result.messageId,
analysisOrderId: result.analysisOrderId,
});
}
}
return acc;
}, {} as GroupedResults);
console.info(
`Processed ${processedMessages.length} messages, results: ${JSON.stringify(groupedResults)}`,
);
}

View File

@@ -0,0 +1,268 @@
import axios from 'axios';
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
import { logSyncResult } from '~/lib/services/audit.service';
import { SyncStatus } from '~/lib/types/audit';
import type {
ISearchLoadResponse,
P_JobTitleTranslation,
} from '~/lib/types/connected-online';
function createTranslationMap(translations: P_JobTitleTranslation[]) {
const result: Map<
number,
Map<number, { textEN: string; textRU: string; textET: string }>
> = new Map();
for (const translation of translations) {
const { ClinicID, TextET, TextEN, TextRU, SyncID } = translation;
if (!result.has(ClinicID)) {
result.set(ClinicID, new Map());
}
result.get(ClinicID)!.set(SyncID, {
textET: TextET,
textEN: TextEN,
textRU: TextRU,
});
}
return result;
}
function getSpokenLanguages(spokenLanguages?: string) {
if (!spokenLanguages || !spokenLanguages.length) return [];
return spokenLanguages.split(',');
}
export default async function syncConnectedOnline() {
const isProd = !['test', 'localhost'].some((pathString) =>
process.env.NEXT_PUBLIC_SITE_URL?.includes(pathString),
);
const baseUrl = process.env.CONNECTED_ONLINE_URL;
if (!baseUrl) {
throw new Error('Could not access all necessary environment variables');
}
const supabase = getSupabaseServerAdminClient();
try {
const searchLoadResponse = await axios.post<{ d: string }>(
`${baseUrl}/Search_Load`,
{
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
param: "{'Value':'|et|-1'}", // get all available services in Estonian
},
);
const responseData: ISearchLoadResponse = JSON.parse(
searchLoadResponse.data.d,
);
if (responseData?.ErrorCode !== 0) {
throw new Error('Failed to get Connected Online data');
}
if (
!responseData.Data.T_Lic?.length ||
!responseData.Data.T_Service?.length
) {
return supabase.schema('audit').from('sync_entries').insert({
operation: 'CONNECTED_ONLINE_SYNC',
comment: 'No clinic or service data received',
status: 'FAIL',
changed_by_role: 'service_role',
});
}
let clinics;
let services;
let serviceProviders;
let jobTitleTranslations;
// Filter out "Dentas Demo OÜ" in prod or only sync "Dentas Demo OÜ" in any other environment
const isDemoClinic = (clinicId: number) =>
isProd ? clinicId !== 2 : clinicId === 2;
clinics = responseData.Data.T_Lic.filter(({ ID }) => isDemoClinic(ID));
services = responseData.Data.T_Service.filter(({ ClinicID }) =>
isDemoClinic(ClinicID),
);
serviceProviders = responseData.Data.T_Doctor.filter(({ ClinicID }) =>
isDemoClinic(ClinicID),
);
jobTitleTranslations = createTranslationMap(
responseData.Data.P_JobTitleTranslations.filter(({ ClinicID }) =>
isDemoClinic(ClinicID),
),
);
const mappedClinics = clinics.map((clinic) => {
return {
id: clinic.ID,
can_select_worker: !!clinic.OnlineCanSelectWorker,
email: clinic.Email || null,
name: clinic.Name,
personal_code_required: !!clinic.PersonalCodeRequired,
phone_number: clinic.Phone || null,
key: clinic.Key,
address: clinic.Address,
};
});
const mappedServices = services.map((service) => {
return {
id: service.ID,
clinic_id: service.ClinicID,
sync_id: Number(service.SyncID),
name: service.Name,
description: service.Description || null,
price: service.Price,
requires_payment: !!service.RequiresPayment,
duration: service.Duration,
neto_duration: service.NetoDuration,
display: service.Display,
price_periods: service.PricePeriods || null,
online_hide_duration: service.OnlineHideDuration,
online_hide_price: service.OnlineHidePrice,
code: service.Code,
has_free_codes: !!service.HasFreeCodes,
};
});
const mappedServiceProviders = serviceProviders.map((serviceProvider) => {
const jobTitleTranslation = serviceProvider.JobTitleID
? jobTitleTranslations
.get(serviceProvider.ClinicID)
?.get(serviceProvider.JobTitleID)
: null;
return {
id: serviceProvider.ID,
prefix: serviceProvider.Prefix,
name: serviceProvider.Name,
spoken_languages: getSpokenLanguages(serviceProvider.SpokenLanguages),
job_title_et: jobTitleTranslation?.textET,
job_title_en: jobTitleTranslation?.textEN,
job_title_ru: jobTitleTranslation?.textRU,
job_title_id: serviceProvider.JobTitleID,
is_deleted: !!serviceProvider.Deleted,
clinic_id: serviceProvider.ClinicID,
};
});
const { error: providersError } = await supabase
.schema('medreport')
.from('connected_online_providers')
.upsert(mappedClinics);
if (providersError) {
return logSyncResult({
operation: 'CONNECTED_ONLINE_SYNC',
comment:
'Error saving connected online providers: ' +
JSON.stringify(providersError),
status: SyncStatus.Fail,
changed_by_role: 'service_role',
});
}
const { error: servicesError } = await supabase
.schema('medreport')
.from('connected_online_services')
.upsert(mappedServices, {
onConflict: 'id',
ignoreDuplicates: false,
});
if (servicesError) {
return logSyncResult({
operation: 'CONNECTED_ONLINE_SYNC',
comment:
'Error saving connected online services: ' +
JSON.stringify(servicesError),
status: SyncStatus.Fail,
changed_by_role: 'service_role',
});
}
const { error: serviceProvidersError } = await supabase
.schema('medreport')
.from('connected_online_service_providers')
.upsert(mappedServiceProviders, {
onConflict: 'id',
ignoreDuplicates: false,
});
if (serviceProvidersError) {
return logSyncResult({
operation: 'CONNECTED_ONLINE_SYNC',
comment:
'Error saving service providers: ' +
JSON.stringify(serviceProvidersError),
status: SyncStatus.Fail,
changed_by_role: 'service_role',
});
}
for (const mappedClinic of mappedClinics) {
const defaultLoadResponse = await axios.post<{ d: string }>(
`${baseUrl}/Default_Load`,
{
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
param: `{'Value':'${mappedClinic.key}|et'}`,
},
);
const defaultLoadResponseData = JSON.parse(defaultLoadResponse.data.d);
if (defaultLoadResponseData?.ErrorCode !== 0) {
throw new Error('Failed to get Connected Online location data');
}
const clinicLocations: {
SyncID: number;
Address: string;
Name: string;
}[] = defaultLoadResponseData.Data.T_SelectableLocation;
if (clinicLocations?.length) {
const mappedLocations = clinicLocations.map(
({ SyncID, Address, Name }) => ({
address: Address,
clinic_id: mappedClinic.id,
sync_id: SyncID,
name: Name,
}),
);
await supabase
.schema('medreport')
.from('connected_online_locations')
.insert(mappedLocations)
.throwOnError();
}
}
await logSyncResult({
operation: 'CONNECTED_ONLINE_SYNC',
status: SyncStatus.Success,
changed_by_role: 'service_role',
});
} catch (e) {
await logSyncResult({
operation: 'CONNECTED_ONLINE_SYNC',
status: SyncStatus.Fail,
comment: JSON.stringify(e),
changed_by_role: 'service_role',
});
throw new Error(
`Failed to sync Connected Online data, error: ${JSON.stringify(e)}`,
);
}
}

View File

@@ -0,0 +1,9 @@
import { NextRequest } from 'next/server';
export default function validateApiKey(request: NextRequest) {
const envApiKey = process.env.JOBS_API_TOKEN;
const requestApiKey = request.headers.get('x-jobs-api-key');
if (requestApiKey !== envApiKey) {
throw new Error('Unauthorized');
}
}

View File

@@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from 'next/server';
import { retrieveOrder } from '@lib/data/orders';
import { getMedipostDispatchTries } from '~/lib/services/audit.service';
import { sendOrderToMedipost } from '~/lib/services/medipost/medipostPrivateMessage.service';
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
import loadEnv from '../handler/load-env';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
const { medusaOrderId } = await request.json();
try {
validateApiKey(request);
} catch (e) {
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
}
const tries = await getMedipostDispatchTries(medusaOrderId);
if (tries >= 3) {
return NextResponse.json(
{
message: 'Order has been retried too many times',
},
{ status: 400 },
);
}
try {
const medusaOrder = await retrieveOrder(medusaOrderId);
const orderedAnalysisElements = await getOrderedAnalysisIds({
medusaOrder,
});
await sendOrderToMedipost({ medusaOrderId, orderedAnalysisElements });
console.info('Successfully sent order to medipost');
return NextResponse.json(
{
message: 'Successfully sent order to medipost',
},
{ status: 200 },
);
} catch (e) {
console.error('Error sending order to medipost', e);
return NextResponse.json(
{
message: 'Failed to send order to medipost',
},
{ status: 500 },
);
}
};

View File

@@ -0,0 +1,54 @@
import { NextRequest, NextResponse } from 'next/server';
import {
NotificationAction,
createNotificationLog,
} from '~/lib/services/audit/notificationEntries.service';
import loadEnv from '../handler/load-env';
import sendOpenJobsEmails from '../handler/send-open-jobs-emails';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
try {
validateApiKey(request);
} catch (e) {
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
}
try {
await sendOpenJobsEmails();
console.info(
'Successfully sent out open job notification emails to doctors.',
);
await createNotificationLog({
action: NotificationAction.DOCTOR_NEW_JOBS,
status: 'SUCCESS',
});
return NextResponse.json(
{
message:
'Successfully sent out open job notification emails to doctors.',
},
{ status: 200 },
);
} catch (e: any) {
console.error(
'Error sending out open job notification emails to doctors.',
e,
);
await createNotificationLog({
action: NotificationAction.DOCTOR_NEW_JOBS,
status: 'FAIL',
comment: e?.message,
});
return NextResponse.json(
{
message: 'Failed to send out open job notification emails to doctors.',
},
{ status: 500 },
);
}
};

View File

@@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from 'next/server';
import loadEnv from '../handler/load-env';
import syncAnalysisGroupsStore from '../handler/sync-analysis-groups-store';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
try {
validateApiKey(request);
} catch (e) {
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
}
try {
await syncAnalysisGroupsStore();
console.info('Successfully synced analysis groups store');
return NextResponse.json(
{
message: 'Successfully synced analysis groups store',
},
{ status: 200 },
);
} catch (e) {
console.error('Error syncing analysis groups store', e);
return NextResponse.json(
{
message: 'Failed to sync analysis groups store',
},
{ status: 500 },
);
}
};

View File

@@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from 'next/server';
import loadEnv from '../handler/load-env';
import syncAnalysisGroups from '../handler/sync-analysis-groups';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
try {
validateApiKey(request);
} catch (e) {
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
}
try {
await syncAnalysisGroups();
console.info('Successfully synced analysis groups');
return NextResponse.json(
{
message: 'Successfully synced analysis groups',
},
{ status: 200 },
);
} catch (e) {
console.error('Error syncing analysis groups', e);
return NextResponse.json(
{
message: 'Failed to sync analysis groups',
},
{ status: 500 },
);
}
};

View File

@@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from 'next/server';
import loadEnv from '../handler/load-env';
import syncAnalysisResults from '../handler/sync-analysis-results';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
try {
validateApiKey(request);
} catch (e) {
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
}
try {
await syncAnalysisResults();
console.info('Successfully synced analysis results');
return NextResponse.json(
{
message: 'Successfully synced analysis results',
},
{ status: 200 },
);
} catch (e) {
console.error('Error syncing analysis results', e);
return NextResponse.json(
{
message: 'Failed to sync analysis results',
},
{ status: 500 },
);
}
};

View File

@@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from 'next/server';
import loadEnv from '../handler/load-env';
import syncConnectedOnline from '../handler/sync-connected-online';
import validateApiKey from '../handler/validate-api-key';
export const POST = async (request: NextRequest) => {
loadEnv();
try {
validateApiKey(request);
} catch (e) {
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
}
try {
await syncConnectedOnline();
console.info('Successfully synced connected-online');
return NextResponse.json(
{
message: 'Successfully synced connected-online',
},
{ status: 200 },
);
} catch (e) {
console.error('Error syncing connected-online', e);
return NextResponse.json(
{
message: 'Failed to sync connected-online',
},
{ status: 500 },
);
}
};

View File

@@ -0,0 +1,72 @@
import { NextRequest, NextResponse } from 'next/server';
import { retrieveOrder } from '@lib/data';
import { getAccountAdmin } from '~/lib/services/account.service';
import {
composeOrderTestResponseXML,
sendPrivateMessageTestResponse,
} from '~/lib/services/medipost/medipostTest.service';
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
import { getAnalysisOrdersAdmin } from '~/lib/services/order.service';
import loadEnv from '../handler/load-env';
import validateApiKey from '../handler/validate-api-key';
export async function POST(request: NextRequest) {
loadEnv();
try {
validateApiKey(request);
} catch (e) {
return NextResponse.json({}, { status: 401, statusText: 'Unauthorized' });
}
const analysisOrders = await getAnalysisOrdersAdmin({
orderStatus: 'PROCESSING',
});
console.error(
`Sending test responses for ${analysisOrders.length} analysis orders`,
);
for (const medreportOrder of analysisOrders) {
const medusaOrderId = medreportOrder.medusa_order_id;
const medusaOrder = await retrieveOrder(medusaOrderId);
const account = await getAccountAdmin({
primaryOwnerUserId: medreportOrder.user_id,
});
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({
medusaOrder,
});
console.info(
`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`,
);
const idsToSend = orderedAnalysisElementsIds;
const messageXml = await composeOrderTestResponseXML({
person: {
idCode: account.personal_code!,
firstName: account.name ?? '',
lastName: account.last_name ?? '',
phone: account.phone ?? '',
},
orderedAnalysisElementsIds: idsToSend
.map(({ analysisElementId }) => analysisElementId)
.filter(Boolean) as number[],
orderedAnalysesIds: idsToSend
.map(({ analysisId }) => analysisId)
.filter(Boolean) as number[],
orderId: medreportOrder.id,
orderCreatedAt: new Date(medreportOrder.created_at),
});
try {
await sendPrivateMessageTestResponse({ messageXml });
} catch (error) {
console.error('Error sending private message test response: ', error);
}
}
return NextResponse.json({ success: true });
}

View File

@@ -1,4 +1,5 @@
import { NextResponse } from 'next/server';
import jwt from 'jsonwebtoken';
import { z } from 'zod';

View File

@@ -0,0 +1,64 @@
import { NextResponse } from 'next/server';
import { retrieveOrder } from '@lib/data';
import { getAccountAdmin } from '~/lib/services/account.service';
import { upsertMedipostActionLog } from '~/lib/services/medipost/medipostMessageBase.service';
import {
composeOrderTestResponseXML,
sendPrivateMessageTestResponse,
} from '~/lib/services/medipost/medipostTest.service';
import { getOrderedAnalysisIds } from '~/lib/services/medusaOrder.service';
import { getAnalysisOrder } from '~/lib/services/order.service';
export async function POST(request: Request) {
// const isDev = process.env.NODE_ENV === 'development';
// if (!isDev) {
// return NextResponse.json({ error: 'This endpoint is only available in development mode' }, { status: 403 });
// }
const { medusaOrderId } = await request.json();
const medusaOrder = await retrieveOrder(medusaOrderId);
const analysisOrder = await getAnalysisOrder({ medusaOrderId });
const account = await getAccountAdmin({
primaryOwnerUserId: analysisOrder.user_id,
});
const orderedAnalysisElementsIds = await getOrderedAnalysisIds({
medusaOrder,
});
console.info(
`Sending test response for order=${medusaOrderId} with ${orderedAnalysisElementsIds.length} ordered analysis elements`,
);
const messageXml = await composeOrderTestResponseXML({
person: {
idCode: account.personal_code!,
firstName: account.name ?? '',
lastName: account.last_name ?? '',
phone: account.phone ?? '',
},
orderedAnalysisElementsIds: orderedAnalysisElementsIds
.map(({ analysisElementId }) => analysisElementId)
.filter(Boolean) as number[],
orderedAnalysesIds: orderedAnalysisElementsIds
.map(({ analysisId }) => analysisId)
.filter(Boolean) as number[],
orderId: analysisOrder.id,
orderCreatedAt: new Date(analysisOrder.created_at),
});
try {
await upsertMedipostActionLog({
action: 'send_fake_analysis_results_to_medipost',
xml: messageXml,
medusaOrderId,
});
await sendPrivateMessageTestResponse({ messageXml });
} catch (error) {
console.error('Error sending private message test response: ', error);
}
return NextResponse.json({ success: true });
}

View File

@@ -3,11 +3,11 @@ import Link from 'next/link';
import type { AuthError } from '@supabase/supabase-js';
import { ResendAuthLinkForm } from '@kit/auth/resend-email-link';
import { pathsConfig } from '@kit/shared/config';
import { Alert, AlertDescription, AlertTitle } from '@kit/ui/alert';
import { Button } from '@kit/ui/button';
import { Trans } from '@kit/ui/trans';
import pathsConfig from '~/config/paths.config';
import { withI18n } from '~/lib/i18n/with-i18n';
interface AuthCallbackErrorPageProps {

View File

@@ -1,6 +1,5 @@
import { AuthLayoutShell } from '@kit/auth/shared';
import { AppLogo } from '~/components/app-logo';
import { AppLogo } from '@kit/shared/components/app-logo';
function AuthLayout({ children }: React.PropsWithChildren) {
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;

View File

@@ -1,18 +1,63 @@
import { redirect } from 'next/navigation';
import type { NextRequest } from 'next/server';
import { createAuthCallbackService } from '@kit/supabase/auth';
import { createAccountsApi } from '@/packages/features/accounts/src/server/api';
import { pathsConfig } from '@kit/shared/config';
import {
createAuthCallbackService,
getErrorURLParameters,
} from '@kit/supabase/auth';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import pathsConfig from '~/config/paths.config';
const ERROR_PATH = '/auth/callback/error';
const redirectOnError = (searchParams?: string) => {
return redirect(`${ERROR_PATH}${searchParams ? `?${searchParams}` : ''}`);
};
export async function GET(request: NextRequest) {
const service = createAuthCallbackService(getSupabaseServerClient());
const { searchParams } = new URL(request.url);
const { nextPath } = await service.exchangeCodeForSession(request, {
joinTeamPath: pathsConfig.app.joinTeam,
redirectPath: pathsConfig.app.home,
const error = searchParams.get('error');
if (error) {
const { searchParams } = getErrorURLParameters({ error });
return redirectOnError(searchParams);
}
const authCode = searchParams.get('code');
if (!authCode) {
return redirectOnError();
}
let redirectPath = searchParams.get('next') || pathsConfig.app.home;
// if we have an invite token, we redirect to the join team page
// instead of the default next url. This is because the user is trying
// to join a team and we want to make sure they are redirected to the
// correct page.
const inviteToken = searchParams.get('invite_token');
if (inviteToken) {
const urlParams = new URLSearchParams({
invite_token: inviteToken,
email: searchParams.get('email') ?? '',
});
return redirect(nextPath);
redirectPath = `${pathsConfig.app.joinTeam}?${urlParams.toString()}`;
}
const service = createAuthCallbackService(getSupabaseServerClient());
const oauthResult = await service.exchangeCodeForSession(authCode);
if (!('isSuccess' in oauthResult)) {
return redirectOnError(oauthResult.searchParams);
}
const api = createAccountsApi(getSupabaseServerClient());
const account = await api.getPersonalAccountByUserId(oauthResult.user.id);
if (!account.email || !account.name || !account.last_name) {
return redirect(pathsConfig.auth.updateAccount);
}
return redirect(redirectPath);
}

View File

@@ -1,6 +1,5 @@
import { AuthLayoutShell } from '@kit/auth/shared';
import { AppLogo } from '~/components/app-logo';
import { AppLogo } from '@kit/shared/components/app-logo';
function AuthLayout({ children }: React.PropsWithChildren) {
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;

View File

@@ -1,10 +1,9 @@
import { NextRequest, NextResponse } from 'next/server';
import { pathsConfig } from '@kit/shared/config';
import { createAuthCallbackService } from '@kit/supabase/auth';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import pathsConfig from '~/config/paths.config';
export async function GET(request: NextRequest) {
const service = createAuthCallbackService(getSupabaseServerClient());

View File

@@ -2,11 +2,11 @@
import React from 'react';
import pathsConfig from '@/config/paths.config';
import { useTranslation } from 'react-i18next';
import { usePersonalAccountData } from '@kit/accounts/hooks/use-personal-account-data';
import { SuccessNotification } from '@kit/notifications/components';
import { pathsConfig } from '@kit/shared/config';
const MembershipConfirmationNotification: React.FC<{
userId: string;
@@ -25,7 +25,7 @@ const MembershipConfirmationNotification: React.FC<{
descriptionKey="account:membershipConfirmation:successDescription"
buttonProps={{
buttonTitleKey: 'account:membershipConfirmation:successButton',
href: pathsConfig.app.selectPackage,
href: pathsConfig.app.home,
}}
/>
);

View File

@@ -1,14 +1,17 @@
import { redirect } from 'next/navigation';
import pathsConfig from '@/config/paths.config';
import { pathsConfig } from '@kit/shared/config';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { withI18n } from '~/lib/i18n/with-i18n';
import {
PageViewAction,
createPageViewLog,
} from '~/lib/services/audit/pageView.service';
import MembershipConfirmationNotification from './_components/membership-confirmation-notification';
async function UpdateAccountSuccess() {
async function MembershipConfirmation() {
const client = getSupabaseServerClient();
const {
@@ -18,8 +21,12 @@ async function UpdateAccountSuccess() {
if (!user?.id) {
redirect(pathsConfig.app.home);
}
await createPageViewLog({
accountId: user.id,
action: PageViewAction.REGISTRATION_SUCCESS,
});
return <MembershipConfirmationNotification userId={user.id} />;
}
export default withI18n(UpdateAccountSuccess);
export default withI18n(MembershipConfirmation);

View File

@@ -1,6 +1,5 @@
import { AuthLayoutShell } from '@kit/auth/shared';
import { AppLogo } from '~/components/app-logo';
import { AppLogo } from '@kit/shared/components/app-logo';
function AuthLayout({ children }: React.PropsWithChildren) {
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;

View File

@@ -1,11 +1,11 @@
import Link from 'next/link';
import { PasswordResetRequestContainer } from '@kit/auth/password-reset';
import { pathsConfig } from '@kit/shared/config';
import { Button } from '@kit/ui/button';
import { Heading } from '@kit/ui/heading';
import { Trans } from '@kit/ui/trans';
import pathsConfig from '~/config/paths.config';
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';

View File

@@ -0,0 +1,56 @@
import Link from 'next/link';
import { Providers, SignInMethodsContainer } from '@kit/auth/sign-in';
import { pathsConfig } from '@kit/shared/config';
import { Button } from '@kit/ui/button';
import { Heading } from '@kit/ui/heading';
import { Trans } from '@kit/ui/trans';
export default function PasswordOption({
inviteToken,
returnPath,
providers,
}: {
inviteToken?: string;
returnPath?: string;
providers: Providers;
}) {
const signUpPath =
pathsConfig.auth.signUp +
(inviteToken ? `?invite_token=${inviteToken}` : '');
const paths = {
callback: pathsConfig.auth.callback,
returnPath: returnPath ?? pathsConfig.app.home,
joinTeam: pathsConfig.app.joinTeam,
updateAccount: pathsConfig.auth.updateAccount,
};
return (
<>
<div className={'flex flex-col items-center gap-1'}>
<Heading level={4} className={'tracking-tight'}>
<Trans i18nKey={'auth:signInHeading'} />
</Heading>
<p className={'text-muted-foreground text-sm'}>
<Trans i18nKey={'auth:signInSubheading'} />
</p>
</div>
<SignInMethodsContainer
inviteToken={inviteToken}
paths={paths}
providers={providers}
/>
<div className={'flex justify-center'}>
<Button asChild variant={'link'} size={'sm'}>
<Link href={signUpPath} prefetch={true}>
<Trans i18nKey={'auth:doNotHaveAccountYet'} />
</Link>
</Button>
</div>
</>
);
}

View File

@@ -0,0 +1,38 @@
'use client';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import Loading from '@/app/home/loading';
import { getSupabaseBrowserClient } from '@/packages/supabase/src/clients/browser-client';
export function SignInPageClientRedirect() {
const router = useRouter();
useEffect(() => {
async function signIn() {
const { data, error } =
await getSupabaseBrowserClient().auth.signInWithOAuth({
provider: 'keycloak',
options: {
redirectTo: `${window.location.origin}/auth/callback`,
queryParams: {
prompt: 'login',
},
},
});
if (error) {
console.error('OAuth error', error);
router.push('/');
} else if (data.url) {
router.push(data.url);
}
}
signIn();
}, [router]);
return <Loading />;
}

View File

@@ -1,6 +1,5 @@
import { AuthLayoutShell } from '@kit/auth/shared';
import { AppLogo } from '~/components/app-logo';
import { AppLogo } from '@kit/shared/components/app-logo';
function AuthLayout({ children }: React.PropsWithChildren) {
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;

View File

@@ -1,17 +1,11 @@
import Link from 'next/link';
import { getServerAuthConfig, pathsConfig } from '@kit/shared/config';
import { register } from 'module';
import { SignInMethodsContainer } from '@kit/auth/sign-in';
import { Button } from '@kit/ui/button';
import { Heading } from '@kit/ui/heading';
import { Trans } from '@kit/ui/trans';
import authConfig from '~/config/auth.config';
import pathsConfig from '~/config/paths.config';
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';
import PasswordOption from './components/PasswordOption';
import { SignInPageClientRedirect } from './components/SignInPageClientRedirect';
interface SignInPageProps {
searchParams: Promise<{
invite_token?: string;
@@ -28,47 +22,26 @@ export const generateMetadata = async () => {
};
async function SignInPage({ searchParams }: SignInPageProps) {
const { invite_token: inviteToken, next = pathsConfig.app.home } =
const { invite_token: inviteToken, next: returnPath = pathsConfig.app.home } =
await searchParams;
const signUpPath =
pathsConfig.auth.signUp +
(inviteToken ? `?invite_token=${inviteToken}` : '');
const paths = {
callback: pathsConfig.auth.callback,
returnPath: next ?? pathsConfig.app.home,
joinTeam: pathsConfig.app.joinTeam,
updateAccount: pathsConfig.auth.updateAccount,
};
const authConfig = await getServerAuthConfig();
if (authConfig.providers.password) {
return (
<>
<div className={'flex flex-col items-center gap-1'}>
<Heading level={4} className={'tracking-tight'}>
<Trans i18nKey={'auth:signInHeading'} />
</Heading>
<p className={'text-muted-foreground text-sm'}>
<Trans i18nKey={'auth:signInSubheading'} />
</p>
</div>
<SignInMethodsContainer
<PasswordOption
inviteToken={inviteToken}
paths={paths}
returnPath={returnPath}
providers={authConfig.providers}
/>
<div className={'flex justify-center'}>
<Button asChild variant={'link'} size={'sm'}>
<Link href={signUpPath} prefetch={true}>
<Trans i18nKey={'auth:doNotHaveAccountYet'} />
</Link>
</Button>
</div>
</>
);
}
if (authConfig.providers.oAuth.includes('keycloak')) {
return <SignInPageClientRedirect />;
}
return null;
}
export default withI18n(SignInPage);

View File

@@ -1,6 +1,5 @@
import { AuthLayoutShell } from '@kit/auth/shared';
import { AppLogo } from '~/components/app-logo';
import { AppLogo } from '@kit/shared/components/app-logo';
function AuthLayout({ children }: React.PropsWithChildren) {
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;

View File

@@ -1,12 +1,12 @@
import Link from 'next/link';
import { redirect } from 'next/navigation';
import { SignUpMethodsContainer } from '@kit/auth/sign-up';
import { getServerAuthConfig, pathsConfig } from '@kit/shared/config';
import { Button } from '@kit/ui/button';
import { Heading } from '@kit/ui/heading';
import { Trans } from '@kit/ui/trans';
import authConfig from '~/config/auth.config';
import pathsConfig from '~/config/paths.config';
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';
@@ -37,6 +37,12 @@ async function SignUpPage({ searchParams }: Props) {
pathsConfig.auth.signIn +
(inviteToken ? `?invite_token=${inviteToken}` : '');
const authConfig = await getServerAuthConfig();
if (!authConfig.providers.password) {
return redirect('/');
}
return (
<>
<div className={'flex flex-col items-center gap-1'}>
@@ -50,8 +56,7 @@ async function SignUpPage({ searchParams }: Props) {
</div>
<SignUpMethodsContainer
providers={authConfig.providers}
displayTermsCheckbox={authConfig.displayTermsCheckbox}
authConfig={authConfig}
inviteToken={inviteToken}
paths={paths}
/>

View File

@@ -0,0 +1,293 @@
'use client';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { pathsConfig } from '@/packages/shared/src/config';
import { ExternalLink } from '@/public/assets/external-link';
import { zodResolver } from '@hookform/resolvers/zod';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { z } from 'zod';
import { Button } from '@kit/ui/button';
import { Checkbox } from '@kit/ui/checkbox';
import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@kit/ui/form';
import { Input } from '@kit/ui/input';
import { toast } from '@kit/ui/sonner';
import { Trans } from '@kit/ui/trans';
import { UpdateAccountSchemaClient } from '../_lib/schemas/update-account.schema';
import { onUpdateAccount } from '../_lib/server/update-account';
type UpdateAccountFormValues = z.infer<
ReturnType<typeof UpdateAccountSchemaClient>
>;
export function UpdateAccountForm({
defaultValues,
isEmailUser,
}: {
defaultValues: UpdateAccountFormValues;
isEmailUser: boolean;
}) {
const router = useRouter();
const { t } = useTranslation('account');
const form = useForm({
resolver: zodResolver(UpdateAccountSchemaClient({ isEmailUser })),
mode: 'onChange',
defaultValues,
});
const { firstName, lastName, personalCode, email, userConsent } =
defaultValues;
const defaultValues_weight =
'weight' in defaultValues ? defaultValues.weight : null;
const defaultValues_height =
'height' in defaultValues ? defaultValues.height : null;
const hasFirstName = !!firstName;
const hasLastName = !!lastName;
const hasPersonalCode = !!personalCode;
const hasEmail = !!email;
const onUpdateAccountOptions = async (values: UpdateAccountFormValues) => {
const loading = toast.loading(t('updateAccount.updateAccountLoading'));
try {
const response = await onUpdateAccount({
firstName: values.firstName || firstName,
lastName: values.lastName || lastName,
personalCode: values.personalCode || personalCode,
email: values.email || email,
phone: values.phone,
weight: ((('weight' in values && values.weight) ??
defaultValues_weight) ||
null) as number,
height: ((('height' in values && values.height) ??
defaultValues_height) ||
null) as number,
userConsent: values.userConsent ?? userConsent,
city: values.city,
});
if (!response) {
throw new Error('Failed to update account');
}
toast.dismiss(loading);
toast.success(t('updateAccount.updateAccountSuccess'));
if (response.hasUnseenMembershipConfirmation) {
router.push(pathsConfig.auth.membershipConfirmation);
} else {
router.push(pathsConfig.app.selectPackage);
}
} catch (error) {
console.info('promiseresult error', error);
toast.error(t('updateAccount.updateAccountError'));
toast.dismiss(loading);
}
};
return (
<Form {...form}>
<form
className="flex flex-col gap-6 px-6 pt-10 text-left"
onSubmit={form.handleSubmit(onUpdateAccountOptions)}
>
<FormField
name="firstName"
disabled={hasFirstName && !isEmailUser}
render={({ field }) => (
<FormItem>
<FormLabel>
<Trans i18nKey={'common:formField:firstName'} />
</FormLabel>
<FormControl>
<Input {...field} autoFocus={!hasFirstName} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="lastName"
disabled={hasLastName && !isEmailUser}
render={({ field }) => (
<FormItem>
<FormLabel>
<Trans i18nKey={'common:formField:lastName'} />
</FormLabel>
<FormControl>
<Input {...field} autoFocus={hasFirstName && !hasLastName} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="personalCode"
disabled={hasPersonalCode && !isEmailUser}
render={({ field }) => (
<FormItem>
<FormLabel>
<Trans i18nKey={'common:formField:personalCode'} />
</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="email"
disabled={hasEmail}
render={({ field }) => (
<FormItem>
<FormLabel>
<Trans i18nKey={'common:formField:email'} />
</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="phone"
render={({ field }) => (
<FormItem>
<FormLabel>
<Trans i18nKey={'common:formField:phone'} />
</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
{!isEmailUser && (
<>
<FormField
name="city"
render={({ field }) => (
<FormItem>
<FormLabel>
<Trans i18nKey={'common:formField:city'} />
</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="flex flex-row justify-between gap-4">
<FormField
name="weight"
render={({ field }) => (
<FormItem className="flex-1 basis-0">
<FormLabel>
<Trans i18nKey={'common:formField:weight'} />
</FormLabel>
<FormControl>
<Input
type="number"
placeholder="kg"
{...field}
value={field.value ?? ''}
onChange={(e) =>
field.onChange(
e.target.value === ''
? null
: Number(e.target.value),
)
}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
name="height"
render={({ field }) => (
<FormItem className="flex-1 basis-0">
<FormLabel>
<Trans i18nKey={'common:formField:height'} />
</FormLabel>
<FormControl>
<Input
placeholder="cm"
type="number"
{...field}
value={field.value ?? ''}
onChange={(e) =>
field.onChange(
e.target.value === ''
? null
: Number(e.target.value),
)
}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
</>
)}
<FormField
name="userConsent"
render={({ field }) => (
<FormItem>
<div className="flex flex-row items-center gap-2 pb-1">
<FormControl>
<Checkbox
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
<FormLabel>
<Trans i18nKey={'account:updateAccount:userConsentLabel'} />
</FormLabel>
</div>
<Link
href={t('account:updateAccount:userConsentUrlPath')}
className="flex flex-row items-center gap-2 text-sm hover:underline"
target="_blank"
>
<ExternalLink />
<Trans i18nKey={'account:updateAccount:userConsentUrlTitle'} />
</Link>
</FormItem>
)}
/>
<Button disabled={form.formState.isSubmitting} type="submit">
<Trans i18nKey={'account:updateAccount:button'} />
</Button>
</form>
</Form>
);
}

View File

@@ -0,0 +1,111 @@
import Isikukood from 'isikukood';
import parsePhoneNumber from 'libphonenumber-js/min';
import { z } from 'zod';
const updateAccountSchema = {
firstName: z
.string({
error: 'First name is required',
})
.nonempty(),
lastName: z
.string({
error: 'Last name is required',
})
.nonempty({
error: 'common:formFieldError.stringNonEmpty',
}),
personalCode: z.string().refine(
(val) => {
try {
return new Isikukood(val).validate();
} catch {
return false;
}
},
{
message: 'common:formFieldError.invalidPersonalCode',
},
),
email: z.string().email({
message: 'Email is required',
}),
phone: z
.string({
error: 'error:invalidPhone',
})
.nonempty()
.refine(
(phone) => {
try {
const phoneNumber = parsePhoneNumber(phone);
return (
!!phoneNumber &&
phoneNumber.isValid() &&
phoneNumber.country === 'EE'
);
} catch {
return false;
}
},
{
message: 'common:formFieldError.invalidPhoneNumber',
},
),
city: z.string().optional(),
weight: z
.number({
error: (issue) =>
issue.input === undefined
? 'Weight is required'
: 'Weight must be a number',
})
.gt(0, { message: 'Weight must be greater than 0' }),
height: z
.number({
error: (issue) =>
issue.input === undefined
? 'Height is required'
: 'Height must be a number',
})
.gt(0, { message: 'Height must be greater than 0' }),
userConsent: z.boolean().refine((val) => val === true, {
message: 'Must be true',
}),
} as const;
export const UpdateAccountSchemaServer = z.object({
firstName: updateAccountSchema.firstName,
lastName: updateAccountSchema.lastName,
personalCode: updateAccountSchema.personalCode,
email: updateAccountSchema.email,
phone: updateAccountSchema.phone,
city: updateAccountSchema.city,
weight: updateAccountSchema.weight.nullable(),
height: updateAccountSchema.height.nullable(),
userConsent: updateAccountSchema.userConsent,
});
export const UpdateAccountSchemaClient = ({
isEmailUser,
}: {
isEmailUser: boolean;
}) =>
z.object({
firstName: updateAccountSchema.firstName,
lastName: updateAccountSchema.lastName,
personalCode: updateAccountSchema.personalCode,
email: updateAccountSchema.email,
phone: updateAccountSchema.phone,
...(isEmailUser
? {
city: z.string().optional(),
weight: z.number().optional(),
height: z.number().optional(),
}
: {
city: updateAccountSchema.city,
weight: updateAccountSchema.weight,
height: updateAccountSchema.height,
}),
userConsent: updateAccountSchema.userConsent,
});

View File

@@ -1,27 +1,13 @@
'use server';
import { redirect } from 'next/navigation';
import { enhanceAction } from '@kit/next/actions';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import pathsConfig from '~/config/paths.config';
import { updateCustomer } from '@lib/data/customer';
import { UpdateAccountSchema } from '../../schemas/update-account.schema';
import { createAuthApi } from '../api';
import { AccountSubmitData, createAuthApi } from '@kit/auth/api';
import { enhanceAction } from '@kit/next/actions';
import { pathsConfig } from '@kit/shared/config';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
export interface AccountSubmitData {
firstName: string;
lastName: string;
personalCode: string;
email: string;
phone?: string;
city?: string;
weight: number | null;
height: number | null;
userConsent: boolean;
}
import { UpdateAccountSchemaServer } from '../schemas/update-account.schema';
export const onUpdateAccount = enhanceAction(
async (params: AccountSubmitData) => {
@@ -38,22 +24,23 @@ export const onUpdateAccount = enhanceAction(
console.warn('On update account error: ', err);
}
try {
await updateCustomer({
first_name: params.firstName,
last_name: params.lastName,
phone: params.phone,
});
} catch (e) {
console.error('Failed to update Medusa customer', e);
}
const hasUnseenMembershipConfirmation =
await api.hasUnseenMembershipConfirmation();
if (hasUnseenMembershipConfirmation) {
redirect(pathsConfig.auth.membershipConfirmation);
} else {
redirect(pathsConfig.app.selectPackage);
}
return {
hasUnseenMembershipConfirmation,
};
},
{
schema: UpdateAccountSchema,
schema: UpdateAccountSchemaServer,
},
);

View File

@@ -1,30 +1,48 @@
import { redirect } from 'next/navigation';
import { BackButton } from '@/components/back-button';
import { MedReportLogo } from '@/components/med-report-logo';
import pathsConfig from '@/config/paths.config';
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
import { signOutAction } from '@/lib/actions/sign-out';
import { UpdateAccountForm } from '@/packages/features/auth/src/components/update-account-form';
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
import { BackButton } from '@kit/shared/components/back-button';
import { MedReportLogo } from '@kit/shared/components/med-report-logo';
import { pathsConfig } from '@kit/shared/config';
import { Trans } from '@kit/ui/trans';
import { withI18n } from '~/lib/i18n/with-i18n';
import { toTitleCase } from '~/lib/utils';
import { UpdateAccountForm } from './_components/update-account-form';
async function UpdateAccount() {
const client = getSupabaseServerClient();
const { account, user } = await loadCurrentUserAccount();
const {
data: { user },
} = await client.auth.getUser();
const isKeycloakUser = user?.app_metadata?.provider === 'keycloak';
const isEmailUser = user?.app_metadata?.provider === 'email';
if (!user) {
redirect(pathsConfig.auth.signIn);
}
const defaultValues = {
firstName: account?.name ? toTitleCase(account.name) : '',
lastName: account?.last_name ? toTitleCase(account.last_name) : '',
personalCode: account?.personal_code ?? '',
email: (() => {
if (isKeycloakUser) {
return account?.email ?? '';
}
return account?.email ?? user?.email ?? '';
})(),
phone: account?.phone ?? '+372',
city: account?.city ?? '',
weight: account?.accountParams?.weight ?? null,
height: account?.accountParams?.height ?? null,
userConsent: account?.has_consent_personal_data ?? false,
};
return (
<div className="border-border flex max-w-5xl flex-row overflow-hidden rounded-3xl border">
<div className="relative flex w-1/2 min-w-md flex-col px-12 pt-7 pb-22 text-center">
<div className="border-border xs:w-3/5 flex w-9/10 flex-row overflow-hidden rounded-3xl border md:w-[988px]">
<div className="xs:px-6 relative flex w-full flex-col pt-7 pb-22 text-center md:w-1/2 md:px-12">
<BackButton onBack={signOutAction} />
<MedReportLogo />
<h1 className="pt-8">
@@ -33,9 +51,12 @@ async function UpdateAccount() {
<p className="text-muted-foreground pt-1 text-sm">
<Trans i18nKey={'account:updateAccount:description'} />
</p>
<UpdateAccountForm user={user} />
<UpdateAccountForm
defaultValues={defaultValues}
isEmailUser={isEmailUser}
/>
</div>
<div className="w-1/2 min-w-[460px] bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat"></div>
<div className="hidden w-1/2 bg-[url(/assets/med-report-logo-big.png)] bg-cover bg-center bg-no-repeat md:block"></div>
</div>
);
}

View File

@@ -1,6 +1,5 @@
import { AuthLayoutShell } from '@kit/auth/shared';
import { AppLogo } from '~/components/app-logo';
import { AppLogo } from '@kit/shared/components/app-logo';
function AuthLayout({ children }: React.PropsWithChildren) {
return <AuthLayoutShell Logo={AppLogo}>{children}</AuthLayoutShell>;

View File

@@ -1,10 +1,10 @@
import { redirect } from 'next/navigation';
import { MultiFactorChallengeContainer } from '@kit/auth/mfa';
import { pathsConfig } from '@kit/shared/config';
import { checkRequiresMultiFactorAuthentication } from '@kit/supabase/check-requires-mfa';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import pathsConfig from '~/config/paths.config';
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';
@@ -40,7 +40,8 @@ async function VerifyPage(props: Props) {
}
const nextPath = (await props.searchParams).next;
const redirectPath = nextPath ?? pathsConfig.app.home;
const redirectPath =
!!nextPath && nextPath.length > 0 ? nextPath : pathsConfig.app.home;
return (
<MultiFactorChallengeContainer

View File

@@ -0,0 +1,149 @@
'use client';
import React, { ReactElement, ReactNode, useMemo, useState } from 'react';
import { UserAnalysisElement } from '@/packages/features/accounts/src/types/accounts';
import { format } from 'date-fns';
import { Info } from 'lucide-react';
import { Trans } from '@kit/ui/trans';
import { cn } from '@kit/ui/utils';
import { AnalysisElement } from '~/lib/services/analysis-element.service';
import AnalysisLevelBar, {
AnalysisLevelBarSkeleton,
AnalysisResultLevel,
} from './analysis-level-bar';
export type AnalysisResultForDisplay = Pick<
UserAnalysisElement,
| 'norm_status'
| 'response_value'
| 'unit'
| 'norm_lower_included'
| 'norm_upper_included'
| 'norm_lower'
| 'norm_upper'
| 'response_time'
>;
export enum AnalysisStatus {
NORMAL = 0,
MEDIUM = 1,
HIGH = 2,
}
const AnalysisDoctor = ({
analysisElement,
results,
startIcon,
endIcon,
isCancelled,
}: {
analysisElement: Pick<AnalysisElement, 'analysis_name_lab'>;
results?: AnalysisResultForDisplay;
isCancelled?: boolean;
startIcon?: ReactElement | null;
endIcon?: ReactNode | null;
}) => {
const name = analysisElement.analysis_name_lab || '';
const status = results?.norm_status || AnalysisStatus.NORMAL;
const value = results?.response_value || 0;
const unit = results?.unit || '';
const normLowerIncluded = results?.norm_lower_included || false;
const normUpperIncluded = results?.norm_upper_included || false;
const normLower = results?.norm_lower || 0;
const normUpper = results?.norm_upper || 0;
const [showTooltip, setShowTooltip] = useState(false);
const analysisResultLevel = useMemo(() => {
if (!results) {
return null;
}
const isUnderNorm = value < normLower;
if (isUnderNorm) {
switch (status) {
case AnalysisStatus.MEDIUM:
return AnalysisResultLevel.LOW;
default:
return AnalysisResultLevel.VERY_LOW;
}
}
switch (status) {
case AnalysisStatus.MEDIUM:
return AnalysisResultLevel.HIGH;
case AnalysisStatus.HIGH:
return AnalysisResultLevel.VERY_HIGH;
default:
return AnalysisResultLevel.NORMAL;
}
}, [results, value, normLower]);
return (
<div className="border-border rounded-lg border px-5">
<div className="flex flex-col items-center justify-between gap-2 py-3 sm:h-[65px] sm:flex-row sm:gap-0">
<div className="flex items-center gap-2 font-semibold">
{startIcon || <div className="w-4" />}
{name}
{results?.response_time && (
<div
className="group/tooltip relative"
onClick={(e) => {
e.stopPropagation();
setShowTooltip(!showTooltip);
}}
onMouseLeave={() => setShowTooltip(false)}
>
<Info className="hover" />{' '}
<div
className={cn(
'absolute bottom-full left-1/2 z-10 mb-2 hidden -translate-x-1/2 rounded border bg-white p-4 text-sm whitespace-nowrap group-hover/tooltip:block',
{ block: showTooltip },
)}
>
<Trans i18nKey="analysis-results:analysisDate" />
{': '}
{format(new Date(results.response_time), 'dd.MM.yyyy HH:mm')}
</div>
</div>
)}
</div>
{results ? (
<>
<div className="flex items-center gap-3 sm:ml-auto">
<div className="font-semibold">{value}</div>
<div className="text-muted-foreground text-sm">{unit}</div>
</div>
<div className="text-muted-foreground mx-8 flex flex-col-reverse gap-2 text-center text-sm sm:block sm:gap-0">
{normLower} - {normUpper}
<div>
<Trans i18nKey="analysis-results:results.range.normal" />
</div>
</div>
<AnalysisLevelBar
results={results}
normLowerIncluded={normLowerIncluded}
normUpperIncluded={normUpperIncluded}
level={analysisResultLevel!}
/>
{endIcon || <div className="mx-2 w-4" />}
</>
) : isCancelled ? null : (
<>
<div className="flex items-center gap-3 sm:ml-auto">
<div className="font-semibold">
<Trans i18nKey="analysis-results:waitingForResults" />
</div>
</div>
<div className="mx-8 w-[60px]"></div>
<AnalysisLevelBarSkeleton />
</>
)}
</div>
</div>
);
};
export default AnalysisDoctor;

View File

@@ -0,0 +1,132 @@
import { useMemo } from 'react';
import { ArrowDown } from 'lucide-react';
import { cn } from '@kit/ui/utils';
import { AnalysisResultForDisplay } from './analysis-doctor';
export enum AnalysisResultLevel {
VERY_LOW = 0,
LOW = 1,
NORMAL = 2,
HIGH = 3,
VERY_HIGH = 4,
}
const Level = ({
isActive = false,
color,
isFirst = false,
isLast = false,
arrowLocation,
}: {
isActive?: boolean;
color: 'destructive' | 'success' | 'warning' | 'gray-200';
isFirst?: boolean;
isLast?: boolean;
arrowLocation?: number;
}) => {
return (
<div
className={cn(`bg-${color} relative h-3 flex-1`, {
'opacity-20': !isActive,
'rounded-l-lg': isFirst,
'rounded-r-lg': isLast,
})}
>
{isActive && (
<div
className="absolute top-[-14px] left-1/2 -translate-x-1/2 rounded-[10px] bg-white p-[2px]"
style={{ left: `${arrowLocation}%` }}
>
<ArrowDown strokeWidth={2} />
</div>
)}
</div>
);
};
export const AnalysisLevelBarSkeleton = () => {
return (
<div className="mt-4 flex h-3 w-[60%] max-w-[360px] gap-1 sm:mt-0 sm:w-[35%]">
<Level color="gray-200" />
</div>
);
};
const AnalysisLevelBar = ({
normLowerIncluded = true,
normUpperIncluded = true,
level,
results,
}: {
normLowerIncluded?: boolean;
normUpperIncluded?: boolean;
level: AnalysisResultLevel;
results: AnalysisResultForDisplay;
}) => {
const {
norm_lower: lower,
norm_upper: upper,
response_value: value,
} = results;
const arrowLocation = useMemo(() => {
if (value < lower!) {
return 0;
}
if (normLowerIncluded || normUpperIncluded) {
return 50;
}
const calculated = ((value - lower!) / (upper! - lower!)) * 100;
if (calculated > 100) {
return 100;
}
return calculated;
}, [value, upper, lower]);
const [isVeryLow, isLow, isHigh, isVeryHigh] = useMemo(
() => [
level === AnalysisResultLevel.VERY_LOW,
level === AnalysisResultLevel.LOW,
level === AnalysisResultLevel.HIGH,
level === AnalysisResultLevel.VERY_HIGH,
],
[level, value, upper, lower],
);
const hasAbnormalLevel = isVeryLow || isLow || isHigh || isVeryHigh;
return (
<div className="mt-4 flex h-3 w-[60%] max-w-[360px] gap-1 sm:mt-0 sm:w-[35%]">
{normLowerIncluded && (
<>
<Level isActive={isVeryLow} color="destructive" isFirst />
<Level isActive={isLow} color="warning" />
</>
)}
<Level
isFirst={!normLowerIncluded}
isLast={!normUpperIncluded}
{...(hasAbnormalLevel
? { color: 'warning', isActive: false }
: { color: 'success', isActive: true })}
arrowLocation={arrowLocation}
/>
{normUpperIncluded && (
<>
<Level isActive={isHigh} color="warning" />
<Level isActive={isVeryHigh} color="destructive" isLast />
</>
)}
</div>
);
};
export default AnalysisLevelBar;

View File

@@ -0,0 +1,287 @@
'use client';
import { useState } from 'react';
import { zodResolver } from '@hookform/resolvers/zod';
import { useQueryClient } from '@tanstack/react-query';
import { capitalize } from 'lodash';
import { useForm } from 'react-hook-form';
import { giveFeedbackAction } from '@kit/doctor/actions/doctor-server-actions';
import {
getDOBWithAgeStringFromPersonalCode,
getResultSetName,
} from '@kit/doctor/lib/helpers';
import {
AnalysisResponse,
DoctorFeedback,
Order,
Patient,
} from '@kit/doctor/schema/doctor-analysis-detail-view.schema';
import {
DoctorAnalysisFeedbackForm,
doctorAnalysisFeedbackFormSchema,
} from '@kit/doctor/schema/doctor-analysis.schema';
import ConfirmationModal from '@kit/shared/components/confirmation-modal';
import { useCurrentLocaleLanguageNames } from '@kit/shared/hooks';
import { getFullName } from '@kit/shared/utils';
import { useUser } from '@kit/supabase/hooks/use-user';
import { Button } from '@kit/ui/button';
import {
Form,
FormControl,
FormField,
FormItem,
FormMessage,
} from '@kit/ui/form';
import { toast } from '@kit/ui/sonner';
import { Textarea } from '@kit/ui/textarea';
import { Trans } from '@kit/ui/trans';
import { bmiFromMetric } from '~/lib/utils';
import DoctorAnalysisWrapper from './doctor-analysis-wrapper';
import DoctorJobSelect from './doctor-job-select';
export default function AnalysisView({
patient,
order,
analyses,
feedback,
}: {
patient: Patient;
order: Order;
analyses: AnalysisResponse[];
feedback?: DoctorFeedback;
}) {
const [isConfirmOpen, setIsConfirmOpen] = useState(false);
const [isDraftSubmitting, setIsDraftSubmitting] = useState(false);
const { data: user } = useUser();
const languageNames = useCurrentLocaleLanguageNames();
const isInProgress = !!(
!!feedback?.status &&
feedback?.doctor_user_id &&
feedback?.status !== 'COMPLETED'
);
const isCurrentDoctorJob =
!!feedback?.doctor_user_id && feedback?.doctor_user_id === user?.id;
const isReadOnly =
!isInProgress ||
(!!feedback?.doctor_user_id && feedback?.doctor_user_id !== user?.id);
const form = useForm({
resolver: zodResolver(doctorAnalysisFeedbackFormSchema),
reValidateMode: 'onChange',
defaultValues: {
feedbackValue: feedback?.value ?? '',
userId: patient.userId,
},
});
const queryClient = useQueryClient();
if (!patient || !order || !analyses) {
return null;
}
const onSubmit = async (
data: DoctorAnalysisFeedbackForm,
status: 'DRAFT' | 'COMPLETED',
) => {
const result = await giveFeedbackAction({
...data,
analysisOrderId: order.analysisOrderId,
status,
});
if (!result.success) {
return toast.error(<Trans i18nKey="common:genericServerError" />);
}
queryClient.invalidateQueries({
predicate: (query) => query.queryKey.includes('doctor-jobs'),
});
toast.success(<Trans i18nKey={'doctor:updateFeedbackSuccess'} />);
return setIsConfirmOpen(false);
};
const handleDraftSubmit = async (e: React.FormEvent) => {
setIsDraftSubmitting(true);
e.preventDefault();
form.formState.errors.feedbackValue = undefined;
const formData = form.getValues();
await onSubmit(formData, 'DRAFT');
setIsDraftSubmitting(false);
};
const handleCompleteSubmit = form.handleSubmit(async () => {
setIsConfirmOpen(true);
});
const confirmComplete = form.handleSubmit(async (data) => {
await onSubmit(data, 'COMPLETED');
});
return (
<>
<div className="xs:flex xs:justify-between">
<h3>
<Trans
i18nKey={getResultSetName(
order.title,
order.isPackage,
Object.keys(analyses)?.length,
)}
/>
</h3>
<div className="xs:flex hidden">
<DoctorJobSelect
analysisOrderId={order.analysisOrderId}
userId={patient.userId}
doctorUserId={feedback?.doctor_user_id}
isRemovable={isCurrentDoctorJob && isInProgress}
onJobUpdate={() =>
queryClient.invalidateQueries({
predicate: (query) => query.queryKey.includes('doctor-jobs'),
})
}
/>
</div>
</div>
<div className="xs:grid-cols-2 grid">
<div className="font-bold">
<Trans i18nKey="doctor:name" />
</div>
<div>{getFullName(patient.firstName, patient.lastName)}</div>
<div className="font-bold">
<Trans i18nKey="doctor:personalCode" />
</div>
<div>{patient.personalCode ?? ''}</div>
<div className="font-bold">
<Trans i18nKey="doctor:dobAndAge" />
</div>
<div>{getDOBWithAgeStringFromPersonalCode(patient.personalCode)}</div>
<div className="font-bold">
<Trans i18nKey="doctor:height" />
</div>
<div>{patient.height}</div>
<div className="font-bold">
<Trans i18nKey="doctor:weight" />
</div>
<div>{patient.weight}</div>
<div className="font-bold">
<Trans i18nKey="doctor:bmi" />
</div>
<div>
{patient?.weight && patient?.height
? bmiFromMetric(patient.weight, patient.height)
: '-'}
</div>
<div className="font-bold">
<Trans i18nKey="doctor:smoking" />
</div>
<div>-</div>
<div className="font-bold">
<Trans i18nKey="doctor:phone" />
</div>
<div>{patient.phone}</div>
<div className="font-bold">
<Trans i18nKey="doctor:email" />
</div>
<div>{patient.email}</div>
<div className="font-bold">
<Trans i18nKey="common:language" />
</div>
<div>
{capitalize(languageNames.of(patient.preferred_locale ?? 'et'))}
</div>
</div>
<div className="xs:hidden block">
<DoctorJobSelect
className="w-full"
analysisOrderId={order.analysisOrderId}
userId={patient.userId}
doctorUserId={feedback?.doctor_user_id}
isRemovable={isCurrentDoctorJob && isInProgress}
onJobUpdate={() =>
queryClient.invalidateQueries({
predicate: (query) => query.queryKey.includes('doctor-jobs'),
})
}
/>
</div>
<h3>
<Trans i18nKey="doctor:results" />
</h3>
<div className="flex flex-col gap-2">
{analyses.map((analysisData) => {
return (
<DoctorAnalysisWrapper
key={analysisData.id}
analysisData={analysisData}
/>
);
})}
</div>
<h3>
<Trans i18nKey="doctor:feedback" />
</h3>
<p>{feedback?.value ?? '-'}</p>
{!isReadOnly && (
<Form {...form}>
<form className="space-y-4 lg:w-1/2">
<FormField
control={form.control}
name="feedbackValue"
render={({ field }) => (
<FormItem>
<FormControl>
<Textarea {...field} disabled={isReadOnly} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="xs:flex block justify-end gap-2 space-y-2">
<Button
type="button"
variant="outline"
onClick={handleDraftSubmit}
disabled={
isReadOnly || isDraftSubmitting || form.formState.isSubmitting
}
className="xs:w-1/4 w-full"
>
<Trans i18nKey="common:saveAsDraft" />
</Button>
<Button
type="button"
onClick={handleCompleteSubmit}
disabled={
isReadOnly || isDraftSubmitting || form.formState.isSubmitting
}
className="xs:w-1/4 w-full"
>
<Trans i18nKey="common:save" />
</Button>
</div>
</form>
</Form>
)}
<ConfirmationModal
isOpen={isConfirmOpen}
onClose={() => setIsConfirmOpen(false)}
onConfirm={confirmComplete}
titleKey="doctor:confirmFeedbackModal.title"
descriptionKey="doctor:confirmFeedbackModal.description"
/>
</>
);
}

View File

@@ -0,0 +1,103 @@
'use client';
import { CaretDownIcon, QuestionMarkCircledIcon } from '@radix-ui/react-icons';
import { useTranslation } from 'react-i18next';
import { AnalysisResponse } from '@kit/doctor/schema/doctor-analysis-detail-view.schema';
import { InfoTooltip } from '@kit/shared/components/ui/info-tooltip';
import { formatDate } from '@kit/shared/utils';
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from '@kit/ui/collapsible';
import { Trans } from '@kit/ui/trans';
import AnalysisDoctor from './analysis-doctor';
export default function DoctorAnalysisWrapper({
analysisData,
}: {
analysisData: AnalysisResponse;
}) {
const { t } = useTranslation();
return (
<Collapsible className="w-full" key={analysisData.id}>
<CollapsibleTrigger
disabled={!analysisData.latestPreviousAnalysis}
asChild
>
<div className="[&[data-state=open]_.caret-icon]:rotate-180">
<AnalysisDoctor
startIcon={
analysisData.latestPreviousAnalysis && (
<CaretDownIcon className="caret-icon transition-transform duration-200" />
)
}
endIcon={
analysisData.comment && (
<>
<div className="xs:flex hidden">
<InfoTooltip
content={analysisData.comment}
icon={
<QuestionMarkCircledIcon className="mx-2 text-blue-800" />
}
/>
</div>
<p className="xs:hidden">
<strong>
<Trans i18nKey="doctor:labComment" />:
</strong>{' '}
{analysisData.comment}
</p>
</>
)
}
analysisElement={{
analysis_name_lab: analysisData.analysis_name,
}}
results={analysisData}
/>
</div>
</CollapsibleTrigger>
{analysisData.latestPreviousAnalysis && (
<CollapsibleContent>
<div className="my-1 flex flex-col">
<AnalysisDoctor
endIcon={
analysisData.latestPreviousAnalysis.comment && (
<>
<div className="xs:flex hidden">
<InfoTooltip
content={analysisData.latestPreviousAnalysis.comment}
icon={
<QuestionMarkCircledIcon className="mx-2 text-blue-800" />
}
/>
</div>
<p className="xs:hidden">
<strong>
<Trans i18nKey="doctor:labComment" />:{' '}
</strong>
{analysisData.latestPreviousAnalysis.comment}
</p>
</>
)
}
analysisElement={{
analysis_name_lab: t('doctor:previousResults', {
date: formatDate(
analysisData.latestPreviousAnalysis.response_time,
),
}),
}}
results={analysisData.latestPreviousAnalysis}
/>
</div>
</CollapsibleContent>
)}
</Collapsible>
);
}

View File

@@ -0,0 +1,37 @@
'use client';
import {
getOpenResponsesAction,
getOtherResponsesAction,
getUserDoneResponsesAction,
getUserInProgressResponsesAction,
} from '@kit/doctor/actions/table-data-fetching-actions';
import ResultsTableWrapper from './results-table-wrapper';
export default function Dashboard() {
return (
<>
<ResultsTableWrapper
titleKey="doctor:openReviews"
action={getOpenResponsesAction}
queryKey="doctor-open-jobs"
/>
<ResultsTableWrapper
titleKey="doctor:myReviews"
action={getUserInProgressResponsesAction}
queryKey="doctor-in-progress-jobs"
/>
<ResultsTableWrapper
titleKey="doctor:completedReviews"
action={getUserDoneResponsesAction}
queryKey="doctor-done-jobs"
/>
<ResultsTableWrapper
titleKey="doctor:otherReviews"
action={getOtherResponsesAction}
queryKey="doctor-other-jobs"
/>
</>
);
}

View File

@@ -0,0 +1,27 @@
import { notFound } from 'next/navigation';
import { isDoctor } from '@kit/doctor/lib/server/utils/is-doctor';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
type LayoutOrPageComponent<Params> = React.ComponentType<Params>;
/**
* DoctorGuard is a server component wrapper that checks if the user is a doctor before rendering the component.
* If the user is not a doctor, we redirect to a 404.
* @param Component - The Page or Layout component to wrap
*/
export function DoctorGuard<Params extends object>(
Component: LayoutOrPageComponent<Params>,
) {
return async function DoctorGuardServerComponentWrapper(params: Params) {
const client = getSupabaseServerClient();
const isUserDoctor = await isDoctor(client);
// if the user is not a super-admin, we redirect to a 404
if (!isUserDoctor) {
notFound();
}
return <Component {...params} />;
};
}

View File

@@ -0,0 +1,120 @@
'use client';
import { useTransition } from 'react';
import { useRouter } from 'next/navigation';
import { LoaderCircle } from 'lucide-react';
import {
selectJobAction,
unselectJobAction,
} from '@kit/doctor/actions/doctor-server-actions';
import { ErrorReason } from '@kit/doctor/schema/error.type';
import { Button, ButtonProps } from '@kit/ui/button';
import { toast } from '@kit/ui/sonner';
import { Trans } from '@kit/ui/trans';
import { cn } from '@kit/ui/utils';
export default function DoctorJobSelect({
className,
size = 'sm',
doctorUserId,
doctorName,
analysisOrderId,
userId,
isRemovable,
onJobUpdate,
linkTo,
}: {
className?: string;
size?: ButtonProps['size'];
doctorUserId?: string | null;
doctorName?: string;
analysisOrderId: number;
userId: string;
isRemovable?: boolean;
linkTo?: string;
onJobUpdate: () => void;
}) {
const [isPending, startTransition] = useTransition();
const router = useRouter();
const handleSelectJob = () => {
startTransition(async () => {
const result = await selectJobAction({
analysisOrderId,
userId,
});
if (result?.success) {
onJobUpdate();
linkTo && router.push(linkTo);
} else {
toast.error(
<Trans
i18nKey={`doctor:error.${result.reason ?? ErrorReason.UNKNOWN}`}
/>,
);
if (result.reason === ErrorReason.JOB_ASSIGNED) {
onJobUpdate();
}
}
});
};
const handleUnselectJob = () => {
startTransition(async () => {
const result = await unselectJobAction({
analysisOrderId,
});
if (result?.success) {
onJobUpdate();
} else {
toast.error(
<Trans
i18nKey={`doctor:error.${result.reason ?? ErrorReason.UNKNOWN}`}
/>,
);
}
});
};
if (isRemovable) {
return (
<Button
className={cn('w-16', className)}
size={size}
variant="destructive"
onClick={handleUnselectJob}
disabled={isPending}
>
{isPending ? (
<LoaderCircle className="h-4 w-4 animate-spin" />
) : (
<Trans i18nKey="doctor:unselectJob" />
)}
</Button>
);
}
if (!doctorUserId) {
return (
<Button
className={cn('w-16', className)}
size={size}
onClick={handleSelectJob}
disabled={isPending}
>
{isPending ? (
<LoaderCircle className="h-4 w-4 animate-spin" />
) : (
<Trans i18nKey="doctor:selectJob" />
)}
</Button>
);
}
return <>{doctorName}</>;
}

View File

@@ -0,0 +1,103 @@
'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { UserWorkspace } from '@/app/home/(user)/_lib/server/load-user-workspace';
import { LayoutDashboard } from 'lucide-react';
import { AppLogo } from '@kit/shared/components/app-logo';
import { ProfileAccountDropdownContainer } from '@kit/shared/components/personal-account-dropdown-container';
import { pathsConfig } from '@kit/shared/config';
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
useSidebar,
} from '@kit/ui/shadcn-sidebar';
import { Trans } from '@kit/ui/trans';
export function DoctorSidebar({
accounts,
}: {
accounts: UserWorkspace['accounts'];
}) {
const path = usePathname();
const { open } = useSidebar();
return (
<Sidebar collapsible="icon">
<SidebarHeader className={'m-2'}>
<AppLogo
href={pathsConfig.app.doctor}
className="max-w-full"
compact={!open}
/>
</SidebarHeader>
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>
<Trans i18nKey="common:doctor" />
</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
<SidebarMenuButton
isActive={path === pathsConfig.app.doctor}
asChild
>
<Link className={'flex gap-2.5'} href={pathsConfig.app.doctor}>
<LayoutDashboard className={'h-4'} />
<Trans i18nKey={'doctor:sidebar.dashboard'} />
</Link>
</SidebarMenuButton>
<SidebarMenuButton
isActive={path === pathsConfig.app.openJobs}
asChild
>
<Link
className={'flex gap-2.5'}
href={pathsConfig.app.openJobs}
>
<LayoutDashboard className={'h-4'} />
<Trans i18nKey={'doctor:sidebar.openReviews'} />
</Link>
</SidebarMenuButton>
<SidebarMenuButton
isActive={path === pathsConfig.app.myJobs}
asChild
>
<Link className={'flex gap-2.5'} href={pathsConfig.app.myJobs}>
<LayoutDashboard className={'h-4'} />
<Trans i18nKey={'doctor:sidebar.myReviews'} />
</Link>
</SidebarMenuButton>
<SidebarMenuButton
isActive={path === pathsConfig.app.completedJobs}
asChild
>
<Link
className={'flex gap-2.5'}
href={pathsConfig.app.completedJobs}
>
<LayoutDashboard className={'h-4'} />
<Trans i18nKey={'doctor:sidebar.completedReviews'} />
</Link>
</SidebarMenuButton>
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<ProfileAccountDropdownContainer accounts={accounts} />
</SidebarFooter>
</Sidebar>
);
}

View File

@@ -0,0 +1,50 @@
import Link from 'next/link';
import { Menu } from 'lucide-react';
import { pathsConfig } from '@kit/shared/config';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@kit/ui/dropdown-menu';
import { Trans } from '@kit/ui/trans';
export function DoctorMobileNavigation() {
return (
<DropdownMenu>
<DropdownMenuTrigger>
<Menu className={'h-8 w-8'} />
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem>
<Link href={pathsConfig.app.home}>
<Trans i18nKey={'common:routes.home'} />
</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href={pathsConfig.app.doctor}>
<Trans i18nKey={'doctor:sidebar.dashboard'} />
</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href={pathsConfig.app.openJobs}>
<Trans i18nKey={'doctor:sidebar.openReviews'} />
</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href={pathsConfig.app.myJobs}>
<Trans i18nKey={'doctor:sidebar.myReviews'} />
</Link>
</DropdownMenuItem>
<DropdownMenuItem>
<Link href={pathsConfig.app.completedJobs}>
<Trans i18nKey={'doctor:sidebar.completedReviews'} />
</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}

View File

@@ -0,0 +1,120 @@
'use client';
import { useState } from 'react';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import {
PaginatedData,
ResponseTable,
ServerActionResponse,
} from '@kit/doctor/schema/doctor-analysis.schema';
import TableSkeleton from '@kit/shared/components/table-skeleton';
import { Trans } from '@kit/ui/trans';
import { cn } from '@kit/ui/utils';
import ResultsTable from './results-table';
const PAGE_SIZE = 10;
export default function ResultsTableWrapper({
titleKey,
action,
queryKey,
}: {
titleKey: string;
action: ({
page,
pageSize,
}: {
page: number;
pageSize: number;
}) => Promise<ServerActionResponse<PaginatedData<ResponseTable>>>;
queryKey: string;
}) {
const [page, setPage] = useState(1);
const {
data: jobs,
isLoading,
isError,
isFetching,
} = useQuery({
queryKey: [queryKey, 'doctor-jobs', page],
queryFn: async () => await action({ page: page, pageSize: PAGE_SIZE }),
placeholderData: (previousData) => previousData,
});
const queryClient = useQueryClient();
const onJobUpdate = () => {
queryClient.invalidateQueries({
predicate: (query) => query.queryKey.includes('doctor-jobs'),
});
};
const createPageChangeHandler = (setPage: (page: number) => void) => {
return async ({ page }: { page: number; pageSize: number }) => {
setPage(page);
return { success: true, data: null };
};
};
if (isLoading) {
return (
<>
<h3>
<Trans i18nKey={titleKey} />
</h3>
<div className="relative">
<div
className={`transition-opacity duration-200 ${
isFetching ? 'opacity-50' : 'opacity-100'
}`}
>
<TableSkeleton />
</div>
</div>
</>
);
}
if (isError) {
return (
<>
<h3>
<Trans i18nKey={titleKey} />
</h3>
<div className="flex items-center justify-center p-8">
<div className="text-lg text-red-600">
<Trans i18nKey="common:genericServerError" />
</div>
</div>
</>
);
}
return (
<>
<h3>
<Trans i18nKey={titleKey} />
</h3>
<div className="relative">
<div
className={cn('opacity-100 transition-opacity duration-200', {
'opacity-50': isFetching,
})}
>
<ResultsTable
results={jobs?.data?.data || []}
pagination={jobs?.data?.pagination}
fetchAction={createPageChangeHandler(setPage)}
onJobUpdate={onJobUpdate}
/>
</div>
</div>
</>
);
}

View File

@@ -0,0 +1,245 @@
'use client';
import { useTransition } from 'react';
import Link from 'next/link';
import { format } from 'date-fns';
import { capitalize } from 'lodash';
import { Eye } from 'lucide-react';
import { getResultSetName } from '@kit/doctor/lib/helpers';
import { ResponseTable } from '@kit/doctor/schema/doctor-analysis.schema';
import { pathsConfig } from '@kit/shared/config';
import { useCurrentLocaleLanguageNames } from '@kit/shared/hooks';
import { getFullName } from '@kit/shared/utils';
import { useUser } from '@kit/supabase/hooks/use-user';
import { Button } from '@kit/ui/button';
import { toast } from '@kit/ui/sonner';
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from '@kit/ui/table';
import { Trans } from '@kit/ui/trans';
import DoctorJobSelect from './doctor-job-select';
export default function ResultsTable({
results = [],
pagination = {
currentPage: 1,
totalPages: 1,
totalCount: 0,
pageSize: 10,
},
fetchAction,
onJobUpdate,
}: {
results: ResponseTable[] | null;
pagination?: {
currentPage: number;
totalPages: number;
totalCount: number;
pageSize: number;
};
fetchAction: ({
page,
pageSize,
}: {
page: number;
pageSize: number;
}) => Promise<{
success: boolean;
data: null;
}>;
onJobUpdate: () => void;
}) {
const [isPending, startTransition] = useTransition();
const { data: currentUser } = useUser();
const languageNames = useCurrentLocaleLanguageNames();
const fetchPage = async (page: number) => {
startTransition(async () => {
const result = await fetchAction({
page,
pageSize: pagination.pageSize,
});
if (!result.success) {
toast.error('common.genericServerError');
}
});
};
const handleNextPage = () => {
if (pagination.currentPage < pagination.totalPages) {
fetchPage(pagination.currentPage + 1);
}
};
const handlePrevPage = () => {
if (pagination.currentPage > 1) {
fetchPage(pagination.currentPage - 1);
}
};
const handleJobUpdate = () => {
onJobUpdate();
fetchPage(pagination.currentPage);
};
if (!results?.length) {
return (
<p>
<Trans i18nKey="common:noData" />.
</p>
);
}
return (
<>
<Table className="border-separate rounded-lg border">
<TableHeader className="text-ui-fg-subtle txt-medium-plus">
<TableRow>
<TableHead className="w-6"></TableHead>
<TableHead className="w-20">
<Trans i18nKey="doctor:resultsTable.patientName" />
</TableHead>
<TableHead className="w-20">
<Trans i18nKey="doctor:resultsTable.serviceName" />
</TableHead>
<TableHead className="w-20">
<Trans i18nKey="doctor:resultsTable.orderNr" />
</TableHead>
<TableHead className="w-20">
<Trans i18nKey="doctor:resultsTable.time" />
</TableHead>
<TableHead className="w-20">
<Trans i18nKey="doctor:resultsTable.resultsStatus" />
</TableHead>
<TableHead className="w-20">
<Trans i18nKey="doctor:resultsTable.language" />
</TableHead>
<TableHead className="w-20">
<Trans i18nKey="doctor:resultsTable.assignedTo" />
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{results
?.sort((a, b) =>
(a.created_at ?? '') > (b.created_at ?? '') ? -1 : 1,
)
.map((result) => {
const isCompleted = result.feedback?.status === 'COMPLETED';
const isCurrentDoctorJob =
!!result.doctor?.primary_owner_user_id &&
result.doctor?.primary_owner_user_id === currentUser?.id;
const resultsReceived = result.elements.length || 0;
const elementsInOrder = Array.from(
new Set(result.analysis_order_id.analysis_element_ids),
)?.length;
return (
<TableRow key={result.order_number}>
<TableCell className="text-center">
<Link
href={`/${pathsConfig.app.analysisDetails}/${result.id}`}
>
<Eye />
</Link>
</TableCell>
<TableCell>
{getFullName(
result.patient?.name,
result.patient?.last_name,
)}
</TableCell>
<TableCell>
<Trans
i18nKey={getResultSetName(
result.order?.title ?? '-',
result.order?.isPackage,
result.elements?.length || 0,
)}
/>
</TableCell>
<TableCell>{result.order_number}</TableCell>
<TableCell>
{result.firstSampleGivenAt
? format(result.firstSampleGivenAt, 'dd.MM.yyyy HH:mm')
: '-'}
</TableCell>
<TableCell>
<Trans
i18nKey={
resultsReceived === elementsInOrder
? 'doctor:resultsTable.responsesReceived'
: 'doctor:resultsTable.waitingForNr'
}
values={{
nr: elementsInOrder - resultsReceived,
}}
/>
</TableCell>
<TableCell>
{capitalize(
languageNames.of(
result?.patient?.preferred_locale ?? 'et',
),
)}
</TableCell>
<TableCell>
<DoctorJobSelect
doctorUserId={result.doctor?.primary_owner_user_id}
doctorName={getFullName(
result.doctor?.name,
result.doctor?.last_name,
)}
analysisOrderId={result.analysis_order_id?.id}
userId={result.patient?.id}
isRemovable={!isCompleted && isCurrentDoctorJob}
onJobUpdate={handleJobUpdate}
linkTo={`/${pathsConfig.app.analysisDetails}/${result.id}`}
/>
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
<div className="mt-4 flex items-center justify-between">
<Button
onClick={handlePrevPage}
disabled={pagination.currentPage === 1 || isPending}
variant="outline"
>
<Trans i18nKey="common:previous" />
</Button>
<span className="text-sm text-gray-600">
<Trans
i18nKey={'common:pageOfPages'}
values={{
page: pagination.currentPage,
total: pagination.totalPages,
}}
/>
</span>
<Button
onClick={handleNextPage}
disabled={
pagination.currentPage === pagination.totalPages || isPending
}
variant="outline"
>
<Trans i18nKey="common:next" />
</Button>
</div>
</>
);
}

View File

@@ -0,0 +1,52 @@
import { cache } from 'react';
import { getAnalysisResultsForDoctor } from '@kit/doctor/services/doctor-analysis.service';
import { PageBody, PageHeader } from '@kit/ui/page';
import {
DoctorPageViewAction,
createDoctorPageViewLog,
} from '~/lib/services/audit/doctorPageView.service';
import AnalysisView from '../../_components/analysis-view';
import { DoctorGuard } from '../../_components/doctor-guard';
async function AnalysisPage({
params,
}: {
params: Promise<{
id: string;
}>;
}) {
const { id: analysisOrderId } = await params;
const analysisResultDetails = await loadResult(Number(analysisOrderId));
if (!analysisResultDetails) {
return null;
}
if (analysisResultDetails) {
await createDoctorPageViewLog({
action: DoctorPageViewAction.VIEW_ANALYSIS_RESULTS,
recordKey: analysisOrderId,
dataOwnerUserId: analysisResultDetails.patient.userId,
});
}
return (
<>
<PageHeader />
<PageBody>
<AnalysisView
patient={analysisResultDetails.patient}
order={analysisResultDetails.order}
analyses={analysisResultDetails.analysisResponse}
feedback={analysisResultDetails.doctorFeedback}
/>
</PageBody>
</>
);
}
export default DoctorGuard(AnalysisPage);
const loadResult = cache(getAnalysisResultsForDoctor);

View File

@@ -0,0 +1,31 @@
import { getUserDoneResponsesAction } from '@kit/doctor/actions/table-data-fetching-actions';
import { PageBody, PageHeader } from '@kit/ui/page';
import {
DoctorPageViewAction,
createDoctorPageViewLog,
} from '~/lib/services/audit/doctorPageView.service';
import { DoctorGuard } from '../_components/doctor-guard';
import ResultsTableWrapper from '../_components/results-table-wrapper';
async function CompletedJobsPage() {
await createDoctorPageViewLog({
action: DoctorPageViewAction.VIEW_DONE_JOBS,
});
return (
<>
<PageHeader />
<PageBody>
<ResultsTableWrapper
titleKey="doctor:completedReviews"
action={getUserDoneResponsesAction}
queryKey="doctor-done-jobs"
/>
</PageBody>
</>
);
}
export default DoctorGuard(CompletedJobsPage);

46
app/doctor/layout.tsx Normal file
View File

@@ -0,0 +1,46 @@
import { use } from 'react';
import { cookies } from 'next/headers';
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
import { loadUserWorkspace } from '../home/(user)/_lib/server/load-user-workspace';
import { DoctorSidebar } from './_components/doctor-sidebar';
import { DoctorMobileNavigation } from './_components/mobile-navigation';
export const metadata = {
title: `Doctor`,
};
export const dynamic = 'force-dynamic';
export default function DoctorLayout(props: React.PropsWithChildren) {
const state = use(getLayoutState());
const workspace = use(loadUserWorkspace());
return (
<SidebarProvider defaultOpen={state.open}>
<Page style={'sidebar'}>
<PageNavigation>
<DoctorSidebar accounts={workspace.accounts} />
</PageNavigation>
<PageMobileNavigation>
<DoctorMobileNavigation />
</PageMobileNavigation>
{props.children}
</Page>
</SidebarProvider>
);
}
async function getLayoutState() {
const cookieStore = await cookies();
const sidebarOpenCookie = cookieStore.get('sidebar:state');
return {
open: sidebarOpenCookie?.value !== 'true',
};
}

3
app/doctor/loading.tsx Normal file
View File

@@ -0,0 +1,3 @@
import { GlobalLoader } from '@kit/ui/global-loader';
export default GlobalLoader;

View File

@@ -0,0 +1,31 @@
import { getUserInProgressResponsesAction } from '@kit/doctor/actions/table-data-fetching-actions';
import { PageBody, PageHeader } from '@kit/ui/page';
import {
DoctorPageViewAction,
createDoctorPageViewLog,
} from '~/lib/services/audit/doctorPageView.service';
import { DoctorGuard } from '../_components/doctor-guard';
import ResultsTableWrapper from '../_components/results-table-wrapper';
async function MyReviewsPage() {
await createDoctorPageViewLog({
action: DoctorPageViewAction.VIEW_OWN_JOBS,
});
return (
<>
<PageHeader />
<PageBody>
<ResultsTableWrapper
titleKey="doctor:myReviews"
action={getUserInProgressResponsesAction}
queryKey="doctor-in-progress-jobs"
/>
</PageBody>
</>
);
}
export default DoctorGuard(MyReviewsPage);

View File

@@ -0,0 +1,31 @@
import { getOpenResponsesAction } from '@kit/doctor/actions/table-data-fetching-actions';
import { PageBody, PageHeader } from '@kit/ui/page';
import {
DoctorPageViewAction,
createDoctorPageViewLog,
} from '~/lib/services/audit/doctorPageView.service';
import { DoctorGuard } from '../_components/doctor-guard';
import ResultsTableWrapper from '../_components/results-table-wrapper';
async function OpenJobsPage() {
await createDoctorPageViewLog({
action: DoctorPageViewAction.VIEW_OPEN_JOBS,
});
return (
<>
<PageHeader />
<PageBody>
<ResultsTableWrapper
titleKey="doctor:openReviews"
action={getOpenResponsesAction}
queryKey="doctor-open-jobs"
/>
</PageBody>
</>
);
}
export default DoctorGuard(OpenJobsPage);

26
app/doctor/page.tsx Normal file
View File

@@ -0,0 +1,26 @@
import { PageBody, PageHeader } from '@kit/ui/page';
import {
DoctorPageViewAction,
createDoctorPageViewLog,
} from '~/lib/services/audit/doctorPageView.service';
import Dashboard from './_components/doctor-dashboard';
import { DoctorGuard } from './_components/doctor-guard';
async function DoctorPage() {
await createDoctorPageViewLog({
action: DoctorPageViewAction.VIEW_DASHBOARD,
});
return (
<>
<PageHeader />
<PageBody>
<Dashboard />
</PageBody>
</>
);
}
export default DoctorGuard(DoctorPage);

View File

@@ -5,12 +5,12 @@ import Link from 'next/link';
import { ArrowLeft, MessageCircle } from 'lucide-react';
import { useCaptureException } from '@kit/monitoring/hooks';
import { RootProviders } from '@kit/shared/components/root-providers';
import { Button } from '@kit/ui/button';
import { Heading } from '@kit/ui/heading';
import { Trans } from '@kit/ui/trans';
import { SiteHeader } from '~/(marketing)/_components/site-header';
import { RootProviders } from '~/components/root-providers';
const GlobalErrorPage = ({
error,

7
app/health/page.tsx Normal file
View File

@@ -0,0 +1,7 @@
const HealthPage = () => {
const commit = process.env.NEXT_PUBLIC_COMMIT_HASH;
return <div>{commit}</div>;
};
export default HealthPage;

View File

@@ -0,0 +1,134 @@
import React from 'react';
import Link from 'next/link';
import { redirect } from 'next/navigation';
import { ButtonTooltip } from '@kit/shared/components/ui/button-tooltip';
import { pathsConfig } from '@kit/shared/config';
import { Button } from '@kit/ui/button';
import { PageBody, PageHeader } from '@kit/ui/page';
import { Trans } from '@kit/ui/trans';
import { loadCurrentUserAccount } from '~/home/(user)/_lib/server/load-user-account';
import { loadUserAnalysis } from '~/home/(user)/_lib/server/load-user-analysis';
import {
PageViewAction,
createPageViewLog,
} from '~/lib/services/audit/pageView.service';
import Analysis from '../_components/analysis';
export default async function AnalysisResultsPage({
params,
}: {
params: Promise<{
id: string;
}>;
}) {
const { id: analysisOrderId } = await params;
const [{ account }, analysisResponse] = await Promise.all([
loadCurrentUserAccount(),
loadUserAnalysis(Number(analysisOrderId)),
]);
if (!account?.id) {
return redirect('/');
}
await createPageViewLog({
accountId: account.id,
action: PageViewAction.VIEW_ANALYSIS_RESULTS,
});
if (!analysisResponse) {
return (
<>
<PageHeader
title={<Trans i18nKey="analysis-results:pageTitle" />}
description={<Trans i18nKey="analysis-results:descriptionEmpty" />}
/>
<PageBody className="gap-4"></PageBody>
</>
);
}
const orderedAnalysisElements = analysisResponse.orderedAnalysisElements;
const hasOrderedAnalysisElements = orderedAnalysisElements.length > 0;
const isPartialStatus =
analysisResponse.order.status === 'PARTIAL_ANALYSIS_RESPONSE';
return (
<>
<PageHeader
title={<Trans i18nKey="analysis-results:pageTitle" />}
description={
hasOrderedAnalysisElements ? (
isPartialStatus ? (
<Trans i18nKey="analysis-results:descriptionPartial" />
) : (
<Trans i18nKey="analysis-results:description" />
)
) : (
<Trans i18nKey="analysis-results:descriptionEmpty" />
)
}
>
<div>
<Button asChild>
<Link href={pathsConfig.app.orderAnalysisPackage}>
<Trans i18nKey="analysis-results:orderNewAnalysis" />
</Link>
</Button>
</div>
</PageHeader>
<PageBody className="gap-4 pt-4">
<div className="flex flex-col gap-4">
<h5 className="break-all">
<Trans
i18nKey="analysis-results:orderTitle"
values={{ orderNumber: analysisResponse.order.medusaOrderId }}
/>
</h5>
<h6>
<Trans i18nKey={`orders:status.${analysisResponse.order.status}`} />
<ButtonTooltip
content={`${analysisResponse.order.createdAt ? new Date(analysisResponse?.order?.createdAt).toLocaleString() : ''}`}
className="ml-6"
/>
</h6>
</div>
{analysisResponse?.summary?.value && (
<div>
<strong>
<Trans i18nKey="account:doctorAnalysisSummary" />
</strong>
<p>{analysisResponse.summary.value}</p>
</div>
)}
<div className="flex flex-col gap-2">
{orderedAnalysisElements ? (
orderedAnalysisElements.map((element, index) => (
<React.Fragment key={element.analysisIdOriginal}>
<Analysis element={element} />
{element.results?.nestedElements?.map(
(nestedElement, nestedIndex) => (
<Analysis
key={`nested-${nestedElement.analysisElementOriginalId}-${nestedIndex}`}
nestedElement={nestedElement}
isNestedElement
/>
),
)}
</React.Fragment>
))
) : (
<div className="text-muted-foreground text-sm">
<Trans i18nKey="analysis-results:noAnalysisElements" />
</div>
)}
</div>
</PageBody>
</>
);
}

View File

@@ -0,0 +1,209 @@
import { useMemo } from 'react';
import type { AnalysisResultDetailsElementResults } from '@/packages/features/user-analyses/src/types/analysis-results';
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
import { ArrowDown } from 'lucide-react';
import { cn } from '@kit/ui/utils';
type AnalysisResultLevelBarResults = Pick<
AnalysisResultDetailsElementResults,
'normLower' | 'normUpper' | 'responseValue'
>;
const Level = ({
isActive = false,
color,
isFirst = false,
isLast = false,
arrowLocation,
normRangeText,
}: {
isActive?: boolean;
color: 'destructive' | 'success' | 'warning' | 'gray-200';
isFirst?: boolean;
isLast?: boolean;
arrowLocation?: number;
normRangeText?: string | null;
}) => {
return (
<div
className={cn(`bg-${color} relative h-3 flex-1`, {
'opacity-60': !isActive,
'rounded-l-lg': isFirst,
'rounded-r-lg': isLast,
})}
>
{isActive && (
<div
className="absolute top-[-14px] left-1/2 -translate-x-1/2 rounded-[10px] bg-white p-[2px]"
{...(arrowLocation
? {
style: {
left: `${arrowLocation}%`,
...(arrowLocation > 92.5 && { left: '92.5%' }),
...(arrowLocation < 7.5 && { left: '7.5%' }),
},
}
: {})}
>
<ArrowDown strokeWidth={2} />
</div>
)}
{color === 'success' && typeof normRangeText === 'string' && (
<p
className={cn(
'text-muted-foreground absolute bottom-[-18px] left-3/8 text-xs font-bold whitespace-nowrap',
{
'opacity-60': isActive,
},
)}
>
{normRangeText}
</p>
)}
</div>
);
};
const AnalysisLevelBar = ({
level,
results: { normLower: lower, normUpper: upper, responseValue: value },
normRangeText,
}: {
level: AnalysisResultLevel;
results: AnalysisResultLevelBarResults;
normRangeText: string | null;
}) => {
// Calculate arrow position based on value within normal range
const arrowLocation = useMemo(() => {
// If no response value, center the arrow
if (value === null || value === undefined) {
return 50;
}
// If no normal ranges defined, center the arrow
if (lower === null && upper === null) {
return 50;
}
// If only upper bound exists
if (lower === null && upper !== null) {
if (value <= upper) {
return Math.min(75, (value / upper) * 75); // Show in left 75% of normal range
}
return 100; // Beyond upper bound
}
// If only lower bound exists
if (upper === null && lower !== null) {
if (value >= lower) {
// Value is in normal range (above lower bound)
// Position proportionally in the normal range section
const normalizedPosition = Math.min((value - lower) / (lower * 0.5), 1); // Use 50% of lower as scale
return normalizedPosition * 100;
}
// Value is below lower bound - position in the "below normal" section
const belowPosition = Math.max(0, Math.min(1, value / lower));
return belowPosition * 100;
}
// Both bounds exist
if (lower !== null && upper !== null) {
if (value < lower) {
return 0; // Below normal range
}
if (value > upper) {
return 100; // Above normal range
}
// Within normal range
return ((value - lower) / (upper - lower)) * 100;
}
return 50; // Fallback
}, [value, upper, lower]);
// Determine level states based on normStatus
const isNormal = level === AnalysisResultLevel.NORMAL;
const isWarning = level === AnalysisResultLevel.WARNING;
const isCritical = level === AnalysisResultLevel.CRITICAL;
const isPending = level === null;
// If pending results, show gray bar
if (isPending) {
return (
<div className="w-60% mt-4 flex h-3 max-w-[360px] gap-1 sm:mt-0 sm:w-[35%]">
<Level color="gray-200" isFirst isLast />
</div>
);
}
// Show appropriate levels based on available norm bounds
const hasLowerBound = lower !== null;
const hasUpperBound = upper !== null;
// Determine which section the value falls into
const isValueBelowLower = hasLowerBound && value !== null && value < lower!;
const isValueAboveUpper = hasUpperBound && value !== null && value > upper!;
const isValueInNormalRange = !isValueBelowLower && !isValueAboveUpper;
const [first, second, third] = useMemo(() => {
const [warning, normal, critical] = [
{
isActive: isWarning,
color: 'warning',
...(isWarning ? { arrowLocation } : {}),
},
{
isActive: isNormal,
color: 'success',
normRangeText,
...(isNormal ? { arrowLocation } : {}),
},
{
isActive: isCritical,
color: 'destructive',
isLast: true,
...(isCritical ? { arrowLocation } : {}),
},
] as const;
if (!hasLowerBound) {
return [{ ...normal, isFirst: true }, warning, critical] as const;
}
return [
{ ...warning, isFirst: true },
normal,
{ ...critical, isLast: true },
] as const;
}, [
isValueBelowLower,
isValueAboveUpper,
isValueInNormalRange,
arrowLocation,
normRangeText,
isNormal,
isWarning,
isCritical,
]);
return (
<div
className={cn(
'flex h-3 gap-1',
'mt-4 sm:mt-0',
'w-[60%] sm:w-[35%]',
'min-w-[50vw] sm:min-w-auto',
'max-w-[360px]',
)}
>
<Level {...first} />
<Level {...second} />
<Level {...third} />
</div>
);
};
export default AnalysisLevelBar;

View File

@@ -0,0 +1,211 @@
'use client';
import React, { useMemo, useState } from 'react';
import type {
AnalysisResultDetailsElement,
AnalysisResultsDetailsElementNested,
} from '@/packages/features/user-analyses/src/types/analysis-results';
import { AnalysisResultLevel } from '@/packages/features/user-analyses/src/types/analysis-results';
import { format } from 'date-fns';
import { Info } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Trans } from '@kit/ui/trans';
import { cn } from '@kit/ui/utils';
import AnalysisLevelBar from './analysis-level-bar';
const Analysis = ({
element: elementOriginal,
nestedElement,
isNestedElement = false,
}: {
element?: AnalysisResultDetailsElement;
nestedElement?: AnalysisResultsDetailsElementNested;
isNestedElement?: boolean;
}) => {
const { t } = useTranslation();
const element = (() => {
if (isNestedElement) {
return nestedElement!;
}
return elementOriginal!;
})();
const results: AnalysisResultDetailsElement['results'] = useMemo(() => {
if (isNestedElement) {
const nestedElement = element as AnalysisResultsDetailsElementNested;
return {
analysisElementOriginalId: nestedElement.analysisElementOriginalId,
normLower: nestedElement.normLower,
normUpper: nestedElement.normUpper,
normStatus: nestedElement.normStatus,
responseTime: nestedElement.responseTime,
responseValue: nestedElement.responseValue,
responseValueIsNegative: nestedElement.responseValueIsNegative,
responseValueIsWithinNorm: nestedElement.responseValueIsWithinNorm,
normLowerIncluded: nestedElement.normLowerIncluded,
normUpperIncluded: nestedElement.normUpperIncluded,
unit: nestedElement.unit,
status: nestedElement.status,
nestedElements: [],
};
}
return (element as AnalysisResultDetailsElement).results;
}, [element, isNestedElement]);
const name = element.analysisName || '';
const hasIsWithinNorm = results?.responseValueIsWithinNorm !== null;
const hasIsNegative = results?.responseValueIsNegative !== null;
const value = (() => {
if (!results) {
return null;
}
const {
responseValue,
responseValueIsNegative,
responseValueIsWithinNorm,
} = results;
if (responseValue === null || responseValue === undefined) {
if (hasIsNegative) {
if (responseValueIsNegative) {
return t('analysis-results:results.value.negative');
}
return t('analysis-results:results.value.positive');
}
if (hasIsWithinNorm) {
if (responseValueIsWithinNorm) {
return t('analysis-results:results.value.isWithinNorm');
}
return t('analysis-results:results.value.isNotWithinNorm');
}
return null;
}
return responseValue;
})();
const unit = results?.unit || '';
const normLower = results?.normLower ?? null;
const normUpper = results?.normUpper ?? null;
const normStatus = results?.normStatus ?? null;
const [showTooltip, setShowTooltip] = useState(false);
const analysisResultLevel = useMemo(() => {
if (normStatus === null) {
return null;
}
switch (normStatus) {
case 1:
return AnalysisResultLevel.WARNING;
case 2:
return AnalysisResultLevel.CRITICAL;
case 0:
default:
return AnalysisResultLevel.NORMAL;
}
}, [normStatus]);
const isCancelled = Number(results?.status) === 5;
const nestedElements = results?.nestedElements ?? null;
const hasNestedElements =
Array.isArray(nestedElements) && nestedElements.length > 0;
const normRangeText = (() => {
if (normLower === null && normUpper === null) {
return null;
}
return `${normLower ?? '...'} - ${normUpper ?? '...'}`;
})();
const hasTextualResponse = hasIsNegative || hasIsWithinNorm;
return (
<div
className={cn('border-border rounded-lg border px-5', {
'ml-8': isNestedElement,
})}
>
<div className="flex flex-col items-center justify-between gap-2 pt-3 pb-6 sm:h-[65px] sm:flex-row sm:gap-0 sm:py-3">
<div
className={cn('flex items-center gap-2 font-semibold', {
'font-bold': isNestedElement,
})}
>
{name}
{results?.responseTime && (
<div
className="group/tooltip relative"
onClick={(e) => {
e.stopPropagation();
setShowTooltip(!showTooltip);
}}
onMouseLeave={() => setShowTooltip(false)}
>
<Info className="hover" />{' '}
<div
className={cn(
'absolute bottom-full left-1/2 z-10 mb-2 hidden -translate-x-1/2 rounded border bg-white p-4 text-sm whitespace-nowrap group-hover/tooltip:block',
{ block: showTooltip },
)}
>
<Trans i18nKey="analysis-results:analysisDate" />
{': '}
{format(new Date(results.responseTime), 'dd.MM.yyyy HH:mm')}
</div>
</div>
)}
</div>
{isCancelled && (
<div className="text-sm font-semibold text-red-600">
<Trans i18nKey="analysis-results:cancelled" />
</div>
)}
{isCancelled || !results || hasNestedElements ? null : (
<>
<div className="flex items-center gap-3 sm:ml-auto">
<div
className={cn('font-semibold', {
'text-yellow-600':
hasTextualResponse &&
analysisResultLevel === AnalysisResultLevel.WARNING,
'text-red-600':
hasTextualResponse &&
analysisResultLevel === AnalysisResultLevel.CRITICAL,
'text-green-600':
hasTextualResponse &&
analysisResultLevel === AnalysisResultLevel.NORMAL,
})}
>
{value}
</div>
<div className="text-muted-foreground text-sm">{unit}</div>
</div>
{!hasTextualResponse && (
<>
<div className="text-muted-foreground mx-8 flex flex-col-reverse gap-2 text-center text-sm sm:block sm:gap-0">
{normRangeText}
<div>
<Trans i18nKey="analysis-results:results.range.normal" />
</div>
</div>
<AnalysisLevelBar
results={results}
level={analysisResultLevel!}
normRangeText={normRangeText}
/>
</>
)}
</>
)}
</div>
</div>
);
};
export default Analysis;

View File

@@ -0,0 +1,108 @@
'use client';
import React, { useState } from 'react';
import Modal from '@modules/common/components/modal';
import { PageBody, PageHeader } from '@kit/ui/page';
import { Button } from '@kit/ui/shadcn/button';
import { Trans } from '@kit/ui/trans';
import Analysis from '../_components/analysis';
import { analysisResponses } from './test-responses';
export default function AnalysisResultsPage() {
const [openBlocks, setOpenBlocks] = useState<number[]>([]);
return (
<>
<PageHeader />
<PageBody className="gap-4">
<div className="mt-8 flex flex-col justify-between gap-4 sm:flex-row sm:items-center sm:gap-0">
<div>
<h2>Analüüsi tulemused demo</h2>
</div>
</div>
<div className="flex flex-col gap-2">
{analysisResponses.map(({ id, orderedAnalysisElements }, index) => {
const isOpen = openBlocks.includes(id);
const closeModal = () =>
setOpenBlocks(openBlocks.filter((block) => block !== id));
return (
<div key={index} className="flex flex-col gap-2 py-4">
<div className="flex flex-col gap-2 pb-4">
<h3>AnalysisOrderId: {id}</h3>
<div className="flex flex-col gap-2">
<h5>OrderedAnalysisElements</h5>
<Button
onClick={() => {
if (isOpen) {
closeModal();
} else {
setOpenBlocks([...openBlocks, id]);
}
}}
className="w-fit"
color={isOpen ? 'orange' : 'grey'}
>
{isOpen ? 'Close' : 'Open'}
</Button>
{isOpen && (
<Modal isOpen={isOpen} close={closeModal} size="large">
<div className="overflow-y-auto">
<p>NormiStaatus</p>
<ul>
<li>
0 - testi väärtus jääb normaalväärtuste piirkonda
või on määramata,
</li>
<li>
1 - testi väärtus jääb hoiatava (tähelepanu
suunava) märkega piirkonda,
</li>
<li>
2 - testi väärtus on normaalväärtuste piirkonnast
väljas või kõrgendatud tähelepanu nõudvas
piirkonnas.
</li>
</ul>
<p>UuringOlek</p>
<ul>
<li>1 - Järjekorras,</li>
<li>2 - Ootel,</li>
<li>3 - Töös,</li>
<li>4 - Lõpetatud,</li>
<li>5 - Tagasi lükatud,</li>
<li>6 - Tühistatud,</li>
</ul>
<pre className="bg-muted rounded-md p-4 text-sm">
{JSON.stringify(orderedAnalysisElements, null, 2)}
</pre>
</div>
</Modal>
)}
</div>
{orderedAnalysisElements ? (
orderedAnalysisElements.map((element, index) => (
<Analysis key={index} element={element} />
))
) : (
<div className="text-muted-foreground text-sm">
<Trans i18nKey="analysis-results:noAnalysisElements" />
</div>
)}
</div>
<hr />
</div>
);
})}
</div>
</PageBody>
</>
);
}

View File

@@ -0,0 +1,906 @@
import type { AnalysisResultDetailsMapped } from '@/packages/features/user-analyses/src/types/analysis-results';
type AnalysisTestResponse = Omit<
AnalysisResultDetailsMapped,
'order' | 'orderedAnalysisElementIds' | 'summary' | 'elements'
>;
const empty1: AnalysisTestResponse = {
id: 1,
orderedAnalysisElements: [],
};
const big1: AnalysisTestResponse = {
id: 2,
orderedAnalysisElements: [
{
analysisIdOriginal: '1744-2',
isWaitingForResults: false,
analysisName: 'ALAT',
results: {
nestedElements: [],
unit: 'U/l',
normLower: null,
normUpper: 45,
normStatus: 2,
responseTime: '2024-02-29T10:42:25+00:00',
responseValue: 84,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '1744-2',
},
},
{
analysisIdOriginal: '1920-8',
isWaitingForResults: false,
analysisName: 'ASAT',
results: {
nestedElements: [],
unit: 'U/l',
normLower: 15,
normUpper: 45,
normStatus: 0,
responseTime: '2024-02-29T10:20:55+00:00',
responseValue: 45,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '1920-8',
},
},
{
analysisIdOriginal: '1988-5',
isWaitingForResults: false,
analysisName: 'CRP',
results: {
nestedElements: [],
unit: 'mg/l',
normLower: null,
normUpper: 5,
normStatus: 0,
responseTime: '2024-02-29T10:18:49+00:00',
responseValue: 0.79,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '1988-5',
},
},
{
analysisIdOriginal: '57747-8',
isWaitingForResults: false,
analysisName: 'Erütrotsüüdid',
results: {
nestedElements: [],
unit: null,
normLower: null,
normUpper: 5,
normStatus: 0,
responseTime: '2024-02-29T10:13:01+00:00',
responseValue: null,
responseValueIsNegative: true,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '57747-8',
},
},
{
analysisIdOriginal: '2276-4',
isWaitingForResults: false,
analysisName: 'Ferritiin',
results: {
nestedElements: [],
unit: 'µg/l',
normLower: 28,
normUpper: 370,
normStatus: 0,
responseTime: '2024-02-29T10:46:54+00:00',
responseValue: 204.1,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '2276-4',
},
},
{
analysisIdOriginal: '14771-0',
isWaitingForResults: false,
analysisName: 'Glükoos',
results: {
nestedElements: [],
unit: 'mmol/l',
normLower: 4.1,
normUpper: 6,
normStatus: 0,
responseTime: '2024-02-29T10:06:24+00:00',
responseValue: 5.4,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '14771-0',
},
},
{
analysisIdOriginal: '59156-0',
isWaitingForResults: false,
analysisName: 'Glükoos',
results: {
nestedElements: [],
unit: null,
normLower: null,
normUpper: 2,
normStatus: 2,
responseTime: '2024-02-29T10:13:01+00:00',
responseValue: null,
responseValueIsNegative: null,
responseValueIsWithinNorm: false,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '59156-0',
},
},
{
analysisIdOriginal: '59156-0',
isWaitingForResults: false,
analysisName: 'Glükoos',
results: {
nestedElements: [],
unit: null,
normLower: null,
normUpper: 2,
normStatus: 0,
responseTime: '2024-02-29T10:13:01+00:00',
responseValue: null,
responseValueIsNegative: null,
responseValueIsWithinNorm: true,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '59156-0',
},
},
{
analysisIdOriginal: '13955-0',
isWaitingForResults: false,
analysisName: 'HCV Ab',
results: {
nestedElements: [],
unit: null,
normLower: null,
normUpper: null,
normStatus: 0,
responseTime: '2024-02-29T13:44:48+00:00',
responseValue: null,
responseValueIsNegative: true,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '13955-0',
},
},
{
analysisIdOriginal: '14646-4',
isWaitingForResults: false,
analysisName: 'HDL kolesterool',
results: {
nestedElements: [],
unit: 'mmol/l',
normLower: 1,
normUpper: null,
normStatus: 1,
responseTime: '2024-02-29T10:20:55+00:00',
responseValue: 0.8,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '14646-4',
},
},
{
analysisIdOriginal: '2000-8',
isWaitingForResults: false,
analysisName: 'Kaltsium',
results: {
nestedElements: [],
unit: 'mmol/l',
normLower: 2.1,
normUpper: 2.55,
normStatus: 0,
responseTime: '2024-02-29T10:12:10+00:00',
responseValue: 2.49,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '2000-8',
},
},
{
analysisIdOriginal: '59158-6',
isWaitingForResults: false,
analysisName: 'Ketokehad',
results: {
nestedElements: [],
unit: null,
normLower: null,
normUpper: 0.5,
normStatus: 0,
responseTime: '2024-02-29T10:13:01+00:00',
responseValue: null,
responseValueIsNegative: true,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '59158-6',
},
},
{
analysisIdOriginal: '14647-2',
isWaitingForResults: false,
analysisName: 'Kolesterool',
results: {
nestedElements: [],
unit: 'mmol/l',
normLower: null,
normUpper: 5,
normStatus: 1,
responseTime: '2024-02-29T10:20:34+00:00',
responseValue: 5.7,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '14647-2',
},
},
{
analysisIdOriginal: '14682-9',
isWaitingForResults: false,
analysisName: 'Kreatiniin',
results: {
nestedElements: [],
unit: 'µmol/l',
normLower: 64,
normUpper: 111,
normStatus: 0,
responseTime: '2024-02-29T10:19:00+00:00',
responseValue: 89,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '14682-9',
},
},
{
analysisIdOriginal: '22748-8',
isWaitingForResults: false,
analysisName: 'LDL kolesterool',
results: {
nestedElements: [],
unit: 'mmol/l',
normLower: null,
normUpper: 3,
normStatus: 1,
responseTime: '2024-02-29T10:21:15+00:00',
responseValue: 4.3,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '22748-8',
},
},
{
analysisIdOriginal: '58805-3',
isWaitingForResults: false,
analysisName: 'Leukotsüüdid',
results: {
nestedElements: [],
unit: null,
normLower: null,
normUpper: 10,
normStatus: 0,
responseTime: '2024-02-29T10:13:01+00:00',
responseValue: null,
responseValueIsNegative: true,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '58805-3',
},
},
{
analysisIdOriginal: '2601-3',
isWaitingForResults: false,
analysisName: 'Magneesium',
results: {
nestedElements: [],
unit: 'mmol/l',
normLower: 0.66,
normUpper: 1.07,
normStatus: 0,
responseTime: '2024-02-29T10:17:26+00:00',
responseValue: 0.82,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '2601-3',
},
},
{
analysisIdOriginal: '70204-3',
isWaitingForResults: false,
analysisName: 'Mitte-HDL kolesterool',
results: {
nestedElements: [],
labComment: 'Mitte-paastu veri <3,9 mmol/L',
unit: 'mmol/l',
normLower: null,
normUpper: 3.8,
normStatus: 1,
responseTime: '2024-02-29T10:20:55+00:00',
responseValue: 4.9,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '70204-3',
},
},
{
analysisIdOriginal: '14798-3',
isWaitingForResults: false,
analysisName: 'Raud',
results: {
nestedElements: [],
unit: 'µmol/l',
normLower: 11.6,
normUpper: 31.3,
normStatus: 0,
responseTime: '2024-02-29T10:21:16+00:00',
responseValue: 16.5,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '14798-3',
},
},
{
analysisIdOriginal: '14927-8',
isWaitingForResults: false,
analysisName: 'Triglütseriidid',
results: {
nestedElements: [],
labComment: 'Mitte-paastu veri <2,0 mmol/L',
unit: 'mmol/l',
normLower: null,
normUpper: 1.7,
normStatus: 1,
responseTime: '2024-02-29T10:21:16+00:00',
responseValue: 1.89,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '14927-8',
},
},
{
analysisIdOriginal: '3016-3',
isWaitingForResults: false,
analysisName: 'TSH',
results: {
nestedElements: [],
unit: 'mIU/l',
normLower: 0.4,
normUpper: 4,
normStatus: 0,
responseTime: '2024-02-29T10:49:02+00:00',
responseValue: 1.27,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '3016-3',
},
},
{
analysisIdOriginal: '22664-7',
isWaitingForResults: false,
analysisName: 'Uurea',
results: {
nestedElements: [],
unit: 'mmol/l',
normLower: 3.2,
normUpper: 7.4,
normStatus: 0,
responseTime: '2024-02-29T10:19:11+00:00',
responseValue: 6.4,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '22664-7',
},
},
{
analysisIdOriginal: '50561-0',
isWaitingForResults: false,
analysisName: 'Valk',
results: {
nestedElements: [],
unit: null,
normLower: null,
normUpper: 0.25,
normStatus: 0,
responseTime: '2024-02-29T10:13:01+00:00',
responseValue: null,
responseValueIsNegative: true,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '50561-0',
},
},
{
analysisIdOriginal: '60493-4',
isWaitingForResults: false,
analysisName: 'Vitamiin D (25-OH)',
results: {
nestedElements: [],
labComment: 'Väärtus >75 nmol/l on D-vitamiini tervislik tase',
unit: 'nmol/l',
normLower: 75,
normUpper: null,
normStatus: 0,
responseTime: '2024-02-29T10:49:22+00:00',
responseValue: 105.5,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '60493-4',
},
},
{
analysisIdOriginal: '60025-4',
isWaitingForResults: false,
analysisName: 'Urobilinogeen',
results: {
nestedElements: [],
unit: null,
normLower: null,
normUpper: 17,
normStatus: 0,
responseTime: '2024-02-29T10:13:01+00:00',
responseValue: null,
responseValueIsNegative: null,
responseValueIsWithinNorm: true,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '60025-4',
},
},
],
};
const big2: AnalysisTestResponse = {
id: 3,
orderedAnalysisElements: [
{
analysisIdOriginal: '1988-5',
isWaitingForResults: false,
analysisName: 'CRP',
results: {
nestedElements: [],
unit: 'mg/L',
normLower: null,
normUpper: 5,
normStatus: 0,
responseTime: '2025-09-12T14:02:04+00:00',
responseValue: 1,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
normLowerIncluded: false,
normUpperIncluded: false,
status: 4,
analysisElementOriginalId: '1988-5',
},
},
{
analysisIdOriginal: '57021-8',
isWaitingForResults: false,
analysisName: 'Hemogramm',
results: {
nestedElements: [
{
status: 4,
unit: 'g/L',
normLower: 134,
normUpper: 170,
normStatus: 0,
responseTime: '2025-09-12 14:02:03',
responseValue: 150,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '718-7',
},
{
status: 4,
unit: '%',
normLower: 40,
normUpper: 49,
normStatus: 0,
responseTime: '2025-09-12 14:02:03',
responseValue: 45,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '4544-3',
},
{
status: 4,
unit: 'E9/L',
normLower: 4.1,
normUpper: 9.7,
normStatus: 0,
responseTime: '2025-09-12 14:02:03',
responseValue: 5,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '6690-2',
},
{
status: 4,
unit: 'E12/L',
normLower: 4.5,
normUpper: 5.7,
normStatus: 0,
responseTime: '2025-09-12 14:02:03',
responseValue: 5,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '789-8',
},
{
status: 4,
unit: 'fL',
normLower: 82,
normUpper: 95,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 85,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '787-2',
},
{
status: 4,
unit: 'pg',
normLower: 28,
normUpper: 33,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 30,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '785-6',
},
{
status: 4,
unit: 'g/L',
normLower: 322,
normUpper: 356,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 355,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '786-4',
},
{
status: 4,
unit: '%',
normLower: 12,
normUpper: 15,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 15,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '788-0',
},
{
status: 4,
unit: 'E9/L',
normLower: 157,
normUpper: 372,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 255,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '777-3',
},
{
status: 4,
unit: '%',
normLower: 0.18,
normUpper: 0.38,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 0.2,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '51637-7',
},
{
status: 4,
unit: 'fL',
normLower: 9.2,
normUpper: 12.3,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 10,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '32623-1',
},
{
status: 4,
unit: 'fL',
normLower: 10.1,
normUpper: 16.2,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 15,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '32207-3',
},
{
status: 4,
unit: 'E9/L',
normLower: 0.01,
normUpper: 0.08,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 0.05,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '704-7',
},
{
status: 4,
unit: 'E9/L',
normLower: 0.02,
normUpper: 0.4,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 0.05,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '711-2',
},
{
status: 4,
unit: 'E9/L',
normLower: 1.9,
normUpper: 6.7,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 5,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '751-8',
},
{
status: 4,
unit: 'E9/L',
normLower: 0.24,
normUpper: 0.8,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 0.5,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '742-7',
},
{
status: 4,
unit: 'E9/L',
normLower: 1.3,
normUpper: 3.1,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 1.5,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '731-0',
},
{
status: 4,
unit: 'E9/L',
normLower: 0,
normUpper: 0.03,
normStatus: 0,
responseTime: '2025-09-12 14:02:03',
responseValue: 0,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '51584-1',
},
{
status: 4,
unit: '%',
normLower: 0,
normUpper: 0.5,
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 0,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '38518-7',
},
{
status: 4,
unit: 'E9/L',
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 0,
normUpper: null,
normLower: null,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '771-6',
},
{
status: 4,
unit: '/100WBC',
normStatus: 0,
responseTime: '2025-09-12 14:02:04',
responseValue: 0,
normUpper: null,
normLower: null,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
analysisElementOriginalId: '58413-6',
},
],
unit: null,
normLower: null,
normUpper: null,
normStatus: null,
responseTime: null,
responseValue: null,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: false,
responseValueIsWithinNorm: false,
status: 4,
analysisElementOriginalId: '57021-8',
},
},
{
analysisIdOriginal: '43583-4',
isWaitingForResults: false,
analysisName: 'Lipoproteiin a',
results: {
nestedElements: [],
labComment: 'Kliendi soovil analüüs tühistatud.',
unit: null,
normLower: null,
normUpper: null,
normStatus: null,
responseTime: null,
responseValue: null,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: false,
responseValueIsWithinNorm: false,
status: 5,
analysisElementOriginalId: '43583-4',
},
},
{
analysisIdOriginal: '60493-4',
isWaitingForResults: false,
analysisName: 'Vitamiin D (25-OH)',
results: {
nestedElements: [],
labComment:
'Väärtus vahemikus 30-49.9 nmol/L on D-vitamiini ebapiisav tase.',
unit: 'nmol/L',
normLower: 75,
normUpper: null,
normStatus: 1,
responseTime: '2025-09-12T14:02:04+00:00',
responseValue: 30,
normLowerIncluded: false,
normUpperIncluded: false,
responseValueIsNegative: null,
responseValueIsWithinNorm: null,
status: 4,
analysisElementOriginalId: '60493-4',
},
},
],
};
export const analysisResponses: AnalysisTestResponse[] = [empty1, big1, big2];

View File

@@ -0,0 +1,70 @@
import { redirect } from 'next/navigation';
import { HomeLayoutPageHeader } from '@/app/home/(user)/_components/home-page-header';
import { loadCategory } from '@/app/home/(user)/_lib/server/load-category';
import { pathsConfig } from '@kit/shared/config';
import { AppBreadcrumbs } from '@kit/ui/makerkit/app-breadcrumbs';
import { Trans } from '@kit/ui/trans';
import BookingContainer from '~/home/(user)/_components/booking/booking-container';
import { loadCurrentUserAccount } from '~/home/(user)/_lib/server/load-user-account';
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';
import {
PageViewAction,
createPageViewLog,
} from '~/lib/services/audit/pageView.service';
export const generateMetadata = async () => {
const i18n = await createI18nServerInstance();
const title = i18n.t('booking:title');
return {
title,
};
};
async function BookingHandlePage({
params,
}: {
params: Promise<{ handle: string }>;
}) {
const { handle } = await params;
const { category } = await loadCategory({ handle });
const { account } = await loadCurrentUserAccount();
if (!category) {
return <div>Category not found</div>;
}
if (!account) {
return redirect(pathsConfig.auth.signIn);
}
await createPageViewLog({
accountId: account.id,
action: PageViewAction.VIEW_TTO_SERVICE_BOOKING,
extraData: {
handle,
},
});
return (
<>
<AppBreadcrumbs
values={{
[handle]: category?.name || handle,
}}
/>
<HomeLayoutPageHeader
title={<Trans i18nKey={'booking:title'} />}
description=""
/>
<BookingContainer category={category} />
</>
);
}
export default withI18n(BookingHandlePage);

View File

@@ -1,3 +1,6 @@
import { use } from 'react';
import { AppBreadcrumbs } from '@kit/ui/makerkit/app-breadcrumbs';
import { PageBody } from '@kit/ui/page';
import { Trans } from '@kit/ui/trans';
@@ -6,6 +9,8 @@ import { withI18n } from '~/lib/i18n/with-i18n';
import { HomeLayoutPageHeader } from '../../_components/home-page-header';
import OrderCards from '../../_components/order-cards';
import ServiceCategories from '../../_components/service-categories';
import { loadTtoServices } from '../../_lib/server/load-tto-services';
export const generateMetadata = async () => {
const i18n = await createI18nServerInstance();
@@ -17,15 +22,34 @@ export const generateMetadata = async () => {
};
function BookingPage() {
const { heroCategories, ttoCategories } = use(loadTtoServices());
if (!heroCategories.length && !ttoCategories.length) {
return (
<>
<AppBreadcrumbs />
<HomeLayoutPageHeader
title={<Trans i18nKey={'booking:title'} />}
description={<Trans i18nKey={'booking:description'} />}
/>
<h4 className="mt-8">
<Trans i18nKey="booking:noCategories" />
</h4>
</>
);
}
return (
<>
<AppBreadcrumbs />
<HomeLayoutPageHeader
title={<Trans i18nKey={'booking:title'} />}
description={<Trans i18nKey={'booking:description'} />}
/>
<PageBody>
<OrderCards />
<PageBody className="space-y-2">
<OrderCards heroCategories={heroCategories} />
<ServiceCategories categories={ttoCategories} />
</PageBody>
</>
);

View File

@@ -1,23 +0,0 @@
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
import { MontonioCheckoutCallback } from '../../../../_components/cart/montonio-checkout-callback';
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
import { Trans } from '@kit/ui/trans';
export async function generateMetadata() {
const { t } = await createI18nServerInstance();
return {
title: t('cart:montonioCallback.title'),
};
}
export default async function MontonioCheckoutCallbackPage() {
return (
<div className={'flex h-full flex-1 flex-col'}>
<PageHeader title={<Trans i18nKey="cart:montonioCallback.title" />} />
<PageBody>
<MontonioCheckoutCallback />
</PageBody>
</div>
);
}

View File

@@ -0,0 +1,53 @@
'use server';
import { MontonioOrderToken } from '@/app/home/(user)/_components/cart/types';
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
import { retrieveCart } from '@lib/data/cart';
import jwt from 'jsonwebtoken';
import { handlePlaceOrder } from '../../../_lib/server/cart-actions';
const MONTONIO_PAID_STATUS = 'PAID';
async function decodeOrderToken(orderToken: string) {
const secretKey = process.env.MONTONIO_SECRET_KEY as string;
const decoded = jwt.verify(orderToken, secretKey, {
algorithms: ['HS256'],
}) as MontonioOrderToken;
if (decoded.paymentStatus !== MONTONIO_PAID_STATUS) {
throw new Error('Payment not successful');
}
return decoded;
}
async function getCartByOrderToken(decoded: MontonioOrderToken) {
const [, , cartId] = decoded.merchantReferenceDisplay.split(':');
if (!cartId) {
throw new Error('Cart ID not found');
}
const cart = await retrieveCart(cartId);
if (!cart) {
throw new Error('Cart not found');
}
return cart;
}
export async function processMontonioCallback(orderToken: string) {
const { account } = await loadCurrentUserAccount();
if (!account) {
throw new Error('Account not found in context');
}
try {
const decoded = await decodeOrderToken(orderToken);
const cart = await getCartByOrderToken(decoded);
const result = await handlePlaceOrder({ cart });
return result;
} catch (error) {
console.error('Failed to place order', error);
throw new Error(`Failed to place order, message=${error}`);
}
}

View File

@@ -0,0 +1,64 @@
'use client';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import { processMontonioCallback } from './actions';
export default function MontonioCallbackClient({
orderToken,
error,
}: {
orderToken?: string;
error?: string;
}) {
const router = useRouter();
const [isProcessing, setIsProcessing] = useState(false);
const [hasProcessed, setHasProcessed] = useState(false);
useEffect(() => {
if (error) {
console.error(error);
router.push('/home/cart/montonio-callback/error');
return;
}
if (!orderToken || hasProcessed || isProcessing) {
return;
}
const processOrder = async () => {
setIsProcessing(true);
setHasProcessed(true);
try {
const result = await processMontonioCallback(orderToken);
if (result.success) {
return router.push(`/home/order/${result.orderId}/confirmed`);
}
if (result.failedServiceBookings?.length) {
router.push(
`/home/cart/montonio-callback/error?reasonFailed=${result.failedServiceBookings.map(({ reason }) => reason).join(',')}`,
);
}
} catch (error) {
console.error('Failed to place order', error);
router.push('/home/cart/montonio-callback/error');
} finally {
setIsProcessing(false);
}
};
processOrder();
}, [orderToken, error, router, hasProcessed, isProcessing]);
return (
<div className="mt-10 flex min-h-screen justify-center">
<div className="text-center">
<div className="border-primary mx-auto mb-4 h-12 w-12 animate-spin rounded-full border-b-2"></div>
</div>
</div>
);
}

View File

@@ -0,0 +1,65 @@
import { use } from 'react';
import Link from 'next/link';
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
import { toArray } from '@kit/shared/utils';
import { Button } from '@kit/ui/button';
import { Alert, AlertDescription } from '@kit/ui/shadcn/alert';
import { AlertTitle } from '@kit/ui/shadcn/alert';
import { Trans } from '@kit/ui/trans';
export async function generateMetadata() {
const { t } = await createI18nServerInstance();
return {
title: t('cart:montonioCallback.title'),
};
}
export default async function MontonioCheckoutCallbackErrorPage({
searchParams,
}: {
searchParams: Promise<{ reasonFailed: string }>;
}) {
const params = await searchParams;
const failedBookingData: string[] = toArray(params.reasonFailed?.split(','));
return (
<div className={'flex h-full flex-1 flex-col'}>
<PageHeader title={<Trans i18nKey="cart:montonioCallback.title" />} />
<PageBody>
<div className={'flex flex-col space-y-4'}>
<Alert variant={'destructive'}>
<AlertTitle>
<Trans i18nKey={'checkout.error.title'} />
</AlertTitle>
<AlertDescription>
{failedBookingData.length ? (
failedBookingData.map((failureReason, index) => (
<p key={index}>
<Trans i18nKey={`checkout.error.${failureReason}`} />
</p>
))
) : (
<Trans i18nKey={'checkout.error.description'} />
)}
</AlertDescription>
</Alert>
<div className={'flex'}>
<Button asChild>
<Link href={'/home'}>
<Trans i18nKey={'checkout.goToDashboard'} />
</Link>
</Button>
</div>
</div>
</PageBody>
</div>
);
}

View File

@@ -0,0 +1,17 @@
import MontonioCallbackClient from './client-component';
export default async function MontonioCallbackPage({
searchParams,
}: {
searchParams: Promise<{
'order-token'?: string;
}>;
}) {
const orderToken = (await searchParams)['order-token'];
if (!orderToken) {
return <MontonioCallbackClient error="Order token is missing" />;
}
return <MontonioCallbackClient orderToken={orderToken} />;
}

View File

@@ -1,14 +1,20 @@
import { createI18nServerInstance } from '@/lib/i18n/i18n.server';
import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
import { retrieveCart } from '@lib/data/cart';
import { listProductTypes } from '@lib/data/products';
import { notFound } from 'next/navigation';
import { retrieveCart } from '~/medusa/lib/data/cart';
import Cart from '../../_components/cart';
import { listCollections } from '@lib/data';
import CartTimer from '../../_components/cart/cart-timer';
import { Trans } from '@kit/ui/trans';
import { withI18n } from '~/lib/i18n/with-i18n';
import { getCartReservations } from '~/lib/services/reservation.service';
import { findProductTypeIdByHandle } from '~/lib/utils';
import Cart from '../../_components/cart';
import CartTimer from '../../_components/cart/cart-timer';
import { loadCurrentUserAccount } from '../../_lib/server/load-user-account';
import { AccountBalanceService } from '@kit/accounts/services/account-balance.service';
import { EnrichedCartItem } from '../../_components/cart/types';
export async function generateMetadata() {
const { t } = await createI18nServerInstance();
@@ -17,31 +23,70 @@ export async function generateMetadata() {
};
}
export default async function CartPage() {
const cart = await retrieveCart().catch((error) => {
console.error(error);
return notFound();
});
async function CartPage() {
const [
cart,
{ productTypes },
{ account },
] = await Promise.all([
retrieveCart(),
listProductTypes(),
loadCurrentUserAccount(),
]);
const { collections } = await listCollections({
limit: "100",
});
if (!account) {
return null;
}
const analysisPackagesCollection = collections.find(({ handle }) => handle === 'analysis-packages');
const analysisPackages = analysisPackagesCollection && cart?.items
? cart.items.filter((item) => item.product?.collection_id === analysisPackagesCollection.id)
const balanceSummary = await new AccountBalanceService().getBalanceSummary(account.id);
const synlabAnalysisTypeId = findProductTypeIdByHandle(
productTypes,
'synlab-analysis',
);
const analysisPackagesTypeId = findProductTypeIdByHandle(
productTypes,
'analysis-packages',
);
const synlabAnalyses =
analysisPackagesTypeId && synlabAnalysisTypeId && cart?.items
? cart.items.filter((item) => {
const productTypeId = item.product?.type_id;
if (!productTypeId) {
return false;
}
return [analysisPackagesTypeId, synlabAnalysisTypeId].includes(
productTypeId,
);
})
: [];
const otherItems = cart?.items?.filter((item) => item.product?.collection_id !== analysisPackagesCollection?.id) ?? [];
const otherItemsSorted = otherItems.sort((a, b) => (a.updated_at ?? "") > (b.updated_at ?? "") ? -1 : 1);
let ttoServiceItems: EnrichedCartItem[] = [];
if (cart?.items?.length) {
ttoServiceItems = await getCartReservations(cart);
}
const otherItemsSorted = ttoServiceItems.sort((a, b) =>
(a.updated_at ?? '') > (b.updated_at ?? '') ? -1 : 1,
);
const item = otherItemsSorted[0];
const isTimerShown =
ttoServiceItems.length > 0 && !!item && !!item.updated_at;
return (
<PageBody>
<PageHeader title={<Trans i18nKey="cart:title" />}>
{item && item.updated_at && <CartTimer cartItem={item} />}
{isTimerShown && <CartTimer cartItem={item} />}
</PageHeader>
<Cart cart={cart} analysisPackages={analysisPackages} otherItems={otherItems} />
<Cart
accountId={account.id}
cart={cart}
synlabAnalyses={synlabAnalyses}
ttoServiceItems={ttoServiceItems}
balanceSummary={balanceSummary}
/>
</PageBody>
);
}
export default withI18n(CartPage);

View File

@@ -1,15 +1,14 @@
import { use } from 'react';
import { cookies } from 'next/headers';
import { z } from 'zod';
import { retrieveCart } from '@lib/data/cart';
import { StoreCart } from '@medusajs/types';
import { UserWorkspaceContextProvider } from '@kit/accounts/components';
import { AppLogo } from '@kit/shared/components/app-logo';
import { pathsConfig } from '@kit/shared/config';
import { Page, PageMobileNavigation, PageNavigation } from '@kit/ui/page';
import { SidebarProvider } from '@kit/ui/shadcn-sidebar';
import { AppLogo } from '~/components/app-logo';
import { personalAccountNavigationConfig } from '~/config/personal-account-navigation.config';
import { withI18n } from '~/lib/i18n/with-i18n';
// home imports
@@ -17,43 +16,13 @@ import { HomeMenuNavigation } from '../_components/home-menu-navigation';
import { HomeMobileNavigation } from '../_components/home-mobile-navigation';
import { HomeSidebar } from '../_components/home-sidebar';
import { loadUserWorkspace } from '../_lib/server/load-user-workspace';
import { retrieveCart } from '@lib/data';
function UserHomeLayout({ children }: React.PropsWithChildren) {
const state = use(getLayoutState());
if (state.style === 'sidebar') {
return <SidebarLayout>{children}</SidebarLayout>;
}
return <HeaderLayout>{children}</HeaderLayout>;
}
export default withI18n(UserHomeLayout);
function SidebarLayout({ children }: React.PropsWithChildren) {
const workspace = use(loadUserWorkspace());
const state = use(getLayoutState());
return (
<UserWorkspaceContextProvider value={workspace}>
<SidebarProvider defaultOpen={state.open}>
<Page style={'sidebar'}>
<PageNavigation>
<HomeSidebar />
</PageNavigation>
<PageMobileNavigation className={'flex items-center justify-between'}>
<MobileNavigation workspace={workspace} />
</PageMobileNavigation>
{children}
</Page>
</SidebarProvider>
</UserWorkspaceContextProvider>
);
}
function HeaderLayout({ children }: React.PropsWithChildren) {
const workspace = use(loadUserWorkspace());
const cart = use(retrieveCart());
@@ -66,7 +35,7 @@ function HeaderLayout({ children }: React.PropsWithChildren) {
</PageNavigation>
<PageMobileNavigation className={'flex items-center justify-between'}>
<MobileNavigation workspace={workspace} />
<MobileNavigation workspace={workspace} cart={cart} />
</PageMobileNavigation>
<SidebarProvider defaultOpen>
@@ -84,38 +53,16 @@ function HeaderLayout({ children }: React.PropsWithChildren) {
function MobileNavigation({
workspace,
cart,
}: {
workspace: Awaited<ReturnType<typeof loadUserWorkspace>>;
cart: StoreCart | null;
}) {
return (
<>
<AppLogo />
<AppLogo href={pathsConfig.app.home} />
<HomeMobileNavigation workspace={workspace} />
<HomeMobileNavigation workspace={workspace} cart={cart} />
</>
);
}
async function getLayoutState() {
const cookieStore = await cookies();
const LayoutStyleSchema = z.enum(['sidebar', 'header', 'custom']);
const layoutStyleCookie = cookieStore.get('layout-style');
const sidebarOpenCookie = cookieStore.get('sidebar:state');
const sidebarOpen = sidebarOpenCookie
? sidebarOpenCookie.value === 'false'
: !personalAccountNavigationConfig.sidebarCollapsed;
const parsedStyle = LayoutStyleSchema.safeParse(layoutStyleCookie?.value);
const style = parsedStyle.success
? parsedStyle.data
: personalAccountNavigationConfig.style;
return {
open: sidebarOpen,
style,
};
}

View File

@@ -1,11 +1,12 @@
import { Scale } from 'lucide-react';
import SelectAnalysisPackages from '@kit/shared/components/select-analysis-packages';
import { Button } from '@kit/ui/button';
import { PageBody } from '@kit/ui/page';
import { Trans } from '@kit/ui/trans';
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';
import { Button } from '@kit/ui/button';
import SelectAnalysisPackages from '@/components/select-analysis-packages';
import { PageBody } from '@kit/ui/page';
import { Trans } from '@kit/ui/trans';
import ComparePackagesModal from '../../_components/compare-packages-modal';
import { loadAnalysisPackages } from '../../_lib/server/load-analysis-packages';
@@ -20,7 +21,8 @@ export const generateMetadata = async () => {
};
async function OrderAnalysisPackagePage() {
const { analysisPackages, countryCode } = await loadAnalysisPackages();
const { analysisPackageElements, analysisPackages, countryCode } =
await loadAnalysisPackages();
return (
<PageBody>
@@ -30,6 +32,7 @@ async function OrderAnalysisPackagePage() {
</h3>
<ComparePackagesModal
analysisPackages={analysisPackages}
analysisPackageElements={analysisPackageElements}
triggerElement={
<Button variant="secondary" className="gap-2">
<Trans i18nKey={'marketing:comparePackages'} />
@@ -38,7 +41,10 @@ async function OrderAnalysisPackagePage() {
}
/>
</div>
<SelectAnalysisPackages analysisPackages={analysisPackages} countryCode={countryCode} />
<SelectAnalysisPackages
analysisPackages={analysisPackages}
countryCode={countryCode}
/>
</PageBody>
);
}

Some files were not shown because too many files have changed in this diff Show More