🎉 first commit

This commit is contained in:
2023-09-10 17:31:20 +02:00
parent e9a19071c2
commit a6bc695506
28 changed files with 1336 additions and 97 deletions

View File

@@ -1,6 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {Title} from "@angular/platform-browser";
import {EngineService} from "./services/engine.service";
import {TreatmentsService} from "./services/treatments.service";
@Component({
selector: 'app-root',
@@ -8,11 +9,11 @@ import {EngineService} from "./services/engine.service";
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
titleStr = 'Help Contra';
titleStr = 'Gynette';
constructor(private title: Title, private engine: EngineService) {
constructor(private title: Title, private engine: EngineService, private treatments: TreatmentsService) {
this.engine.loadOutcomes();
this.engine.loadTreatments();
this.treatments.loadTreatments();
}

View File

@@ -10,6 +10,8 @@ import { PageFormComponent } from './pages/page-form/page-form.component';
import { LogoComponent } from './compos/logo/logo.component';
import {HttpClientModule} from "@angular/common/http";
import { ResultsComponent } from './compos/results/results.component';
import { TreatmentDetailsModalComponent } from './compos/treatment-details-modal/treatment-details-modal.component';
import { FormattedLineComponent } from './compos/treatment-details-modal/formatted-line/formatted-line.component';
@NgModule({
declarations: [
@@ -20,6 +22,8 @@ import { ResultsComponent } from './compos/results/results.component';
PageFormComponent,
LogoComponent,
ResultsComponent,
TreatmentDetailsModalComponent,
FormattedLineComponent,
],
imports: [
BrowserModule,

View File

@@ -1 +1 @@
<div class="logo">help<span class="contra">Contra</span></div>
<div class="logo"><span class="contra">Gyn</span>ette</div>

View File

@@ -10,7 +10,6 @@
background-color: $color-E;
color: #FFF;
border-radius: 8px;
text-transform: uppercase;
padding: 4px 8px;
margin-left: 4px;
}

View File

@@ -24,7 +24,7 @@
</div>
<div class="buttons">
<button *ngIf="!isFirstQuestion" class="btn secondary">Question précédente</button>
<button *ngIf="!isFirstQuestion" class="btn secondary" (click)="previous()">Question précédente</button>
<button *ngIf="!isLastQuestion" [disabled]="hasTaken === undefined" class="btn" (click)="next()">Question suivante</button>
<button *ngIf="isLastQuestion" [disabled]="hasTaken === undefined" class="btn" (click)="validate()">Valider</button>
</div>

View File

@@ -2,18 +2,20 @@
<div class="container">
<app-logo></app-logo>
<h2>Résultats</h2>
<div class="explanation">
<p>Les résultats sont classés du plus recommandé au moins recommandé.</p>
<p>Les résultats sont classés du plus conseillé au moins conseillé.</p>
<p>Cliquez sur un traitement pour plus d'information.</p>
</div>
<h3>Recommandé</h3>
<div class="recommendation" *ngFor="let r of recommendations">
<div class="treatment">{{r.treatment.label}} ({{r.score}})</div>
</div>
<h3 class="discouragement">Non-recommandé</h3>
<div class="recommendation" *ngFor="let r of discouragements">
<div class="treatment">{{r.treatment.label}} ({{r.score}})</div>
<h3>Conseils</h3>
<div class="recommendation" *ngFor="let r of recommendations.concat(discouragements)">
<div class="treatment" [style.border-color]="computeScoreColor(r.score)" [style.color]="computeScoreColor(r.score)" (click)="openTreatmentDetails(r.treatment.code)">{{r.treatment.label}} ({{r.score}})</div>
</div>
<button class="btn" (click)="onReset.emit()">Relancer le formulaire</button>
</div>
<ng-container *ngIf="currentDetailsCode">
<app-treatment-details-modal [treatmentCode]="currentDetailsCode" (onClose)="closeTreatmentDetails()"></app-treatment-details-modal>
</ng-container>

View File

@@ -36,8 +36,18 @@
& .treatment {
font-size: 16px;
margin-bottom: 8px;
border-left: 6px solid transparent;
padding: 8px;
cursor: pointer;
&:hover{
text-decoration: underline;
}
}
}
}
.btn {
margin-top: 32px;
}

View File

@@ -12,6 +12,8 @@ export class ResultsComponent implements OnInit {
recommendations: RecommendationModel[] = [];
discouragements: RecommendationModel[] = [];
currentDetailsCode: string | null = null;
@Output() onReset: EventEmitter<void> = new EventEmitter<void>();
constructor(private engine: EngineService, private answers: AnswersService) { }
@@ -21,4 +23,36 @@ export class ResultsComponent implements OnInit {
this.recommendations = recommendations.filter((r) => r.score >= 0).sort((r1, r2) => r2.score - r1.score);
this.discouragements = recommendations.filter((r) => r.score < 0);
}
openTreatmentDetails = (code: string): void => {
this.currentDetailsCode = code;
}
closeTreatmentDetails = () => {
this.currentDetailsCode = null;
}
computeScoreColor = (score: number) => {
score += 1;
// warning, we put ourselves in a [1.5, 0] range instead of [0.5, -1]
const maxScore = 1.5;
if(score > maxScore){
score = maxScore;
}
return lerpColor("#d3274f", "#3fa58f", score / maxScore);
}
}
const lerpColor = (a: string, b: string, amount: number) => {
const ah = +a.replace('#', '0x'),
ar = ah >> 16, ag = ah >> 8 & 0xff, ab = ah & 0xff,
bh = +b.replace('#', '0x'),
br = bh >> 16, bg = bh >> 8 & 0xff, bb = bh & 0xff,
rr = ar + amount * (br - ar),
rg = ag + amount * (bg - ag),
rb = ab + amount * (bb - ab);
return '#' + ((1 << 24) + (rr << 16) + (rg << 8) + rb | 0).toString(16).slice(1);
}

View File

@@ -0,0 +1,3 @@
<p>
<span>{{treatment}}</span> {{info}}
</p>

View File

@@ -0,0 +1,6 @@
@import "../../../../styles/variables.scss";
span {
color: $color-B;
font-weight: 500;
}

View File

@@ -0,0 +1,27 @@
import {Component, Input, OnInit} from '@angular/core';
@Component({
selector: 'app-formatted-line',
templateUrl: './formatted-line.component.html',
styleUrls: ['./formatted-line.component.scss']
})
export class FormattedLineComponent implements OnInit {
@Input() line!: string;
treatment!: string;
info!: string;
constructor() { }
ngOnInit(): void {
const split = this.line.split(':');
if(split.length > 1){
this.treatment = split[0];
this.info = this.line.replace(`${this.treatment}`, '');
}else{
this.info = this.line;
}
}
}

View File

@@ -0,0 +1,25 @@
<div class="container">
<div class="modal">
<div class="header">
<h2>{{details.treatment.label}}</h2>
<button title="Fermer le traitement" (click)="onClose.emit()">X</button>
</div>
<div class="scrollable">
<div class="sections">
<div class="section" *ngFor="let section of details.sections" [ngClass]="{'free': section.type === 'free'}">
<h3>{{section.title}}</h3>
<div class="section-line" *ngFor="let line of section.rows">
<ng-container *ngIf="section.type === 'free'">
<p>{{line}}</p>
</ng-container>
<ng-container *ngIf="section.type === 'formatted'">
<app-formatted-line [line]="line"></app-formatted-line>
</ng-container>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,84 @@
@import "../../../styles/variables.scss";
.container {
position: fixed;
inset: 0;
z-index: 999;
background-color: #00000033;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.modal {
position: relative;
height: 80vh;
width: 80vw;
max-width: 80vw;
background-color: #FFFFFF;
padding: 32px;
border-radius: 32px;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 32px;
padding-bottom: 16px;
border-bottom: 2px solid $border-color;
& button {
border: none;
background-color: $color-E;
color: white;
font-size: 2em;
width: 40px;
height: 40px;
border-radius: 50%;
&:hover {
background-color: darken($color-E, 10%);
cursor: pointer;
}
}
}
.scrollable {
overflow-y: auto;
max-height: 90%;
}
h2 {
font-size: 1.5em;
font-weight: 500;
color: $color-B;
}
h3 {
font-size: 1.2em;
margin-bottom: 8px;
font-weight: 500;
color: $color-B;
}
.sections {
display: flex;
flex-direction: column;
gap: 32px;
}
.section {
border-left: 4px solid $color-B;
padding-left: 8px;
line-height: 24px;
&.free {
border-color: $color-A;
& h3 {
color: $color-A;
}
}
}

View File

@@ -0,0 +1,28 @@
import {Component, EventEmitter, Input, Output, OnInit, HostListener} from '@angular/core';
import {Section, TreatmentDetails} from "../../models";
import {TreatmentsService} from "../../services/treatments.service";
@Component({
selector: 'app-treatment-details-modal',
templateUrl: './treatment-details-modal.component.html',
styleUrls: ['./treatment-details-modal.component.scss']
})
export class TreatmentDetailsModalComponent implements OnInit {
@Input() treatmentCode!: string;
@Output() onClose: EventEmitter<void> = new EventEmitter();
details!: TreatmentDetails;
constructor(private treatmentsService: TreatmentsService) { }
ngOnInit(): void {
this.details = this.treatmentsService.getTreatmentDetails(this.treatmentCode);
this.details.sections = this.details.sections.sort((s1: Section, s2: Section) => (s1.type === "free") ? 1 : -1);
}
@HostListener('document:keydown.escape', ['$event']) onKeydownHandler(event: KeyboardEvent) {
this.onClose.emit();
}
}

View File

@@ -1,4 +1,20 @@
export interface Treatment {
code: string;
label: string;
weight: number;
}
export type SectionType = "info" | "formatted" | "free";
export interface TreatmentDetails {
treatment: Treatment;
sections: Section[];
}
export interface Section {
type: SectionType;
title: string;
rows: string[];
}

View File

@@ -1,6 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {AfterViewInit, Component, OnInit} from '@angular/core';
import {Question, QUESTIONS} from "../../questions.constants";
import {AnswersService} from "../../services/answers.service";
import {TreatmentsService} from "../../services/treatments.service";
@Component({
selector: 'app-page-form',

View File

@@ -22,6 +22,22 @@ export const QUESTIONS = [
{ key: 'G', label: "Cholestase, Lithiase / cholécystite, Tumeur bénigne du foie", description: "HNF, adénome" }
]
},
{
id: 2,
question: "La patiente a déjà pris une contraception *oestroprogestative par anneau vaginal",
symptoms: [
{ key: 'B', label: "Effets indésirables de type androgéniques", description: "Acné, Pilosité, Prise de poids, Diminution de la libido, Humeur dépressive" },
{ key: 'C', label: "Effets indésirables de type oestrogéniques", description: "Céphalées non migraineuses, Tensions mammaires / Mastodynies, Irritabilité, Nausées , Ballonnement, Jambes lourdes / rétention hydrique, HTA (non contre-indiquant)" },
{ key: 'D', label: "Spottings" },
{ key: 'E', label: "Dysménorrhées" },
{ key: 'F', label: "Modifications métaboliques", description: "Dyslipidémie, métabolisme glucidique" },
{ key: 'G', label: "Cholestase, Lithiase / cholécystite, Tumeur bénigne du foie", description: "HNF, adénome" },
{ key: 'H', label: "Vaginite / Leucorrhées"}
]
},
{
id: 3,
question: "La patiente a-t-elle déjà pris une contraception *oestroprogestative par patch transdermique",
@@ -96,5 +112,5 @@ export const QUESTIONS = [
{ key: 'D', label: "Brûlures vaginales liées au spermicide" },
{ key: 'E', label: "Douleurs locales liées au dispositif à taille unique" },
]
},
}
]

View File

@@ -1,6 +1,7 @@
import {Injectable, OnInit} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {Treatment} from "../models";
import {TreatmentsService} from "./treatments.service";
interface Outcomes {
firstIntent: string[];
@@ -25,9 +26,8 @@ const DISCOURAGED_SCORE = -1;
export class EngineService {
OUTCOMES_MAP: Record<string, Outcomes> = {};
TREATMENTS_MAP: Record<string, Treatment> = {};
constructor(private http: HttpClient) {
constructor(private http: HttpClient, private treatmentsService: TreatmentsService) {
}
loadOutcomes(): void {
@@ -37,30 +37,15 @@ export class EngineService {
for (let index = 1; index < csvToRowArray.length - 1; index++) {
let row = csvToRowArray[index].split("\t");
this.OUTCOMES_MAP[row[0]] = {
firstIntent: row[1].replace('\r', '').split(''),
secondIntent: row[2].replace('\r', '').split(''),
discouraged: row[3].replace('\r', '').split('')
firstIntent: row[1].replace('\r', '').replace('_', '').split(''),
secondIntent: row[2].replace('\r', '').replace('_', '').split(''),
discouraged: row[3].replace('\r', '').replace('_', '').split('')
};
}
console.log('Outcomes loaded', this.OUTCOMES_MAP);
});
};
loadTreatments(): void {
this.http.get('assets/engine/treatments.tsv', {responseType: 'text'})
.subscribe((data) => {
let csvToRowArray = data.split("\n");
for (let index = 1; index < csvToRowArray.length - 1; index++) {
let row = csvToRowArray[index].split("\t");
this.TREATMENTS_MAP[row[0]] = {
weight: parseFloat(row[1]),
label: row[2]
};
}
console.log('Treatments loaded', this.TREATMENTS_MAP);
});
}
fromAnswerIndexesToOutcomes = (answerIndexes: string[]): Outcomes => {
const globalOutcomes: Outcomes = {
@@ -87,12 +72,8 @@ export class EngineService {
fromOutcomeToRecommendations = (globalOutcomes: Outcomes): Recommendations => {
const recommendations: Recommendations = {};
console.log(globalOutcomes.firstIntent);
console.log(globalOutcomes.secondIntent);
console.log(globalOutcomes.discouraged);
globalOutcomes.firstIntent.forEach((treatmentCode: string) => {
const treatment = this.fromCodeToTreatment(treatmentCode);
const treatment = this.treatmentsService.getTreatmentDetails(treatmentCode).treatment;
if(!recommendations[treatmentCode]){
recommendations[treatmentCode] = 0;
@@ -101,7 +82,7 @@ export class EngineService {
});
globalOutcomes.secondIntent.forEach((treatmentCode: string) => {
const treatment = this.fromCodeToTreatment(treatmentCode);
const treatment = this.treatmentsService.getTreatmentDetails(treatmentCode).treatment;
if(!recommendations[treatmentCode]){
recommendations[treatmentCode] = 0;
@@ -127,19 +108,11 @@ export class EngineService {
for (let k in recommendations){
recommendationArray.push({
treatment: this.fromCodeToTreatment(k as string),
treatment: this.treatmentsService.getTreatmentDetails(k as string).treatment,
score: recommendations[k]
})
}
return recommendationArray;
}
fromCodeToTreatment = (treatmentCode: string): Treatment => {
const treatment: Treatment = this.TREATMENTS_MAP[treatmentCode];
if(!treatment){
throw new Error(`Could not find treatment for code: ${treatmentCode}`);
}
return treatment;
}
}

View File

@@ -0,0 +1,138 @@
import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {take} from "rxjs";
import {Section, SectionType, Treatment, TreatmentDetails} from "../models";
const isEmptyLine = (row: string): boolean => {
const trimmed = row.trim();
return trimmed === "" || trimmed === "\n";
}
const isSectionLine = (row: string): boolean => {
return row.startsWith('#');
}
const getSectionType = (firstSectionRow: string): SectionType => {
if(firstSectionRow.startsWith('###')){
return "free";
}else if (firstSectionRow.startsWith('##')){
return "formatted";
}else if (firstSectionRow.startsWith('#')){
return "info";
}else{
throw new Error(`First row of section has no recognizable pattern: ${firstSectionRow}`);
}
}
const parseTreatmentInfo = (row: string): Treatment => {
const split = row.replace('#', '').split(',');
if(split.length !== 3){
throw new Error(`Invalid treatment line: ${row}`);
}
return {
code: split[0].trim(),
weight: parseFloat(split[1].trim()),
label: split[2].trim()
}
}
const parseSectionTitle = (row: string, sectionType: SectionType): string => {
switch(sectionType){
case "info":
throw new Error(`Should not try to parse section title for info line: ${row}`);
case "formatted":
return row.replace('##', '').trim();
case "free":
return row.replace('###', '').trim();
}
}
@Injectable({
providedIn: 'root'
})
export class TreatmentsService {
private TREATMENT_DETAILS: TreatmentDetails[] = [];
constructor(private http: HttpClient) {}
public loadTreatments = () => {
this.http.get('assets/engine/treatments.txt', {responseType: 'text'})
.pipe(take(1))
.subscribe((data) => {
let rows = data.split("\n");
let currentSectionType: SectionType | null = null;
let currentSection: Section | null = null;
let currentTreatmentDetails: TreatmentDetails | null = null;
rows.forEach((row: string) => {
// ignore empty lines
if(isEmptyLine(row)){
return;
}
if(isSectionLine(row)){
// new section starts
currentSectionType = getSectionType(row);
if(currentSectionType === "info"){
// new treatment starts
// push previous treatment if exists
if(currentTreatmentDetails){
this.TREATMENT_DETAILS.push(currentTreatmentDetails);
}
// init next treatment
currentTreatmentDetails = {
treatment: parseTreatmentInfo(row),
sections: []
};
}else{
// new free or formatted section starts
// push previous section if exists
if(currentSection){
if(currentTreatmentDetails){
currentTreatmentDetails.sections.push(currentSection)
}else{
throw new Error(`Tried to push section in a non existing treatment: ${currentSection}`);
}
}
currentSection = {
type: currentSectionType,
title: parseSectionTitle(row, currentSectionType),
rows: []
}
}
return;
}
// new line of current section
if(currentSection){
currentSection.rows.push(row.trim());
}else{
throw new Error(`Tried to push row without a section: ${row}`);
}
});
console.log(this.TREATMENT_DETAILS);
});
}
public getTreatmentDetails = (code: string): TreatmentDetails => {
const treatment: TreatmentDetails | undefined = this.TREATMENT_DETAILS.find((t: TreatmentDetails) => t.treatment.code === code);
if(!treatment){
throw new Error(`Could not find treatment of code: ${code}`);
}
return treatment;
}
}