@@ -2,7 +2,7 @@ import React, { useState, useEffect, useRef } from "react";
22import { PatientInfo } from "./PatientTypes" ;
33import Tooltip from "../../components/Tooltip" ;
44import TypingAnimation from "../../components/Header/components/TypingAnimation.tsx" ;
5- import { FaPencilAlt , FaPrint , FaMinus , FaRegThumbsDown } from "react-icons/fa" ;
5+ import { FaPencilAlt , FaPrint , FaMinus , FaRegThumbsDown , FaAngleDown , FaAngleUp } from "react-icons/fa" ;
66import FeedbackForm from "../Feedback/FeedbackForm" ;
77import Modal from "../../components/Modal/Modal" ;
88import { EllipsisVertical } from "lucide-react" ;
@@ -45,22 +45,17 @@ const truncate = (s = "", n = 220) =>
4545
4646const MedicationItem = ( {
4747 medication,
48-
4948 isClicked,
5049 riskData,
5150 loading,
52- onSourcesClick,
53- onBenefitsRisksClick,
54- activePanel,
51+ onTierClick,
5552} : {
5653 medication : string ;
5754 source : string ;
5855 isClicked : boolean ;
5956 riskData : RiskData | null ;
6057 loading : boolean ;
61- onSourcesClick : ( ) => void ;
62- onBenefitsRisksClick : ( ) => void ;
63- activePanel : "sources" | "benefits-risks" | null ;
58+ onTierClick : ( ) => void ;
6459} ) => {
6560 if ( medication === "None" ) {
6661 return (
@@ -76,7 +71,7 @@ const MedicationItem = ({
7671
7772 return (
7873 < div className = "border-b last:border-b-0" >
79- < li className = "flex items-center justify-between py-4 pl-4 pr-5 text-sm leading-4 hover:bg-indigo-100" >
74+ < li className = "flex items-center justify-between py-4 pl-4 pr-5 text-sm leading-4 hover:bg-indigo-100" onClick = { onTierClick } >
8075 < div className = "flex items-center flex-1 w-0" >
8176 < div className = "flex flex-1 min-w-0 gap-2 ml-4" >
8277 < span className = "font-medium truncate" > { medication } </ span >
@@ -88,108 +83,103 @@ const MedicationItem = ({
8883 </ div >
8984 </ div >
9085 < div className = "flex-shrink-0 ml-4" >
91- < span
92- className = { `font-medium text-indigo-600 hover:text-indigo-500 border border-transparent hover:border-indigo-300 cursor-pointer px-2 py-1 rounded ${
93- isClicked && activePanel === "sources" ? "bg-indigo-100" : ""
94- } `}
95- onClick = { onSourcesClick }
96- >
97- Sources
98- </ span >
99- </ div >
100- < div className = "flex-shrink-0 ml-4" >
101- < span
102- className = { `font-medium text-indigo-600 hover:text-indigo-500 border border-transparent hover:border-indigo-300 cursor-pointer px-2 py-1 rounded ${
103- isClicked && activePanel === "benefits-risks"
104- ? "bg-indigo-100"
105- : ""
106- } `}
107- onClick = { onBenefitsRisksClick }
108- >
109- Benefits and risks
110- </ span >
86+ { isClicked ? < FaAngleUp /> : < FaAngleDown /> }
11187 </ div >
11288 </ li >
11389
114- { isClicked && riskData && activePanel === "benefits-risks" && (
90+ { isClicked && riskData && (
11591 < div className = "px-6 py-4 bg-gray-50" >
116- < div className = "flex" >
92+ < div className = "flex flex-wrap " >
11793 < div className = "w-1/2 pr-4" >
11894 < h4 className = "mb-3 text-sm font-medium text-indigo-600" >
11995 Benefits:
12096 </ h4 >
121- < ul className = "space-y-2" >
122- { riskData . benefits . map ( ( b , i ) => (
123- < li key = { i } className = "text-sm hover:bg-indigo-100" >
124- { b }
125- </ li >
126- ) ) }
127- </ ul >
97+ {
98+ riskData . benefits ?. length ? (
99+ < ul className = "space-y-2" >
100+ { riskData . benefits . map ( ( r , i ) => (
101+ < li key = { i } className = "text-sm hover:bg-indigo-100" >
102+ { r }
103+ </ li >
104+ ) ) }
105+ </ ul >
106+ ) : (
107+ < p className = "mt-3 text-sm text-gray-500" >
108+ No benefits identified.
109+ </ p >
110+ )
111+ }
128112 </ div >
129113 < div className = "w-1/2 pl-4" >
130114 < h4 className = "mb-3 text-sm font-medium text-indigo-600" >
131115 Risks:
132116 </ h4 >
133- < ul className = "space-y-2" >
134- { riskData . risks . map ( ( r , i ) => (
135- < li key = { i } className = "text-sm hover:bg-indigo-100" >
136- { r }
137- </ li >
138- ) ) }
139- </ ul >
117+ {
118+ riskData . risks ?. length ? (
119+ < ul className = "space-y-2" >
120+ { riskData . risks . map ( ( r , i ) => (
121+ < li key = { i } className = "text-sm hover:bg-indigo-100" >
122+ { r }
123+ </ li >
124+ ) ) }
125+ </ ul >
126+ ) : (
127+ < p className = "mt-3 text-sm text-gray-500" >
128+ No risks identified.
129+ </ p >
130+ )
131+ }
140132 </ div >
141- </ div >
142- </ div >
143- ) }
144-
145- { isClicked && riskData && activePanel === "sources" && (
146- < div className = "px-6 py-4 bg-gray-50" >
147- < div className = "flex items-center" >
148- < h4 className = "text-sm font-medium text-indigo-600" > Sources</ h4 >
149- </ div >
150-
151- { riskData . sources ?. length ? (
152- < ul className = "mt-3 divide-y divide-gray-200 rounded-md border border-gray-200 bg-white" >
153- { riskData . sources . map ( ( s , idx ) => (
154- < li key = { idx } className = "px-4 py-3" >
155- < div className = "mt-1 text-sm font-medium text-gray-900 flex items-center justify-between" >
156- < span > { s . title || "Untitled source" } </ span >
157-
158- { s . link_url && (
159- < a
160- href = { s . link_url }
161- target = "_blank"
162- rel = "noopener noreferrer"
163- className = "ml-2 px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded hover:bg-blue-200 transition-colors"
164- >
165- View PDF
166- </ a >
167- ) }
168- </ div >
133+ < div className = "w-full mt-8" >
134+ < h4 className = "mb-3 text-sm font-medium text-indigo-600" >
135+ Sources:
136+ </ h4 >
137+ { riskData . sources ?. length ? (
138+ < ul >
139+ { riskData . sources . map ( ( s , idx ) => (
140+ < li key = { idx } className = "py-3" >
141+ < div className = "mt-1 text-sm font-medium text-gray-900 flex items-center justify-between" >
142+ < span > { s . title || "Untitled source" } </ span >
143+
144+ { s . link_url && (
145+ < a
146+ href = { s . link_url }
147+ target = "_blank"
148+ rel = "noopener noreferrer"
149+ className = "ml-2 px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded hover:bg-blue-200 transition-colors"
150+ >
151+ View PDF
152+ </ a >
153+ ) }
154+ </ div >
169155
170- { s . publication && (
171- < div className = "text-xs text-gray-500" > { s . publication } </ div >
172- ) }
156+ { s . publication && (
157+ < div className = "text-xs text-gray-500" > { s . publication } </ div >
158+ ) }
173159
174- < p className = "mt-2 text-sm text-gray-700" >
175- { truncate ( s . text ) }
176- </ p >
160+ < p className = "mt-2 text-sm text-gray-700" >
161+ { truncate ( s . text ) }
162+ </ p >
177163
178- { s . page && (
179- < div className = "mt-1 text-xs text-gray-400" >
180- Page { s . page }
181- </ div >
182- ) }
183- </ li >
184- ) ) }
185- </ ul >
186- ) : (
187- < p className = "mt-3 text-sm text-gray-500" >
188- No sources available for this medication.
189- </ p >
190- ) }
164+ { s . page && (
165+ < div className = "mt-1 text-xs text-gray-400" >
166+ Page { s . page }
167+ </ div >
168+ ) }
169+ </ li >
170+ ) ) }
171+ </ ul >
172+ ) : (
173+ < p className = "mt-3 text-sm text-gray-500" >
174+ No sources available for this medication.
175+ </ p >
176+ ) }
177+ </ div >
178+ </ div >
191179 </ div >
192180 ) }
181+
182+
193183 </ div >
194184 ) ;
195185} ;
@@ -201,19 +191,15 @@ const MedicationTier = ({
201191 clickedMedication,
202192 riskData,
203193 loading,
204- onSourcesClick,
205- onBenefitsRisksClick,
206- activePanel,
194+ onTierClick,
207195} : {
208196 title : string ;
209197 tier : string ;
210198 medications : MedicationWithSource [ ] ;
211199 clickedMedication : string | null ;
212200 riskData : RiskData | null ;
213201 loading : boolean ;
214- onSourcesClick : ( medication : MedicationWithSource ) => void ;
215- onBenefitsRisksClick : ( medication : MedicationWithSource ) => void ;
216- activePanel : "sources" | "benefits-risks" | null ;
202+ onTierClick : ( medication : MedicationWithSource ) => void ;
217203} ) => (
218204 < >
219205 < dt className = "flex ml-2 text-sm font-medium leading-6 text-gray-900" >
@@ -229,9 +215,7 @@ const MedicationTier = ({
229215 isClicked = { medicationObj . name === clickedMedication }
230216 riskData = { riskData }
231217 loading = { loading }
232- onSourcesClick = { ( ) => onSourcesClick ( medicationObj ) }
233- onBenefitsRisksClick = { ( ) => onBenefitsRisksClick ( medicationObj ) }
234- activePanel = { activePanel }
218+ onTierClick = { ( ) => onTierClick ( medicationObj ) }
235219 />
236220 ) ) }
237221 </ ul >
@@ -254,9 +238,6 @@ const PatientSummary = ({
254238 const [ clickedMedication , setClickedMedication ] = useState < string | null > (
255239 null
256240 ) ;
257- const [ activePanel , setActivePanel ] = useState <
258- "sources" | "benefits-risks" | null
259- > ( null ) ;
260241
261242 const [ isModalOpen , setIsModalOpen ] = useState ( { status : false , id : "" } ) ;
262243
@@ -276,67 +257,28 @@ const PatientSummary = ({
276257 setLoading ( false ) ;
277258 setRiskData ( null ) ;
278259 setClickedMedication ( null ) ;
279- setActivePanel ( null ) ;
280260 }
281261 } , [ isPatientDeleted , setShowSummary ] ) ;
282262
283263 useEffect ( ( ) => {
284264 setRiskData ( null ) ;
285265 setClickedMedication ( null ) ;
286- setActivePanel ( null ) ;
287266 } , [ patientInfo ] ) ;
288267
289268 const handleClickSummary = ( ) => {
290269 setShowSummary ( ! showSummary ) ;
291270 } ;
292- const handleSourcesClick = async ( medicationObj : MedicationWithSource ) => {
293- const { name : medication , source } = medicationObj ;
294-
295- if ( clickedMedication === medication && activePanel === "sources" ) {
296- setClickedMedication ( null ) ;
297- setActivePanel ( null ) ;
298- setRiskData ( null ) ;
299- return ;
300- }
301-
302- setClickedMedication ( medication ) ;
303- setActivePanel ( "sources" ) ;
304- setLoading ( true ) ;
305271
306- try {
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 ) ;
317- setRiskData ( data as RiskData ) ;
318- } catch ( error ) {
319- console . error ( "Error fetching risk data: " , error ) ;
320- setRiskData ( null ) ;
321- } finally {
322- setLoading ( false ) ;
323- }
324- } ;
325-
326- const handleBenefitsRisksClick = async (
327- medicationObj : MedicationWithSource
328- ) => {
272+ const handleTierClick = async ( medicationObj : MedicationWithSource ) => {
329273 const { name : medication , source } = medicationObj ;
330274
331- if ( clickedMedication === medication && activePanel === "benefits-risks" ) {
275+ if ( clickedMedication === medication ) {
332276 setClickedMedication ( null ) ;
333- setActivePanel ( null ) ;
334277 setRiskData ( null ) ;
335278 return ;
336279 }
337280
338281 setClickedMedication ( medication ) ;
339- setActivePanel ( "benefits-risks" ) ;
340282 setLoading ( true ) ;
341283
342284 try {
@@ -347,10 +289,13 @@ const PatientSummary = ({
347289 }
348290
349291 const data = await fetchRiskDataWithSources ( medication , apiSource ) ;
292+ // console.log("Risk data received for", medication, "with source", apiSource, ":", data);
293+ // console.log("Sources array:", data.sources);
294+ // console.log("Sources length:", data.sources?.length);
350295 setRiskData ( data as RiskData ) ;
351296 } catch ( error ) {
352297 console . error ( "Error fetching risk data: " , error ) ;
353- setRiskData ( null ) ;
298+ setRiskData ( { benefits : [ ] , risks : [ ] , source : "" , sources : [ ] } ) ;
354299 } finally {
355300 setLoading ( false ) ;
356301 }
@@ -428,9 +373,7 @@ const PatientSummary = ({
428373 clickedMedication = { clickedMedication }
429374 riskData = { riskData }
430375 loading = { loading }
431- onSourcesClick = { handleSourcesClick }
432- onBenefitsRisksClick = { handleBenefitsRisksClick }
433- activePanel = { activePanel }
376+ onTierClick = { handleTierClick }
434377 />
435378 < div className = "mt-6" >
436379 < MedicationTier
@@ -440,9 +383,7 @@ const PatientSummary = ({
440383 clickedMedication = { clickedMedication }
441384 riskData = { riskData }
442385 loading = { loading }
443- onSourcesClick = { handleSourcesClick }
444- onBenefitsRisksClick = { handleBenefitsRisksClick }
445- activePanel = { activePanel }
386+ onTierClick = { handleTierClick }
446387 />
447388 </ div >
448389 < div className = "mt-6" >
@@ -453,9 +394,7 @@ const PatientSummary = ({
453394 clickedMedication = { clickedMedication }
454395 riskData = { riskData }
455396 loading = { loading }
456- onSourcesClick = { handleSourcesClick }
457- onBenefitsRisksClick = { handleBenefitsRisksClick }
458- activePanel = { activePanel }
397+ onTierClick = { handleTierClick }
459398 />
460399 </ div >
461400 </ >
0 commit comments