@@ -53,6 +53,7 @@ const capinovReferential: Record<string, SSD2Id> = {
5353 'RF-0096-001-PPP' ,
5454 'Clodinafop (incl. S-clodinafop + sels)' : 'RF-0097-001-PPP' ,
5555 Cloquintocet : 'RF-0568-001-PPP' ,
56+ 'Chlormequat (+salts expr. as chlormequat chloride)' : 'RF-00005727-PAR' ,
5657 'Cyflufenamid (sum of E & Z isomers)' : 'RF-0107-001-PPP' ,
5758 'Cyfluthrin (incl. cyfluthrin-beta - sum of isomers)' : 'RF-0108-001-PPP' ,
5859 Cyhalofop : 'RF-00003378-PAR' ,
@@ -721,10 +722,17 @@ const capinovReferential: Record<string, SSD2Id> = {
721722 Vamidothion : 'RF-0969-001-PPP' ,
722723 Vinclozolin : 'RF-0450-003-PPP' ,
723724 'Warfarin (Coumaphene)' : 'RF-1043-001-PPP' ,
724- Zoxamide : 'RF-0452-001-PPP'
725+ Zoxamide : 'RF-0452-001-PPP' ,
726+ 'Aldicarb-metabolite (-sulfone expr. as aldicarb)' : 'RF-0020-004-PPP' ,
727+ 'Aldicarb-metabolite (-sufloxide expr. as aldicarb)' : 'RF-0020-003-PPP' ,
728+ Glyphosate : 'RF-1020-001-PPP' ,
729+ 'Glyphosate-metabolite (AMPA)' : 'RF-0471-001-PPP' ,
730+ Ethephon : 'RF-0160-001-PPP'
725731} ;
726732
727733const codeMethods = [
734+ 'LC/MS/MS' ,
735+ 'GC/MS/MS ou LC/MS/MS' ,
728736 'LC/MS/MS ou GC/MS/MS' ,
729737 'GC/MS/MS' ,
730738 'M.I. LC-MS/MS' ,
@@ -759,6 +767,8 @@ const codeMethods = [
759767] as const ;
760768
761769const codeMethodsAnalyseMethod = {
770+ 'LC/MS/MS' : 'Multi' ,
771+ 'GC/MS/MS ou LC/MS/MS' : 'Multi' ,
762772 'LC/MS/MS ou GC/MS/MS' : 'Multi' ,
763773 'GC/MS/MS' : 'Multi' ,
764774 'M.I. LC-MS/MS' : 'Multi' ,
@@ -807,17 +817,22 @@ const capinovCodeEchantillonValidator = z.string().transform((l) => {
807817// Visible for testing
808818export const extractAnalyzes = (
809819 fileContent : Record < string , string > [ ]
810- ) : Omit < ExportAnalysis , 'pdfFile' > [ ] => {
820+ ) : ( Omit < ExportAnalysis , 'pdfFile' > & { capinovRef : string } ) [ ] => {
811821 const fileValidator = z . array (
812822 z . object ( {
823+ PREFIXE_NOM : z . string ( ) ,
824+ DEMANDE_NUMERO : z . string ( ) ,
825+ ECHANT_NUMERO : z . string ( ) ,
813826 LOT : capinovCodeEchantillonValidator ,
814827 PARAMETRE_NOM : z . string ( ) ,
815828 RESULTAT_VALTEXTE : z . string ( ) ,
816829 RESULTAT_VALNUM : frenchNumberStringValidator ,
817830 PARAMETRE_LIBELLE : z . string ( ) ,
818831 LIMITE_LQ : z . string ( ) ,
819832 CAS_NUMBER : z . string ( ) . transform ( ( r ) => ( r === '' ? null : r ) ) ,
820- TECHNIQUE : z . enum ( [ ...codeMethods , 'Calcul' ] ) ,
833+ TECHNIQUE : z . enum ( [ ...codeMethods , 'Calcul' ] , {
834+ error : ( iss ) : string => `Received ${ iss . input } `
835+ } ) ,
821836 LMR_NUM : frenchNumberStringValidator . nullish ( ) ,
822837 // 16/04/2025
823838 ECHANT_DATE_DIFFUSION : z
@@ -848,12 +863,14 @@ export const extractAnalyzes = (
848863 }
849864
850865 const resultsBySample = groupBy ( resultatsData , 'LOT' ) ;
851- const result : Omit < ExportAnalysis , 'pdfFile' > [ ] = [ ] ;
866+ const result : ReturnType < typeof extractAnalyzes > = [ ] ;
852867
853868 for ( const sampleReference in resultsBySample ) {
854- const analysis : Omit < ExportAnalysis , 'pdfFile' > = {
869+ const firstLine = resultsBySample [ sampleReference ] [ 0 ] ;
870+ const analysis : ( typeof result ) [ number ] = {
855871 sampleReference,
856- notes : resultatsData [ 0 ] . COMMENTAIRE ?? '' ,
872+ capinovRef : `${ firstLine . PREFIXE_NOM } ${ firstLine . DEMANDE_NUMERO } ${ firstLine . ECHANT_NUMERO } ` ,
873+ notes : firstLine . COMMENTAIRE ?? '' ,
857874 residues : [ ]
858875 } ;
859876
@@ -913,7 +930,9 @@ const exportDataFromEmail: ExportDataFromEmail = async (attachments) => {
913930
914931 for ( const analysis of analyzes ) {
915932 const pdfAttachment = attachments . find (
916- ( { contentType } ) => contentType === 'application/pdf'
933+ ( { contentType, filename } ) =>
934+ contentType === 'application/pdf' &&
935+ filename ?. startsWith ( analysis . capinovRef )
917936 ) ;
918937
919938 if ( pdfAttachment === undefined ) {
0 commit comments