fix: handle multiple situations on a CPS

This commit is contained in:
Florian Briand 2024-08-02 23:02:44 +02:00
parent 9126d1311b
commit 83aef34750
Signed by: florian_briand
GPG Key ID: CC981B9E6B98E70B

View File

@ -116,7 +116,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
let byte = field.content[0];
carte_ps.titulaire.categorie_carte = byte as char;
}
(2, 1) => {
(2..=16, 1) => {
carte_ps.situations.push(SituationPS::default());
carte_ps
.situations
@ -124,19 +124,19 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.unwrap()
.numero_logique_de_la_situation_de_facturation_du_ps = field.content[0];
}
(2, 2) => {
(2..=16, 2) => {
carte_ps.situations.last_mut().unwrap().mode_d_exercice =
String::from_utf8_lossy(field.content).to_string();
}
(2, 3) => {
(2..=16, 3) => {
carte_ps.situations.last_mut().unwrap().statut_d_exercice =
String::from_utf8_lossy(field.content).to_string();
}
(2, 4) => {
(2..=16, 4) => {
carte_ps.situations.last_mut().unwrap().secteur_d_activite =
String::from_utf8_lossy(field.content).to_string();
}
(2, 5) => {
(2..=16, 5) => {
carte_ps
.situations
.last_mut()
@ -144,7 +144,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.type_d_identification_structure =
String::from_utf8_lossy(field.content).to_string();
}
(2, 6) => {
(2..=16, 6) => {
carte_ps
.situations
.last_mut()
@ -152,7 +152,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.numero_d_identification_structure =
String::from_utf8_lossy(field.content).to_string();
}
(2, 7) => {
(2..=16, 7) => {
carte_ps
.situations
.last_mut()
@ -160,7 +160,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.cle_du_numero_d_identification_structure =
String::from_utf8_lossy(field.content).to_string();
}
(2, 8) => {
(2..=16, 8) => {
carte_ps
.situations
.last_mut()
@ -168,7 +168,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.raison_sociale_structure =
String::from_utf8_lossy(field.content).to_string();
}
(2, 9) => {
(2..=16, 9) => {
carte_ps
.situations
.last_mut()
@ -176,7 +176,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.numero_d_identification_de_facturation_du_ps =
String::from_utf8_lossy(field.content).to_string();
}
(2, 10) => {
(2..=16, 10) => {
carte_ps
.situations
.last_mut()
@ -184,7 +184,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.cle_du_numero_d_identification_de_facturation_du_ps =
String::from_utf8_lossy(field.content).to_string();
}
(2, 11) => {
(2..=16, 11) => {
carte_ps
.situations
.last_mut()
@ -192,7 +192,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.numero_d_identification_du_ps_remplaçant =
String::from_utf8_lossy(field.content).to_string();
}
(2, 12) => {
(2..=16, 12) => {
carte_ps
.situations
.last_mut()
@ -200,35 +200,35 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.cle_du_numero_d_identification_du_ps_remplaçant =
String::from_utf8_lossy(field.content).to_string();
}
(2, 13) => {
(2..=16, 13) => {
carte_ps.situations.last_mut().unwrap().code_conventionnel =
String::from_utf8_lossy(field.content).to_string();
}
(2, 14) => {
(2..=16, 14) => {
carte_ps.situations.last_mut().unwrap().code_specialite =
String::from_utf8_lossy(field.content).to_string();
}
(2, 15) => {
(2..=16, 15) => {
carte_ps.situations.last_mut().unwrap().code_zone_tarifaire =
String::from_utf8_lossy(field.content).to_string();
}
(2, 16) => {
(2..=16, 16) => {
carte_ps.situations.last_mut().unwrap().code_zone_ik =
String::from_utf8_lossy(field.content).to_string();
}
(2, 17) => {
(2..=16, 17) => {
carte_ps.situations.last_mut().unwrap().code_agrement_1 =
String::from_utf8_lossy(field.content).to_string();
}
(2, 18) => {
(2..=16, 18) => {
carte_ps.situations.last_mut().unwrap().code_agrement_2 =
String::from_utf8_lossy(field.content).to_string();
}
(2, 19) => {
(2..=16, 19) => {
carte_ps.situations.last_mut().unwrap().code_agrement_3 =
String::from_utf8_lossy(field.content).to_string();
}
(2, 20) => {
(2..=16, 20) => {
carte_ps
.situations
.last_mut()
@ -236,7 +236,7 @@ fn decode_carte_ps(groups: Vec<Block>) -> Result<CartePS, String> {
.habilitation_à_signer_une_facture =
String::from_utf8_lossy(field.content).to_string();
}
(2, 21) => {
(2..=16, 21) => {
carte_ps
.situations
.last_mut()
@ -348,6 +348,46 @@ mod test_decode_carte_ps {
assert_eq!(carte_ps.situations[0].habilitation_à_signer_un_lot, "1");
}
#[test]
fn test_multiple_situations() {
let bytes: &[u8] = &[
0, 1, 51, // Block 01, Content size 51
1, 48, 1, 56, 11, 57, 57, 55, 48, 48, 53, 50, 52, 49, 57, 52, 1, 52, 2, 50, 50, 17, 80,
72, 65, 82, 77, 65, 67, 73, 69, 78, 48, 48, 53, 50, 52, 49, 57, 9, 70, 82, 65, 78, 67,
79, 73, 83, 69, 1, 84, 0, 2, 83, // Block 02, Content size 83
1, 1, 1, 48, 1, 49, 2, 56, 54, 1, 49, 9, 48, 66, 48, 50, 50, 49, 57, 53, 56, 1, 56, 24,
80, 72, 65, 82, 77, 65, 67, 73, 69, 32, 68, 85, 32, 67, 69, 78, 84, 82, 69, 50, 50, 49,
57, 53, 8, 48, 48, 50, 48, 50, 52, 49, 57, 1, 56, 0, 1, 48, 1, 49, 2, 53, 48, 2, 49,
48, 2, 48, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49, 0, 3,
83, // Block 03, Content size 83
1, 1, 1, 48, 1, 49, 2, 56, 54, 1, 49, 9, 48, 66, 48, 50, 50, 49, 57, 53, 56, 1, 56, 24,
80, 72, 65, 82, 77, 65, 67, 73, 69, 32, 68, 85, 32, 67, 69, 78, 84, 82, 69, 50, 50, 49,
57, 53, 8, 48, 48, 50, 48, 50, 52, 49, 57, 1, 56, 0, 1, 48, 1, 49, 2, 53, 48, 2, 49,
48, 2, 48, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49, 0, 4,
83, // Block 04, Content size 83
1, 1, 1, 48, 1, 49, 2, 56, 54, 1, 49, 9, 48, 66, 48, 50, 50, 49, 57, 53, 56, 1, 56, 24,
80, 72, 65, 82, 77, 65, 67, 73, 69, 32, 68, 85, 32, 67, 69, 78, 84, 82, 69, 50, 50, 49,
57, 53, 8, 48, 48, 50, 48, 50, 52, 49, 57, 1, 56, 0, 1, 48, 1, 49, 2, 53, 48, 2, 49,
48, 2, 48, 48, 1, 48, 1, 48, 1, 48, 1, 49, 1, 49,
];
let blocks = decode_ssv_memory(bytes, bytes.len());
let carte_ps = decode_carte_ps(blocks).unwrap();
assert_eq!(carte_ps.situations.len(), 3);
assert_eq!(
carte_ps.situations[0].raison_sociale_structure,
"PHARMACIE DU CENTRE22195"
);
assert_eq!(
carte_ps.situations[1].raison_sociale_structure,
"PHARMACIE DU CENTRE22195"
);
assert_eq!(
carte_ps.situations[2].raison_sociale_structure,
"PHARMACIE DU CENTRE22195"
);
}
#[test]
#[should_panic]
fn test_missing_field() {