File size: 10,088 Bytes
2e34456
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import gradio as gr
from service import GPT_Service, Stage


title_html = """
<div style="display: flex; align-items: center; width=100%; background-color:#FFC90E;">
    <img src='https://i.ibb.co/gPFskvg/LOGO-1.png' style='height: 90px; width:90px; margin-left: 20px;'>
    <span style="margin-left: 20px;font-size:30px">
        <span>Patient Assessment Documentation</span>
    </span>
</div>

"""

css = """
#subButton, #rephraseBtn {
    background-color: #EA580C !important;
    background: #EA580C !important;
    border: none !important; /* Remove the border */
    transition: background-color 0.3s ease; /* Add transition for smoother hover effect */
}

#subButton:hover, #rephraseBtn:hover {
    background-color: #FFC90E !important; /* Change to a lighter background color on hover */
}

"""

def split_based_on_commas(string):
    return [substring.strip() for substring in string.split(",")]

def process_text(keywords, stage, medical_history):
    if(keywords.strip()!='' and stage!=None and len(stage)!=0 and  len(split_based_on_commas(keywords))<=5):
        try:
            gptService=GPT_Service()
            if stage == Stage.INITIAL_ASSESSMENT.value:
                return gptService.getInitialAssessment(keywords,medical_history)
            elif stage == Stage.FOLLOWUP_ASSESSMENT.value:
                return gptService.getFollowUpAssessment(keywords,medical_history)
            elif stage == Stage.EVALUATION.value:
                return gptService.getEvaluation(keywords,medical_history)
            elif stage == Stage.DETAILED_EVALUATION.value:
                return gptService.getDetailedEvaluation(keywords,medical_history)
            elif stage == Stage.PROGRESS_NOTE.value:
                return gptService.getProgressNote(keywords,medical_history)
            elif stage == Stage.DISCHARGE_SUMMARY.value:
                return gptService.getDischargeSummary(keywords,medical_history)
            elif stage == Stage.SHORT_TERM_GOALS.value:
                return gptService.getShortTermGoals(keywords,medical_history)
            elif stage == Stage.LONG_TERM_GOALS.value:
                return gptService.getLongTermGoals(keywords,medical_history)
            elif stage == Stage.RECOMMENDATION.value:
                return gptService.getRecommendation(keywords,medical_history)
            else:
                print("Unknown stage")
                raise gr.Error('Unknown stage encountered')
        except:
            print("GPT error encounters")
            raise gr.Error('Something went wrong please try again')
    else:
        print("Unknown stage parameters")
        raise gr.Error('Provide appropriate parameters and try again')


def select_handler(prevResponse, newResponse):
    if newResponse.strip() not in prevResponse:
        return f"{prevResponse + (' ' if prevResponse.strip() != '' else '')} {newResponse}"
    else:
        return prevResponse


def getRephrasedSentences(sentences):
      if sentences.strip() == '':
          raise gr.Error('Provide appropriate parameters and try again')
      else:
           try:
                print(sentences)
                gptService=GPT_Service()
                return gptService.getRephrasedSentences(sentences)
           except:
                raise gr.Error('Something went wrong please try again')
          

with gr.Blocks(css=css) as demo:
    gr.HTML(title_html)
    gr.HTML("<h2>Patient Assessment Input</h2>")
    with gr.Row():
        keywords = gr.Textbox(label="Assessment Keywords", placeholder="Write comma separated sample keywords (max=5)")
        medicalHistory = gr.Textbox(label="Medical History", placeholder="Enter patient history")
        stage_choices = [Stage.INITIAL_ASSESSMENT.value,Stage.SHORT_TERM_GOALS.value,Stage.LONG_TERM_GOALS.value, Stage.RECOMMENDATION.value]
        stage = gr.Dropdown(choices=stage_choices, label="Assessment Stage")
    
    with gr.Row():
        clearInputFields = gr.ClearButton(value="Clear Inputs",components=[keywords,medicalHistory,stage])
        responseButton = gr.Button("Submit",elem_id="subButton")

    gr.HTML("<h2 style=\"margin-top:10\">Suggested Assessment Documentation</h2>")
    with gr.Column():
        label1 = gr.Markdown(value="Keyword 1",show_label=False)
        with gr.Row() as firstKeywordResponses:
            firstKeywordResponseUtterance1 = gr.Textbox(label="Variant 1",interactive=False, show_copy_button=True)
            firstKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
            firstKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)

        label2 = gr.Markdown(value="Keyword 2",show_label=False)
        with gr.Row() as secondKeywordResponses:
            secondKeywordResponseUtterance1 = gr.Textbox(label="Variant 1", interactive=False, show_copy_button=True)
            secondKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
            secondKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)

        label3 = gr.Markdown(value="Keyword 3",show_label=False)
        with gr.Row() as thirdKeywordResponses:
            thirdKeywordResponseUtterance1 = gr.Textbox(label="Variant 1", interactive=False, show_copy_button=True)
            thirdKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
            thirdKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)

        label4 = gr.Markdown(value="Keyword 4",show_label=False)
        with gr.Row() as fourthKeywordResponses:
            fourthKeywordResponseUtterance1 = gr.Textbox(label="Variant 1", interactive=False, show_copy_button=True)
            fourthKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
            fourthKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)

        label5 = gr.Markdown(value="Keyword 5",show_label=False)
        with gr.Row() as fifthKeywordResponses:
            fifthKeywordResponseUtterance1 = gr.Textbox(label="Variant 1", interactive=False, show_copy_button=True)
            fifthKeywordResponseUtterance2 = gr.Textbox(label="Variant 2", interactive=False, show_copy_button=True)
            fifthKeywordResponseUtterance3 = gr.Textbox(label="Variant 3", interactive=False, show_copy_button=True)

    gr.HTML("<h2>Documentation Generator</h2>")
    with gr.Row():
        # clearSelectedSentences = gr.ClearButton(value="Clear Inputs",components=[selectedSentence])
        with gr.Column():
            selectedSentence=gr.Textbox(label="Selected Sentences", show_copy_button=True,lines=5)
            rephraseButton = gr.Button("Generate Documentation",elem_id="rephraseBtn",)

        rephrasedSentence=gr.Textbox(label="Patient Visit Documentation", interactive=False, show_copy_button=True,lines=7)


    # First response event listeners
    firstKeywordResponseUtterance1.select(select_handler,[selectedSentence,firstKeywordResponseUtterance1],selectedSentence)
    firstKeywordResponseUtterance2.select(select_handler,[selectedSentence,firstKeywordResponseUtterance2],selectedSentence)
    firstKeywordResponseUtterance3.select(select_handler,[selectedSentence,firstKeywordResponseUtterance3],selectedSentence)

    # Second response event listeners
    secondKeywordResponseUtterance1.select(select_handler,[selectedSentence,secondKeywordResponseUtterance1],selectedSentence)
    secondKeywordResponseUtterance2.select(select_handler,[selectedSentence,secondKeywordResponseUtterance2],selectedSentence)
    secondKeywordResponseUtterance3.select(select_handler,[selectedSentence,secondKeywordResponseUtterance3],selectedSentence)

    # Third response event listeners
    thirdKeywordResponseUtterance1.select(select_handler,[selectedSentence,thirdKeywordResponseUtterance1],selectedSentence)
    thirdKeywordResponseUtterance2.select(select_handler,[selectedSentence,thirdKeywordResponseUtterance2],selectedSentence)
    thirdKeywordResponseUtterance3.select(select_handler,[selectedSentence,thirdKeywordResponseUtterance3],selectedSentence)

    # Fourth response event listeners
    fourthKeywordResponseUtterance1.select(select_handler,[selectedSentence,fourthKeywordResponseUtterance1],selectedSentence)
    fourthKeywordResponseUtterance2.select(select_handler,[selectedSentence,fourthKeywordResponseUtterance2],selectedSentence)
    fourthKeywordResponseUtterance3.select(select_handler,[selectedSentence,fourthKeywordResponseUtterance3],selectedSentence)

    # Fifth response event listeners
    fifthKeywordResponseUtterance1.select(select_handler,[selectedSentence,fifthKeywordResponseUtterance1],selectedSentence)
    fifthKeywordResponseUtterance2.select(select_handler,[selectedSentence,fifthKeywordResponseUtterance2],selectedSentence)
    fifthKeywordResponseUtterance3.select(select_handler,[selectedSentence,fifthKeywordResponseUtterance3],selectedSentence)

    responseButton.click(process_text,[keywords,stage,medicalHistory],[label1,firstKeywordResponseUtterance1,firstKeywordResponseUtterance2,firstKeywordResponseUtterance3,
                                                                    label2,secondKeywordResponseUtterance1,secondKeywordResponseUtterance2,secondKeywordResponseUtterance3,
                                                                    label3,thirdKeywordResponseUtterance1,thirdKeywordResponseUtterance2,thirdKeywordResponseUtterance3,
                                                                    label4,fourthKeywordResponseUtterance1,fourthKeywordResponseUtterance2,fourthKeywordResponseUtterance3,
                                                                    label5,fifthKeywordResponseUtterance1,fifthKeywordResponseUtterance2,fifthKeywordResponseUtterance3])
    rephraseButton.click(getRephrasedSentences,selectedSentence,rephrasedSentence)
    
        
demo.launch()