use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PostcodeGeography {
pub postcode: String,
pub lsoa11: Option<String>,
pub local_authority: Option<String>,
pub local_authority_name: Option<String>,
pub icb: Option<String>,
pub icb_name: Option<String>,
pub nhs_england_region: Option<String>,
pub nhs_england_region_name: Option<String>,
pub parliamentary_constituency: Option<String>,
pub parliamentary_constituency_name: Option<String>,
pub government_office_region: Option<String>,
pub cancer_alliance: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_postcode_geography_construction() {
let geo = PostcodeGeography {
postcode: "SW1A 1AA".to_string(),
lsoa11: Some("E01004736".to_string()),
local_authority: Some("E09000033".to_string()),
local_authority_name: Some("Westminster".to_string()),
icb: Some("QWE".to_string()),
icb_name: Some("NHS North West London ICB".to_string()),
nhs_england_region: Some("Y56".to_string()),
nhs_england_region_name: Some("London".to_string()),
parliamentary_constituency: Some("E14000639".to_string()),
parliamentary_constituency_name: Some("Cities of London and Westminster".to_string()),
government_office_region: Some("E12000007".to_string()),
cancer_alliance: None,
};
assert_eq!(geo.postcode, "SW1A 1AA");
assert_eq!(geo.local_authority_name.as_deref(), Some("Westminster"));
}
#[test]
fn test_postcode_geography_serialization() {
let geo = PostcodeGeography {
postcode: "LS1 4AP".to_string(),
lsoa11: Some("E01011229".to_string()),
local_authority: Some("E08000035".to_string()),
local_authority_name: Some("Leeds".to_string()),
icb: Some("X2C4Y".to_string()),
icb_name: Some("NHS West Yorkshire ICB".to_string()),
nhs_england_region: None,
nhs_england_region_name: None,
parliamentary_constituency: None,
parliamentary_constituency_name: None,
government_office_region: None,
cancer_alliance: None,
};
let json = serde_json::to_string(&geo).unwrap();
let deser: PostcodeGeography = serde_json::from_str(&json).unwrap();
assert_eq!(deser.postcode, "LS1 4AP");
assert_eq!(deser.icb_name.as_deref(), Some("NHS West Yorkshire ICB"));
}
}