| name | healthcare-expert |
| version | 1.0.0 |
| description | Expert-level healthcare systems, medical informatics, HIPAA compliance, and health data standards |
| category | domains |
| tags | ["healthcare","medical","hipaa","hl7","fhir","ehr"] |
| allowed-tools | ["Read","Write","Edit"] |
Healthcare Expert
Expert guidance for healthcare systems, medical informatics, regulatory compliance (HIPAA), and health data standards (HL7, FHIR).
Core Concepts
Healthcare IT
- Electronic Health Records (EHR)
- Health Information Exchange (HIE)
- Clinical Decision Support Systems
- Telemedicine platforms
- Medical imaging systems (PACS)
- Laboratory information systems
Standards and Protocols
- HL7 (Health Level 7)
- FHIR (Fast Healthcare Interoperability Resources)
- DICOM (Digital Imaging and Communications in Medicine)
- ICD-10 (diagnostic codes)
- CPT (procedure codes)
- SNOMED CT (clinical terminology)
Regulatory Compliance
- HIPAA (Health Insurance Portability and Accountability Act)
- HITECH Act
- GDPR for health data
- FDA regulations for medical devices
- 21 CFR Part 11 for electronic records
FHIR Resource Handling
from fhirclient import client
from fhirclient.models import patient, observation, medication
from datetime import datetime
settings = {
'app_id': 'my_healthcare_app',
'api_base': 'https://fhir.example.com/r4'
}
smart = client.FHIRClient(settings=settings)
def create_patient(first_name, last_name, gender, birth_date):
"""Create FHIR Patient resource"""
p = patient.Patient()
p.name = [{
'use': 'official',
'family': last_name,
'given': [first_name]
}]
p.gender = gender
p.birthDate = birth_date.isoformat()
return p.create(smart.server)
def create_vital_signs_observation(patient_id, code, value, unit):
"""Create vital signs observation"""
obs = observation.Observation()
obs.status = 'final'
obs.category = [{
'coding': [{
'system': 'http://terminology.hl7.org/CodeSystem/observation-category',
'code': 'vital-signs',
'display': 'Vital Signs'
}]
}]
obs.code = {
'coding': [{
'system': 'http://loinc.org',
'code': code,
:
}]
}
obs.subject = {: }
obs.effectiveDateTime = datetime.now().isoformat()
obs.valueQuantity = {
: value,
: unit,
: ,
: unit
}
obs.create(smart.server)
():
search = patient.Patient.where(struct={})
family_name:
search = search.where(struct={: family_name})
given_name:
search = search.where(struct={: given_name})
search.perform(smart.server)
():
search = observation.Observation.where(struct={
: patient_id
})
category:
search = search.where(struct={: category})
search.perform(smart.server)
HL7 v2 Message Processing
import hl7
def parse_hl7_message(message_text):
"""Parse HL7 v2 message"""
h = hl7.parse(message_text)
message_type = str(h.segment('MSH')[9])
pid = h.segment('PID')
patient_info = {
'patient_id': str(pid[3]),
'name': str(pid[5]),
'dob': str(pid[7]),
'gender': str(pid[8])
}
return {
'message_type': message_type,
'patient': patient_info
}
def create_admission_message(patient_id, patient_name, dob, gender):
"""Create HL7 ADT^A01 admission message"""
message = hl7.Message(
"MSH",
[
"MSH", "|", "^~\\&", "SENDING_APP", "SENDING_FACILITY",
"RECEIVING_APP", "RECEIVING_FACILITY",
datetime.now().strftime("%Y%m%d%H%M%S"), "",
"ADT^A01", "MSG00001", "P", "2.5"
]
)
message.append(hl7.Segment(
,
[
, , , patient_id, ,
patient_name, , dob, gender
]
))
message.append(hl7.Segment(
,
[
, , , , , , ,
, , , , , , ,
, , , , , , ,
]
))
(message)
():
:
h = hl7.parse(message_text)
h.segment():
,
msh = h.segment()
(msh) < :
,
,
Exception e:
,
HIPAA Compliance Implementation
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2
import hashlib
import logging
from datetime import datetime
class HIPAACompliantLogger:
"""HIPAA-compliant logging system"""
def __init__(self, log_file):
self.logger = logging.getLogger('hipaa_audit')
self.logger.setLevel(logging.INFO)
handler = logging.FileHandler(log_file)
formatter = logging.Formatter(
'%(asctime)s - %(levelname)s - %(message)s'
)
handler.setFormatter(formatter)
self.logger.addHandler(handler)
def log_access(self, user_id, patient_id, action, phi_accessed):
"""Log PHI access (HIPAA audit requirement)"""
self.logger.info(
f"USER:{user_id} | PATIENT:{patient_id} | "
f"ACTION:{action} | PHI:{phi_accessed}"
)
def log_modification(self, user_id, resource_type, resource_id, changes):
"""Log data modifications"""
self.logger.info(
f"USER:{user_id} | MODIFIED:{resource_type}/{resource_id} | "
)
():
.logger.info(
)
:
():
.fernet = Fernet(master_key)
():
(data, ):
data = data.encode()
.fernet.encrypt(data)
():
decrypted = .fernet.decrypt(encrypted_data)
decrypted.decode()
():
hashlib.sha256(identifier.encode()).hexdigest()
:
ROLES = {
: [, , ],
: [, ],
: [],
: []
}
():
.role = user_role
.permissions = .ROLES.get(user_role, [])
():
action .permissions:
action == .permissions:
patient_id == user_patient_id
():
():
():
action .permissions:
PermissionError(
)
func(*args, **kwargs)
wrapper
decorator
Electronic Health Record System
from dataclasses import dataclass
from typing import List, Optional
from datetime import datetime
@dataclass
class Patient:
"""Patient record"""
patient_id: str
mrn: str
first_name: str
last_name: str
dob: datetime
gender: str
ssn: Optional[str]
address: dict
phone: str
email: str
emergency_contact: dict
insurance: dict
@dataclass
class Encounter:
"""Clinical encounter"""
encounter_id: str
patient_id: str
encounter_date: datetime
encounter_type: str
chief_complaint: str
provider_id: str
facility_id: str
diagnosis_codes: List[str]
procedure_codes: List[str]
notes: str
@dataclass
class Medication:
"""Medication order"""
medication_id:
patient_id:
drug_name:
dosage:
frequency:
route:
start_date: datetime
end_date: [datetime]
prescriber_id:
pharmacy_notes:
:
():
.db = db
.logger = logger
.access_control = access_control
.encryption = encryption
():
.access_control.can_access(, patient_id):
.logger.log_access(
user_id, patient_id, ,
)
PermissionError()
.logger.log_access(
user_id, patient_id, ,
)
patient = .db.get_patient(patient_id)
patient.ssn:
patient.ssn = .encryption.decrypt_phi(patient.ssn)
patient
():
.access_control.can_access(, encounter.patient_id):
PermissionError()
encounter.notes:
encounter.notes = .encryption.encrypt_phi(encounter.notes)
.db.save_encounter(encounter)
.logger.log_modification(
user_id, , encounter.encounter_id,
)
encounter
():
.access_control.can_access(, patient_id):
PermissionError()
.logger.log_access(
user_id, patient_id, ,
)
.db.get_active_medications(patient_id)
():
.access_control.can_access(, medication.patient_id):
PermissionError()
active_meds = .get_patient_medications(user_id, medication.patient_id)
interactions = .check_drug_interactions(medication, active_meds)
interactions:
{: , : interactions}
.db.save_medication(medication)
.logger.log_modification(
user_id, , medication.medication_id,
)
{: , : medication.medication_id}
():
interactions = []
interactions
Best Practices
Security and Compliance
- Encrypt PHI at rest and in transit
- Implement comprehensive audit logging
- Use role-based access control
- Conduct regular security assessments
- Implement data backup and disaster recovery
- Train staff on HIPAA requirements
- Use de-identification for research data
Data Standards
- Use standard terminologies (SNOMED, LOINC)
- Implement FHIR for interoperability
- Support HL7 messaging
- Use ICD-10 for diagnoses
- Use CPT for procedures
- Validate data quality
System Design
- Design for high availability
- Implement redundancy
- Ensure data integrity
- Support audit trails
- Enable patient access portals
- Integrate with HIE networks
Anti-Patterns
❌ Storing PHI unencrypted
❌ No audit logging
❌ Inadequate access controls
❌ Using proprietary formats
❌ No data backup strategy
❌ Ignoring interoperability standards
❌ Weak authentication
Resources