270 likes | 399 Views
Tips, Tricks and Toolkits. Ian Cargill Development Manager Dendrite Clinical Systems. Terminal Window Tricks. ! To run an OS Shell command Do ##class(%SQL.Shell).%Go() or Do $System.SQL.Shell() q(uit) to exit back to terminal User defined Function Keys. Error Handling.
E N D
Tips, Tricks and Toolkits Ian Cargill Development Manager Dendrite Clinical Systems
Terminal Window Tricks • ! To run an OS Shell command • Do ##class(%SQL.Shell).%Go() or • Do $System.SQL.Shell() • q(uit) to exit back to terminal • User defined Function Keys
Error Handling • “Old” style - $ZTrap • I still prefer this • Try / Catch / Return • Would prefer, but not until Return available • Return - Available in Caché 2013.1
Error Handling try { set res="ok" } catch { set res="fail" } Quit Res // oh dear!!!!!
Error HandlingCaché 2013 - RETURN try { return ok" ;; Yippeee !!!! } catch { return "fail" }
SOAP debugging Set ^ISCSOAP("LogFile")="c:\temp\log.txt" Set ^ISCSOAP("Log")="oi" Set ^ISCSOAP("Log")=""
Snippets • Caché 2012 - just the one • Caché 2013 - three, • user definable, redistributable • Ctrl-5
Using Unique Indexes • Normally work with classes using the ID or IdKey field: • ##class(My.Class).%ExistsId(idval) • ##class(My.Class).%OpenId(idval) • ##class(My.Class).%DeleteId(idval) • Not well known, you can actually test / open / delete objects based on a unique index.
Using Unique Indexes • E.g. if a class contains: Index IxNHSNumber On NHSNumber [unique] • You can use: • ##class(My.Class). IxNHSNumberExists(NhsNum) • ##class(My.Class). IxNHSNumberOpen(NhsNum) • ##class(My.Class). IxNHSNumberDelete(NhsNum) • indexnameCheck() ?????????
Useful (Windows) Shortcuts • Start Studio and automatically connect to namespace MYTEST, using user account Fred (password is xxxx). • Shortcut with Target: C:\CacheSys\Bin\CStudio.exe /fastconnect=127.0.0.1[1972]:MYTEST: Fred:xxxx • Similar for other Caché utility tools
Useful Intrinsic Functions: Listblocks • $LISTFROMSTRING • $LISTTOSTRING • $LISTSAME • $LISTVALID • $LISTDATA • $LISTNEXT
Config Package • In %SYS. Not % package, so can only use it in %SYS • Large number of classes for automating tasks that you would normally do via Portal. • http://localhost:57772/csp/documatic/%25CSP.Documatic.cls
ObjectScript Highlights Ian Cargill Development Manager Dendrite Clinical Systems
Using Unique Indexes • Normally work with classes using the ID or IdKey field: • ##class(My.Class).%ExistsId(idval) • ##class(My.Class).%OpenId(idval) • ##class(My.Class).%DeleteId(idval) • Not well known, you can actually test / open / delete objects based on a unique index.
Using Unique Indexes • E.g. if a class contains: Index IxNHSNumber On NHSNumber [unique] • You can use: • ##class(My.Class). IxNHSNumberExists(NhsNum,.id) • ##class(My.Class). IxNHSNumberOpen(NhsNum,.sc) • ##class(My.Class). IxNHSNumberDelete(NhsNum) • ##class(My.Class). IxNHSNumberCheck(NhsNum) ?? • %Library.CacheIndex documents these!
Runtime Class Access $CLASSMETHOD $METHOD $PROPERTY $CLASSNAME
Syntax Set oDat=$CLASSMETHOD(Class, "%New") Set oDat=$CLASSMETHOD(Class, "%OpenId", ObjId) Set CurrentVal=$PROPERTY(oDat, FldName) Set $PROPERTY(oDat, FldName)=NewValue
Useful Intrinsic Functions • $INCREMENT - DIY locks +1, -1 • Set x=$I(x) Set x=$I(x,-1) • $CASE • Set x=$Case(val,1:"red",2:"blue",:"green") • $ZSTRIP • Set str=$ZStrip(str, "<>W") • Set str=$ZStrip(str, "*P", "; ", "Z")
Useful Intrinsic Functions • $ZCONVERT • $ZCVT(str, "U") - to uppercase • $ZCVT(str, "L") - to lowercase • $ZCVT(str, "O","HTML ") • $ZCVT(str, "O", "JS") • $ZCVT(str, "O","URL")
Useful Intrinsic Functions: Listblocks • $LISTFROMSTRING • $LISTTOSTRING • $LISTSAME • $LISTVALID • $LISTDATA • $LISTNEXT
Bulk loading data • $SORTBEGIN • $SORTEND • Use these to inhibit indexing while bulk loading data. • Do all indexing in one hit.
Error Handling • “Old” style - $ZTrap • I still prefer this • Try / Catch / Return • Would prefer, but not until Return available • Return - coming, but not yet !!
Error Handling try { set res="ok" } catch { set res="fail" } Quit Res // oh dear!!!!!
Class Storage • You can control class storage • View | Storage in Studio • Default like • ^Test.PersonD ^Test.PersonI • I prefer • ^MYDB("Test","Person","D") • ^MYDB("Test","Person","I")
%SYSTEM.Encryption • This class provides class functions to perform data encryption, Base64 encoding, hashing, and generation of message authentication codes. • Some complex encryption support for experts, but a number of useful applications for the more humble programmer:
%SYSTEM.Encryption • Encrypting passwords for storage • e.g. MD5Hash, SHA1Hash • Encoding binary data for 'plain text' transmission. E.g. SOAP messages. • Base64Encode • Base64Decode