-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
138 lines (122 loc) · 4.45 KB
/
app.py
File metadata and controls
138 lines (122 loc) · 4.45 KB
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
from flask import Flask, request, jsonify
from flask_cors import CORS
import json
import os
app = Flask(__name__)
CORS(app) # Enable CORS for all routes
# Load mappings from JSON file
def load_mappings():
try:
with open('mappings.json', 'r', encoding='utf-8') as f:
return json.load(f)
except FileNotFoundError:
return {}
@app.route('/map_disease', methods=['POST'])
def map_disease():
try:
# Get JSON data from request
data = request.get_json()
if not data or 'disease' not in data:
return jsonify({
"error": "Invalid request. Please provide 'disease' field in JSON."
}), 400
disease_name = data['disease'].strip()
if not disease_name:
return jsonify({
"error": "Disease name cannot be empty."
}), 400
# Load mappings
mappings = load_mappings()
# Look for the disease (case-insensitive)
disease_mapping = None
for key, value in mappings.items():
if key.lower() == disease_name.lower():
disease_mapping = value
break
if not disease_mapping:
return jsonify({
"error": f"Disease '{disease_name}' not found in mappings.",
"available_diseases": list(mappings.keys())
}), 404
# Create FHIR-compliant response
fhir_response = {
"resourceType": "Condition",
"id": f"condition-{disease_name.lower().replace(' ', '-')}",
"meta": {
"versionId": "1",
"lastUpdated": "2024-01-01T00:00:00Z",
"source": "AYUSH-Disease-Mapping-System"
},
"status": "active",
"category": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/condition-category",
"code": "encounter-diagnosis",
"display": "Encounter Diagnosis"
}
]
}
],
"code": {
"coding": [
{
"system": "http://namaste.gov.in/ayush-terminology",
"code": disease_mapping.get("namaste_code", ""),
"display": disease_name
}
]
},
"subject": {
"reference": "Patient/example-patient"
},
"extension": [
{
"url": "http://namaste.gov.in/ayush-mapping",
"valueCodeableConcept": {
"coding": [
{
"system": "http://namaste.gov.in/ayush-codes",
"code": disease_mapping.get("namaste_code", ""),
"display": disease_mapping.get("namaste_description", "")
}
]
}
}
]
}
# Add ICD mapping if available
if disease_mapping.get("icd_code"):
fhir_response["code"]["coding"].append({
"system": "http://hl7.org/fhir/sid/icd-10",
"code": disease_mapping["icd_code"],
"display": disease_mapping.get("icd_description", "")
})
return jsonify(fhir_response), 200
except Exception as e:
return jsonify({
"error": f"Internal server error: {str(e)}"
}), 500
@app.route('/health', methods=['GET'])
def health_check():
return jsonify({
"status": "healthy",
"message": "AYUSH Disease Mapping API is running"
}), 200
@app.route('/', methods=['GET'])
def home():
return jsonify({
"message": "AYUSH Disease Mapping API",
"endpoints": {
"/map_disease": "POST - Map AYUSH disease to FHIR format",
"/health": "GET - Health check"
}
}), 200
if __name__ == '__main__':
print("Starting AYUSH Disease Mapping API...")
print("API will be available at: http://127.0.0.1:5000")
print("Endpoints:")
print(" POST /map_disease - Map disease to FHIR format")
print(" GET /health - Health check")
app.run(debug=True, host='127.0.0.1', port=5000)