Skip to content

Commit

Permalink
KHP3-5017-HTS-ML-NewModel-May2024-Eligibilty-Screening-Form-Processing (
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickWaweru authored and donaldkibet committed May 15, 2024
1 parent e3db32d commit d95c3ff
Show file tree
Hide file tree
Showing 10 changed files with 4,315 additions and 502 deletions.
1 change: 1 addition & 0 deletions .eslintcache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"/opt/develop/palladium/frontend/openmrs-ngx-formentry/projects/ngx-formentry/src/components/machine-learning-button/machine-learning.component.ts":"1","/opt/develop/palladium/frontend/openmrs-ngx-formentry/projects/ngx-formentry/src/components/machine-learning-button/machine-learning.service.ts":"2","/opt/develop/palladium/frontend/openmrs-ngx-formentry/src/app/app.component.ts":"3","/opt/develop/palladium/frontend/openmrs-ngx-formentry/projects/ngx-formentry/src/components/machine-learning-button/model-helper.ts":"4"},{"size":7138,"mtime":1715753089362,"results":"5","hashOfConfig":"6"},{"size":6020,"mtime":1715753089450,"results":"7","hashOfConfig":"6"},{"size":12608,"mtime":1715153878280,"results":"8","hashOfConfig":"9"},{"size":23732,"mtime":1715757868525,"results":"10","hashOfConfig":"6"},{"filePath":"11","messages":"12","errorCount":0,"fatalErrorCount":0,"warningCount":1,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"gz3qmb",{"filePath":"13","messages":"14","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"15","messages":"16","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1hhmf4j",{"filePath":"17","messages":"18","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/opt/develop/palladium/frontend/openmrs-ngx-formentry/projects/ngx-formentry/src/components/machine-learning-button/machine-learning.component.ts",["19"],"/opt/develop/palladium/frontend/openmrs-ngx-formentry/projects/ngx-formentry/src/components/machine-learning-button/machine-learning.service.ts",[],"/opt/develop/palladium/frontend/openmrs-ngx-formentry/src/app/app.component.ts",[],"/opt/develop/palladium/frontend/openmrs-ngx-formentry/projects/ngx-formentry/src/components/machine-learning-button/model-helper.ts",[],{"ruleId":"20","severity":1,"message":"21","line":13,"column":13,"nodeType":"22","messageId":"23","endLine":13,"endColumn":42},"@angular-eslint/component-selector","The selector should start with one of these prefixes: \"ofe\" (https://angular.io/guide/styleguide#style-02-07)","Literal","prefixFailure"]
Binary file added .yarn/install-state.gz
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ export class MachineLearningComponent implements OnInit {
this.setRiskScore(message);
this.setAutoGenerateRiskScore(riskScore, message);
this.isLoading = false;
// this.restoreRequiredFields();
},
(error) => {
this.hasError = true;
this.isLoading = false;
this.errorMessage =
error.message ?? 'An error occurred while fetching risk score';
this.setRiskScore(this.errorMessage);
// this.restoreRequiredFields();
}
);
} else {
Expand Down Expand Up @@ -103,7 +105,7 @@ export class MachineLearningComponent implements OnInit {

private buildRiskPayload(machineLearningScore: any): object {
const modelConfigs = {
modelId: 'hts_xgb_1211_jan_2023',
modelId: 'hts_xgb_01052024_may_2024',
encounterDate: new Date().toISOString().slice(0, 10),
facilityId: '',
debug: 'true'
Expand All @@ -129,9 +131,9 @@ export class MachineLearningComponent implements OnInit {
return questionConcepts;
}

private setRiskScore(score: string) {
const riskScore = this.node.form.searchNodeByQuestionId('riskScore')[0];
riskScore.control.setValue(score);
private setRiskScore(scoreMessage: string) {
const riskScoreMessage = this.node.form.searchNodeByQuestionId('riskScore')[0];
riskScoreMessage.control.setValue(scoreMessage);
}

private extractNumbersOrUuid(inputStr: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,29 @@ export class MachineLearningService {
return this.http.post(url, predicationPayload, { headers: headers });
}

// Predict the risk
public predictRisk(res) {
// Check if the prediction is available
const probabilityForPositivity = res?.result?.predictions['probability(1)'];
const probabilityForPositivity = res?.result?.predictions['probability(Positive)'];
if (!probabilityForPositivity) {
return { message: 'No results found', riskScore: 0 };
}

// Define risk thresholds
const highRiskThreshold = 0.1079255;
const mediumRiskThreshold = 0.02795569;
const lowRiskThreshold = 0.005011473;
const lowRiskThreshold = res.result.thresholds['Medium'];
const mediumRiskThreshold = res.result.thresholds['High'];
const highRiskThreshold = res.result.thresholds['Very_High'];

const riskThresholds = {
lowRisk: lowRiskThreshold,
mediumRisk: mediumRiskThreshold,
highRisk: highRiskThreshold
};

console.warn("Low Risk Threshold is: ", lowRiskThreshold);
console.warn("Medium Risk Threshold is: ", mediumRiskThreshold);
console.warn("High Risk Threshold is: ", highRiskThreshold);
console.warn("Got prediction as: ", probabilityForPositivity);

// Define risk messages
const riskMessages = {
veryHigh:
'This client has a very high probability of a HIV positive test result. Testing is strongly recommended',
Expand Down Expand Up @@ -90,6 +100,13 @@ export class MachineLearningService {
testStrategy: result['facilityHTStrategy'] ?? '',
selfTested: result['teSteR'] ?? '',
tbScreening: result['screenedTB'] ?? '',
tbFever: result['fever'] ?? '',
tbNightSweats: result['experiencingSweats'] ?? '',
tbCough: result['coughDuration'] ?? '',
tbScreeningStatus: result['tbResultstaTuS'] ?? '',
everHadSex: result['sexuallyActive'] ?? '',
multipleSexPartners: result['multipleSexPartners'] ?? '',
patientType: result['patienTyPe'] ?? '',
onPREP: result['currentlyPrep'] ?? '',
hasSTI: result['currentlySti'] ?? '',
activeSexually: result['activeSexually'] ?? '',
Expand Down
Loading

0 comments on commit d95c3ff

Please sign in to comment.