Skip to content

Commit 8d9439a

Browse files
committed
save changes to insert sources in patent summary
1 parent 15d2ee8 commit 8d9439a

File tree

10 files changed

+267
-75
lines changed

10 files changed

+267
-75
lines changed

docker-compose.yml

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
services:
22
db:
3-
build:
4-
context: ./db
5-
dockerfile: Dockerfile
6-
volumes:
7-
- postgres_data:/var/lib/postgresql/data/
8-
environment:
9-
- POSTGRES_USER=balancer
10-
- POSTGRES_PASSWORD=balancer
11-
- POSTGRES_DB=balancer_dev
12-
ports:
13-
- "5433:5432"
14-
networks:
15-
app_net:
16-
ipv4_address: 192.168.0.2
17-
pgadmin:
18-
container_name: pgadmin4
19-
image: dpage/pgadmin4
3+
build:
4+
context: ./db
5+
dockerfile: Dockerfile
6+
volumes:
7+
- postgres_data:/var/lib/postgresql/data/
208
environment:
21-
PGADMIN_DEFAULT_EMAIL: [email protected]
22-
PGADMIN_DEFAULT_PASSWORD: balancer
23-
# PGADMIN_LISTEN_PORT = 80
24-
# volumes:
25-
# - ./pgadmin-data:/var/lib/pgadmin
26-
# # PGADMIN_LISTEN_PORT = 80
9+
- POSTGRES_USER=balancer
10+
- POSTGRES_PASSWORD=balancer
11+
- POSTGRES_DB=balancer_dev
2712
ports:
28-
- "5050:80"
13+
- "5433:5432"
2914
networks:
3015
app_net:
31-
ipv4_address: 192.168.0.4
16+
ipv4_address: 192.168.0.2
17+
# pgadmin:
18+
# container_name: pgadmin4
19+
# image: dpage/pgadmin4
20+
# environment:
21+
# PGADMIN_DEFAULT_EMAIL: [email protected]
22+
# PGADMIN_DEFAULT_PASSWORD: balancer
23+
# # PGADMIN_LISTEN_PORT = 80
24+
# # volumes:
25+
# # - ./pgadmin-data:/var/lib/pgadmin
26+
# # # PGADMIN_LISTEN_PORT = 80
27+
# ports:
28+
# - "5050:80"
29+
# networks:
30+
# app_net:
31+
# ipv4_address: 192.168.0.4
3232
backend:
3333
image: balancer-backend
3434
build: ./server
@@ -52,13 +52,13 @@ services:
5252
args:
5353
- IMAGE_NAME=balancer-frontend
5454
ports:
55-
- "3000:3000"
55+
- "3000:3000"
5656
environment:
57-
- CHOKIDAR_USEPOLLING=true
58-
# - VITE_API_BASE_URL=https://balancertestsite.com/
57+
- CHOKIDAR_USEPOLLING=true
58+
# - VITE_API_BASE_URL=https://balancertestsite.com/
5959
volumes:
60-
- "./frontend:/usr/src/app:delegated"
61-
- "/usr/src/app/node_modules/"
60+
- "./frontend:/usr/src/app:delegated"
61+
- "/usr/src/app/node_modules/"
6262
depends_on:
6363
- backend
6464
networks:
@@ -72,4 +72,4 @@ networks:
7272
driver: default
7373
config:
7474
- subnet: "192.168.0.0/24"
75-
gateway: 192.168.0.1
75+
gateway: 192.168.0.1

frontend/src/api/apiClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const handleRuleExtraction = async (guid: string) => {
6767
}
6868
};
6969

70-
const fetchRiskDataWithSources = async (medication: string, source: "include" | "diagnosis" = "include") => {
70+
const fetchRiskDataWithSources = async (medication: string, source: "include" | "diagnosis" | "diagnosis_depressed" = "include") => {
7171
try {
7272
const response = await api.post(`/v1/api/riskWithSources`, {
7373
drug: medication,

frontend/src/pages/PatientManager/PatientSummary.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,16 @@ const PatientSummary = ({
304304
setLoading(true);
305305

306306
try {
307-
const data = await fetchRiskDataWithSources(medication, source);
307+
// Map source based on patient's diagnosis
308+
let apiSource: "include" | "diagnosis" | "diagnosis_depressed" = source;
309+
if (source === "diagnosis" && patientInfo.Diagnosis === "Depressed") {
310+
apiSource = "diagnosis_depressed";
311+
}
312+
313+
const data = await fetchRiskDataWithSources(medication, apiSource);
314+
console.log("Risk data received for", medication, "with source", apiSource, ":", data);
315+
console.log("Sources array:", data.sources);
316+
console.log("Sources length:", data.sources?.length);
308317
setRiskData(data as RiskData);
309318
} catch (error) {
310319
console.error("Error fetching risk data: ", error);
@@ -331,7 +340,13 @@ const PatientSummary = ({
331340
setLoading(true);
332341

333342
try {
334-
const data = await fetchRiskDataWithSources(medication, source);
343+
// Map source based on patient's diagnosis
344+
let apiSource: "include" | "diagnosis" | "diagnosis_depressed" = source;
345+
if (source === "diagnosis" && patientInfo.Diagnosis === "Depressed") {
346+
apiSource = "diagnosis_depressed";
347+
}
348+
349+
const data = await fetchRiskDataWithSources(medication, apiSource);
335350
setRiskData(data as RiskData);
336351
} catch (error) {
337352
console.error("Error fetching risk data: ", error);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.3 on 2025-10-25 16:37
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0013_medrule_medications'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='medrule',
15+
name='rule_type',
16+
field=models.CharField(choices=[('INCLUDE', 'Include'), ('EXCLUDE', 'Exclude')], max_length=500),
17+
),
18+
]

server/api/models/model_medRule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MedRule(models.Model):
88
('INCLUDE', 'Include'),
99
('EXCLUDE', 'Exclude'),
1010
]
11-
rule_type = models.CharField(max_length=7, choices=RULE_TYPE_CHOICES)
11+
rule_type = models.CharField(max_length=500, choices=RULE_TYPE_CHOICES)
1212
history_type = models.CharField(max_length=255)
1313
reason = models.TextField(blank=True, null=True)
1414
label = models.CharField(max_length=255, blank=True, null=True)

server/api/views/embeddings/embeddingsView.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def stream_generator():
9090
return Response({
9191
"question": message,
9292
"llm_response": answer,
93-
"embeddings_info": embeddings_results,
93+
"embeddings_info": listOfEmbeddings,
9494
"sent_to_llm": prompt_text,
9595
}, status=status.HTTP_200_OK)
9696

server/api/views/listMeds/views.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class GetMedication(APIView):
2424
def post(self, request):
2525
data = request.data
2626
state_query = data.get('state', '')
27+
print(state_query)
2728
include_result = []
2829
exclude_result = []
2930
for condition in MEDS_INCLUDE:
@@ -43,7 +44,8 @@ def post(self, request):
4344
meds = {'first': [], 'second': [], 'third': []}
4445

4546
priorMeds = data.get('priorMedications', "").split(',')
46-
exclude_result.extend([med.strip() for med in priorMeds if med.strip()])
47+
exclude_result.extend([med.strip()
48+
for med in priorMeds if med.strip()])
4749
included_set = set(include_result)
4850
excluded_set = set(exclude_result)
4951

@@ -62,7 +64,7 @@ def post(self, request):
6264
continue
6365
meds[tier_label].append({
6466
'name': med_name,
65-
'source': 'diagnosis'
67+
'source': 'diagnosis_' + state_query.lower()
6668
})
6769

6870
return Response(meds)
@@ -97,15 +99,15 @@ def post(self, request):
9799
name = data.get('name', '').strip()
98100
benefits = data.get('benefits', '').strip()
99101
risks = data.get('risks', '').strip()
100-
102+
101103
# Validate required fields
102104
if not name:
103105
return Response({'error': 'Medication name is required'}, status=status.HTTP_400_BAD_REQUEST)
104106
if not benefits:
105107
return Response({'error': 'Medication benefits are required'}, status=status.HTTP_400_BAD_REQUEST)
106108
if not risks:
107109
return Response({'error': 'Medication risks are required'}, status=status.HTTP_400_BAD_REQUEST)
108-
110+
109111
# Check if medication already exists
110112
if Medication.objects.filter(name=name).exists():
111113
return Response({'error': f'Medication "{name}" already exists'}, status=status.HTTP_400_BAD_REQUEST)
@@ -125,11 +127,11 @@ class DeleteMedication(APIView):
125127
def delete(self, request):
126128
data = request.data
127129
name = data.get('name', '').strip()
128-
130+
129131
# Validate required fields
130132
if not name:
131133
return Response({'error': 'Medication name is required'}, status=status.HTTP_400_BAD_REQUEST)
132-
134+
133135
# Check if medication exists and delete
134136
try:
135137
medication = Medication.objects.get(name=name)

0 commit comments

Comments
 (0)