Skip to content

Commit

Permalink
Merge pull request #54 from EveCrystali/dev/DiabetesRiskPrediction---…
Browse files Browse the repository at this point in the history
…Enhance-prediction-quality-#49

Dev/diabetes risk prediction   enhance prediction quality #49
  • Loading branch information
EveCrystali authored Nov 13, 2024
2 parents da83564 + 4063685 commit 6279e5c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ public class DiabetesRiskNotePredictionService(ILogger<DiabetesRiskNotePredictio

private readonly HashSet<string> triggerWords =
[
// TODO: Hémoglobine A1C is still consider as two separated words
"Hémoglobine A1C",
"Microalbumine",
"Taille",
"Poids",
"Fumeur",
"Fumeuse",
"Fumer",
"Anormal",
"Cholestérol",
"Vertiges",
Expand Down
90 changes: 1 addition & 89 deletions BackendDiabetesRiskPrediction/Services/ElasticsearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@ public async Task<int> CountUniqueWordsInNotes(int patientId, HashSet<string> wo
return 0;
}

_logger.LogInformation("Found {total} notes for PatientId: {patientId}", response.HitsMetadata.Total.Value, patientId);

foreach (IHit<NoteRiskInfo> hit in response.Hits)
{
_logger.LogDebug("Note found: {note}", hit.Source.Body);
}

_logger.LogInformation("Search query executed successfully.");
_logger.LogInformation("Found {total} notes for PatientId: {patientId}", response?.HitsMetadata?.Total.Value, patientId);

Check warning on line 100 in BackendDiabetesRiskPrediction/Services/ElasticsearchService.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Conditional access qualifier expression is known to be null or not null

Conditional access qualifier expression is known to be not null

// Step 3: Analyze the Body text of each document and count unique matching words
HashSet<string> uniqueWordsInNotes = new();

Check notice on line 103 in BackendDiabetesRiskPrediction/Services/ElasticsearchService.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
Expand Down Expand Up @@ -139,87 +132,6 @@ public async Task<int> CountUniqueWordsInNotes(int patientId, HashSet<string> wo

_logger.LogInformation("Unique word count is: {uniqueWordCount}", uniqueWordCount);

_logger.LogInformation("Unique words found: {uniqueWords}", string.Join(", ", uniqueWordsInNotes));

return uniqueWordCount;
}

// if (response.HitsMetadata?.Total.Value == 0)
// {
// _logger.LogWarning("NO PATIENTS FOUND WITH PATIENTID: {patientId}", patientId);
// }

// if (response.IsValid)
// {
// _logger.LogInformation("Search query executed successfully.");
// }
// else
// {
// _logger.LogError("Search query failed. Reason: {reason}", response.OriginalException.Message);
// }

// if (!response.IsValid)
// {
// throw new Exception($"Failed to search notes: {response.OriginalException.Message}");
// }

// // Étape 3 : Extraire les termes uniques de l'agrégation
// TermsAggregate<string> termsAgg = response.Aggregations.Terms("unique_terms");

// if (termsAgg != null)
// {
// _logger.LogInformation($"Unique word count is : {termsAgg.Buckets.Count}");
// return termsAgg.Buckets.Count;
// }
// else
// {
// _logger.LogInformation("Unique word count is : 0");
// return 0;
// }
// }


// public async Task<int> CountUniqueWordsInNotes(int patientId, HashSet<string> wordsToCount)
// {
// _logger.LogInformation("CountWordsInNotes called");

// var response = await _elasticsearchClient.SearchAsync<NoteRiskInfo>(s => s
// .Query(q => q
// .Bool(b => b
// .Must(m => m.Term("PatientId", patientId)) // Utilisation correcte du champ
// .Should(wordsToCount.Select(word => (Func<QueryContainerDescriptor<NoteRiskInfo>, QueryContainer>)(m => m.Match(mt => mt
// .Field("Body")
// .Query(word)
// .Analyzer("custom_french_analyzer"))))
// .ToArray())
// .MinimumShouldMatch(1)
// )
// )
// .Aggregations(a => a
// .Terms("unique_word_counts", t => t
// .Field("Body.keyword")
// .Size(10000)
// )
// )
// );

// if (!response.IsValid)
// {
// throw new Exception($"Failed to search notes: {response.OriginalException.Message}");
// }

// // Extraire les résultats d'agrégation
// var uniqueWordsFound = new HashSet<string>();
// var termsAgg = response.Aggregations.Terms("unique_word_counts");
// if (termsAgg != null)
// {
// foreach (var bucket in termsAgg.Buckets)
// {
// uniqueWordsFound.Add(bucket.Key.ToString().ToLowerInvariant());
// }
// }

// _logger.LogInformation($"Unique word count is : {uniqueWordsFound.Count}");
// return uniqueWordsFound.Count;
// }
}
4 changes: 2 additions & 2 deletions Frontend/Controllers/NotesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public async Task<IActionResult> Create(Note note)
return View(note);
}

[HttpGet("edit/{id}")]
[HttpGet("edit/{id:int}")]
public async Task<IActionResult> Edit(string id)

Check notice on line 137 in Frontend/Controllers/NotesController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Parameter's type can be made stricter due to applied constraints

Type of parameter 'id' can be made 'int' because of applied constraint 'IntRouteConstraint'
{
if (ModelState.IsValid)
Expand All @@ -158,7 +158,7 @@ public async Task<IActionResult> Edit(string id)
return View();
}

[HttpPost("edit/{id}")]
[HttpPost("edit/{id:int}")]

Check notice on line 161 in Frontend/Controllers/NotesController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

RoslynAnalyzers Unused route parameter

Unused route parameter 'id'

Check notice on line 161 in Frontend/Controllers/NotesController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Route parameter can be passed to method

Route parameter 'id' is not passed to method
public async Task<IActionResult> Edit(Note note)

Check notice on line 162 in Frontend/Controllers/NotesController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Not all route parameters are passed to method

Not all route parameters are passed to the method
{
note.LastUpdatedDate = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
Expand Down
4 changes: 2 additions & 2 deletions Frontend/Controllers/PatientsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public async Task<IActionResult> Details(int id)

patientViewModel.DiabetesRiskPrediction = await responseFromDiabetesRiskService.Content.ReadFromJsonAsync<DiabetesRiskPrediction>();


return View(patientViewModel);
}

Expand Down Expand Up @@ -169,7 +168,8 @@ public async Task<IActionResult> Edit(int id)
return View();
}

[HttpPost("edit")]
[HttpPost("edit/{id:int}")]

Check notice on line 171 in Frontend/Controllers/PatientsController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

RoslynAnalyzers Unused route parameter

Unused route parameter 'id'

Check notice on line 171 in Frontend/Controllers/PatientsController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Route parameter can be passed to method

Route parameter 'id' is not passed to method
// TODO: Cette page n’est pas disponible pour le moment Si le problème persiste, contactez le propriétaire du site. HTTP ERROR 405
public async Task<IActionResult> Edit(Patient patient)

Check notice on line 173 in Frontend/Controllers/PatientsController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Not all route parameters are passed to method

Not all route parameters are passed to the method
{
if (ModelState.IsValid)
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ services:
mem_limit: 2g

init-template:
image: curlimages/curl:latest # Image légère pour exécuter des commandes curl
image: curlimages/curl:latest
container_name: init-template
depends_on:
- elasticsearch
Expand All @@ -56,8 +56,7 @@ services:
curl -X PUT 'http://elasticsearch:9200/_index_template/notes_index_template' \
-H 'Content-Type: application/json' \
-d @/usr/share/elasticsearch/config/notes_index_template.json;
echo 'Template loaded successfully!';
"
echo 'Template loaded successfully!';"
volumes:
- ./elasticsearch/config/notes_index_template.json:/usr/share/elasticsearch/config/notes_index_template.json
networks:
Expand Down Expand Up @@ -238,3 +237,4 @@ volumes:
networks:
elastic:
driver: bridge

7 changes: 6 additions & 1 deletion elasticsearch/config/notes_index_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"filter": [
"lowercase",
"french_stem",
"asciifolding"
"asciifolding",
"french_stop"
]
}
},
Expand All @@ -31,6 +32,10 @@
"french_stem": {
"type": "stemmer",
"language": "light_french"
},
"french_stop": {
"type": "stop",
"stopwords": "_french_"
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions elasticsearch/elasticsearch.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ COPY /config/elasticsearch.yml /usr/share/elasticsearch/config/config/elasticsea
COPY load_template.sh /usr/local/bin/load_template.sh
RUN chmod +x /usr/local/bin/load_template.sh

# Copier le script de configuration
COPY setup_pipeline.sh /usr/share/elasticsearch/setup_pipeline.sh
RUN chmod +x /usr/share/elasticsearch/setup_pipeline.sh

# Lancer le script après le démarrage d'Elasticsearch
CMD ["sh", "-c", "/usr/local/bin/docker-entrypoint.sh && /usr/share/elasticsearch/setup_pipeline.sh"]

# Configuration de l'environnement
ENV discovery.type=single-node
Expand Down

0 comments on commit 6279e5c

Please sign in to comment.