Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion schemas/opnoteschema/src/opnoteschema/examples/example.json
Original file line number Diff line number Diff line change
@@ -1 +1,76 @@
{}
{
"content": "OPERATION NOTE\n\nPatient's Name: [redacted]\nDate of birth: [redacted]\nGender: female\nHospital number: [redacted]\nNHS number: [redacted]\n\nDate of Surgery: [redacted]\n\nPost-op Diagnosis: Displaced intracapsular fracture neck of femur, right\n\nProcedure(s): Right Hip Hemiarthroplasty; Cerclage wiring of intraoperative periprosthetic femoral fracture - Right\n\nPatient Class: Inpatient (trauma list)\n\nConsultant on Case: [redacted]\n\nSurgeons:\n* [redacted] - Consultant\n* [redacted] - Primary Operator (Registrar)\n* [redacted] - Assisting\n\nAnaesthetist: [redacted]\nResponsible Anaesthetist: [redacted]\nAnaesthetic Type: spinal, peripheral nerve block\nASA Grade: III\n\nIndication: 82 year old admitted after a fall at home with a displaced intracapsular fracture of the right neck of femur, confirmed on plain film and CT. Booked on the trauma list for hemiarthroplasty.\n\nDescription of Procedure\n\nWHO checklist completed. IV teicoplanin and gentamicin given at induction. Lateral position with front and back bolsters. Skin prepped with betadine and chlorhexidine, iodine-impregnated incise drape.\n\nAnterolateral approach to proximal right femur. Dissection through fat and fascia lata. Gluteus medius and minimus incised from the greater trochanter. T-shaped capsulotomy. Femoral neck cut 1cm above the lesser trochanter. Femoral head removed, measured 44mm.\n\nFemur prepared with box chisel, pencil reamers and raspers sequential to size 2. During broaching of the femoral canal a longitudinal crack was noted extending from the calcar down the medial cortex of the proximal femoral shaft, approximately 4cm in length, with no displacement. This was considered an intraoperative periprosthetic fracture. Two cerclage wires (18-gauge) were passed around the proximal femur proximal and distal to the crack and tensioned to secure the fracture prior to proceeding with stem insertion. No further propagation was seen on trialling.\n\nCanal prepared with pulsed lavage (1L) and dried with ribbon gauze and suction catheter. Canal cemented. Cemented stem with centraliser inserted, taking care to avoid further distraction of the cerclage-wired fracture. Trialled with standard +4mm head; equal leg lengths and a stable hip on internal and external rotation. 44mm bipolar head +4 inserted. Stable hip reduction confirmed, equal leg lengths, stable on internal and external rotation. Image intensifier check confirmed satisfactory wire position and no further fracture propagation. Saline wash.\n\nEstimated blood loss 450ml, no transfusion required intraoperatively.\n\nClosure\nCapsule - 5 Ethibond\nGluteus medius and minimus - 5 Ethibond inter-osseous followed by continuous suture in tendon\nFascia lata - 1 Vicryl\nFat - 1 Vicryl interrupted\nSubdermal - 2-0 Vicryl\nSkin - 3-0 Monocryl, skin glue, steristrips\n\nTotal operative time 105 minutes.\n\nPost op Plan\nToe-touch weight bearing on the right for 6 weeks given the periprosthetic fracture and cerclage wiring, then progress as tolerated with physiotherapy input.\nRepeat plain film in recovery to confirm implant and wire position.\nFBC, U+E tomorrow.\nNo further antibiotics needed beyond the two post-op doses.\nVTE prophylaxis as per protocol for NOF fractures.\nOrthopaedic follow up at 2 and 6 weeks with weight-bearing progression reviewed at 6 week appointment.\n\nImplant(s):\nImplant Name | Type | Manufacturer | Site | No. Used | Action\nPALACOS R+G 2x40g bone cement | Cement / Putty | Movianto UK Ltd | Right Hip | 1 | Implanted\nStryker Orthopaedics Exeter V40 Cemented Hip Stem, size 2 | Orthopaedic Prosthesis | Stryker UK Ltd | Right Hip | 1 | Implanted\nStryker Orthopaedics UHR Universal Head Bipolar Component, OD 44mm | Orthopaedic Prosthesis | Stryker UK Ltd | Right Hip | 1 | Implanted\nStryker Orthopaedics V40 Femoral Head, OD 28mm, OFFST +4 | Orthopaedic Prosthesis | Stryker UK Ltd | Right Hip | 1 | Implanted\n18-gauge cerclage wire | Fixation wire | DePuy Synthes | Right femur | 2 | Implanted",
"output": {
"is_operation_note": true,
"indication": "Displaced intracapsular fracture of the right neck of femur following a fall at home, confirmed on plain film and CT.",
"procedures": [
{
"procedure_type": "hip_hemiarthroplasty_cemented",
"procedure_desc": "Right Hip Hemiarthroplasty via anterolateral approach",
"laterality": "right",
"implants": [
{
"implant_desc": "PALACOS R+G 2x40g bone cement",
"device_type": "bone cement",
"manufacturer": "Movianto UK Ltd",
"size_or_specification": "2x40g",
"serial_or_lot_number": null
},
{
"implant_desc": "Stryker Orthopaedics Exeter V40 Cemented Hip Stem, size 2",
"device_type": "femoral stem",
"manufacturer": "Stryker UK Ltd",
"size_or_specification": "size 2",
"serial_or_lot_number": null
},
{
"implant_desc": "Stryker Orthopaedics UHR Universal Head Bipolar Component, OD 44mm",
"device_type": "bipolar head",
"manufacturer": "Stryker UK Ltd",
"size_or_specification": "OD 44mm",
"serial_or_lot_number": null
},
{
"implant_desc": "Stryker Orthopaedics V40 Femoral Head, OD 28mm, OFFST +4",
"device_type": "femoral head",
"manufacturer": "Stryker UK Ltd",
"size_or_specification": "OD 28mm, OFFST +4",
"serial_or_lot_number": null
}
]
},
{
"procedure_type": "other",
"procedure_desc": "Cerclage wiring of intraoperative periprosthetic femoral fracture, right",
"laterality": "right",
"implants": [
{
"implant_desc": "18-gauge cerclage wire",
"device_type": "fixation wire",
"manufacturer": "DePuy Synthes",
"size_or_specification": "18-gauge",
"serial_or_lot_number": null
}
]
}
],
"findings": "During broaching of the femoral canal a longitudinal crack was noted extending from the calcar down the medial cortex of the proximal femoral shaft, approximately 4cm in length, with no displacement. Image intensifier check after cerclage wiring and stem insertion confirmed satisfactory wire position and no further fracture propagation.",
"complications": [
{
"complication_type": "iatrogenic_fracture",
"complication_desc": "Longitudinal crack noted extending from the calcar down the medial cortex of the proximal femoral shaft, approximately 4cm in length, with no displacement, during broaching of the femoral canal - an intraoperative periprosthetic fracture.",
"management": "Two 18-gauge cerclage wires passed around the proximal femur proximal and distal to the crack and tensioned to secure the fracture prior to stem insertion; no further propagation seen on trialling or on image intensifier check."
}
],
"metadata": {
"urgency": "urgent",
"anaesthetic_type": "regional",
"operative_time_minutes": 105,
"estimated_blood_loss_ml": 450,
"tourniquet_time_minutes": null,
"asa_grade": 3,
"surgeon_grade": "registrar"
},
"operation_summary": "Right hip hemiarthroplasty for a displaced intracapsular neck of femur fracture, complicated intraoperatively by a periprosthetic crack of the proximal femoral shaft during canal broaching. This was secured with two cerclage wires before proceeding with cemented stem and bipolar head insertion, with no further fracture propagation on trialling or image intensifier check. Toe-touch weight bearing advised for 6 weeks given the fracture and wiring."
}
}
42 changes: 41 additions & 1 deletion schemas/opnoteschema/src/opnoteschema/prompt_datagen.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
OPERATION NOTE EXTRACTION

You are an experienced surgeon and medical information expert. Extract operative information from operation notes / operative records into a structured JSON format according to the provided Pydantic schema:

{SCHEMA}
{EXAMPLE}

OUTPUT STRUCTURE:
Return ONLY the extracted JSON wrapped in `<output></output>` tags. The JSON must follow the OperationNote schema structure.

MINIMAL INPUT/OUTPUT EXAMPLE:

{EXAMPLE}

CRITICAL REQUIREMENTS:
1. Absolute precision is paramount - This is a medicolegal requirement. Only extract correct information that is explicit and unambiguous.
2. Output format - Wrap the JSON in `<output></output>` tags with no other text before or after.
3. Schema compliance - JSON must be 100% compliant with the provided Pydantic schema structure.
4. Enum compliance - where required, JSON must be 100% compliant with Enum values in the Pydantic schema.
5. REPLACE ANY PII! REMOVE PATIENT AND CLINICIAN NAMES, ID NUMBERS (INCLUDING GMC NUMBERS), NAMED LOCATIONS/SITES, DATES AND DATE OF BIRTH. IN YOUR OUTPUT, ENSURE THESE ARE REPLACED WITH "[redacted]"

WHAT NOT TO DO:
1. Do not infer procedures, findings, or complications that are not explicitly documented
2. Do not assume laterality, urgency, or metadata that is not stated or clearly inferable from context
3. Do not create information to fill fields - use None/null for absent information and leave list fields empty when nothing applies
4. Do not guess at operative times, blood loss, or implant details
5. Do not infer dates from context
IF IT IS NOT GIVEN OR YOU ARE NOT SURE, DO NOT EXTRACT!

CLASSIFICATION RULE:
Set is_operation_note = TRUE only if the document is an operative note or operation record describing a surgical/interventional procedure performed on a patient. If FALSE, procedures, complications and operation_summary should be empty/null.

DOMAIN RULES (OPERATION NOTES):
1. PROCEDURE_TYPE ENUM MATCHING. Match procedure_type to the closest listed OPCS-4-derived enum value based on what was actually performed, not the listed operation title alone (e.g. a note titled "Hip surgery" that describes a cemented total hip replacement should be coded TOTAL_HIP_REPLACEMENT_CEMENTED). Use OTHER with procedure_desc naming the procedure as documented when nothing in the enum reasonably matches.
2. MULTIPLE PROCEDURES. List every distinct procedure performed in the order documented, including combined/staged procedures in the same operative episode (e.g. "laparoscopic cholecystectomy and appendicectomy" -> two Procedure entries).
3. IMPLANTS. Only populate implants for the procedure during which they were inserted/used. Do not duplicate an implant across multiple procedure entries.
4. COMPLICATIONS. complications captures only complications occurring during, or documented in immediate relation to, the procedure itself (intraoperative or immediate postoperative note) - not pre-existing comorbidities or unrelated past medical history. Use OTHER with complication_desc when nothing in the enum reasonably matches.
5. FINDINGS vs INDICATION. indication is the reason/preoperative diagnosis for the operation. findings is what was observed/discovered intraoperatively. Do not conflate the two.
6. METADATA. Populate ProcedureMetadata fields only where explicitly stated in the note (e.g. an ASA grade sheet, documented operative time, documented estimated blood loss). Redact surgeon names/identifiers from surgeon_grade, keeping only the grade/seniority (e.g. "consultant", "registrar").

REMEMBER - IF INFORMATION IS NOT GIVEN OR YOU ARE NOT SURE, LEAVE EMPTY AND DO NOT EXTRACT!

The operation note follows below:
39 changes: 38 additions & 1 deletion schemas/opnoteschema/src/opnoteschema/prompt_main.txt
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
{SCHEMA}
OPERATION NOTE EXTRACTION

You are an experienced surgeon and medical information expert. Extract operative information from operation notes / operative records into a structured JSON format according to the provided Pydantic schema:

{SCHEMA}

OUTPUT STRUCTURE:
Return ONLY the extracted JSON wrapped in `<output></output>` tags. The JSON must follow the OperationNote schema structure.

CRITICAL REQUIREMENTS:
1. Absolute precision is paramount - This is a medicolegal requirement. Only extract correct information that is explicit and unambiguous.
2. Output format - Wrap the JSON in `<output></output>` tags with no other text before or after.
3. Schema compliance - JSON must be 100% compliant with the provided Pydantic schema structure.
4. Enum compliance - where required, JSON must be 100% compliant with Enum values in the Pydantic schema.
5. REPLACE ANY PII! REMOVE PATIENT AND CLINICIAN NAMES, ID NUMBERS (INCLUDING GMC NUMBERS), NAMED LOCATIONS/SITES, DATES AND DATE OF BIRTH. IN YOUR OUTPUT, ENSURE THESE ARE REPLACED WITH "[redacted]"

WHAT NOT TO DO:
1. Do not infer procedures, findings, or complications that are not explicitly documented
2. Do not assume laterality, urgency, or metadata that is not stated or clearly inferable from context
3. Do not create information to fill fields - use None/null for absent information and leave list fields empty when nothing applies
4. Do not guess at operative times, blood loss, or implant details
5. Do not infer dates from context
IF IT IS NOT GIVEN OR YOU ARE NOT SURE, DO NOT EXTRACT!

CLASSIFICATION RULE:
Set is_operation_note = TRUE only if the document is an operative note or operation record describing a surgical/interventional procedure performed on a patient. If FALSE, procedures, complications and operation_summary should be empty/null.

DOMAIN RULES (OPERATION NOTES):
1. PROCEDURE_TYPE ENUM MATCHING. Match procedure_type to the closest listed OPCS-4-derived enum value based on what was actually performed, not the listed operation title alone (e.g. a note titled "Hip surgery" that describes a cemented total hip replacement should be coded TOTAL_HIP_REPLACEMENT_CEMENTED). Use OTHER with procedure_desc naming the procedure as documented when nothing in the enum reasonably matches.
2. MULTIPLE PROCEDURES. List every distinct procedure performed in the order documented, including combined/staged procedures in the same operative episode (e.g. "laparoscopic cholecystectomy and appendicectomy" -> two Procedure entries).
3. IMPLANTS. Only populate implants for the procedure during which they were inserted/used. Do not duplicate an implant across multiple procedure entries.
4. COMPLICATIONS. complications captures only complications occurring during, or documented in immediate relation to, the procedure itself (intraoperative or immediate postoperative note) - not pre-existing comorbidities or unrelated past medical history. Use OTHER with complication_desc when nothing in the enum reasonably matches.
5. FINDINGS vs INDICATION. indication is the reason/preoperative diagnosis for the operation. findings is what was observed/discovered intraoperatively. Do not conflate the two.
6. METADATA. Populate ProcedureMetadata fields only where explicitly stated in the note (e.g. an ASA grade sheet, documented operative time, documented estimated blood loss). Redact surgeon names/identifiers from surgeon_grade, keeping only the grade/seniority (e.g. "consultant", "registrar").

REMEMBER - IF INFORMATION IS NOT GIVEN OR YOU ARE NOT SURE, LEAVE EMPTY AND DO NOT EXTRACT!

The operation note follows below:
Loading
Loading