graph values fix and comparision with the pdf

lab-graph
tahaalam 1 day ago
parent 24fa8e18f3
commit fc21746683

@ -377,7 +377,8 @@ class LabViewModel extends ChangeNotifier {
LoaderBottomSheet.hideLoader(); LoaderBottomSheet.hideLoader();
if (apiResponse.messageStatus == 2) { if (apiResponse.messageStatus == 2) {
} else if (apiResponse.messageStatus == 1) { } else if (apiResponse.messageStatus == 1) {
var recentThree = sort(apiResponse.data!); var sortedResult = sort(apiResponse.data!);
var recentThree = sortedResult.take(3).toList();
mainLabResults = recentThree; mainLabResults = recentThree;
double highRefrenceValue = double.negativeInfinity; double highRefrenceValue = double.negativeInfinity;
@ -385,11 +386,12 @@ class LabViewModel extends ChangeNotifier {
double lowRefenceValue = double.infinity; double lowRefenceValue = double.infinity;
String? flagForLowReferenceRange; String? flagForLowReferenceRange;
recentThree.reversed.forEach((element) { sortedResult.take(3).toList().reversed.forEach((element) {
try { try {
var dateTime = DateUtil.convertStringToDate(element.verifiedOnDateTime!); var dateTime = DateUtil.convertStringToDate(element.verifiedOnDateTime!);
var resultValue = double.parse(element.resultValue!); var resultValue = double.parse(element.resultValue!);
var transformedValue = transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag ?? ""); // var transformedValue = transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag ?? "");
var transformedValue = resultValue;
if (resultValue > maxY) { if (resultValue > maxY) {
maxY = resultValue; maxY = resultValue;
maxX = maxY; maxX = maxY;
@ -421,9 +423,9 @@ class LabViewModel extends ChangeNotifier {
highRefrenceValue = maxY; highRefrenceValue = maxY;
lowRefenceValue = minY; lowRefenceValue = minY;
} }
//
if (minY > lowRefenceValue) { if (minY > lowRefenceValue) {
minY = lowRefenceValue - 25; minY = lowRefenceValue - getInterval();
} }
this.flagForHighReferenceRange = flagForHighReferenceRange; this.flagForHighReferenceRange = flagForHighReferenceRange;
@ -432,12 +434,16 @@ class LabViewModel extends ChangeNotifier {
lowTransformedReferenceValue = double.parse(transformValueInRange(lowRefenceValue, flagForLowReferenceRange ?? "").toStringAsFixed(1)); lowTransformedReferenceValue = double.parse(transformValueInRange(lowRefenceValue, flagForLowReferenceRange ?? "").toStringAsFixed(1));
this.highRefrenceValue = double.parse(highRefrenceValue.toStringAsFixed(1)); this.highRefrenceValue = double.parse(highRefrenceValue.toStringAsFixed(1));
this.lowRefenceValue = double.parse(lowRefenceValue.toStringAsFixed(1)); this.lowRefenceValue = double.parse(lowRefenceValue.toStringAsFixed(1));
if(maxY<highRefrenceValue){
if (maxY < highRefrenceValue) {
maxY = highRefrenceValue; maxY = highRefrenceValue;
maxX = maxY;
} }
maxY += 25; // if (maxY < highRefrenceValue) {
minY -= 25; // minY = highRefrenceValue - getInterval();
// }
// maxY += 25;
// minY -= 25;
LabResult recentResult = recentThree.first; LabResult recentResult = recentThree.first;
recentResult.uOM = unitOfMeasure; recentResult.uOM = unitOfMeasure;
checkIfGraphShouldBeDisplayed(recentResult); checkIfGraphShouldBeDisplayed(recentResult);
@ -454,6 +460,17 @@ class LabViewModel extends ChangeNotifier {
}, },
); );
} }
num getInterval() {
// return .1;
var maxX = maxY;
if(maxX<1) return .2;
if(maxX >=1.0 && maxX < 5.0) return .3;
if(maxX >=5.0 && maxX < 10.0) return 1.5;
if(maxX >=10.0 && maxX < 50.0) return 2.5;
if(maxX >=50.0 && maxX < 100.0) return 5;
if(maxX >=100.0 && maxX < 200.0) return 10;
return 15;
}
void checkIfGraphShouldBeDisplayed(LabResult recentResult) { void checkIfGraphShouldBeDisplayed(LabResult recentResult) {
shouldShowGraph = recentResult.checkIfGraphShouldBeDisplayed(); shouldShowGraph = recentResult.checkIfGraphShouldBeDisplayed();
@ -576,7 +593,8 @@ class LabViewModel extends ChangeNotifier {
try { try {
var dateTime = DateUtil.convertStringToDate(element.verifiedOnDateTime!); var dateTime = DateUtil.convertStringToDate(element.verifiedOnDateTime!);
var resultValue = double.parse(element.resultValue!); var resultValue = double.parse(element.resultValue!);
var transformedValue = transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag ?? ""); // var transformedValue = transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag ?? "");
var transformedValue = double.parse(element.resultValue!);
if (resultValue > maxY) { if (resultValue > maxY) {
maxY = resultValue; maxY = resultValue;
} }

@ -326,20 +326,20 @@ class LabResultDetails extends StatelessWidget {
}, },
leftLabelFormatter: (value) { leftLabelFormatter: (value) {
value = double.parse(value.toStringAsFixed(1)); value = double.parse(value.toStringAsFixed(1));
// return leftLabels(value.toStringAsFixed(2)); return leftLabels(value.toStringAsFixed(2));
if (value == labmodel.highRefrenceValue) { // if (value == labmodel.highRefrenceValue) {
return leftLabels(LocaleKeys.high.tr()); // return leftLabels(LocaleKeys.high.tr());
} // }
//
if (value == labmodel.lowRefenceValue) { // if (value == labmodel.lowRefenceValue) {
return leftLabels(LocaleKeys.low.tr()); // return leftLabels(LocaleKeys.low.tr());
} // }
return SizedBox.shrink(); return SizedBox.shrink();
// } // }
}, },
graphColor: AppColors.blackColor, graphColor: AppColors.graphGridColor,
graphShadowColor: Colors.transparent, graphShadowColor: AppColors.graphGridColor.withOpacity(.5),
graphGridColor: graphColor.withOpacity(.4), graphGridColor: graphColor.withOpacity(.4),
bottomLabelFormatter: (value, data) { bottomLabelFormatter: (value, data) {
if (data.isEmpty) return SizedBox.shrink(); if (data.isEmpty) return SizedBox.shrink();
@ -371,7 +371,7 @@ class LabResultDetails extends StatelessWidget {
ranges.add(HorizontalRangeAnnotation( ranges.add(HorizontalRangeAnnotation(
y1: model.minY, y1: model.minY,
y2: model.lowRefenceValue, y2: model.lowRefenceValue,
color: AppColors.highAndLow.withOpacity(0.05), color: Colors.transparent,
)); ));
ranges.add(HorizontalRangeAnnotation( ranges.add(HorizontalRangeAnnotation(
@ -383,7 +383,7 @@ class LabResultDetails extends StatelessWidget {
ranges.add(HorizontalRangeAnnotation( ranges.add(HorizontalRangeAnnotation(
y1: model.highRefrenceValue, y1: model.highRefrenceValue,
y2: model.maxY, y2: model.maxY,
color: AppColors.criticalLowAndHigh.withOpacity(0.05), color: Colors.transparent,
)); ));
return ranges; return ranges;
} }
@ -412,15 +412,17 @@ class LabResultDetails extends StatelessWidget {
} }
double? getInterval(LabViewModel labmodel) { double? getInterval(LabViewModel labmodel) {
return .1; // return .1;
// var maxX = labmodel.maxY; var maxX = labmodel.maxY;
// if(maxX<1) return .5; if(maxX<1) return .3;
// if(maxX >1 && maxX < 5) return 1; if(maxX >1 && maxX <= 5) return .7;
// if(maxX >5 && maxX < 10) return 5; if(maxX >5 && maxX <= 10) return 2.5;
// if(maxX >10 && maxX < 50) return 10; if(maxX >10 && maxX <= 50) return 5;
// if(maxX >50 && maxX < 100) return 20; if(maxX >50 && maxX <= 100) return 10;
// if(maxX >100 && maxX < 200) return 30; if(maxX >100 && maxX <= 200) return 30;
// return 50; if(maxX >200 && maxX <= 300) return 50;
if(maxX >300 && maxX <= 400) return 100;
return 200 ;
} }
Widget getLabDescription(BuildContext context) { Widget getLabDescription(BuildContext context) {

@ -257,7 +257,7 @@ class CustomGraph extends StatelessWidget {
isCurved: true, isCurved: true,
isStrokeCapRound: true, isStrokeCapRound: true,
isStrokeJoinRound: true, isStrokeJoinRound: true,
barWidth: 2, barWidth: 3,
gradient: LinearGradient( gradient: LinearGradient(
colors: [resolvedGraphColor, resolvedGraphColor], colors: [resolvedGraphColor, resolvedGraphColor],
begin: Alignment.centerLeft, begin: Alignment.centerLeft,

Loading…
Cancel
Save