/*!
 *
 * Copyright (c) 2021-2024 Diality Inc. - All Rights Reserved.
 * \copyright
 * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN
 * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER.
 *
 * \file    PostTreatmentReview.qml
 * \author  (last)      Behrouz NematiPour
 * \date    (last)      31-Jul-2024
 * \author  (original)  Behrouz NematiPour
 * \date    (original)  21-Apr-2021
 *
 */

// Qt
import QtQuick 2.12

// Project
//  Qml imports
import "qrc:/globals"
import "qrc:/components"
import "qrc:/compounds"
import "qrc:/pages/posttreatment"

/*!
 * \brief   the post treatment Treatment Log review screen
 */
PostTreatmentBase { id: _root
    property int colSpacing : Variables.defaultMargin
    property int columnWidth: ( _flickable.width / 2 ) - (colSpacing)

    component LegendItem: Row { id: _legendItem
        property string color   : Colors.offWhite
        property string text    : ""
        spacing: 10

        Rectangle {
            anchors.verticalCenter: parent.verticalCenter
            height  : 10
            width   : height
            radius  : height
            color   : _legendItem.color
        }

        Text {
            color           : _legendItem.color
            text            : _legendItem.text
            font.pixelSize  : Fonts.fontPixelDialogText
            font.weight     : Font.Medium
        }
    }

    Row { id: _topRow
        spacing     : Variables.defaultMargin
        height      : 75

        anchors {
            top             : header.bottom
            topMargin       : Variables.defaultMargin / 2
            left            : parent.left
            leftMargin      : Variables.defaultMargin * 4
            right           : parent.right
            rightMargin     : Variables.defaultMargin * 4
        }

        Item { id: _legend
            width: _root.columnWidth
            height: _topRow.height

            LegendItem { id: _prescribed
                anchors {
                    right       : _actual.left
                    rightMargin : Variables.defaultMargin
                    bottom      : parent.bottom
                }
                text    : qsTr("Prescribed Values")
            }

            LegendItem { id: _actual
                anchors {
                    right   : parent.right
                    bottom  : parent.bottom
                }
                text    : qsTr("Actual Values")
                color   : Colors.ufVolumeGoalText
            }
        }


        Item { id: _qrContainer
            width: _root.columnWidth
            height: _topRow.height

            QRCode { id: _qrCode
                anchors {
                    left: parent.left
                }

                qrcode          : vPostTreatmentAdjustmentTreatmentLog.txCode
                clear           : ! _root.visible
            }

            Text { id: _txCodeText
                anchors {
                    left        : _qrCode.right
                    leftMargin  : Variables.defaultMargin / 2
                    bottom      : _qrCode.bottom
                }
                text            : vPostTreatmentAdjustmentTreatmentLog.txCode ? qsTr("Tx Code: ") + vPostTreatmentAdjustmentTreatmentLog.txCode : " "
                color           : "#DBE9FA"
                font.pixelSize  : Fonts.fontPixelButton
            }
        }
    }

    Flickable { id: _flickable
        anchors {
            top             : _topRow.bottom
            topMargin       : Variables.defaultMargin
            bottom          : _root.bottom
            bottomMargin    : Variables.notificationHeight + Variables.minVGap
            left            : parent.left
            leftMargin      : Variables.defaultMargin * 4
            right           : parent.right
            rightMargin     : Variables.defaultMargin * 4

        }

        contentWidth    : width
        contentHeight   : _row.height
        clip            : true

        Row { id: _row
            width   : _flickable.width
            spacing : Variables.defaultMargin

            Column {  id: _leftColumn
                width   : _root.columnWidth
                spacing : _root.colSpacing

                ReviewContainer { id: _patientInfo
                    title   : qsTr("Patient Information")
                    width   : parent.width

                    label   : [ qsTr("Patient ID")          ,
                                qsTr("Secondary Patient ID")]

                    initial : [ vPostTreatmentAdjustmentTreatmentLog.patientID          ,
                                vPostTreatmentAdjustmentTreatmentLog.secondaryPatientID ]

                    actual  : [ "" , "" ]
                    units   : [ "" , "" ]
                }

                ReviewContainer { id: _bloodFlowDiaysate
                    title   : qsTr("Blood Flow Rate and Dialysate Settings")
                    width   : parent.width
                    label   : [ qsTr("Blood Flow Rate")         ,
                                qsTr("Dialysis Flow Rate")      ,
                                qsTr("Dialyzer Type")           ,
                                qsTr("Dialysate Temperature")   ,
                                qsTr("Dialysate Volume Used")   ]

                    initial : [ vPostTreatmentAdjustmentTreatmentLog.bloodFlowRate          ,
                                vPostTreatmentAdjustmentTreatmentLog.dialysateFlowRate      ,
                                vTreatmentRanges.dialyzerTypeOptions[vPostTreatmentAdjustmentTreatmentLog.dialyzerType]           ,
                                vPostTreatmentAdjustmentTreatmentLog.dialysateTemperature          ,
                                vPostTreatmentAdjustmentTreatmentLog.dialysateVolumeUsed    ]

                    actual  : [ vPostTreatmentAdjustmentTreatmentLog.bloodFlowRateActual        ,
                                vPostTreatmentAdjustmentTreatmentLog.dialysateFlowRateActual    ,
                                 ""                                                             , // leave empty
                                vPostTreatmentAdjustmentTreatmentLog.dialysateTemperatureActual ,
                                 ""                                                             ] // leave empty

                    precision   : [ 0,
                                    0,
                                    0,
                                    Variables.dialysateTempPrecision,
                                    Variables.ultrafiltrationPrecision  ]

                    units   : [ Variables.unitTextFlowRate      ,
                                Variables.unitTextFlowRate      ,
                                ""                              ,
                                Variables.unitTextTemperature   ,
                                Variables.unitVolume            ]
                }

                ReviewContainer { id: _concentrateSettings
                    title   : qsTr("Concentrate Settings")
                    width   : parent.width
                    label   : [ qsTr("Acid Concentrate Type")       ,
                                qsTr("Bicarbonate Cartridge Size")  ,
                                qsTr("Potassium Concentration")     ,
                                qsTr("Calcium Concentration")       ,
                                qsTr("Bicarbonate Concentration")   ,
                                qsTr("Sodium Concentration")        ]

                    initial : [ vTreatmentRanges.acidConcentrateOptions[vPostTreatmentAdjustmentTreatmentLog.acidConcentrateType]               ,
                                vTreatmentRanges.dryBicabCartridgeSizeOptions[vPostTreatmentAdjustmentTreatmentLog.bicarbonateCartridgeSize]    ,
                                vPostTreatmentAdjustmentTreatmentLog.potassiumConcentration    ,
                                vPostTreatmentAdjustmentTreatmentLog.calciumConcentration      ,
                                vPostTreatmentAdjustmentTreatmentLog.bicarbonateConcentration  ,
                                vPostTreatmentAdjustmentTreatmentLog.sodiumConcentration       ]

                    actual  : [ vTreatmentRanges.acidConcentrateOptions[vPostTreatmentAdjustmentTreatmentLog.acidConcentrateTypeActual]             ,
                                vTreatmentRanges.dryBicabCartridgeSizeOptions[vPostTreatmentAdjustmentTreatmentLog.bicarbonateCartridgeSizeActual]  ,
                                vPostTreatmentAdjustmentTreatmentLog.potassiumConcentrationActual      ,
                                vPostTreatmentAdjustmentTreatmentLog.calciumConcentrationActual        ,
                                vPostTreatmentAdjustmentTreatmentLog.bicarbonateConcentrationActual    ,
                                vPostTreatmentAdjustmentTreatmentLog.sodiumConcentrationActual         ]

                    units   : [ ""                              ,
                                ""                              ,
                                Variables.unitTextConcentration ,
                                Variables.unitTextConcentration ,
                                Variables.unitTextConcentration ,
                                Variables.unitTextConcentration ]
                }

                ReviewContainer { id: _vitalsFluidBolus
                    title   : qsTr("Vitals and Fluid Bolus")
                    width   : parent.width

                    label   : [ qsTr("Vitals Interval")         ,
                                qsTr("Fluid Bolus Volume")      ]

                    initial : [ vPostTreatmentAdjustmentTreatmentLog.vitalsInterval         ,
                                vPostTreatmentAdjustmentTreatmentLog.fluidBolusVolume       ]

                    actual  : [ vPostTreatmentAdjustmentTreatmentLog.vitalsIntervalActual   ,
                                vPostTreatmentAdjustmentTreatmentLog.fluidBolusVolumeActual ]

                    units   : [ Variables.unitTextMins  ,
                                Variables.unitTextFluid ]
                }

                ReviewContainer { id: _heparin
                    title   : qsTr("Heparin")
                    width   : parent.width

                    label   : [ qsTr("Heparin Type")                ,
                                qsTr("Heparin Bolus Volume")        ,
                                qsTr("Heparin Delivery Rate")       ,
                                qsTr("Heparin Delivered Volume")    ,
                                qsTr("Heparin Delivery Durraion")   ]

                    initial : [ vTreatmentRanges.heparinTypeOptions[vPostTreatmentAdjustmentTreatmentLog.heparinType]       ,
                                vPostTreatmentAdjustmentTreatmentLog.heparinBolusVolume                                     ,
                                vPostTreatmentAdjustmentTreatmentLog.heparinDispenseRate                                    ,
                                vPostTreatmentAdjustmentTreatmentLog.heparinDeliveredVolume                                 ,
                                vPostTreatmentAdjustmentTreatmentLog.heparinDeliveryDuration                                ]

                    actual  : [ ""                                                                  ,
                                vPostTreatmentAdjustmentTreatmentLog.heparinBolusVolumeActual       ,
                                vPostTreatmentAdjustmentTreatmentLog.heparinDispenseRateActual      ,
                                ""                                                                  ,
                                vPostTreatmentAdjustmentTreatmentLog.heparinDeliveryDurationActual  ]

                    precision   : [ 0                           ,
                                    Variables.heparinPrecision  ,
                                    Variables.heparinPrecision  ,
                                    Variables.heparinPrecision  ,
                                    0                           ]

                    units   : [ Variables.unitHeparinType       ,
                                Variables.unitTextFluid         ,
                                Variables.unitTextDispensingRate,
                                Variables.unitTextFluid         ,
                                Variables.unitTextMins          ]
                }
            }

            Column { id: _rightColumn
                width   : _root.columnWidth
                spacing : _root.colSpacing

                ReviewContainer { id: _treatmentDateTime
                    title   : qsTr("Treatment Date and Time")
                    width   : parent.width

                    label   : [ qsTr("Treatment Start Date, Time")      ,
                                qsTr("Treatment End Date, Time")        ]

                    initial : [ Qt.formatDateTime(new Date(vPostTreatmentAdjustmentTreatmentLog.treatmentStartEpoch), "yyyy/MM/dd, HH:mm")  ,
                                Qt.formatDateTime(new Date(vPostTreatmentAdjustmentTreatmentLog.treatmentEndEpoch)  , "yyyy/MM/dd, HH:mm")  ]

                    actual  : [ "" , "" ]
                    units   : [ "" , ""]
                }

                ReviewContainer { id: _treatmentInformation
                    title   : qsTr("Treatment Information")
                    width   : parent.width

                    label   : [ qsTr("Treatment Modality")  ,
                                qsTr("HDF Operating Mode")  ,
                                qsTr("Duration")            ]

                    initial : [ vTreatmentRanges.treatmentModalityOptions[vPostTreatmentAdjustmentTreatmentLog.treatmentModality]   ,
                                vTreatmentRanges.hdfTreatmentModeOptions[vPostTreatmentAdjustmentTreatmentLog.hDFOperatingMode ]    ,
                                vPostTreatmentAdjustmentTreatmentLog.treatmentDuration                                              ]

                    actual  : [ vTreatmentRanges.treatmentModalityOptions[vPostTreatmentAdjustmentTreatmentLog.treatmentModalityActual] ,
                                vTreatmentRanges.hdfTreatmentModeOptions[vPostTreatmentAdjustmentTreatmentLog.hDFOperatingModeActual ]  ,
                                vPostTreatmentAdjustmentTreatmentLog.treatmentDurationActual                                            ]

                    units   : [ "" , "" , Variables.unitTextMins ]
                }

                ReviewContainer { id: _ultrafiltration
                    title   : qsTr("Ultrafiltration")
                    width   : parent.width

                    label   : [ qsTr("Prescribed Ultrafiltration Volume")   ,
                                qsTr("Final Target Ultrafiltration Volume") ,
                                qsTr("Prescribed Ultrafiltration Rate")     ,
                                qsTr("Final Target Ultrafiltration Rate")   ]

                    initial : [ vPostTreatmentAdjustmentTreatmentLog.uFVolume       ,
                                vPostTreatmentAdjustmentTreatmentLog.uFVolumeTarget ,
                                vPostTreatmentAdjustmentTreatmentLog.uFRate         ,
                                vPostTreatmentAdjustmentTreatmentLog.uFRateTarget   ]

                    actual  : [ vPostTreatmentAdjustmentTreatmentLog.uFVolumeActual ,
                                ""                                                  ,
                                vPostTreatmentAdjustmentTreatmentLog.uFRateActual   ,
                                ""                                                  ]

                    precision   : [ Variables.ultrafiltrationPrecision  ,
                                    Variables.ultrafiltrationPrecision  ,
                                    Variables.ultrafiltrationPrecision  ,
                                    Variables.ultrafiltrationPrecision  ]

                    units   : [ Variables.unitVolume    ,
                                Variables.unitVolume    ,
                                Variables.unitTextRate  ,
                                Variables.unitTextRate  ]
                }

                ReviewContainer { id: _substitutionFluid
                    title   : qsTr("Substitution Fluid")
                    width   : parent.width

                    label   : [ qsTr("Prescribed Substitution Fluid Volume")   ,
                                qsTr("Final Target Substitution Fluid Volume") ,
                                qsTr("Prescribed Substitution Fluid Rate")     ,
                                qsTr("Final Target Substitution Fluid Rate")   ]

                    initial : [ vPostTreatmentAdjustmentTreatmentLog.substitutionVolume         ,
                                vPostTreatmentAdjustmentTreatmentLog.substitutionVolumeTarget   ,
                                vPostTreatmentAdjustmentTreatmentLog.substitutionRate           ,
                                vPostTreatmentAdjustmentTreatmentLog.substitutionRateTarget     ]

                    actual  : [ vPostTreatmentAdjustmentTreatmentLog.substitutionVolumeActual   ,
                                ""                                                              ,
                                vPostTreatmentAdjustmentTreatmentLog.substitutionRateActual     ,
                                ""                                                              ]

                    precision   : [ Variables.substitutionPrecision  ,
                                    Variables.substitutionPrecision  ,
                                    Variables.substitutionPrecision  ,
                                    Variables.substitutionPrecision  ]

                    units   : [ Variables.unitVolume        ,
                                Variables.unitVolume        ,
                                Variables.unitTextFlowRate  ,
                                Variables.unitTextFlowRate  ]
                }

                ReviewContainer { id: _isolatedUltrafiltration
                    title   : qsTr("Isolated Ultrafiltration")
                    width   : parent.width

                    label   : [ qsTr("Prescribed Isolated Ultrafiltration Volume")   ,
                                qsTr("Final Target Isolated Ultrafiltration Volume") ,
                                qsTr("Prescribed Isolated Ultrafiltration Rate")     ,
                                qsTr("Final Target Isolated Ultrafiltration Rate")   ]

                    initial : [ vPostTreatmentAdjustmentTreatmentLog.isoUfVolume        ,
                                vPostTreatmentAdjustmentTreatmentLog.isoUfVolumeTarget  ,
                                vPostTreatmentAdjustmentTreatmentLog.isoUfRate          ,
                                vPostTreatmentAdjustmentTreatmentLog.isoUfRateTarget    ]

                    actual  : [ vPostTreatmentAdjustmentTreatmentLog.isoUfVolumeActual  ,
                                ""                                                      ,
                                vPostTreatmentAdjustmentTreatmentLog.isoUfRateActual    ,
                                ""                                                      ]

                    precision   : [ Variables.ultrafiltrationPrecision  ,
                                    Variables.ultrafiltrationPrecision  ,
                                    Variables.ultrafiltrationPrecision  ,
                                    Variables.ultrafiltrationPrecision  ]

                    units   : [ Variables.unitVolume    ,
                                Variables.unitVolume    ,
                                Variables.unitTextRate  ,
                                Variables.unitTextRate  ]
                }

                ReviewContainer { id: _additionalSettings
                    title   : qsTr("Additional Settings")
                    width   : parent.width

                    label   : [ qsTr("Water Sample Test Result")    ,
                                qsTr("Hepatitis B")                 ]

                    initial : [ vPostTreatmentAdjustmentTreatmentLog.waterSampleTestResult                              ,
                                vTreatmentRanges.hepatitisStatus[vPostTreatmentAdjustmentTreatmentLog.hepatitisStatus]  ]

                    actual      : [ "" , "" ]
                    precision   : [ Variables.waterSamplePrecision  ,
                                    0                               ]
                    units       : [ Variables.unitTextChlorine      ,
                                    Variables.hepatitis             ]
                }
            }
        }
    }

    ScrollBar {
        flickable   : _flickable
        anchors {
            top             : _root.top
            topMargin       : Variables.defaultMargin * 6
            bottom          : _root.bottom
            bottomMargin    : Variables.notificationHeight + Variables.minVGap
            right           : _root.right
        }
    }

    reasonText      : vPostTreatmentAdjustmentTreatmentLog.text()
    informationText : vPostTreatmentAdjustmentTreatmentLog.notification
}
