Public Class frmPatient


    Private Sub btnclose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclose.Click

        Me.Close()
        


    End Sub

    Private Sub txtcasenum_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcasenum.TextChanged
        Try
            If txtcasenum.Text <> "" Then
                sql = "SELECT * FROM `tblpatient` WHERE  `CASENUM` = " & txtcasenum.Text
                result = RETRIEVESINGLE(sql)
 
                If result = True Then

                    With dt.Rows(0)
                        txtfname.Text = .Item("FNAME")
                        txtlname.Text = .Item("LNAME")
                        txtmname.Text = .Item("MNAME")
                        txtaddress.Text = .Item("PADD")
                        txttelno.Text = .Item("TELNO")
                        txtbirthplace.Text = .Item("BIRTHPLACE")
                        txtnationality.Text = .Item("NATIONALITY")
                        txtReligion.Text = .Item("RELIGION")
                        txtOccupation.Text = .Item("OCCUPATION")
                        txtFather.Text = .Item("FATHER")
                        txtFatherAdd.Text = .Item("FATHERADD")
                        txtTelAdd.Text = .Item("FATHERTEL")
                        txtMother.Text = .Item("MOTHER")
                        txtMotherAdd.Text = .Item("MOTHERADD")
                        txtMotherTel.Text = .Item("MOTHERTEL")
                        txtSpouse.Text = .Item("SPOUSE")
                        txtSpouseAdd.Text = .Item("SPOUSEADD")
                        txtSpouseTel.Text = .Item("SPOUSETEL")
                        cboCivilstats.Text = .Item("CIVILSTATUS")
                        txtHospitalPlan.Text = .Item("HOPITALIZATIONPLAN")
                        txtHealthInsurance.Text = .Item("HEALTHINSURANCE")

                        ' DISPLAYPHIC(rdoSSS, rdoSSSDep, rdoGSIS, rdoGSISDep)

                        dtpDateOfBirth.Text = DISPLAYDATE(.Item("DBIRTH"), "dd/MM/yyyy")
                        txtAge.Text = DISPLAYAGE(dtpDateOfBirth.Text, Now())
                        If .Item(5) = "Male" Then
                            rdomale.Checked = True
                        Else
                            rdofemale.Checked = True
                        End If
                        'cboCivilstats.Text = .Item(6)
                        If .Item(7) = True Then
                            chkPhilhealth.Checked = True
                        Else
                            chkPhilhealth.Checked = False
                        End If
                    End With

                    With dt.Rows(0)
 
                    End With
                    sql = "SELECT DATE( `MEDICATIONDATE` )  as 'Date', `MEDECATION` as 'Medication',`TREATMENT` as 'Nursing Procedure and Treatment'  FROM `tblmedication` WHERE  `CASENUM`=" & txtcasenum.Text
                    result = RETRIEVEDTG(dtghistory, sql)
                End If
            End If

        Catch ex As Exception
            'MsgBox(ex.Message)
        End Try

    End Sub
    Dim INC As Integer
    Dim MAXROW As Integer
    Private Sub frmPatient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try 

            SQLINC()
            If result = True Then
                Dim INC As Integer = 0
                RELOAD(INC)
            End If

            lblfirst.Text = INC + 1
            lblend.Text = MAXROW
        Catch ex As Exception
            'MsgBox(ex.Message)
        End Try
    End Sub

    Public Sub SQLINC()
        Try
            sql = "SELECT  `CASENUM`   FROM `tblpatient`"
            result = RETRIEVESINGLE(sql)
            MAXROW = dt.Rows.Count
        Catch ex As Exception
            'MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub RELOAD(ByVal INC As Integer)

        txtcasenum.Text = dt.Rows(INC).Item(0)

    End Sub

    Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click
        Try
            SQLINC()
            INC = 0
            If INC = 0 Then

                RELOAD(INC)
            Else
                MsgBox("No more rows", MsgBoxStyle.Exclamation)
                INC = 0
            End If

            lblfirst.Text = INC + 1
            lblend.Text = MAXROW

        Catch ex As Exception
            'MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click
        Try
            SQLINC()

            If INC > 0 Then
                INC = INC - 1

                RELOAD(INC)

            Else
                MsgBox("No more rows", MsgBoxStyle.Exclamation)
                INC = 0
            End If
            lblfirst.Text = INC + 1
            lblend.Text = MAXROW
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
        Try
            SQLINC()
            If INC <> MAXROW Then
                INC = INC + 1
                RELOAD(INC)

            Else
                If INC = MAXROW - 1 Then
                    MsgBox("No more rows", MsgBoxStyle.Information)
                End If
            End If
            lblfirst.Text = INC
            lblend.Text = MAXROW
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlast.Click
        Try
            SQLINC()

            INC = MAXROW - 1


            RELOAD(INC)

            lblfirst.Text = INC + 1
            lblend.Text = MAXROW

        Catch ex As Exception
            'MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Try
            Dim phil As Integer

            If chkPhilhealth.Checked = True Then
                phil = 1
            Else
                phil = 0
            End If

            sql = "UPDATE tblpatient SET  FNAME = '" & txtfname.Text & _
                        "', LNAME = '" & txtlname.Text & _
                        "', MNAME = '" & txtmname.Text & _
                        "', PADD =   '" & txtaddress.Text & _
                        "', GENDER = '" & INSERTGENDER(rdofemale, rdomale) & _
                        "', TELNO = '" & txttelno.Text & _
                        "', DBIRTH = '" & DISPLAYMYSQLDATE(dtpDateOfBirth.Text, "yyyy-MM-dd") & _
                        "', BIRTHPLACE = '" & txtbirthplace.Text & _
                        "', NATIONALITY = '" & txtnationality.Text & _
                        "', RELIGION = '" & txtReligion.Text & _
                        "', OCCUPATION = '" & txtOccupation.Text & _
                        "', FATHER  = '" & txtFather.Text & _
                        "', FATHERADD = '" & txtFatherAdd.Text & _
                        "', FATHERTEL = '" & txtTelAdd.Text & _
                        "', MOTHER = '" & txtMother.Text & _
                        "', MOTHERADD = '" & txtMotherAdd.Text & _
                        "', MOTHERTEL = '" & txtMotherTel.Text & _
                        "', SPOUSE = '" & txtSpouse.Text & _
                        "', SPOUSEADD = '" & txtSpouseAdd.Text & _
                        "', SPOUSETEL = '" & txtSpouseTel.Text & _
                        "', CIVILSTATUS = '" & cboCivilstats.Text & _
                        "', PHILHEALTH =  " & phil & _
                        " , HOPITALIZATIONPLAN = '" & txtHospitalPlan.Text & _
                        "', HEALTHINSURANCE = '" & txtHealthInsurance.Text & _
                        "'  WHERE CASENUM=" & txtcasenum.Text
              result = CUD(sql)

            MsgBox("Patient has been updated!")

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub rdoSSS_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdoSSSDep.CheckedChanged, rdoSSS.CheckedChanged, rdoGSISDep.CheckedChanged, rdoGSIS.CheckedChanged

    End Sub

    Private Sub dtpDateOfBirth_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles dtpDateOfBirth.KeyPress
        e.Handled = True
    End Sub
 
    Private Sub TabControl1_Selected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControl1.Selected
        Try
            sql = "SELECT `ADMITTINGDIAGNOSIS` ,`OTHERDIAGNOSIS`, `FINALDIAGNOSIS` " & _
            " FROM `tbldischargesummary` d ,`tbladmitting` a " & _
            " WHERE  d.`ADMITTINGID`=a.`ADMITTINGID` AND a.`CASENUM` =" & txtcasenum.Text
            RETRIEVEDTG(dtghistory, sql)
        Catch ex As Exception

        End Try
    End Sub
End Class