CPatient.cls

 VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CPatient"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

Private m_Conn As ADODB.Connection
Private m_FirstName As String
Private m_LastName As String
Private m_CNP As String
Private m_RegistrationID As String
Private m_RegistrationDate As String
Private m_PreviousLastName As String
Private m_FatherName As String
Private m_MotherName As String
Private m_DateOfBirth As String
Private m_PlaceOfBirthCity As String
Private m_PlaceOfBirthCounty As String
Private m_Address As String
Private m_City As String
Private m_County As String
Private m_PostalCode As String
Private m_CardID As String
Private m_BloodType As String
Private m_Sex As String
Private m_JobTitle As String
Private m_Employer As String
Private m_AntecedentsHC As String
Private m_AntecedentsPF As String
Private m_AntecedentsPP As String
Private m_blnIsNew As Boolean


Private Sub Class_Initialize()
      
    Set m_Conn = New ADODB.Connection
    m_Conn.Open ConnectString
   
End Sub

Private Sub Class_Terminate()
    m_Conn.Close
    Set m_Conn = Nothing
End Sub

Public Function GetNew() As ADODB.Recordset
   
    Dim rs As New ADODB.Recordset
       
    With rs.Fields
        .Append "Address", adChar, 50, adFldUpdatable
        .Append "AntecedentsHC", adLongVarChar, 1024, adFldUpdatable
        .Append "AntecedentsPF", adLongVarChar, 1024, adFldUpdatable
        .Append "AntecedentsPP", adLongVarChar, 1024, adFldUpdatable
        .Append "BloodType", adChar, 5, adFldUpdatable
        .Append "CardID", adChar, 10, adFldUpdatable
        .Append "City", adChar, 50, adFldUpdatable
        .Append "CNP", adChar, 13, adFldUpdatable
        .Append "County", adChar, 2, adFldUpdatable
        .Append "DateOfBirth", adChar, 10, adFldUpdatable
        .Append "Employer", adChar, 50, adFldUpdatable
        .Append "FatherName", adChar, 50, adFldUpdatable
        .Append "FirstName", adChar, 50, adFldUpdatable
        .Append "JobTitle", adChar, 50, adFldUpdatable
        .Append "LastName", adChar, 50, adFldUpdatable
        .Append "MotherName", adChar, 50, adFldUpdatable
        .Append "PlaceOfBirthCity", adChar, 50, adFldUpdatable
        .Append "PlaceOfBirthCounty", adChar, 50, adFldUpdatable
        .Append "PostalCode", adChar, 5, adFldUpdatable
        .Append "PreviousLastName", adChar, 50, adFldUpdatable
        .Append "RegistrationDate", adChar, 10, adFldUpdatable
        .Append "RegistrationID", adChar, 50, adFldUpdatable
        .Append "Sex", adChar, 1, adFldUpdatable
    End With
    rs.Open
    With rs
        .AddNew
        !Address = ""
        !AntecedentsHC = ""
        !AntecedentsPF = ""
        !AntecedentsPP = ""
        !BloodType = ""
        !CardID = ""
        !City = ""
        !CNP = ""
        !County = ""
        !DateOfBirth = ConvertDate2String(FormatDateTime(Now(), vbShortDate))
        !Employer = ""
        !FatherName = ""
        !FirstName = ""
        !JobTitle = ""
        !LastName = ""
        !MotherName = ""
        !PlaceOfBirthCity = ""
        !PlaceOfBirthCounty = ""
        !PostalCode = ""
        !PreviousLastName = ""
        !RegistrationDate = ConvertDate2String(FormatDateTime(Now(), vbShortDate))
        !RegistrationID = ""
        !Sex = ""
        .Update
    End With
   
    m_Address = ""
    m_AntecedentsHC = ""
    m_AntecedentsPF = ""
    m_AntecedentsPP = ""
    m_BloodType = ""
    m_CardID = ""
    m_City = ""
    m_CNP = ""
    m_County = ""
    m_DateOfBirth = ConvertDate2String(FormatDateTime(Now(), vbShortDate))
    m_Employer = ""
    m_FatherName = ""
    m_FirstName = ""
    m_JobTitle = ""
    m_LastName = ""
    m_MotherName = ""
    m_PlaceOfBirthCity = ""
    m_PlaceOfBirthCounty = ""
    m_PostalCode = ""
    m_PreviousLastName = ""
    m_RegistrationDate = ConvertDate2String(FormatDateTime(Now(), vbShortDate))
    m_RegistrationID = ""
    m_Sex = ""
   
    Set GetNew = rs
    Set rs.ActiveConnection = Nothing
   
End Function

Public Function CheckDuplicateRegistrationID(ByVal strRegistrationID As String, Optional ByVal strCNP As String) As Boolean
   
    Dim cmdCheckDuplicate As ADODB.Command
    Dim rs As ADODB.Recordset
    Dim strSQL As String
   
    strSQL = "Select RegistrationID from Patients Where RegistrationID='" & strRegistrationID & "'"
   
    If strCNP <> "" Then strSQL = strSQL & " and CNP<>'" & strCNP & "';"
    Set cmdCheckDuplicate = New ADODB.Command
    cmdCheckDuplicate.ActiveConnection = m_Conn
    cmdCheckDuplicate.CommandType = adCmdText
    cmdCheckDuplicate.CommandText = strSQL
   
    Set rs = cmdCheckDuplicate.Execute
    If rs.EOF Then
        CheckDuplicateRegistrationID = False
    Else
        CheckDuplicateRegistrationID = True
    End If
   
    Set cmdCheckDuplicate = Nothing
    Set rs = Nothing
   
   
End Function


Public Function CheckDuplicateCNP(ByVal strCNP As String) As Boolean
   
    Dim cmdCheckDuplicate As ADODB.Command
    Dim rs As ADODB.Recordset
    Dim strSQL As String
   
    strSQL = "Select CNP from Patients Where CNP='" & strCNP & "';"
   
    Set cmdCheckDuplicate = New ADODB.Command
    cmdCheckDuplicate.ActiveConnection = m_Conn
    cmdCheckDuplicate.CommandType = adCmdText
    cmdCheckDuplicate.CommandText = strSQL
   
    Set rs = cmdCheckDuplicate.Execute
    If rs.EOF Then
        CheckDuplicateCNP = False
    Else
        CheckDuplicateCNP = True
    End If
   
    Set cmdCheckDuplicate = Nothing
    Set rs = Nothing
   
   
End Function

Public Function GetPatientDetails(ByVal strCNP As String) As ADODB.Recordset

    Dim rs As New ADODB.Recordset
    Dim strSQL As String
       
    'construct query string for recordset
    strSQL = "Select * from Patients Where CNP='" & strCNP & "';"
    'set up a recordset object for patient
    rs.ActiveConnection = m_Conn
    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenStatic
    rs.LockType = adLockOptimistic
    rs.Open strSQL

    If rs.EOF Then
        Set GetPatientDetails = Nothing
    Else
        Call SaveAttributes(rs)
        Set GetPatientDetails = rs
    End If
    Set rs.ActiveConnection = Nothing
   
End Function


Private Function SaveAttributes(ByVal rs As ADODB.Recordset)
       
        FirstName = rs!FirstName
        LastName = rs!LastName
        CNP = rs!CNP
        RegistrationID = IIf(IsNull(rs!RegistrationID), "", rs!RegistrationID)
        RegistrationDate = ConvertDate2String(rs!RegistrationDate)
        PreviousLastName = IIf(IsNull(rs!PreviousLastName), "", rs!PreviousLastName)
        FatherName = IIf(IsNull(rs!FatherName), "", rs!FatherName)
        MotherName = IIf(IsNull(rs!MotherName), "", rs!MotherName)
        DateOfBirth = ConvertDate2String(rs!DateOfBirth)
        PlaceOfBirthCity = IIf(IsNull(rs!PlaceOfBirthCity), "", rs!PlaceOfBirthCity)
        PlaceOfBirthCounty = IIf(IsNull(rs!PlaceOfBirthCounty), "", rs!PlaceOfBirthCounty)
        Address = IIf(IsNull(rs!Address), "", rs!Address)
        City = IIf(IsNull(rs!City), "", rs!City)
        County = IIf(IsNull(rs!County), "", rs!County)
        PostalCode = IIf(IsNull(rs!PostalCode), "", rs!PostalCode)
        CardID = IIf(IsNull(rs!CardID), "", rs!CardID)
        BloodType = IIf(IsNull(rs!BloodType), "", rs!BloodType)
        Sex = IIf(IsNull(rs!Sex), "", rs!Sex)
        JobTitle = IIf(IsNull(rs!JobTitle), "", rs!JobTitle)
        Employer = IIf(IsNull(rs!Employer), "", rs!Employer)
        AntecedentsHC = IIf(IsNull(rs!AntecedentsHC), "", rs!AntecedentsHC)
        AntecedentsPF = IIf(IsNull(rs!AntecedentsPF), "", rs!AntecedentsPF)
        AntecedentsPP = IIf(IsNull(rs!AntecedentsPP), "", rs!AntecedentsPP)

End Function

'saves modification to db
Public Function Save(rs As ADODB.Recordset) As Boolean

    On Error GoTo myerr
   
    Dim cmdPatient As ADODB.Command
    Dim strSQL As String
   
    Select Case m_blnIsNew
    Case True
        strSQL = "Insert into Patients "
        strSQL = strSQL & "(CNP,"
        strSQL = strSQL & "FirstName,"
        strSQL = strSQL & "LastName,"
        strSQL = strSQL & "RegistrationID,"
        strSQL = strSQL & "RegistrationDate,"
        strSQL = strSQL & "PreviousLastName,"
        strSQL = strSQL & "FatherName,"
        strSQL = strSQL & "MotherName,"
        strSQL = strSQL & "DateOfBirth,"
        strSQL = strSQL & "PlaceOfBirthCity,"
        strSQL = strSQL & "PlaceOfBirthCounty,"
        strSQL = strSQL & "Address,"
        strSQL = strSQL & "City,"
        strSQL = strSQL & "County,"
        strSQL = strSQL & "PostalCode,"
        strSQL = strSQL & "CardID,"
        strSQL = strSQL & "BloodType,"
        strSQL = strSQL & "Sex,"
        strSQL = strSQL & "JobTitle,"
        strSQL = strSQL & "Employer,"
        strSQL = strSQL & "AntecedentsHC,"
        strSQL = strSQL & "AntecedentsPF,"
        strSQL = strSQL & "AntecedentsPP) values ("
        strSQL = strSQL & rs!CNP & ","
        strSQL = strSQL & "'" & rs!FirstName & "',"
        strSQL = strSQL & "'" & rs!LastName & "',"
        strSQL = strSQL & "'" & rs!RegistrationID & "',"
        strSQL = strSQL & "#" & ConvertDate2String(rs!RegistrationDate) & "#,"
        strSQL = strSQL & "'" & rs!PreviousLastName & "',"
        strSQL = strSQL & "'" & rs!FatherName & "',"
        strSQL = strSQL & "'" & rs!MotherName & "',"
        strSQL = strSQL & "#" & ConvertDate2String(rs!DateOfBirth) & "#,"
        strSQL = strSQL & "'" & rs!PlaceOfBirthCity & "',"
        strSQL = strSQL & "'" & rs!PlaceOfBirthCounty & "',"
        strSQL = strSQL & "'" & rs!Address & "',"
        strSQL = strSQL & "'" & rs!City & "',"
        strSQL = strSQL & "'" & rs!County & "',"
        strSQL = strSQL & "'" & rs!PostalCode & "',"
        strSQL = strSQL & "'" & rs!CardID & "',"
        strSQL = strSQL & "'" & rs!BloodType & "',"
        strSQL = strSQL & "'" & rs!Sex & "',"
        strSQL = strSQL & "'" & rs!JobTitle & "',"
        strSQL = strSQL & "'" & rs!Employer & "',"
        strSQL = strSQL & "'" & rs!AntecedentsHC & "',"
        strSQL = strSQL & "'" & rs!AntecedentsPF & "',"
        strSQL = strSQL & "'" & rs!AntecedentsPP & "')"
    Case False
        strSQL = "Update Patients Set "
        strSQL = strSQL & "FirstName='" & rs!FirstName & "', "
        strSQL = strSQL & "LastName='" & rs!LastName & "', "
        strSQL = strSQL & "RegistrationID='" & rs!RegistrationID & "', "
        strSQL = strSQL & "RegistrationDate=#" & ConvertDate2String(rs!RegistrationDate) & "#, "
        strSQL = strSQL & "PreviousLastName='" & rs!PreviousLastName & "', "
        strSQL = strSQL & "FatherName='" & rs!FatherName & "', "
        strSQL = strSQL & "MotherName='" & rs!MotherName & "', "
        strSQL = strSQL & "DateOfBirth=#" & ConvertDate2String(rs!DateOfBirth) & "#, "
        strSQL = strSQL & "PlaceOfBirthCity='" & rs!PlaceOfBirthCity & "', "
        strSQL = strSQL & "PlaceOfBirthCounty='" & rs!PlaceOfBirthCounty & "', "
        strSQL = strSQL & "Address='" & rs!Address & "', "
        strSQL = strSQL & "City='" & rs!City & "', "
        strSQL = strSQL & "County='" & rs!County & "', "
        strSQL = strSQL & "PostalCode='" & rs!PostalCode & "', "
        strSQL = strSQL & "CardID='" & rs!CardID & "', "
        strSQL = strSQL & "BloodType='" & rs!BloodType & "', "
        strSQL = strSQL & "Sex='" & rs!Sex & "', "
        strSQL = strSQL & "JobTitle='" & rs!JobTitle & "', "
        strSQL = strSQL & "Employer='" & rs!Employer & "', "
        strSQL = strSQL & "AntecedentsHC='" & rs!AntecedentsHC & "', "
        strSQL = strSQL & "AntecedentsPF='" & rs!AntecedentsPF & "', "
        strSQL = strSQL & "AntecedentsPP='" & rs!AntecedentsPP & "' "
        strSQL = strSQL & "Where CNP='" & rs!CNP & "'"
    End Select
    'set up a command object
    Set cmdPatient = New ADODB.Command
    cmdPatient.ActiveConnection = m_Conn
    cmdPatient.CommandText = strSQL
    cmdPatient.CommandType = adCmdText
    cmdPatient.Execute 'insert or update the record
   
    'saves object atributes
    Call SaveAttributes(rs)
    Save = True
    Exit Function
   
myerr:
    Save = False
    Err.Clear
   
End Function

'atributes
Public Property Get FirstName() As String
    FirstName = m_FirstName
End Property

Public Property Let FirstName(ByVal vNewValue As String)
    m_FirstName = vNewValue
End Property

Public Property Get LastName() As String
    LastName = m_LastName
End Property

Public Property Let LastName(ByVal vNewValue As String)
    m_LastName = vNewValue
End Property

Public Property Get CNP() As String
    CNP = m_CNP
End Property

Public Property Let CNP(ByVal vNewValue As String)
    m_CNP = vNewValue
End Property

Public Property Get RegistrationID() As String
    RegistrationID = m_RegistrationID
End Property

Public Property Let RegistrationID(ByVal vNewValue As String)
    m_RegistrationID = vNewValue
End Property

Public Property Get RegistrationDate() As String
    RegistrationDate = m_RegistrationDate
End Property

Public Property Let RegistrationDate(ByVal vNewValue As String)
    m_RegistrationDate = vNewValue
End Property

Public Property Get PreviousLastName() As String
    PreviousLastName = m_PreviousLastName
End Property

Public Property Let PreviousLastName(ByVal vNewValue As String)
    m_PreviousLastName = vNewValue
End Property

Public Property Get FatherName() As String
    FatherName = m_FatherName
End Property

Public Property Let FatherName(ByVal vNewValue As String)
    m_FatherName = vNewValue
End Property

Public Property Get MotherName() As String
    MotherName = m_MotherName
End Property

Public Property Let MotherName(ByVal vNewValue As String)
    m_MotherName = vNewValue
End Property

Public Property Get DateOfBirth() As String
    DateOfBirth = m_DateOfBirth
End Property

Public Property Let DateOfBirth(ByVal vNewValue As String)
    m_DateOfBirth = vNewValue
End Property

Public Property Get PlaceOfBirthCity() As String
    PlaceOfBirthCity = m_PlaceOfBirthCity
End Property

Public Property Let PlaceOfBirthCity(ByVal vNewValue As String)
    m_PlaceOfBirthCity = vNewValue
End Property

Public Property Get PlaceOfBirthCounty() As String
    PlaceOfBirthCounty = m_PlaceOfBirthCounty
End Property

Public Property Let PlaceOfBirthCounty(ByVal vNewValue As String)
    m_PlaceOfBirthCounty = vNewValue
End Property

Public Property Get Address() As String
    Address = m_Address
End Property

Public Property Let Address(ByVal vNewValue As String)
    m_Address = vNewValue
End Property

Public Property Get City() As String
    City = m_City
End Property

Public Property Let City(ByVal vNewValue As String)
    m_City = vNewValue
End Property

Public Property Get County() As String
    County = m_County
End Property

Public Property Let County(ByVal vNewValue As String)
    m_County = vNewValue
End Property

Public Property Get PostalCode() As String
    PostalCode = m_PostalCode
End Property

Public Property Let PostalCode(ByVal vNewValue As String)
    m_PostalCode = vNewValue
End Property

Public Property Get CardID() As String
    CardID = m_CardID
End Property

Public Property Let CardID(ByVal vNewValue As String)
    m_CardID = vNewValue
End Property

Public Property Get BloodType() As String
    BloodType = m_BloodType
End Property

Public Property Let BloodType(ByVal vNewValue As String)
    m_BloodType = vNewValue
End Property

Public Property Get Sex() As String
    Sex = m_Sex
End Property

Public Property Let Sex(ByVal vNewValue As String)
    m_Sex = vNewValue
End Property

Public Property Get JobTitle() As String
    JobTitle = m_JobTitle
End Property

Public Property Let JobTitle(ByVal vNewValue As String)
    m_JobTitle = vNewValue
End Property

Public Property Get Employer() As String
    Employer = m_Employer
End Property

Public Property Let Employer(ByVal vNewValue As String)
    m_Employer = vNewValue
End Property

Public Property Get AntecedentsHC() As String
    AntecedentsHC = m_AntecedentsHC
End Property

Public Property Let AntecedentsHC(ByVal vNewValue As String)
    m_AntecedentsHC = vNewValue
End Property

Public Property Get AntecedentsPF() As String
    AntecedentsPF = m_AntecedentsPF
End Property

Public Property Let AntecedentsPF(ByVal vNewValue As String)
    m_AntecedentsPF = vNewValue
End Property

Public Property Get AntecedentsPP() As String
    AntecedentsPP = m_AntecedentsPP
End Property

Public Property Let AntecedentsPP(ByVal vNewValue As String)
    m_AntecedentsPP = vNewValue
End Property

Public Property Get IsNew() As Boolean
    IsNew = m_blnIsNew
End Property

Public Property Let IsNew(ByVal vNewValue As Boolean)
    m_blnIsNew = vNewValue
End Property

Project Homepage: