Fixed patient generation with separate script approach
This commit is contained in:
78
generate_patients.sh
Executable file
78
generate_patients.sh
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to generate synthetic patients directly using modules created by the pipeline
|
||||
# Usage: ./generate_patients.sh <module_name> <output_directory> <population_size>
|
||||
|
||||
MODULE_NAME=$1
|
||||
OUTPUT_DIR=$2
|
||||
POPULATION=${3:-10}
|
||||
|
||||
if [ -z "$MODULE_NAME" ] || [ -z "$OUTPUT_DIR" ]; then
|
||||
echo "Usage: $0 <module_name> <output_directory> [population_size]"
|
||||
echo "Example: $0 diabetes /path/to/output 20"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create output directory
|
||||
mkdir -p "$OUTPUT_DIR/m" "$OUTPUT_DIR/f"
|
||||
|
||||
# Location of module file
|
||||
MODULE_PATH="/data/olamide/synthea-alldiseases/modules/${MODULE_NAME}.json"
|
||||
|
||||
if [ ! -f "$MODULE_PATH" ]; then
|
||||
echo "Module file not found: $MODULE_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create a temporary directory for the container output
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
echo "Created temporary directory: $TEMP_DIR"
|
||||
|
||||
# Run for male patients
|
||||
echo "Generating male patients..."
|
||||
docker run --rm \
|
||||
-v "$MODULE_PATH:/app/modules/${MODULE_NAME}.json" \
|
||||
-v "$TEMP_DIR:/app/output" \
|
||||
synthea-module-generator \
|
||||
bash -c "cd /app && ./run_synthea -p $((POPULATION/2)) -g M -m ${MODULE_NAME} Massachusetts"
|
||||
|
||||
# Copy male patient files to the output directory
|
||||
echo "Copying male patient files..."
|
||||
find "$TEMP_DIR/fhir" -name "*.json" ! -name "*hospital*" ! -name "*practitioner*" | while read file; do
|
||||
# Check if it's a patient file by looking for gender field
|
||||
if grep -q '"gender"' "$file"; then
|
||||
cp "$file" "$OUTPUT_DIR/m/"
|
||||
fi
|
||||
done
|
||||
|
||||
# Clear the temp directory
|
||||
rm -rf "$TEMP_DIR/fhir"/*
|
||||
|
||||
# Run for female patients
|
||||
echo "Generating female patients..."
|
||||
docker run --rm \
|
||||
-v "$MODULE_PATH:/app/modules/${MODULE_NAME}.json" \
|
||||
-v "$TEMP_DIR:/app/output" \
|
||||
synthea-module-generator \
|
||||
bash -c "cd /app && ./run_synthea -p $((POPULATION/2)) -g F -m ${MODULE_NAME} Massachusetts"
|
||||
|
||||
# Copy female patient files to the output directory
|
||||
echo "Copying female patient files..."
|
||||
find "$TEMP_DIR/fhir" -name "*.json" ! -name "*hospital*" ! -name "*practitioner*" | while read file; do
|
||||
# Check if it's a patient file by looking for gender field
|
||||
if grep -q '"gender"' "$file"; then
|
||||
cp "$file" "$OUTPUT_DIR/f/"
|
||||
fi
|
||||
done
|
||||
|
||||
# Count the results
|
||||
male_count=$(find "$OUTPUT_DIR/m" -type f -name "*.json" | wc -l)
|
||||
female_count=$(find "$OUTPUT_DIR/f" -type f -name "*.json" | wc -l)
|
||||
|
||||
# Report results
|
||||
echo "Patient generation complete. Results saved to $OUTPUT_DIR"
|
||||
echo "Male patients: $male_count"
|
||||
echo "Female patients: $female_count"
|
||||
|
||||
# Clean up temp directory
|
||||
rm -rf "$TEMP_DIR"
|
||||
Reference in New Issue
Block a user