Update app.py
Browse files
app.py
CHANGED
@@ -40,112 +40,116 @@ class PDFTextExtractor:
|
|
40 |
Extract the Patient Admission Form (KMHIPF002V3) from this image and format it in clean markdown.
|
41 |
Follow this exact markdown structure:
|
42 |
|
43 |
-
# PATIENT ADMISSION FORM
|
44 |
-
## DR.KAMAKSHI MEMORIAL HOSPITAL, PALLIKARANAI, CHENNAI.
|
45 |
-
|
46 |
-
### PATIENT PROFILE
|
47 |
-
*Please paste the sticker within the box*
|
48 |
-
|
49 |
-
* UHID: ______
|
50 |
-
* Patient Name: ______
|
51 |
-
* Age/Gender: ______
|
52 |
-
* Doctor Name: ______
|
53 |
-
|
54 |
-
### BASIC INFORMATION
|
55 |
-
* Date & Time of Admission: [DD/MM/YYYY]
|
56 |
-
* Date of Birth: [DD/MM/YYYY]
|
57 |
-
|
58 |
-
### IDENTIFICATION
|
59 |
-
**ID Proof Already Registered**: □ Yes □ No
|
60 |
-
|
61 |
-
**Type of ID**:
|
62 |
-
* □ Aadhar
|
63 |
-
* □ Passport
|
64 |
-
* □ Voter ID
|
65 |
-
* □ Driving License
|
66 |
-
* □ Others
|
67 |
-
|
68 |
-
ID No.: ________________
|
69 |
-
Contact No.: ________________
|
70 |
-
|
71 |
-
### MEDICAL DETAILS
|
72 |
-
* Provisional Diagnosis:
|
73 |
-
* Reason for Admission:
|
74 |
-
* Plan of Care:
|
75 |
-
* Expected Outcome*:
|
76 |
-
|
77 |
-
### CONSULTANT DETAILS
|
78 |
-
* Primary Consultant Name:
|
79 |
-
* Speciality:
|
80 |
-
|
81 |
-
### PATIENT REFERENCE INFORMATION
|
82 |
-
*(To be filled by Front Office)*
|
83 |
-
|
84 |
-
**Reference Via**:
|
85 |
-
* □ Doctor
|
86 |
-
* □ Hospital
|
87 |
-
* □ Ambulance
|
88 |
-
* □ DRKMH Employee
|
89 |
-
* □ Self / Walk In
|
90 |
-
|
91 |
-
**Referrer Details**:
|
92 |
-
* Name: ________________
|
93 |
-
* Contact No.: ________________
|
94 |
-
|
95 |
-
### TYPE OF ADMISSION
|
96 |
-
* □ Emergency
|
97 |
-
* □ Elective
|
98 |
-
* □ MLC
|
99 |
-
* □ Surgery
|
100 |
-
* □ Medical
|
101 |
-
* □ Others: ________________
|
102 |
-
|
103 |
-
### TREATMENT TYPE
|
104 |
-
* □ In Patient
|
105 |
-
* □ Day Care
|
106 |
-
* Transfer To: ________________
|
107 |
-
|
108 |
-
### CONTACT DETAILS
|
109 |
-
**Person to Contact (Next of Kin)**:
|
110 |
-
* Name: ________________
|
111 |
-
* Relationship with Patient: ________________
|
112 |
-
* Address: ________________
|
113 |
-
* Pincode: ________________
|
114 |
-
* Mobile: ________________
|
115 |
-
* Email: ________________
|
116 |
-
|
117 |
-
### OFFICIAL USE
|
118 |
-
* Front Office Executive Name:
|
119 |
-
* Front Office Executive Signature:
|
120 |
-
* Advance Amount Paid:
|
121 |
-
* ICD-10 Code (For Medical Records Section):
|
122 |
-
|
123 |
-
*\\* Subject to change during the course of diseases*
|
124 |
-
|
125 |
-
---
|
126 |
-
*Form No: KMHIPF002V3*
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
)
|
147 |
-
|
148 |
-
return response.choices[0].message.content
|
|
|
|
|
|
|
|
|
149 |
|
150 |
def extract_text(pdf_file):
|
151 |
if OPENAI_API_KEY is None:
|
|
|
40 |
Extract the Patient Admission Form (KMHIPF002V3) from this image and format it in clean markdown.
|
41 |
Follow this exact markdown structure:
|
42 |
|
43 |
+
# PATIENT ADMISSION FORM
|
44 |
+
## DR.KAMAKSHI MEMORIAL HOSPITAL, PALLIKARANAI, CHENNAI.
|
45 |
+
|
46 |
+
### PATIENT PROFILE
|
47 |
+
*Please paste the sticker within the box*
|
48 |
+
|
49 |
+
* UHID: ______
|
50 |
+
* Patient Name: ______
|
51 |
+
* Age/Gender: ______
|
52 |
+
* Doctor Name: ______
|
53 |
+
|
54 |
+
### BASIC INFORMATION
|
55 |
+
* Date & Time of Admission: [DD/MM/YYYY]
|
56 |
+
* Date of Birth: [DD/MM/YYYY]
|
57 |
+
|
58 |
+
### IDENTIFICATION
|
59 |
+
**ID Proof Already Registered**: □ Yes □ No
|
60 |
+
|
61 |
+
**Type of ID**:
|
62 |
+
* □ Aadhar
|
63 |
+
* □ Passport
|
64 |
+
* □ Voter ID
|
65 |
+
* □ Driving License
|
66 |
+
* □ Others
|
67 |
+
|
68 |
+
ID No.: ________________
|
69 |
+
Contact No.: ________________
|
70 |
+
|
71 |
+
### MEDICAL DETAILS
|
72 |
+
* Provisional Diagnosis:
|
73 |
+
* Reason for Admission:
|
74 |
+
* Plan of Care:
|
75 |
+
* Expected Outcome*:
|
76 |
+
|
77 |
+
### CONSULTANT DETAILS
|
78 |
+
* Primary Consultant Name:
|
79 |
+
* Speciality:
|
80 |
+
|
81 |
+
### PATIENT REFERENCE INFORMATION
|
82 |
+
*(To be filled by Front Office)*
|
83 |
+
|
84 |
+
**Reference Via**:
|
85 |
+
* □ Doctor
|
86 |
+
* □ Hospital
|
87 |
+
* □ Ambulance
|
88 |
+
* □ DRKMH Employee
|
89 |
+
* □ Self / Walk In
|
90 |
+
|
91 |
+
**Referrer Details**:
|
92 |
+
* Name: ________________
|
93 |
+
* Contact No.: ________________
|
94 |
+
|
95 |
+
### TYPE OF ADMISSION
|
96 |
+
* □ Emergency
|
97 |
+
* □ Elective
|
98 |
+
* □ MLC
|
99 |
+
* □ Surgery
|
100 |
+
* □ Medical
|
101 |
+
* □ Others: ________________
|
102 |
+
|
103 |
+
### TREATMENT TYPE
|
104 |
+
* □ In Patient
|
105 |
+
* □ Day Care
|
106 |
+
* Transfer To: ________________
|
107 |
+
|
108 |
+
### CONTACT DETAILS
|
109 |
+
**Person to Contact (Next of Kin)**:
|
110 |
+
* Name: ________________
|
111 |
+
* Relationship with Patient: ________________
|
112 |
+
* Address: ________________
|
113 |
+
* Pincode: ________________
|
114 |
+
* Mobile: ________________
|
115 |
+
* Email: ________________
|
116 |
+
|
117 |
+
### OFFICIAL USE
|
118 |
+
* Front Office Executive Name:
|
119 |
+
* Front Office Executive Signature:
|
120 |
+
* Advance Amount Paid:
|
121 |
+
* ICD-10 Code (For Medical Records Section):
|
122 |
+
|
123 |
+
*\\* Subject to change during the course of diseases*
|
124 |
+
|
125 |
+
---
|
126 |
+
*Form No: KMHIPF002V3*
|
127 |
+
"""
|
128 |
+
},
|
129 |
+
{
|
130 |
+
"role": "user",
|
131 |
+
"content": [
|
132 |
+
{
|
133 |
+
"type": "text",
|
134 |
+
"text": "Extract and format the Patient Admission Form from this image according to the specified markdown format. Preserve all form fields and checkboxes (as □)."
|
135 |
+
},
|
136 |
+
{
|
137 |
+
"type": "image_url",
|
138 |
+
"image_url": {
|
139 |
+
"url": f"data:image/png;base64,{img_base64}"
|
140 |
+
}
|
141 |
+
}
|
142 |
+
]
|
143 |
+
}
|
144 |
+
],
|
145 |
+
max_tokens=4096
|
146 |
+
)
|
147 |
+
|
148 |
+
return response.choices[0].message.content
|
149 |
+
|
150 |
+
except Exception as e:
|
151 |
+
print(f"Error in text extraction: {str(e)}")
|
152 |
+
return None
|
153 |
|
154 |
def extract_text(pdf_file):
|
155 |
if OPENAI_API_KEY is None:
|