Spain Diagnostic Data Processing – Script Overview

This pipeline builds and refines Spain’s ICD diagnostic datasets from regional totals through to corrected 4-digit ICD codes.



1. Database Formation

Script: diag_spain_database_formation.php


Creates the initial Spain regional diagnostics table

Iterates through all Spanish regions

Inserts one record per ICD code × region

Populates baseline case counts from the national diagnostic dataset

Establishes the foundation dataset used by all downstream scripts


2. Database Populating

Script: diag_spain_database_populating.php

•

Fills in missing or incomplete regional case counts

Cross-references national diagnostic data by year

Updates records where valid case numbers exist

Ensures regional diagnostic totals are accurate before processing


3. 3-Digit ICD Generation

Script: diag_spain_3_digit.php

Processes diagnostics at the 3-digit ICD level

Allocates cases using hospital capacity and regional weighting logic

Generates structured 3-digit diagnostic records

Acts as the aggregation layer between raw data and detailed ICD expansion

•


4. 3-Digit ICD Correction

Script: diag_spain_3_digit_correction.php

Corrects imbalances in 3-digit ICD allocations

Recalculates regional totals using grouping logic

Adjusts rounding errors and allocation drift

Ensures 3-digit totals align with regional constraints


5. 3-Digit to 4-Digit Expansion

Script: diag_spain_3_to_4_digit.php

Expands each 3-digit ICD code into valid 4-digit subcodes

Distributes case counts across 4-digit codes

Uses temporary tables to allocate cases incrementally

Produces a detailed but uncorrected 4-digit dataset


6. 4-Digit ICD Final Correction

Script: diag_spain_4_digit_correction.php

Rebalances 4-digit ICD distributions

Applies probability weighting to ensure realistic allocation

Maintains consistency with original 3-digit totals

Produces the final, corrected 4-digit Spain diagnostic dataset

•



Summary Flow

Create regional base dataset

Populate and validate case counts

Generate 3-digit ICD structure

Correct 3-digit allocations

Expand to 4-digit ICD codes

Apply final corrections and balancing


Execution Order

Scripts must be run sequentially in the following order:

1.diag_spain_database_formation.php

2.diag_spain_database_populating.php

3.diag_spain_3_digit.php

4.diag_spain_3_digit_correction.php

5.diag_spain_3_to_4_digit.php

6.diag_spain_4_digit_correction.php




Notes

•Scripts are not independent; skipping steps will invalidate results