Skip to main content

Python flask APIs

 

from flask import Flask, request, jsonify from flask_sqlalchemy import SQLAlchemy from datetime import datetime from sqlalchemy import and_ app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///patient_data.db' # Use SQLite for simplicity app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) class PatientData(db.Model): id = db.Column(db.Integer, primary_key=True) patient_id = db.Column(db.String(50), nullable=False) timestamp = db.Column(db.DateTime, nullable=False) temperature = db.Column(db.Float) blood_pressure = db.Column(db.String(20)) heart_rate = db.Column(db.Integer) oxygen_saturation = db.Column(db.Integer) ecg = db.Column(db.String(20)) ppg = db.Column(db.String(20)) def to_dict(self): return { "timestamp": self.timestamp.isoformat(), "temperature": self.temperature, "blood_pressure": self.blood_pressure, "heart_rate": self.heart_rate, "oxygen_saturation": self.oxygen_saturation, "ecg": self.ecg, "ppg": self.ppg } @app.route('/api/patient_data', methods=['GET']) def get_patient_data(): patient_id = request.args.get('patient_id') start_time = request.args.get('start_time') end_time = request.args.get('end_time') # Validate input parameters if not all([patient_id, start_time, end_time]): return jsonify({"error": "Missing required parameters"}), 400 try: start_time = datetime.fromisoformat(start_time) end_time = datetime.fromisoformat(end_time) except ValueError: return jsonify({"error": "Invalid datetime format. Use ISO format (YYYY-MM-DDTHH:MM:SS)"}), 400 if start_time > end_time: return jsonify({"error": "Start time must be before end time"}), 400 # Query the database for patient data patient_data = PatientData.query.filter( and_( PatientData.patient_id == patient_id, PatientData.timestamp >= start_time, PatientData.timestamp <= end_time ) ).order_by(PatientData.timestamp).all() return jsonify({ "patient_id": patient_id, "start_time": start_time.isoformat(), "end_time": end_time.isoformat(), "data": [data.to_dict() for data in patient_data] }) @app.route('/api/add_patient_data', methods=['POST']) def add_patient_data(): data = request.json new_data = PatientData( patient_id=data['patient_id'], timestamp=datetime.fromisoformat(data['timestamp']), temperature=data['temperature'], blood_pressure=data['blood_pressure'], heart_rate=data['heart_rate'], oxygen_saturation=data['oxygen_saturation'], ecg=data['ecg'], ppg=data['ppg'] ) db.session.add(new_data) db.session.commit() return jsonify({"message": "Data added successfully"}), 201 if __name__ == '__main__': with app.app_context(): db.create_all() # Create database tables app.run(debug=True)

Comments

Popular posts from this blog

Telecom OSS and BSS: A Comprehensive Guide

  Telecom OSS and BSS: A Comprehensive Guide Table of Contents Part I: Foundations of Telecom Operations Chapter 1: Introduction to Telecommunications Networks A Brief History of Telecommunications Network Architectures: From PSTN to 5G Key Network Elements and Protocols Chapter 2: Understanding OSS and BSS Defining OSS and BSS The Role of OSS in Network Management The Role of BSS in Business Operations The Interdependence of OSS and BSS Chapter 3: The Telecom Business Landscape Service Providers and Their Business Models The Evolving Customer Experience Regulatory and Compliance Considerations The Impact of Digital Transformation Part II: Operations Support Systems (OSS) Chapter 4: Network Inventory Management (NIM) The Importance of Accurate Inventory NIM Systems and Their Functionality Data Modeling and Management Automation and Reconciliation Chapter 5: Fault Management (FM) Detecting and Isolating Network Faults FM Systems and Alerting Mecha...

The AI Revolution: Are You Ready? my speech text in multiple languages -Hindi,Arabic,Malayalam,English

  The AI Revolution: Are You Ready?  https://www.linkedin.com/company/105947510 CertifAI Labs My Speech text on Future of Tomorrow in English, Arabic ,Hindi and Malayalam , All translations done by Gemini LLM "Imagine a world with self-writing software, robots working alongside us, and doctors with instant access to all the world's medical information. This isn't science fiction, friends; this is the world AI is building right now. The future isn't a distant dream, but a wave crashing upon our shores, rapidly transforming the job landscape. The question isn't if this change will happen, but how we will adapt to it." "Think about how we create. For generations, software development was a complex art mastered by a select few. But what if anyone with an idea and a voice could bring that idea to life? What if a child could build a virtual solar system in minutes, simply by asking? We're moving towards a world where computers speak our language, paving the...

The Silicon Race: AI Chips and the Future of Competition

  The Silicon Race: AI Chips and the Future of Competition The landscape of Artificial Intelligence (AI) is being reshaped at an unprecedented pace, and at its heart lies a furious competition in the development of specialized AI chips. These miniature marvels, whether powering vast data centers or enabling intelligence on the edge, are the silent workhorses transforming industries, enabling real-time decision-making, and pushing the boundaries of what AI can achieve. The stakes are immense, with the global AI chip market projected to surge from approximately $31.6 billion today to over $846 billion by 2035, highlighting an intense and evolving competitive arena. The Driving Force: Why Specialized AI Chips? Traditional CPUs, the general-purpose workhorses of computing, simply cannot meet the insatiable demands of modern AI workloads. The core operations of machine learning, particularly linear algebra and matrix multiplications, are inherently parallel. This led to the rise of s...