You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
NORM/FHIR_OCR_POC/sample_data/create_sample_image.py

77 lines
3.1 KiB
Python

#!/usr/bin/env python
"""
Create a sample insurance card image for testing.
This script generates a simple image that resembles an insurance card
with synthetic patient data for OCR testing.
"""
import os
from PIL import Image, ImageDraw, ImageFont
import argparse
def create_insurance_card(output_path, patient_name="John Doe", dob="01/15/1980",
member_id="ABC12345678", plan="HealthPlus Gold"):
"""
Create a sample insurance card image.
Args:
output_path: Path to save the image
patient_name: Patient name
dob: Date of birth
member_id: Member ID
plan: Insurance plan
"""
# Create a blank image (standard card size in pixels at 300 DPI)
width, height = 1050, 650 # ~3.5" x 2.17"
image = Image.new('RGB', (width, height), color=(255, 255, 255))
draw = ImageDraw.Draw(image)
# Try to load a font, falling back to default if not available
try:
font_large = ImageFont.truetype("Arial", 36)
font_medium = ImageFont.truetype("Arial", 28)
font_small = ImageFont.truetype("Arial", 24)
except IOError:
# Use default font if Arial not available
font_large = ImageFont.load_default()
font_medium = ImageFont.load_default()
font_small = ImageFont.load_default()
# Draw a blue rectangle at the top (insurance company header)
draw.rectangle([(0, 0), (width, 120)], fill=(0, 82, 156))
# Add insurance company name
draw.text((50, 40), "HealthCorp Insurance", fill=(255, 255, 255), font=font_large)
# Add card details
draw.text((50, 150), f"Name: {patient_name}", fill=(0, 0, 0), font=font_medium)
draw.text((50, 200), f"DOB: {dob}", fill=(0, 0, 0), font=font_medium)
draw.text((50, 250), f"Member ID: {member_id}", fill=(0, 0, 0), font=font_medium)
draw.text((50, 300), f"Plan: {plan}", fill=(0, 0, 0), font=font_medium)
# Add gender field
draw.text((50, 350), "Gender: Male", fill=(0, 0, 0), font=font_medium)
# Add additional information
draw.text((50, 450), "Customer Service: 1-800-555-1234", fill=(0, 0, 0), font=font_small)
draw.text((50, 500), "Group #: HC987654", fill=(0, 0, 0), font=font_small)
draw.text((50, 550), "RxBIN: 123456 RxPCN: ABC", fill=(0, 0, 0), font=font_small)
# Add a border
draw.rectangle([(0, 0), (width-1, height-1)], outline=(0, 0, 0), width=2)
# Save the image
image.save(output_path)
print(f"Sample insurance card saved to: {output_path}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Create a sample insurance card image')
parser.add_argument('--output', default='sample_insurance_card.png', help='Output image path')
parser.add_argument('--name', default='John Doe', help='Patient name')
parser.add_argument('--dob', default='01/15/1980', help='Date of birth')
parser.add_argument('--id', default='ABC12345678', help='Member ID')
parser.add_argument('--plan', default='HealthPlus Gold', help='Insurance plan')
args = parser.parse_args()
create_insurance_card(args.output, args.name, args.dob, args.id, args.plan)