NetTalk Central

Author Topic: Help with NT 14.13 API  (Read 6248 times)

rjolda

  • Sr. Member
  • ****
  • Posts: 329
    • View Profile
    • Email
Re: Help with NT 14.13 API
« Reply #15 on: February 06, 2024, 10:55:48 AM »
Jeff,
GREAT!  Let us know if you want us to try and break it.
Ron :)

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: Help with NT 14.13 API
« Reply #16 on: February 08, 2024, 04:28:31 PM »
Hi Bruce and Ron,

   Here is what I'm doing now, after looking at the flow in the generated source:

1.  The InsertRecord:PatientEnrollment routine has the following code at the beginning:

   code
  ! Start of "Start of InsertRecord: Routine"
  ! [Priority 5000]
 
  ! End of "Start of InsertRecord: Routine"
  Clear(Enr:Record)
  do QueueToFile:PatientEnrollment
  TableAction = 'insert'
  do PrimeFields:PatientEnrollment
  Do ValidateRecord:PatientEnrollment
  If err = 0
    Get(PatientEnrollment,0) ! Prime duplicate checking for Insert
    errString = p_web.CheckForDuplicates(PatientEnrollment)
    if ErrString
      ! Start of "InsertRecord Duplicate Detected"
      ! [Priority 5000]
     
      ! End of "InsertRecord Duplicate Detected"
      Err = DupKeyErr
      p_web.AddServiceError(DupKeyErr,'EDC_Enrollment', p_web.RecordIdentifier(PatientEnrollment), clip(ErrString),'')
      p_web.trace('EDC_Enrollment -- InsertRecord:PatientEnrollment -- Error Inserting: ' & ErrString)
    Else
      ! Start of "InsertRecord Before Add"
      ! [Priority 4000]

   
   The "If err = 0", is where I think I can cause the InsertRecord routine to run conditionally.  The ValidateRecord routine is run just before this.  So, in the End of ValidateRecord embed I placed the following:

   Ins:Institution_ID = Enr:Institution_ID
         If Access:Institution.Fetch(Ins:InstID_key) <> Level:Benign     
          err = 1       
          p_web.AddServiceError(999, '', 'Inst ID Not found:', '', 'Check Institution ID')
         ELSE
          !
         END


   This allows me to check the incoming Institution_ID and if not valid, I set err = 1.  This causes most of the "Insert" code in the InsertRecord routine to be skipped, and an error message is sent back to the client, 'Inst ID Not found:'.

Finally, in the InsertRecord Before Add embed, I have the following code:

     Ins:Institution_ID = Enr:Institution_ID
          If Access:Institution.Fetch(Ins:InstID_key) = Level:Benign             
              Access:PatientEnrollment.PrimeAutoInc()   
              !Access:PatientEnrollment.PrimeRecord(1)
              Enr:Study_ID = 'Z'&Format(Enr:Institution_ID, '@N02')&'-'&Format(Enr:Patient_ID, '@N04')         
          END

This primes the auto-numbered field Patient_ID properly and the Study_ID is constructed and passed back to the client.  Let me know if you have any thoughts or comments on ways I might do this better.

Thanks,

Jeff
« Last Edit: February 08, 2024, 04:31:20 PM by jking »