@ -15,35 +15,38 @@ import 'package:hmg_patient_app_new/presentation/lab/lab_results/lab_result_list
 
		
	
		
			
				import  ' package:hmg_patient_app_new/theme/colors.dart '  show  AppColors ;  
		
	
		
			
				import  ' package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart ' ;  
		
	
		
			
				import  ' package:hmg_patient_app_new/widgets/graph/custom_graph.dart ' ;  
		
	
		
			
				import  ' package:provider/provider.dart '  show  Consumer ,  Provider  
		
	
		
			
				import  ' package:provider/provider.dart '  show  Consumer ,  Provider , ReadContext  ; 
		
	
		
			
				
 
		
	
		
			
				import  ' ../../../widgets/common_bottom_sheet.dart '  
		
	
		
			
				    show  showCommonBottomSheetWithoutHeight ; 
 
		
	
		
			
				
 
		
	
		
			
				class  LabResultDetails  extends  StatelessWidget  {  
		
	
		
			
				  final  LabResult  recentLabResult ; 
 
		
	
		
			
				  final  String ?  testDescription ; 
 
		
	
		
			
				
 
		
	
		
			
				  / /  final  List < DataPoint >  graphPoint ; 
 
		
	
		
			
				  late  LabViewModel  model ; 
 
		
	
		
			
				  String ?  testDescription ; 
 
		
	
		
			
				
 
		
	
		
			
				  LabResultDetails ( { super . key ,  required  this . recentLabResult ,  required  this . testDescription } ) ; 
 
		
	
		
			
				  const  LabResultDetails ( 
 
		
	
		
			
				      { super . key , 
 
		
	
		
			
				      required  this . recentLabResult , 
 
		
	
		
			
				      required  this . testDescription } ) ; 
 
		
	
		
			
				
 
		
	
		
			
				  @ override 
 
		
	
		
			
				  Widget  build ( BuildContext  context )  { 
 
		
	
		
			
				    model  =  Provider . of < LabViewModel > ( context ,  listen:  false ) ; 
 
		
	
		
			
				    return  CollapsingListView ( 
 
		
	
		
			
				      title:  ' Lab Result Details ' . needTranslation , 
 
		
	
		
			
				      child:  SingleChildScrollView ( 
 
		
	
		
			
				        child:  Column ( 
 
		
	
		
			
				          spacing:  16. h , 
 
		
	
		
			
				          children:  [ LabNameAndStatus ,  LabGraph ( context ) ] , 
 
		
	
		
			
				          children:  [ 
 
		
	
		
			
				            LabNameAndStatus ( context ) , 
 
		
	
		
			
				            getLabDescription ( context ) , 
 
		
	
		
			
				            LabGraph ( context ) 
 
		
	
		
			
				          ] , 
 
		
	
		
			
				        ) . paddingAll ( 24. h ) , 
 
		
	
		
			
				      ) , 
 
		
	
		
			
				    ) ; 
 
		
	
		
			
				  } 
 
		
	
		
			
				
 
		
	
		
			
				  Widget  get  LabNameAndStatus  = >  Container ( 
 
		
	
		
			
				  Widget  LabNameAndStatus ( BuildContext  context ) = >  Container ( 
 
		
	
		
			
				      decoration:  RoundedRectangleBorder ( ) . toSmoothCornerDecoration ( 
 
		
	
		
			
				        color:  AppColors . whiteColor , 
 
		
	
		
			
				        borderRadius:  24. h , 
 
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
			
			@ -80,11 +83,12 @@ class LabResultDetails extends StatelessWidget {
 
		
	
		
			
				          / / todo  change  the  text  color  according  to  the  provided  test  values 
 
		
	
		
			
				          Row ( 
 
		
	
		
			
				            crossAxisAlignment:  CrossAxisAlignment . center , 
 
		
	
		
			
				
 
		
	
		
			
				            children:  [ 
 
		
	
		
			
				              Expanded ( 
 
		
	
		
			
				                child:  Row ( 
 
		
	
		
			
				                  spacing:  4. h , 
 
		
	
		
			
				
 
		
	
		
			
				                  mainAxisSize:  MainAxisSize . max , 
 
		
	
		
			
				                  children:  [ 
 
		
	
		
			
				                    Flexible ( 
 
		
	
		
			
				                      child:  Text ( 
 
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
			
			@ -93,8 +97,8 @@ class LabResultDetails extends StatelessWidget {
 
		
	
		
			
				                          fontSize:  24. fSize , 
 
		
	
		
			
				                          fontWeight:  FontWeight . w600 , 
 
		
	
		
			
				                          fontFamily:  ' Poppins ' , 
 
		
	
		
			
				                          color:  model . getColor ( 
 
		
	
		
			
				                            recentLabResult . calculatedResultFlag  ? ?  " " , 
 
		
	
		
			
				                          color:  context. read < LabViewModel > ( )  . getColor ( 
 
		
	
		
			
				                                 recentLabResult . calculatedResultFlag  ? ?  " " , 
 
		
	
		
			
				                          ) , 
 
		
	
		
			
				                          letterSpacing:  - 2 , 
 
		
	
		
			
				                        ) , 
 
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
			
			@ -103,30 +107,37 @@ class LabResultDetails extends StatelessWidget {
 
		
	
		
			
				                        softWrap:  false , 
 
		
	
		
			
				                      ) , 
 
		
	
		
			
				                    ) , 
 
		
	
		
			
				                    Visibility ( 
 
		
	
		
			
				                      visible:  recentLabResult . referanceRange  ! =  null , 
 
		
	
		
			
				                      child:  Text ( 
 
		
	
		
			
				                        " (Reference range  ${ recentLabResult . referanceRange } ) " . needTranslation , 
 
		
	
		
			
				                        style:  TextStyle ( 
 
		
	
		
			
				                          fontSize:  12. fSize , 
 
		
	
		
			
				                          fontWeight:  FontWeight . w500 , 
 
		
	
		
			
				                          fontFamily:  ' Poppins ' , 
 
		
	
		
			
				                          color:  AppColors . greyTextColor , 
 
		
	
		
			
				                    SizedBox ( width:  4. h , ) , 
 
		
	
		
			
				                    Expanded ( 
 
		
	
		
			
				                      flex:  2 , 
 
		
	
		
			
				                      child:  Visibility ( 
 
		
	
		
			
				                        visible:  recentLabResult . referanceRange  ! =  null , 
 
		
	
		
			
				                        child:  Text ( 
 
		
	
		
			
				                          " (Reference range  ${ recentLabResult . referanceRange } ) " . needTranslation , 
 
		
	
		
			
				                          style:  TextStyle ( 
 
		
	
		
			
				                            fontSize:  12. fSize , 
 
		
	
		
			
				                            fontWeight:  FontWeight . w500 , 
 
		
	
		
			
				                            fontFamily:  ' Poppins ' , 
 
		
	
		
			
				                            color:  AppColors . greyTextColor , 
 
		
	
		
			
				                          ) , 
 
		
	
		
			
				                          / /  overflow:  TextOverflow . ellipsis , 
 
		
	
		
			
				                          / /  maxLines:  2 , 
 
		
	
		
			
				                          softWrap:  true , 
 
		
	
		
			
				                        ) , 
 
		
	
		
			
				                        overflow:  TextOverflow . ellipsis , 
 
		
	
		
			
				                        maxLines:  1 , 
 
		
	
		
			
				                        softWrap:  false , 
 
		
	
		
			
				                      ) , 
 
		
	
		
			
				                    ) , 
 
		
	
		
			
				                  ] , 
 
		
	
		
			
				                ) , 
 
		
	
		
			
				              ) , 
 
		
	
		
			
				              Utils . buildSvgWithAssets ( 
 
		
	
		
			
				                icon:  AppAssets . lab_result_indicator , 
 
		
	
		
			
				              SizedBox ( 
 
		
	
		
			
				                width:  21 , 
 
		
	
		
			
				                height:  23 , 
 
		
	
		
			
				                iconColor:  model . getColor ( 
 
		
	
		
			
				                  recentLabResult . calculatedResultFlag  ? ?  " " , 
 
		
	
		
			
				                child:  Utils . buildSvgWithAssets ( 
 
		
	
		
			
				                  icon:  AppAssets . lab_result_indicator , 
 
		
	
		
			
				                  width:  21 , 
 
		
	
		
			
				                  height:  23 , 
 
		
	
		
			
				                  iconColor:  context . read < LabViewModel > ( ) . getColor ( 
 
		
	
		
			
				                        recentLabResult . calculatedResultFlag  ? ?  " " , 
 
		
	
		
			
				                  ) , 
 
		
	
		
			
				                ) , 
 
		
	
		
			
				              ) , 
 
		
	
		
			
				            ] , 
 
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
			
			@ -135,73 +146,80 @@ class LabResultDetails extends StatelessWidget {
 
		
	
		
			
				        ] , 
 
		
	
		
			
				      ) ) ; 
 
		
	
		
			
				
 
		
	
		
			
				  Widget  LabGraph ( BuildContext  context )  = >  Consumer < DateRangeSelectorRangeViewModel > ( 
 
		
	
		
			
				      builder:  ( _ ,  model ,  ___ )  = >  Consumer < LabViewModel > ( 
 
		
	
		
			
				            builder:  ( _ ,  labmodel ,  ___ )  = >  Container ( 
 
		
	
		
			
				                decoration:  RoundedRectangleBorder ( ) . toSmoothCornerDecoration ( 
 
		
	
		
			
				                  color:  AppColors . whiteColor , 
 
		
	
		
			
				                  borderRadius:  24. h , 
 
		
	
		
			
				                  hasShadow:  true , 
 
		
	
		
			
				                ) , 
 
		
	
		
			
				                height:  model . isGraphVisible ? 260. h: ( labmodel . filteredGraphValues . length < 3 ) ? ( labmodel . filteredGraphValues . length * 64 ) + 80. h: 260. h , 
 
		
	
		
			
				                padding:  EdgeInsets . all ( 16. h ) , 
 
		
	
		
			
				                child:  Column ( 
 
		
	
		
			
				                  mainAxisAlignment:  MainAxisAlignment . spaceAround , 
 
		
	
		
			
				  Widget  LabGraph ( BuildContext  context )  = >  Consumer < LabViewModel > ( 
 
		
	
		
			
				        builder:  ( _ ,  labmodel ,  ___ )  = >  Container ( 
 
		
	
		
			
				            decoration:  RoundedRectangleBorder ( ) . toSmoothCornerDecoration ( 
 
		
	
		
			
				              color:  AppColors . whiteColor , 
 
		
	
		
			
				              borderRadius:  24. h , 
 
		
	
		
			
				              hasShadow:  true , 
 
		
	
		
			
				            ) , 
 
		
	
		
			
				            height:  labmodel . isGraphVisible 
 
		
	
		
			
				                ?  260. h 
 
		
	
		
			
				                :  ( labmodel . filteredGraphValues . length  <  3 ) 
 
		
	
		
			
				                    ?  ( labmodel . filteredGraphValues . length  *  64 )  +  80. h 
 
		
	
		
			
				                    :  260. h , 
 
		
	
		
			
				            padding:  EdgeInsets . all ( 16. h ) , 
 
		
	
		
			
				            child:  Column ( 
 
		
	
		
			
				              mainAxisAlignment:  MainAxisAlignment . spaceAround , 
 
		
	
		
			
				              children:  [ 
 
		
	
		
			
				                / / title  and  filter  icon 
 
		
	
		
			
				                Row ( 
 
		
	
		
			
				                  mainAxisAlignment:  MainAxisAlignment . spaceBetween , 
 
		
	
		
			
				                  children:  [ 
 
		
	
		
			
				                    / / title  and  filter  icon 
 
		
	
		
			
				                    Text ( 
 
		
	
		
			
				                      labmodel . isGraphVisible 
 
		
	
		
			
				                          ?  LocaleKeys . historyFlowchart . tr ( ) 
 
		
	
		
			
				                          :  LocaleKeys . history . tr ( ) , 
 
		
	
		
			
				                      style:  TextStyle ( 
 
		
	
		
			
				                        fontSize:  16 , 
 
		
	
		
			
				                        fontFamily:  ' Poppins ' , 
 
		
	
		
			
				                        fontWeight:  FontWeight . w600 , 
 
		
	
		
			
				                        color:  AppColors . textColor , 
 
		
	
		
			
				                      ) , 
 
		
	
		
			
				                    ) , 
 
		
	
		
			
				                    Row ( 
 
		
	
		
			
				                      mainAxisAlignment:  MainAxisAlignment . spaceBetween , 
 
		
	
		
			
				                      spacing: 16. h  , 
 
		
	
		
			
				                      children:  [ 
 
		
	
		
			
				                        Text ( 
 
		
	
		
			
				                          model . isGraphVisible ? LocaleKeys . historyFlowchart . tr ( ) :  LocaleKeys . history . tr ( ) , 
 
		
	
		
			
				                          style:  TextStyle ( 
 
		
	
		
			
				                            fontSize:  16 , 
 
		
	
		
			
				                            fontFamily:  ' Poppins ' , 
 
		
	
		
			
				
 
		
	
		
			
				                            fontWeight:  FontWeight . w600 , 
 
		
	
		
			
				                            color:  AppColors . textColor , 
 
		
	
		
			
				                          ) , 
 
		
	
		
			
				                        ) , 
 
		
	
		
			
				                        Row ( 
 
		
	
		
			
				                          spacing:  16. h , 
 
		
	
		
			
				                          children:  [ 
 
		
	
		
			
				                            / / todo  handle  when  the  graph  icon  is  being  displayed 
 
		
	
		
			
				                            Utils . buildSvgWithAssets ( 
 
		
	
		
			
				                                    icon:  model . isGraphVisible ? AppAssets . ic_list: AppAssets . ic_graph , 
 
		
	
		
			
				                                    width:  24. h , 
 
		
	
		
			
				                                    height:  24. h ) 
 
		
	
		
			
				                                . onPress ( ( )  { 
 
		
	
		
			
				                                  model . alterGraphVisibility ( ) ; 
 
		
	
		
			
				                            } ) , 
 
		
	
		
			
				                            Utils . buildSvgWithAssets ( 
 
		
	
		
			
				                                    icon:  AppAssets . ic_date_filter , 
 
		
	
		
			
				                                    width:  24 , 
 
		
	
		
			
				                                    height:  24 ) 
 
		
	
		
			
				                                . onPress ( ( )  { 
 
		
	
		
			
				                              showCommonBottomSheetWithoutHeight ( 
 
		
	
		
			
				                                title:  LocaleKeys . setTheDateRange . tr ( ) , 
 
		
	
		
			
				                                context , 
 
		
	
		
			
				                                child:  DateRangeSelector ( 
 
		
	
		
			
				                                  onRangeSelected:  ( start ,  end )  { 
 
		
	
		
			
				
 
		
	
		
			
				                                    / /  if  ( start  ! =  null )  { 
 
		
	
		
			
				                                      labmodel . getSelectedDateRange ( start ,  end ) ; 
 
		
	
		
			
				                                    / /  } 
 
		
	
		
			
				                                  } , 
 
		
	
		
			
				                                ) , 
 
		
	
		
			
				                                isFullScreen:  false , 
 
		
	
		
			
				                                isCloseButtonVisible:  true , 
 
		
	
		
			
				                                callBackFunc:  ( )  { } , 
 
		
	
		
			
				                              ) ; 
 
		
	
		
			
				                            } ) , 
 
		
	
		
			
				                          ] , 
 
		
	
		
			
				                        ) 
 
		
	
		
			
				                        / / todo  handle  when  the  graph  icon  is  being  displayed 
 
		
	
		
			
				                        Utils . buildSvgWithAssets ( 
 
		
	
		
			
				                                icon:  labmodel . isGraphVisible 
 
		
	
		
			
				                                    ?  AppAssets . ic_list 
 
		
	
		
			
				                                    :  AppAssets . ic_graph , 
 
		
	
		
			
				                                width:  24. h , 
 
		
	
		
			
				                                height:  24. h ) 
 
		
	
		
			
				                            . onPress ( ( )  { 
 
		
	
		
			
				                          if  ( labmodel . shouldShowGraph )  { 
 
		
	
		
			
				                            labmodel . alterGraphVisibility ( ) ; 
 
		
	
		
			
				                          } 
 
		
	
		
			
				                        } ) , 
 
		
	
		
			
				                        Utils . buildSvgWithAssets ( 
 
		
	
		
			
				                                icon:  AppAssets . ic_date_filter , 
 
		
	
		
			
				                                width:  24 , 
 
		
	
		
			
				                                height:  24 ) 
 
		
	
		
			
				                            . onPress ( ( )  { 
 
		
	
		
			
				                          showCommonBottomSheetWithoutHeight ( 
 
		
	
		
			
				                            title:  LocaleKeys . setTheDateRange . tr ( ) , 
 
		
	
		
			
				                            context , 
 
		
	
		
			
				                            child:  DateRangeSelector ( 
 
		
	
		
			
				                              onRangeSelected:  ( start ,  end )  { 
 
		
	
		
			
				                                / /  if  ( start  ! =  null )  { 
 
		
	
		
			
				                                labmodel . getSelectedDateRange ( start ,  end ) ; 
 
		
	
		
			
				                                / /  } 
 
		
	
		
			
				                              } , 
 
		
	
		
			
				                            ) , 
 
		
	
		
			
				                            isFullScreen:  false , 
 
		
	
		
			
				                            isCloseButtonVisible:  true , 
 
		
	
		
			
				                            callBackFunc:  ( )  { } , 
 
		
	
		
			
				                          ) ; 
 
		
	
		
			
				                        } ) , 
 
		
	
		
			
				                      ] , 
 
		
	
		
			
				                    ) . paddingOnly ( bottom:  model . isGraphVisible ?  16. h  : 24. h ) , 
 
		
	
		
			
				                    historyBody ( model ,  labmodel ) 
 
		
	
		
			
				                    ) 
 
		
	
		
			
				                  ] , 
 
		
	
		
			
				                ) ) , 
 
		
	
		
			
				          ) ) ; 
 
		
	
		
			
				                ) . paddingOnly ( bottom:  labmodel . isGraphVisible  ?  16. h  :  24. h ) , 
 
		
	
		
			
				                historyBody ( labmodel ) 
 
		
	
		
			
				              ] , 
 
		
	
		
			
				            ) ) , 
 
		
	
		
			
				      ) ; 
 
		
	
		
			
				
 
		
	
		
			
				  Widget  leftLabels ( String  value )  { 
 
		
	
		
			
				    return  Text ( 
 
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
			
			@ -229,17 +247,15 @@ class LabResultDetails extends StatelessWidget {
 
		
	
		
			
				    ) ; 
 
		
	
		
			
				  } 
 
		
	
		
			
				
 
		
	
		
			
				  Widget  historyBody ( DateRangeSelectorRangeViewModel model ,   LabViewModel labmodel )  { 
 
		
	
		
			
				    if ( . isGraphVisible ) { 
 
		
	
		
			
				  Widget  historyBody ( labmodel )  { 
 
		
	
		
			
				    if   ( lab model. isGraphVisible  & &  labmodel . shouldShowGraph  )   { 
 
		
	
		
			
				      var  graphColor  =  labmodel . getColor ( recentLabResult . calculatedResultFlag ? ? " N " ) ; 
 
		
	
		
			
				      return  CustomGraph ( 
 
		
	
		
			
				          dataPoints:  labmodel . filteredGraphValues , 
 
		
	
		
			
				          / /  maxY:  100 , 
 
		
	
		
			
				
 
		
	
		
			
				          makeGraphBasedOnActualValue:  true , 
 
		
	
		
			
				          leftLabelReservedSize:  40 , 
 
		
	
		
			
				          leftLabelInterval:  getInterval ( labmodel ) , 
 
		
	
		
			
				          maxY:  ( labmodel . maxY ) + ( getInterval ( labmodel ) ? ? 0 ) / 5 , 
 
		
	
		
			
				          maxY:  ( labmodel . maxY ) + ( getInterval ( labmodel ) ? ? 0 ) / 2 , 
 
		
	
		
			
				          maxX:  labmodel . filteredGraphValues . length . toDouble ( ) - . 75 , 
 
		
	
		
			
				          leftLabelFormatter:  ( value )  { 
 
		
	
		
			
				            return  leftLabels ( value . toStringAsFixed ( 2 ) . tr ( ) ) ; 
 
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
			
			@ -279,11 +295,11 @@ class LabResultDetails extends StatelessWidget {
 
		
	
		
			
				          scrollDirection:  Axis . horizontal , 
 
		
	
		
			
				          height:  180. h ) ; 
 
		
	
		
			
				    } else  { 
 
		
	
		
			
				      return  labHistoryList ( model,   labmodel) ; 
 
		
	
		
			
				      return  labHistoryList ( ) ; 
 
		
	
		
			
				    } 
 
		
	
		
			
				  } 
 
		
	
		
			
				
 
		
	
		
			
				  Widget  labHistoryList ( DateRangeSelectorRangeViewModel model ,   LabViewModel labmodel )  { 
 
		
	
		
			
				  Widget  labHistoryList ( labmodel )  { 
 
		
	
		
			
				    return  SizedBox ( 
 
		
	
		
			
				      height:  labmodel . filteredGraphValues . length < 3 ? labmodel . filteredGraphValues . length * 64 : 180. h , 
 
		
	
		
			
				      child:  ListView . separated ( 
 
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
			
			@ -315,4 +331,27 @@ class LabResultDetails extends StatelessWidget {
 
		
	
		
			
				    if ( maxX  > 100  & &  maxX  <  200 )  return  30 ; 
 
		
	
		
			
				    return  50 ; 
 
		
	
		
			
				  } 
 
		
	
		
			
				
 
		
	
		
			
				  Widget  getLabDescription ( BuildContext  context )  { 
 
		
	
		
			
				    return  Container ( 
 
		
	
		
			
				        decoration:  RoundedRectangleBorder ( ) . toSmoothCornerDecoration ( 
 
		
	
		
			
				          color:  AppColors . whiteColor , 
 
		
	
		
			
				          borderRadius:  24. h , 
 
		
	
		
			
				          hasShadow:  true , 
 
		
	
		
			
				        ) , 
 
		
	
		
			
				        height:  98. h , 
 
		
	
		
			
				        padding:  EdgeInsets . all ( 16. h ) , 
 
		
	
		
			
				        child:  Column ( 
 
		
	
		
			
				          crossAxisAlignment:  CrossAxisAlignment . start , 
 
		
	
		
			
				          spacing:  8. h , 
 
		
	
		
			
				          children:  [ 
 
		
	
		
			
				            " What is this result? " 
 
		
	
		
			
				                . needTranslation 
 
		
	
		
			
				                . toText16 ( weight:  FontWeight . w600 ,  color:  AppColors . textColor ) , 
 
		
	
		
			
				            testDescription ? . toText12 ( 
 
		
	
		
			
				                    fontWeight:  FontWeight . w500 ,  color:  AppColors . textColorLight )  ? ? 
 
		
	
		
			
				                SizedBox . shrink ( ) 
 
		
	
		
			
				          ] , 
 
		
	
		
			
				        ) ) ; 
 
		
	
		
			
				  } 
 
		
	
		
			
				}