Hi Bruce,
I have a NT 12.19 Web App that has an API Client in it (standard windows procedure). This client, when called from a button in my web app (running in a browser), works fine. It connects to the remote server and gets data (JSON) as expected.
I now want to use it to fill in missing data in a tps file. My plan is to loop through the tps file and check a status field. If blank, I want to call the API Client and search the remote server for the missing data and place this data in a queue. After the loop finishes, I'll process the queue to update my target tps file.
So, I copied the API Client procedure and made some modifications. First, I added a button the the window so I can call it manually during testing. I placed the following code in the button embed:
Access:Pathology_MKD.Open()
Access:Pathology_MKD.UseFile()
Set(Pathology_MKD,PatMKD:GUID_KEY)
Loop
Case Access:Pathology_MKD.Next()
OF Level:Benign
If PatMKD:LIS_STATUS = '' OR 'Patient Not Found'
net.customheader = ''
net.ContentType = 'application/json'
net.authorization = '****************'
net.FreeFieldsQueue()
myURL = 'https://*******************/StudyAPI/api/Study?'&|
'firstName='&Clip(PatMKD:FirstName)&|
'&lastName='&Clip(PatMKD:LastName)&|
'&DateOfBirth='&Format(PatMKD:DateOfBirth, @D02B)&|
'&city='&Clip(PatMKD:SubjectCity)&|
'&country='&Clip(PatMKD:SubjectCountry)
net.Get(Clip(myURL),'')
END
ELSE
BREAK
END
END
Access:Pathology_MKD.Close()
!!Post-process queue and update MKD file here...
To process the incoming JSON data and place in a queue, I have the following code in my PageReceived embed:
net.removeheader()
?response{prop:text} = self.ThisPage.GetValue()
str.SetValue(?response{prop:text})
json.Start()
json.LoadString(str)
!Free(PreludePathology)
loop X# = 1 to json.Records()
jsonItem &= json.Get(X#)
PPTH:StudyId = jsonItem.GetValueByName('StudyId')
PPTH:ReportType = jsonItem.GetValueByName('ReportType')
PPTH:Focality = jsonItem.GetValueByName('Focality')
PPTH:BiopsyType = jsonItem.GetValueByName('BiopsyType')
PPTH:Grade = jsonItem.GetValueByName('Grade')
PPTH:TumorSize = jsonItem.GetValueByName('TumorSize')
PPTH:SiteOfDCIS = jsonItem.GetValueByName('SiteOfDCIS')
PPTH:Palpable = jsonItem.GetValueByName('Palpable')
PPTH:Necrosis = jsonItem.GetValueByName('Necrosis')
PPTH:MarginStatus = jsonItem.GetValueByName('MarginStatus')
PPTH:MarginDistance = jsonItem.GetValueByName('MarginDistance')
PPTH:Architecture = jsonItem.GetValueByName('Architecture')
PPTH:ERStatus = jsonItem.GetValueByName('ERStatus')
PPTH:ERScore = jsonItem.GetValueByName('ERScore')
PPTH:PRStatus = jsonItem.GetValueByName('PRStatus')
PPTH:PRScore = jsonItem.GetValueByName('PRScore')
PPTH:HER2Status = jsonItem.GetValueByName('HER2Status')
PPTH:HER2Score = jsonItem.GetValueByName('HER2Score')
PPTH:TotalScore = jsonItem.GetValueByName('TotalScore')
PPTH:BCSRisk = jsonItem.GetValueByName('BCSRisk')
PPTH:RTRisk = jsonItem.GetValueByName('RTRisk')
PPTH:OrderId = jsonItem.GetValueByName('OrderId')
PPTH:Guid = jsonItem.GetValueByName('Guid')
PPTH:ReportId = jsonItem.GetValueByName('ReportId')
PPTH:InsertDate = jsonItem.GetValueByName('InsertDate')
PPTH:Accession = jsonItem.GetValueByName('Accession')
PPTH:MasterAccession = jsonItem.GetValueByName('MasterAccession')
PPTH:Version = jsonItem.GetValueByName('Version')
PPTH:AddComments = jsonItem.GetValueByName('AddComments')
PPTH:PatientAgeAtDCISDx = jsonItem.GetValueByName('PatientAgeAtDCISDx')
Add(PreludePathology)
END
Sort(PreludePathology, +PPTH:StudyId)
I find I'm only getting the last record in the file, placed into the queue. I suspect my loop logic is incorrect or there is a timing issue. Perhaps the loop completes before the API Client data arrives. Can you suggest where I went wrong here?
Thanks,
Jeff King