NetTalk Central

Author Topic: Detect change in record before save?  (Read 3313 times)

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Detect change in record before save?
« on: January 18, 2013, 07:40:46 AM »
Bruce,

     In testing the NT7 app I'm working on, I find some users use the Change button to view a record, instead of the View button.  I have embedded code (post Insert and Post Change) that saves a bit of info in an "audit" file, upon clicking save.  Is there a way to detect if the record was actually changed?  The idea being, not run this code if the user did not change the record.

Thanks,

Jeff King

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11239
    • View Profile
Re: Detect change in record before save?
« Reply #1 on: January 18, 2013, 11:44:24 PM »
Hi Jeff,

this is somewhat outside the scope of NetTalk, because it's more related to the Audit system you're using. Usually the audit software maintains a "watch" of the record before the change, compares it to the write, and then makes a "difference record".

So perhaps tell us a bit more about your system, and a little bit about what you actually store. Do you store the whole record in the audit, or only the fields that changed?

that said it's probably reasonably easy to hook into the Save button for a form, because it loads the record there anyway. I'll need to investigate to find the best approach though.

cheers
Bruce

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: Detect change in record before save?
« Reply #2 on: January 19, 2013, 08:27:10 AM »
Bruce,

     Basically, I have two apps in play here.  One is a NT7 app for patients to enter and maintain their own history information.  The other is our main desktop database, that physicians use to view all data and produce reports.  The desktop app will have access to the history data patients create in the NT7 app.  The physician needs to know if there is new history data or if existing data has been changed/updated, so it can be verified before use in reports.
     So, my idea was to add a new file (PHRRecords.tps) that will be contain a few fields to indicate the status of the patient given history data.  In the PostInsert and PostUpdate embeds of the NT app I have the following code:

  Access:Main_PHRRecords.Open()
  Access:Main_PHRRecords.UseFile()

  PHR:SRC_ID = p_web.GSV('CLI:CLINHX_ID')
  PHR:SRC_FILE = 'Clinical History'
  If Access:Main_PHRRecords.Fetch(PHR:SRCID_KEY) = Level:Benign
    PHR:SRC_ID = p_web.GSV('CLI:CLINHX_ID')
    PHR:SRC_FILE = 'Clinical History'
    PHR:SRC_DATA = 'PHR'
    PHR:SRC_DATE = Today()
    PHR:SRC_TIME = Clock()
    PHR:SRC_ACTION = 'Update'
    PHR:SRC_USER = p_web.GSV('PatientName')
    PHR:SRC_STATUS = 'Not Verified'
    Access:Main_PHRRecords.Update()
  ElsIf Access:Main_PHRRecords.Fetch(PHR:SRCID_KEY) = Level:Notify
    PHR:SRC_ID = p_web.GSV('CLI:CLINHX_ID')
    PHR:SRC_FILE = 'Clinical History'
    PHR:SRC_DATA = 'PHR'
    PHR:SRC_DATE = Today()
    PHR:SRC_TIME = Clock()
    PHR:SRC_ACTION = 'Insert'
    PHR:SRC_USER = p_web.GSV('PatientName')
    PHR:SRC_STATUS = 'Not Verified'
    Access:Main_PHRRecords.Insert()
  END
    Access:Main_PHRRecords.Close()


     As you can see, I'm only storing basic data about the source (src) of the data, such as Clinical History, time and date and whether this was an new record (Insert) or edited data (Change) and the status (eg. Not Verified).  I have added a new browse to the desktop app to display this data so a physician can get an idea of what the patient has entered and have an opportunity to verify if needed.  Once verified, the physician will change the status to 'Verified', and data marked as 'Verified' can be used in reports.  Later on, if the patient updates data or adds new data via the NT app, the status is re-set to Not Verified, and the file will show which data needs to be addressed by the pysician.
     I had a few test users look at the app.  I found that most would open a form by clicking the Change button, look at a few pages and then click the Save button to close the form.  They made no changes to the data, but because they clicked on Save, a new record was created in the PHRRecords file.  Now there is a new entry on the desktop app indicating there is new data that requires verification, when in fact no new data was added.  My understanding is that code in the "PostAction" embed of a form is run when the user clicks on the Save button, so I want to conditionally control when the code in the PostInsert and PostUpdate runs.
     One thought I have is to store the contents of the form record when a form first opens.  Then, when the Save button is clicked, compare the current record to the stored record.  If they are the same then no code is run.  I attempted to do this with the following:

     Added:   SAV:Record    Like(CLI:Record)          in the local data, other declarations embed.
     Then set:  SAV:Record = CLI:Record                 tried various embeds.

     Finally, I wrapped the code mentioned above in a condition, testing to see if the current record was the same as the stored record:

     If CLI:Record <> SAV:Record
          run code above...
     End            

     I did not get this working and I think this is because I have not retreived the current record properly.  So this is where I need assistance.  Am I on the right track?  Can I conditionally fire the code in the PostInsert/PostUpdate embeds?  Or is there a better way to do this?

Thanks,

Jeff
« Last Edit: January 19, 2013, 08:51:47 AM by kingja »

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: Detect change in record before save?
« Reply #3 on: January 19, 2013, 12:11:13 PM »
Bruce,

     In a reply you made to another user question back in October, you mentioned that the ValidateRecord routine contains the record primed for saving (but not yet saved).  Seems this is a good place to test to see if the record has changed at all.  What do you think?  If so, would it be appropriate to test CLI:Record at this point ?

Thanks,

Jeff

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11239
    • View Profile
Re: Detect change in record before save?
« Reply #4 on: January 19, 2013, 09:27:08 PM »
Hi Jeff,

I'm thinking that the best place to check it is just after the record is saved, but before it copies the session values, and values, into the record. Thus a sort of "watch / report" type approach. But I'll need to spend some time figureing out how best to do that in the code, and the best place for it to go.

cheers
Bruce