Skip to content

Commit

Permalink
Merge pull request #55 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 14, 2024
2 parents 6279e5c + b05d365 commit 981f19d
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public async Task<int> CountUniqueWordsInNotes(int patientId, HashSet<string> wo
continue;
}


IEnumerable<string> bodyTokens = analyzeBodyResponse.Tokens.Select(token => token.Token);

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

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred 'var' style (elsewhere)

Use 'var' (elsewhere)

IEnumerable<string> commonWords = bodyTokens.Intersect(analyzedWords);

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

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred 'var' style (elsewhere)

Use 'var' (elsewhere)
Expand Down
61 changes: 42 additions & 19 deletions BackendPatient/Data/DataSeeder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BackendPatient.Models;
using Microsoft.EntityFrameworkCore;
namespace BackendPatient.Data;

public class DataSeeder(ApplicationDbContext dbContext)
Expand All @@ -12,7 +13,7 @@ public void SeedPatients()
{

Check notice on line 13 in BackendPatient/Data/DataSeeder.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
("TestNone", "Test", "1966-12-31", "F", "1 Brookside St", "100-222-3333"),
("TestBorderline", "Test", "1945-06-24", "M", "2 High St", "200-333-4444"),
("TestInDanger", "Test", "2004-06-18", "M", "3 Club Road", "300-444-5555"),
("TestInDanger", "Test", "2005-06-18", "M", "3 Club Road", "300-444-5555"),
("TestEarlyOnset", "Test", "2002-06-28", "F", "4 Valley Dr", "400-555-6666")
};

Expand All @@ -34,33 +35,55 @@ public void SeedPatients()
int batchSize = 10;

Check notice on line 35 in BackendPatient/Data/DataSeeder.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert local variable or field into constant (private accessibility)

Convert into constant

Check notice on line 35 in BackendPatient/Data/DataSeeder.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred 'var' style (for built-in types)

Use 'var' (built-in types)
int counter = 0;

Check notice on line 36 in BackendPatient/Data/DataSeeder.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred 'var' style (for built-in types)

Use 'var' (built-in types)

foreach (Patient patient in patientsFormatted)
using var transaction = _dbContext.Database.BeginTransaction();
try
{
// Avoid duplicate patients
if (existingPatients.Exists(p => p.FirstName == patient.FirstName &&
p.LastName == patient.LastName &&
p.DateOfBirth == patient.DateOfBirth))
SetIdentityInsert("Patients", true);

Check warning on line 41 in BackendPatient/Data/DataSeeder.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant argument with default value

The parameter 'enable' has the same default value

foreach (Patient patient in patientsFormatted)

Check notice on line 43 in BackendPatient/Data/DataSeeder.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred 'var' style (when type is simple)

Use 'var' (simple types)
{
Console.WriteLine($"Skipping duplicate patient: {patient.FirstName} {patient.LastName} {patient.DateOfBirth}");
continue;
}
// Avoid duplicate patients
if (existingPatients.Exists(p => p.FirstName == patient.FirstName &&
p.LastName == patient.LastName &&
p.DateOfBirth == patient.DateOfBirth))
{
Console.WriteLine($"Skipping duplicate patient: {patient.FirstName} {patient.LastName} {patient.DateOfBirth}");
continue;
}
patient.Id = counter + 1;
_dbContext.Patients.Add(patient);
counter++;

_dbContext.Patients.Add(patient);
counter++;
// Save every 10 patients (batch size)
if (counter % batchSize == 0)

Check notice on line 58 in BackendPatient/Data/DataSeeder.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Invert 'if' statement to reduce nesting

Invert 'if' statement to reduce nesting
{
_dbContext.SaveChanges();
Console.WriteLine($"Saved {counter} patients so far...");
}
}

// Save every 10 patients (batch size)
if (counter % batchSize == 0)
// Save any remaining patients
if (counter % batchSize != 0)
{
_dbContext.SaveChanges();
Console.WriteLine($"Saved {counter} patients so far...");
Console.WriteLine($"Final save, total patients saved: {counter}");
}
}

// Save any remaining patients
if (counter % batchSize != 0)
transaction.Commit();
}
catch
{
_dbContext.SaveChanges();
Console.WriteLine($"Final save, total patients saved: {counter}");
transaction.Rollback();
throw;
}

}

private void SetIdentityInsert(string tableName, bool enable = true)
{
string sql = enable

Check notice on line 84 in BackendPatient/Data/DataSeeder.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use preferred 'var' style (for built-in types)

Use 'var' (built-in types)
? $"SET IDENTITY_INSERT {tableName} ON;"
: $"SET IDENTITY_INSERT {tableName} OFF;";
_dbContext.Database.ExecuteSqlRaw(sql);
}
}
1 change: 0 additions & 1 deletion Frontend/Controllers/PatientsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public async Task<IActionResult> Edit(int id)
}

[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 172 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
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ services:
condition: service_healthy
networks:
- elastic
command: [ "sh", "/mongodb/wait-for-mongo.sh", "/docker-entrypoint.sh" ]

apigateway:
container_name: apigateway
Expand Down
9 changes: 8 additions & 1 deletion elasticsearch/config/create_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lowercase",
"french_stem",
"asciifolding",
"synonym_filter",
"french_stop"
]
}
Expand All @@ -27,11 +28,17 @@
"filter": {
"french_stem": {
"type": "stemmer",
"language": "light_french"
"language": "french"
},
"french_stop": {
"type": "stop",
"stopwords": "_french_"
},
"synonym_filter": {
"type": "synonym_graph",
"synonyms": [
"hémoglobine a1c => hemoglobine_a1c"
]
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion elasticsearch/config/notes_index_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lowercase",
"french_stem",
"asciifolding",
"synonym_filter",
"french_stop"
]
}
Expand All @@ -31,11 +32,17 @@
"filter": {
"french_stem": {
"type": "stemmer",
"language": "light_french"
"language": "french"
},
"french_stop": {
"type": "stop",
"stopwords": "_french_"
},
"synonym_filter": {
"type": "synonym_graph",
"synonyms": [
"hémoglobine a1c => hemoglobine_a1c"
]
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions mongodb/mongo-express.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
FROM mongo-express

COPY /wait-for-mongo.sh /wait-for-mongo.sh

RUN chmod +x /wait-for-mongo.sh
FROM mongo-express:latest
4 changes: 0 additions & 4 deletions mongodb/wait-for-mongo.sh

This file was deleted.

0 comments on commit 981f19d

Please sign in to comment.