Article
· Feb 3 2m read

My first real use case for Embedded Python

The architect of the JSON schema (MS) asked if IRIS could  perform schema validation. I asked on Discord objectscript channel how we could validate a Dynamic Object against a JSON schema. Dmitry Maslennikov replied that probably the easiest way would be to use python, but it would require converting ObjectScript JSON to Python dict.

I refer to this as my first real use case for Embedded Python, because previous examples I had tried I could have implemented in ObjectScript just as easily as in Python.

Yesterday I worked with MS to use jsonschema project to validate one of my HL7 test messages against the schema file (https://github.com/oliverwilms/iris-hl7/blob/main/schema/hl7jsonschema.yml)

 I added a new class otw.python.test (https://github.com/oliverwilms/iris-hl7/blob/main/src/otw/python/test.cls) in iris-hl7 repo. MS provided a requirements.txt file (https://github.com/oliverwilms/iris-hl7/blob/main/requirements.txt)

A variable called json holds the converted HL7 test message:

Set dobj = {"message_type":"MFN","message_event_type":"Z01","message_activity_type":"Item Record Update","hl7_version":"2.3","site_id":"688","segment":[{"name":"MSH","sequence":{"1":"MSH","2":"~^\\&","3":"PRCP_SS_VISTA","5":"PRCP_SSTATION","7":"20240125141848-0500","9":"MFN~Z01","10":"442464384179","11":"T","12":"2.3","15":"AL","16":"NE","17":"USA"}},{"name":"MFI","sequence":{"1":"445","3":"UPD","4":"20240125141848","6":"NE"}},{"name":"MFE","sequence":{"1":"MUP","4":"278~STRAW,DRINKING,PLSTC,L 7 3/4IN,FLEX,WRAPPED,SUPER JUMBO,WHT"}},{"name":"ZIM","sequence":{"1":"278~STRAW-DRINK-1I12","2":"~442-TEST092","3":"10","4":"5","5":"2","6":"BX","7":"1","8":"3.224"}}]}

    Set json = dobj.%ToJSON

I read the schema file into variable called schema.

The magic appeared to work when we used the following line:

Do js.validate(json, yml.”safe_load”(schema))

I opened IRIS session and executed

Do ##class(otw.python.test).jsonschema()

Discussion (0)1
Log in or sign up to continue