Spaces:
Sleeping
Sleeping
refactor: Structure spiritual care prompt and simplify fallback message generation to a concise narrative, increasing conversation context length.
Browse files
src/config/prompts/spiritual_care_message.txt
CHANGED
|
@@ -1,12 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<role>
|
| 2 |
+
You are a specialist assistant generating a clear, concise handoff message for the Spiritual Health Team regarding a patient with a Red Flag classification.
|
| 3 |
+
</role>
|
| 4 |
+
|
| 5 |
+
<goal>
|
| 6 |
+
Generate a brief summary that reflects the patient's emotional or spiritual concerns, ensuring providers receive a clear handoff.
|
| 7 |
+
</goal>
|
| 8 |
+
|
| 9 |
+
<strict_formatting_rules>
|
| 10 |
+
1. Write a SINGLE, continuous paragraph. No line breaks.
|
| 11 |
+
2. DO NOT use emojis.
|
| 12 |
+
3. DO NOT use bullet points, list markers (1., -), or bold text (**).
|
| 13 |
+
4. DO NOT use headers or section titles.
|
| 14 |
+
</strict_formatting_rules>
|
| 15 |
+
|
| 16 |
+
<structure_and_content>
|
| 17 |
+
1. Starts immediately with the patient's Name and Phone Number.
|
| 18 |
+
2. Briefly summarizes the patient's situation and the specific indicators that triggered the Red classification.
|
| 19 |
+
3. Includes relevant context from any clarifying questions (Triage) if available.
|
| 20 |
+
</structure_and_content>
|
| 21 |
+
|
| 22 |
+
<tone>
|
| 23 |
+
Professional, objective, and concise. Focus on ensuring the spiritual health providers receive a clear picture of the concerns.
|
| 24 |
+
</tone>
|
src/core/provider_summary_generator.py
CHANGED
|
@@ -744,7 +744,7 @@ class ProviderSummaryGenerator:
|
|
| 744 |
triage_section = "\n**TRIAGE EXCHANGES:**\n" + "\n".join(exchanges)
|
| 745 |
|
| 746 |
# Build conversation snippet
|
| 747 |
-
conversation_snippet = summary.conversation_context[:
|
| 748 |
|
| 749 |
# Extract patient info from medical_context
|
| 750 |
patient_age = "N/A"
|
|
@@ -807,91 +807,35 @@ class ProviderSummaryGenerator:
|
|
| 807 |
return self._generate_fallback_care_message(summary, language)
|
| 808 |
|
| 809 |
def _generate_fallback_care_message(self, summary: ProviderSummary, language: str = "English") -> str:
|
| 810 |
-
"""Generate fallback
|
| 811 |
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
'
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
if language.lower() in ['ukrainian', 'uk', 'укр', 'українська']:
|
| 819 |
-
message = f"""{urgency_prefix}
|
| 820 |
-
|
| 821 |
-
👤 ІНФОРМАЦІЯ ПРО ПАЦІЄНТА
|
| 822 |
-
Ім'я: {summary.patient_name}
|
| 823 |
-
Телефон: {summary.patient_phone}
|
| 824 |
-
{'Email: ' + summary.patient_email if summary.patient_email else ''}
|
| 825 |
-
|
| 826 |
-
📊 КЛАСИФІКАЦІЯ
|
| 827 |
-
Рівень: ЧЕРВОНИЙ ПРАПОР - Духовний дистрес
|
| 828 |
-
Серйозність: {summary.severity_level}
|
| 829 |
-
Впевненість: {summary.confidence:.0%}
|
| 830 |
-
|
| 831 |
-
🔍 СИТУАЦІЯ
|
| 832 |
-
{summary.situation_description}
|
| 833 |
-
|
| 834 |
-
⚠️ ІНДИКАТОРИ ДИСТРЕСУ
|
| 835 |
-
"""
|
| 836 |
-
for indicator in summary.indicators:
|
| 837 |
-
message += f"• {indicator}\n"
|
| 838 |
|
| 839 |
-
|
| 840 |
-
💭 ОБҐРУНТУВАННЯ
|
| 841 |
-
{summary.reasoning}
|
| 842 |
-
|
| 843 |
-
⏰ ТЕРМІН ДІЇ
|
| 844 |
-
{summary.follow_up_timeline}
|
| 845 |
-
|
| 846 |
-
✅ РЕКОМЕНДОВАНІ ДІЇ
|
| 847 |
-
"""
|
| 848 |
-
for action in summary.recommended_actions[:3]:
|
| 849 |
-
message += f"• {action}\n"
|
| 850 |
-
|
| 851 |
-
else: # English
|
| 852 |
-
message = f"""{urgency_prefix}
|
| 853 |
-
|
| 854 |
-
👤 PATIENT INFORMATION
|
| 855 |
-
Name: {summary.patient_name}
|
| 856 |
-
Phone: {summary.patient_phone}
|
| 857 |
-
{'Email: ' + summary.patient_email if summary.patient_email else ''}
|
| 858 |
-
|
| 859 |
-
📊 CLASSIFICATION
|
| 860 |
-
Level: RED FLAG - Spiritual Distress
|
| 861 |
-
Severity: {summary.severity_level}
|
| 862 |
-
Confidence: {summary.confidence:.0%}
|
| 863 |
-
|
| 864 |
-
🔍 SITUATION
|
| 865 |
-
{summary.situation_description}
|
| 866 |
-
|
| 867 |
-
⚠️ DISTRESS INDICATORS
|
| 868 |
-
"""
|
| 869 |
-
for indicator in summary.indicators:
|
| 870 |
-
message += f"• {indicator}\n"
|
| 871 |
-
|
| 872 |
-
message += f"""
|
| 873 |
-
💭 REASONING
|
| 874 |
-
{summary.reasoning}
|
| 875 |
-
|
| 876 |
-
⏰ ACTION TIMELINE
|
| 877 |
-
{summary.follow_up_timeline}
|
| 878 |
-
|
| 879 |
-
✅ RECOMMENDED ACTIONS
|
| 880 |
-
"""
|
| 881 |
-
for action in summary.recommended_actions[:3]:
|
| 882 |
-
message += f"• {action}\n"
|
| 883 |
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 895 |
|
| 896 |
def generate_summary_with_validation(self, **kwargs) -> tuple[ProviderSummary, List[str]]:
|
| 897 |
"""
|
|
|
|
| 744 |
triage_section = "\n**TRIAGE EXCHANGES:**\n" + "\n".join(exchanges)
|
| 745 |
|
| 746 |
# Build conversation snippet
|
| 747 |
+
conversation_snippet = summary.conversation_context[:2000] if summary.conversation_context else "No recent conversation"
|
| 748 |
|
| 749 |
# Extract patient info from medical_context
|
| 750 |
patient_age = "N/A"
|
|
|
|
| 807 |
return self._generate_fallback_care_message(summary, language)
|
| 808 |
|
| 809 |
def _generate_fallback_care_message(self, summary: ProviderSummary, language: str = "English") -> str:
|
| 810 |
+
"""Generate fallback narrative message when LLM is unavailable."""
|
| 811 |
|
| 812 |
+
# Prepare components for narrative
|
| 813 |
+
conditions = "None listed"
|
| 814 |
+
if summary.medical_context and summary.medical_context.get('conditions'):
|
| 815 |
+
cond_list = summary.medical_context.get('conditions', [])
|
| 816 |
+
conditions = ", ".join(cond_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 817 |
|
| 818 |
+
indicators = ", ".join(summary.indicators) if summary.indicators else "Unspecified distress"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 819 |
|
| 820 |
+
action = "Assess and support"
|
| 821 |
+
if summary.recommended_actions:
|
| 822 |
+
action = summary.recommended_actions[0]
|
| 823 |
+
|
| 824 |
+
# Construct narrative based on language
|
| 825 |
+
if language.lower() in ['ukrainian', 'uk', 'укр', 'українська']:
|
| 826 |
+
return (
|
| 827 |
+
f"Пацієнт {summary.patient_name} ({summary.patient_phone}) виявляє ознаки духовного дистресу, "
|
| 828 |
+
f"зокрема: {indicators}. Медичний контекст: {conditions}. "
|
| 829 |
+
f"Клінічна оцінка вказує на рівень серйозності: {summary.severity_level}. "
|
| 830 |
+
f"Рекомендована дія: {action}. Будь ласка, забезпечте подальший супровід {summary.follow_up_timeline}."
|
| 831 |
+
)
|
| 832 |
+
else:
|
| 833 |
+
return (
|
| 834 |
+
f"The patient {summary.patient_name} ({summary.patient_phone}) is presenting with spiritual distress "
|
| 835 |
+
f"indicators including {indicators}. Relevant medical context includes {conditions}. "
|
| 836 |
+
f"Clinical assessment indicates {summary.severity_level} severity with {summary.confidence:.0%} confidence. "
|
| 837 |
+
f"Please review for {action} and follow up {summary.follow_up_timeline.lower()}."
|
| 838 |
+
)
|
| 839 |
|
| 840 |
def generate_summary_with_validation(self, **kwargs) -> tuple[ProviderSummary, List[str]]:
|
| 841 |
"""
|