diff --git a/frontend/src/components/Header/Chat.tsx b/frontend/src/components/Header/Chat.tsx index c30de217..c70f3519 100644 --- a/frontend/src/components/Header/Chat.tsx +++ b/frontend/src/components/Header/Chat.tsx @@ -7,7 +7,7 @@ import ErrorMessage from "../ErrorMessage"; import ConversationList from "./ConversationList"; import { extractContentFromDOM } from "../../services/domExtraction"; import axios from "axios"; -import { FaPlus, FaMinus, FaTimes, FaComment, FaComments, FaPills, FaLightbulb, FaArrowCircleDown } from "react-icons/fa"; +import { FaPlus, FaMinus, FaTimes, FaComment, FaComments, FaPills, FaLightbulb, FaArrowCircleDown, FaExpandAlt, FaExpandArrowsAlt } from "react-icons/fa"; import { fetchConversations, continueConversation, @@ -72,13 +72,6 @@ const Chat: React.FC = ({ showChat, setShowChat }) => { setPageContent(extractedContent); }, []); - // useEffect(() => { - // if (chatContainerRef.current) { - // const chatContainer = chatContainerRef.current; - // chatContainer.scrollTop = chatContainer.scrollHeight; - // } - // }, [chatLog]); - const [bottom, setBottom] = useState(false); const handleScroll = (event: React.UIEvent) => { @@ -87,6 +80,8 @@ const Chat: React.FC = ({ showChat, setShowChat }) => { setBottom(bottom) }; + const [expandChat, setExpandChat] = useState(false); + useEffect(() => { if (chatContainerRef.current && activeConversation) { const chatContainer = chatContainerRef.current; @@ -204,52 +199,6 @@ const Chat: React.FC = ({ showChat, setShowChat }) => { } }; - // const systemMessage = { - // role: "system", - // content: "You are a bot please keep conversation going.", - // }; - // const sendMessage = (message: ChatLogItem[]) => { - // const baseUrl = import.meta.env.VITE_API_BASE_URL; - // const url = `${baseUrl}/chatgpt/chat`; - - // const apiMessages = message.map((messageObject) => { - // let role = ""; - // if (messageObject.is_user) { - // role = "user"; - // } else { - // role = "assistant"; - // } - // return { role: role, content: messageObject.content }; - // }); - - // systemMessage.content += `If applicable, please use the following content to ask questions. If not applicable, - // please answer to the best of your ability: ${pageContent}`; - - // const apiRequestBody = { - // prompt: [systemMessage, ...apiMessages], - // }; - - // setIsLoading(true); - - // axios - // .post(url, apiRequestBody) - // .then((response) => { - // console.log(response); - // setChatLog((prevChatLog) => [ - // ...prevChatLog, - // { - // is_user: false, - // content: response.data.message.choices[0].message.content, - // }, - // ]); - // setIsLoading(false); - // }) - // .catch((error) => { - // setIsLoading(false); - // console.log(error); - // }); - // }; - const handleSelectConversation = (id: Conversation["id"]) => { const selectedConversation = conversations.find( (conversation: any) => conversation.id === id, @@ -267,13 +216,25 @@ const Chat: React.FC = ({ showChat, setShowChat }) => { }; useEffect(() => { - if (showChat) loadConversations(); + if (showChat) { + loadConversations(); + + const resizeObserver = new ResizeObserver(() => { + const target = chatContainerRef.current; + if (target) { + const bottom = target.scrollHeight - Math.round(target.scrollTop) === target.clientHeight; + setBottom(bottom); + } + }); + resizeObserver.observe(chatContainerRef.current); + return () => resizeObserver.disconnect(); // clean up + } }, [showChat]); return ( <> {showChat ? ( -
+
= ({ showChat, setShowChat }) => {
- +
+ + +
+ +
- - ))} - - + ))} + + + + + + ); }; diff --git a/frontend/src/pages/PatientManager/PatientSummary.tsx b/frontend/src/pages/PatientManager/PatientSummary.tsx index d7ceb878..5a32a3a9 100644 --- a/frontend/src/pages/PatientManager/PatientSummary.tsx +++ b/frontend/src/pages/PatientManager/PatientSummary.tsx @@ -3,7 +3,9 @@ import axios from "axios"; import { PatientInfo } from "./PatientTypes"; import Tooltip from "../../components/Tooltip"; import TypingAnimation from "../../components/Header/components/TypingAnimation.tsx"; -import { FaPencilAlt, FaPrint, FaMinus } from "react-icons/fa"; +import { FaPencilAlt, FaPrint, FaMinus, FaBug } from "react-icons/fa"; +import FeedbackForm from "../Feedback/FeedbackForm" +import Modal from "../../components/Modal/Modal"; interface PatientSummaryProps { showSummary: boolean; @@ -152,6 +154,18 @@ const PatientSummary = ({ null ); + const [isModalOpen, setIsModalOpen] = useState({status: false, id: ''}); + + const handleOpenModal = (id: string, event: React.MouseEvent) => { + event.stopPropagation(); + setIsModalOpen({status: true, id: id}); + }; + + const handleCloseModal = (event: React.MouseEvent) => { + event.stopPropagation(); + setIsModalOpen({status: false, id: ''}); + }; + useEffect(() => { if (isPatientDeleted) { setShowSummary(true); @@ -257,134 +271,148 @@ const PatientSummary = ({

{patientInfo.ID && ( -
- {!showSummary && ( -
-
-

- Patient Summary -

-
- - - -
-
-
- )} - {showSummary && ( -
-
+ <> +
+ {!showSummary && ( +
-

- Summary +

+ Patient Summary

- +
+ + + +
-
-

- {" "} - {patientInfo.ID} -

-

- Patient details and application -

-
-
-
-
-
-
- Current State: + )} + {showSummary && ( +
+
+
+

+ Summary +

+ +
+
+
+

+ {" "} + {patientInfo.ID} +

+

+ Patient details and application +

+
+
+
+
+
+
+ Current State: +
+
+ {patientInfo.Diagnosis} +
+
+
+
+
+ Risk Assessment:
-
- {patientInfo.Diagnosis} +
+
    + {/* Risk Assessment Items */} + {patientInfo.Psychotic === "Yes" && ( +
  • + Currently psychotic +
  • + )} + {patientInfo.Suicide === "Yes" && ( +
  • + + Patient has a history of suicide attempts + + info + + +
  • + )} + {/* Add other risk assessment items similarly */} +
-
-
-
- Risk Assessment: -
-
-
    - {/* Risk Assessment Items */} - {patientInfo.Psychotic === "Yes" && ( -
  • - Currently psychotic -
  • - )} - {patientInfo.Suicide === "Yes" && ( -
  • - - Patient has a history of suicide attempts - - info - - -
  • - )} - {/* Add other risk assessment items similarly */} -
-
-
-
-
-
- -
- {patientInfo.PriorMedications} -
+
+
+
+ +
+ {patientInfo.PriorMedications} +
+
-
- {renderMedicationsSection()} -
+ {renderMedicationsSection()} + +
-
- )} -
+ )} +
+ + + + )}
diff --git a/server/api/views/conversations/views.py b/server/api/views/conversations/views.py index ffe60e65..27c30df7 100644 --- a/server/api/views/conversations/views.py +++ b/server/api/views/conversations/views.py @@ -142,12 +142,12 @@ def update_title(self, request, pk=None): def get_chatgpt_response(self, conversation, user_message, page_context=None): messages = [{ - "role": "system", + "role": "system", "content": "You are a knowledgeable assistant. Balancer is a powerful tool for selecting bipolar medication for patients. We are open-source and available for free use. Your primary role is to assist licensed clinical professionals with information related to Balancer and bipolar medication selection. If applicable, use the supplied tools to assist the professional." }] if page_context: - context_message = f"If applicable, please use the following content to ask questions. If not applicable, please answer to the best of your ability: {page_context}" + context_message = f"If applicable, please use the following content to ask questions and support your response with a numbered list of 3 reputable URL sources from peer-reviewed journals. The URL sources must start with 'Sources:', include a line break, follow the APA Citation Style, and at the end a line break followed by a link to the Publication URL. If not applicable, please answer to the best of your ability: {page_context}" messages.append({"role": "system", "content": context_message}) for msg in conversation.messages.all(): @@ -178,23 +178,23 @@ def get_chatgpt_response(self, conversation, user_message, page_context=None): "content": response_message.get('content', ''), "tool_calls": tool_calls }) - + # Process each tool call for tool_call in tool_calls: tool_call_id = tool_call['id'] tool_function_name = tool_call['function']['name'] tool_arguments = json.loads(tool_call['function'].get('arguments', '{}')) - + # Execute the tool results = execute_tool(tool_function_name, tool_arguments) - + # Add the tool response message messages.append({ "role": "tool", "content": str(results), # Convert results to string "tool_call_id": tool_call_id }) - + # Final API call with tool results final_response = openai.ChatCompletion.create( model="gpt-3.5-turbo",