github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/frontend/directeurs/src/components/inscrits/FichesSanitaires.ts (about) 1 import Vue from "vue"; 2 import Component from "vue-class-component"; 3 import { C } from "@/logic/controller"; 4 import { Formatter } from "@/logic/formatter"; 5 import { 6 DownloadFicheSanitaireIn, 7 Inscrit, 8 OptionnalBool 9 } from "@/logic/types"; 10 import ToolbarSwitch from "../ToolbarSwitch.vue"; 11 import TooltipBtn from "@/components/TooltipBtn.vue"; 12 13 type FilterFiche = 14 | "traitement" 15 | "allergies_all" 16 | "allergies_asthme" 17 | "allergies_alimentaires" 18 | "allergies_medicamenteuses" 19 | "allergies_autres"; 20 type FilterOption = { value: FilterFiche; text: string } | { divider: boolean }; 21 22 const FichesSanitairesProps = Vue.extend({ 23 props: { 24 items: Array as () => Inscrit[] 25 } 26 }); 27 @Component({ 28 components: { ToolbarSwitch, TooltipBtn } 29 }) 30 export class FichesSanitaires extends FichesSanitairesProps { 31 filterFiches: FilterFiche | null = null; 32 showDownloadOptions = false; 33 downloadOptions: DownloadFicheSanitaireIn = { 34 mode: "all_in_one_document", 35 tri_groupe: true, 36 only_mineurs: true, 37 id_participant: -1 38 }; 39 headers = [ 40 { text: "Participant", value: "nom_prenom" }, 41 { 42 text: "Remplie", 43 value: "is_fiche_sanitaire_up_to_date", 44 align: "center" 45 }, 46 { text: "Documents", value: "document", align: "center" }, 47 { text: "Accès", value: "lien_fiche_sanitaire" } 48 ]; 49 50 fmt = Formatter; 51 asI = (ins: Inscrit) => ins; // for template type checking 52 53 get filteredItems() { 54 return this.items.filter(r => { 55 const al = r.fiche_sanitaire.allergies; 56 if (this.filterFiches == "traitement") { 57 return r.fiche_sanitaire.traitement_medical; 58 } else if (this.filterFiches == "allergies_all") { 59 return al.alimentaires || al.asthme || al.autres || al.medicamenteuses; 60 } else if (this.filterFiches == "allergies_alimentaires") { 61 return al.alimentaires; 62 } else if (this.filterFiches == "allergies_medicamenteuses") { 63 return al.medicamenteuses; 64 } else if (this.filterFiches == "allergies_autres") { 65 return al.autres; 66 } else if (this.filterFiches == "allergies_asthme") { 67 return al.asthme; 68 } else { 69 // pas de filtre 70 return true; 71 } 72 }); 73 } 74 75 filterOptions: FilterOption[] = [ 76 { value: "traitement", text: "Traitement médical" }, 77 { divider: true }, 78 { value: "allergies_all", text: "Toutes les allergies" }, 79 { divider: true }, 80 { value: "allergies_asthme", text: "Asthme" }, 81 { value: "allergies_alimentaires", text: "Allergies alimentaires" }, 82 { value: "allergies_medicamenteuses", text: "Allergies médicamenteuses" }, 83 { value: "allergies_autres", text: "Autres allergies" } 84 ]; 85 86 colorDocument(item: Inscrit) { 87 if (item.age_debut_camp < 18) { 88 if (this.hasVaccins(item) || this.hasFicheSanitaire(item)) { 89 return "green"; 90 } else { 91 return "orange"; 92 } 93 } 94 } 95 96 colorUpTodate(item: Inscrit) { 97 const status = item.is_fiche_sanitaire_up_to_date; 98 if (status == OptionnalBool.OBOui) { 99 return "green"; 100 } else if (status == OptionnalBool.OBPeutEtre) { 101 return "orange"; 102 } 103 return "red"; 104 } 105 106 hasVaccins(item: Inscrit) { 107 return (item.vaccins || []).length > 0; 108 } 109 110 hasFicheSanitaire(item: Inscrit) { 111 const date = new Date((item.fiche_sanitaire || {}).last_modif); 112 return date.getFullYear() > 1; 113 } 114 115 async downloadAll() { 116 this.showDownloadOptions = false; 117 const file = await C.downloadFicheSanitaire(this.downloadOptions); 118 if (file === undefined) return; 119 C.notifications.success = "Fiches sanitaires téléchargées avec succés."; 120 } 121 122 downloadFicheSanitaire(item: Inscrit) { 123 C.downloadFicheSanitaire({ 124 mode: "one", 125 id_participant: item.id, 126 tri_groupe: false, 127 only_mineurs: false 128 }); 129 C.notifications.success = "Fiche sanitaire téléchargée avec succés."; 130 // downloadFicheSanitaire( 131 132 // onDone, 133 // this.showError, 134 // this.$root 135 // ); 136 } 137 }