Pesquisar

Article
· Mar 16, 2023 6m read

Kinds of properties in IRIS

InterSystems IRIS has quite a few different kinds properties. Let’s put them in order so that they make better sense.

First of all, I would divide them into categories:

  • Atomic or simple properties (all those %String, %Integer, %Data and other system or user datatypes)
  • References to stored objects
  • Built-in objects
  • Streams (both binary and character)
  • Collections (which are divided into arrays and lists)
  • Relationships (one-many and parent-children)

Some of these kinds of properties are quite straightforward. For example, atomic properties:

Property Name As %Name;
Property DoB As %Date
Property Age As %Integer

They are also easily created using Studio Wizard:

The concepts of references to stored objects and built-in objects are also quite easy to grasp. Basically, if the class of an object you’re trying to use as a property extends %Persistent, then it’s a reference to a stored object. If the related class extends %SerialObject – then it’s a built-in object, because such objects can’t be stored themselves, only inside other objects. And in a class definition they look exactly the same:

Property Human as Sample.Human;

To create this kind of property, on the second step of the Wizard in Studio enter the name of the class:

Streams are also quite easy to explain. You have a big chunk of unstructured data, be it binary or character, and here is your stream. Can be anything – audio, video, document, text etc. Depending on what type of data you want to store, you may choose to use Binary or Character Stream. Another defining characteristic of a stream is the place where you want to store it – on disk (takes less space but accessible from your OS unless you set up access rules for the folder) or in the database (secure, no unauthorized access, takes more space). To work with streams, use classes from package %Stream. For example:

Property Log As %Stream.GlobalCharacter;
Property Instruction As %Stream.FileCharacter(LOCATION = "D:\Temp");
Property Doc As %Stream.FileBinary;
Property Audio As %Stream.GlobalBinary;

In this case input the classname of the stream you wish to use:

Then there are two types of collections:

  • Lists – a collection where each element is defined by its position in the collection
Property FavoriteColors as list of %String;
  • Arrays – key-value pairs, where value is defined by its key that is set by a user
Property Contacts as array of %String;

Both collections can be of simple types or of objects. And when we’re talking about a collection of objects, the objects inside collection aren’t “aware” that they are inside any collection. Meaning that it’s a one-way link.

When working with arrays, it’s necessary to remember that both key and value should be new and useful piece of info. There is no point of making an integer key that will imitate a position in a list. In the example above, key of the Contacts array is a name of the type of the contact, e.g. “Facebook”, “LinkedIn”, “Twitter” etc and the value is a link to a personal page.

Under the hood, when working with a list, you’re working with the class %Collection.ListOfDT for a list of simple types, %Collection.ListOfObj when working with a list of objects and %Collection.ListOfStream when dealing with a list of streams.

The same is true for arrays. %Collection.ArrayOfDT is used when working with an array of simple datatypes, %Collection.ArrayOfObj – when working with an array of objects and %Collection.ArrayOfStream – when working with an array of streams.

For the collection on the second step of the Wizard in Studio choose the second option “The collection of type” 

and then specify the type:

And probably the most challenging kind of the property for people who switch from relational databases – relationship. The relationship is a two-way one-to-many link between two stored objects. In relational DBMS people are taught that they need an additional table to store the foreign keys to two other tables to realize one-to-many link of independent entities. For example:

table Invoice – table Product – table Invoice_Product

There is no need for an additional table/class to do this in IRIS. If there’s no need to often query the information about all the invoices in which the exact Product is listed you can make products as an array or list in an invoice. In this case you will have to manually ascertain logical integrity so that your invoice doesn’t reference products that are no longer in a DB.

To automatically check for the logical integrity of data in this case you can use a relationship between these two classes: Invoice, Product. There are two types of relationships:

  • Parent-children – it’s a dependent link between objects of two different persistent classes. It means that the dependent object can’t exist without the main object. For example, let’s say that a chapter in a book can’t exist without a book. This will be an example of parent-children relationship, where a book is a main object and chapter is a dependent object and if we delete a book all the chapters from this book will be deleted as well.
  • One-many – it’s an independent link between objects of one or two persistent classes. It means that both objects can exist and make sense one without the other and if you try to delete the aggregating object, you’ll get an error saying that you first have to unlink all the linked objects. If you try to delete the linked objects, they will disappear from the aggregating object. Let’s take our invoice and products as an example. We have many products in an invoice. If we try to delete an invoice, we first need to delete all the products from our invoice. If we delete a product, it will disappear from the invoice.

Since it’s a two-way link you need to define the properties in both classes. For example in a class Sample.Invoice you will have the definition:

Relationship Products As Sample.Product [ Cardinality = many, Inverse = Invoice ];


Note that the property is called Relationship and that it has two characteristics:

Cardinality = manymeaning that there are links to many objects inside this property

Inverse = Invoicethis is the name of the property on the other side of the relationship

At the same time in the other class (or it can be in the same class for one-many relationship) there should be the mirror property:

Relationship Invoice As Sample.Invoice [ Cardinality = one, Inverse = Products ];

Here cardinality “one” means that in this property there is a link only to one object.

To create a relationship using Wizard in Studio just choose on the second step Relationship:

Then choose the correct cardinality for the property in the class and fill in the name of the related class and property in it:

For the example with the book with chapters the properties would look as follows.

In a class Sample.Book:

Relationship Chapters As Sample.Chapter [ Cardinality = children, Inverse = Book ];

In a class Sample.Chapter:

Relationship Book As Sample.Book [ Cardinality = parent, Inverse = Chapters ];

This is the end of a brief overview of different kinds of properties present in IRIS. Hope it makes it clearer.

4 Comments
Discussion (4)2
Log in or sign up to continue
Question
· Mar 15, 2023

How to convert a FHIR Patient resource in XML format into a Cache object

Hi.

We are going to have basic patient demographic data coming in to Cache via a webservice. I thought that I should define the input as XML something like the FHIR format (with UK extensions).

In the past we've input XML streams and used the  %XML.Reader to convert them to matching classes successfully, so I thought it would be easy. However, I've found that the FHIR format stores everything in attributes like:

  <gender value="male"/>
  <birthDate value="1982-01-23"/>

Looking in the Cache documentation here there seems no easy way to make a property match to an attribute of "value" without defining another class for each item with a single property called "value" and  XMLPROJECTION = "ATTRIBUTE" . Is that correct or have I missed something? I could invest in Ensemble or IRIS (though I can see nothing different in the IRIS documentation), but seems overkill for one small inbound message. Or should I forget FHIR and stick to a simple XML structure.

Thanks / Mike

6 Comments
Discussion (6)2
Log in or sign up to continue
Article
· Mar 8, 2023 5m read

Keep your docker iris images in shape ;)

iris-docker-multi-stage-script

A python script to keep your docker iris images in shape ;)

Witout changing your dockerfile or your code you can reduce the size of your image by 50% or more !

TL;DR

Name the builder image builder and the final image final and add this to end of your Dockerfile:

Modify your Dockerfile to use a multi-stage build:

ARG IMAGE=intersystemsdc/irishealth-community:latest
FROM $IMAGE as builder

Add this to end of your Dockerfile:

FROM $IMAGE as final

ADD --chown=${ISC_PACKAGE_MGRUSER}:${ISC_PACKAGE_IRISGROUP} https://github.com/grongierisc/iris-docker-multi-stage-script/releases/latest/download/copy-data.py /irisdev/app/copy-data.py

RUN --mount=type=bind,source=/,target=/builder/root,from=builder \
    cp -f /builder/root/usr/irissys/iris.cpf /usr/irissys/iris.cpf && \
    python3 /irisdev/app/copy-data.py -c /usr/irissys/iris.cpf -d /builder/root/ 

Boom! You're done!

11 Comments
Discussion (11)4
Log in or sign up to continue
Article
· Mar 2, 2023 4m read

Tutorial - Streams in Pieces

This tutorial is a follow on to Working with %Query    
It was displaying the content of the input stream chopped in fixed-size chunks.
But often those streams are structured and have well-defined separators (e.g HL7)
So as a side subject of this tutorial, this chapter shows how to break a stream into PIECES.

It is exactly the same idea as the $PIECE() function for strings with some add-ons.


The query takes these input parameters:

  • idfrom = first ID to show
  • idto = last ID to show - missing shos al higher IDs available
  • maxtxt = maximum size of output text from the stream. Default = 25
  • separator = characters as know from $Piece function 
  • startpiece = first piece to display
  • endpiece = last piece to display - if missing only the first is displayed
  • grouped = number of pieces in output text.  limited by maxtxt - default = 1
  • before = number of characters before the limiter from the previous piece

Implementation

The base for the Query was shown in the previous chapters.
Again the Source Object is kept local while processing the related Stream.
And as for the fixed-sized chunks also the Stream Object is kept while
processing the resulting output lines.

To find the pieces and count them method FindAt() scans the whole Stream
as a first action and builds a list of start points. It is used when the pieces
are collected into their groups by line.
The Streàm-Function used is ReadSQL(start, end). It is somewhat sensitive
and honors unprecise values with no result or ERROR. So besides locating all
pieces correctly composing precise and meaningful limits is the major challenge
for this part of the exercise.
It is all packaged in the method Piece() of the example code 

To enable multiple reentrances in the Fetch method all parameters are kept in
the common JSON object of the customized Query.

Here are some examples

  • Record #3 was deleted
  • Record#4 has no stream
  • PieceCnt shows the total pieces in the first row and number of pieces following
  • PieceId shows the number of the first Piece displayed

Some variations to the previous Tutorials:

  • the common variable qHandle that hat holds all requirements changed its name to qj to demonstrate independence from docu and for less typing.
  • the layout of the output in ROWSPEC is changed to also show the number of the starting piece, the total number of pieces in the first row, and the number of pieces in the following rows.

The first example shows objects 1..5 with max 33 chars
separated by || pieces 2..4  grouped by 2  with 3 previous characters

 

[SQL]USER>>call rcc.Q3(1,5,33,'||',2,4,2,3)
7.     call rcc.Q3(1,5,33,'||',2,4,2,3)

Dumping result #1
ID      City    Name    Age     pcCnt   PieceId PieceTxt
1       Bensonh Kovalev 16      52      2       ty.||Scope ||An AmAn LoIcA On
_       _       _       _       2       4        On||Iso
2       Queensb Yeats   15      52      2       00.||LoI||IesMorphSy
_       _       _       _       2       4       hSy||Re Uni
4       Newton  Evans   61      0       2
5       Hialeah Zemaiti 47      52      2       ks.||TwoToLy Wa||LoGraphIc Theti
_       _       _       _       2       4       eti||Ism LoToTri AticViaOpOp
 
7 Rows(s) Affected
statement prepare time(s)/globals/lines/disk: 0.0064s/2159/18029/0ms
          execute time(s)/globals/lines/disk: 0.0060s/186/21480/0ms
                          cached query class: %sqlcq.USER.cls86
---------------------------------------------------------------------------

Next example:
All records from 5 to end, maximum 33 characters, separated with || pieces 50 ..55 and 1 by line

USER>>call rcc.Q3(5,,33,'||',50,55,1)
9.     call rcc.Q3(5,,33,'||',50,55,1)

Dumping result #1
ID      City    Name    Age     pcCnt   PieceId PieceTxt
5       Hialeah Zemaiti 47      52      50      ||LoOp Am TriAmGeo LookMuch ReAble
_       _       _       _       1       51      ||AnIAn I GeoIc Ly Copter A IcA
_       _       _       _       1       52      ||***Done***
6       Elmhurs Jenkins 29      52      50      ||Re PhotoTech Ies
_       _       _       _       1       51      ||A
_       _       _       _       1       52      ||***Done***
7       Islip   Drabek  61      52      50      ||Thetic Status Cycle AmAm To Tech
_       _       _       _       1       51      ||Ly SoundCo CoCo AmCo Am ToRePus
_       _       _       _       1       52      ||***Done***
8       Islip   Kovalev 88      52      50      ||IcGeoType PhysicalLyIsm Ies To T
_       _       _       _       1       51      ||ComI An GeoRange On AnOnTo Two P
_       _       _       _       1       52      ||***Done***
 
12 Rows(s) Affected
statement prepare time(s)/globals/lines/disk: 0.0065s/2158/18091/0ms
          execute time(s)/globals/lines/disk: 0.0082s/245/28753/0ms
                          cached query class: %sqlcq.USER.cls103
---------------------------------------------------------------------------

Just a reminder:
All test data are generated using the System method %Populate
So your output will be different. I suggest you run our tests also with other parameters
than the shown examples to get the full power of this tool.

The full code example is again available on GitHub  

The Video is available now. See section Streams in Pieces 

For immediate access, you can use Demo Server WebTerminal  
and the related system Management Portal on Demo Server SMP

I hope you liked it so far and I can count on your votes.

1 Comment
Discussion (1)1
Log in or sign up to continue
Article
· Mar 2, 2023 5m read

Tutorial - Working with %Query #3

My previous article introduced you to the COS based Custom Class Query.
There were some features missing like more lines of the stream displayed
and numbered.

The basic idea is the same.
A new input parameter chunks is introduced that sets a limit of displayed
pieces of our stream.

/// pack all params into qHandle
/// called only once at start
ClassMethod Q2Execute(
	ByRef qHandle As %Binary,
	idfrom As %Integer = 1,
	idto As %Integer = 0,
	maxtxt As %Integer = 25,
	chunks As %Integer = 1) As %Status
{
  set qHandle={}
  set qHandle.id=0
  set qHandle.idfrom=idfrom
  set qHandle.idto=idto
  set qHandle.obj=0
  set qHandle.stream=0
  set qHandle.maxtxt=maxtxt
  set qHandle.chunks=chunks
  set qHandle.chcnt=1
  Quit $$$OK
}
  • I now have a limit and a counter of displayed chunks default is 1 chunk
  • the Stream Object is kept open in qHandle to avoid reload
  • once the stream is empty I jump to the next available object.

and it looks like that:
 

[SQL]USER>>call rcc.Q2(1,,,3)
11.     call rcc.Q2(1,,,3)

Dumping result #1
ID      City    Name    Age     chunk   Stream
1       Bensonh Kovalev 16      1       Building shareholder valu
_       _       _       _       2       e by delivering secure di
_       _       _       _       3       stributed devices and med
2       Queensb Yeats   15      1       Spearheading the next gen
_       _       _       _       2       eration of high-performan
_       _       _       _       3       ce genetic virtualized in
4       Newton  Evans   61      1
5       Hialeah Zemaiti 47      1       Resellers of premise-base
_       _       _       _       2       d secure XML services for
_       _       _       _       3        social networks.||TwoToL
6       Elmhurs Jenkins 29      1       Enabling individuals and
_       _       _       _       2       businesses to manage ente
_       _       _       _       3       rprise models for social
7       Islip   Drabek  61      1       Building shareholder valu
_       _       _       _       2       e by delivering open crow
_       _       _       _       3       d-sourced voice-enabled c
8       Islip   Kovalev 88      1       Experts in standards-base
_       _       _       _       2       d distributed voice-enabl
_       _       _       _       3       ed services for social ne
 
19 Rows(s) Affected
statement prepare time(s)/globals/lines/disk: 0.0069s/2022/14949/0ms
          execute time(s)/globals/lines/disk: 0.0025s/48/5520/0ms
                          cached query class: %sqlcq.USER.cls82
---------------------------------------------------------------------------

for shorter streams it terminates when stream ends

[SQL]USER>>call rcc.Q2(,4,70,20)
22.     call rcc.Q2(,4,70,20)
 
Dumping result #1
ID      City    Name    Age     chunk   Stream
1       Bensonh Kovalev 16      1       Building shareholder value by delivering secure distributed devices an
_       _       _       _       2       d media for the Health Care community.||Scope ||An AmAn LoIcA On||Iso|
_       _       _       _       3       |PlasmA||Atic CoLoIO||IcOpIon An Lo||Re||Ies Tw||Lo Dyna I||Atic To Ly
_       _       _       _       4       ||Ecto O||AticL||Ism IAn Look||Plasm ||A||A Cop||Two IRe ||Two ||I||Dy
_       _       _       _       5       na Much LoN||Ion AmQuoAn Ec||OpOc||IcTwoCycl||A ComRe||I||GeoPedeLo ||
_       _       _       _       6       Pus EndoPyro||IesIsoIsmCom Te||A||Pyro||I On An I Tr||Syn AIcA||Gyro P
_       _       _       _       7       ho||AmCo UniTe||AScope ComQuo IH||Two A Ect||Graph ||A ||Pyro Heli AnR
_       _       _       _       8       eAn||Muc||Range IcTri||IonIsoIonAnC||A Wave Lo I||PusAt||To||Able ||Lo
_       _       _       _       9       Ati||A||Quo||Ly LyIc||***Done***
2       Queensb Yeats   15      1       Spearheading the next generation of high-performance genetic virtualiz
_       _       _       _       2       ed instruments for the Fortune 500.||LoI||IesMorphSy||Re Uni ||CoQuoEc
_       _       _       _       3       to||Tech IesOn ||Invent Vi||To LyIonGeoIc||Able||Ion Ect||Co I Ic Quo
_       _       _       _       4       U||AOn Much Ly To||Iso Much G||Am||LoIsmGraph Pus ||ReOp ViaComLo||OpI
_       _       _       _       5        TheticOn R||Ly OpCopter Mil||Quo Am Te||T||Plasm Type||On IsoIOpIcOp
_       _       _       _       6       P||I Dyna Tech Q||IGeo Dyna ||An AmLyCo Ion||Ic AnIsm Phot||IesAmI Am
_       _       _       _       7       OpA||KiloAnLo Am Co||Op ATr||TheticGraph||P||IcIc IOnTwoT||Ped||On On
_       _       _       _       8       QuoAnGrap||I||Copter LyQuo||ALookIcMuch Dyn||Abl||Re CoIcMuchCo A||ReO
_       _       _       _       9       nMuchAnToGr||TheticToTec||Ism Ies A||An AIAbleCo ||Q||LoI||Pus Ly ATri
_       _       _       _       10      On G||SoundU||To Heli Com||AOn||Ly Re||ComInventLoR||***Done***
4       Newton  Evans   61      1
20 Rows(s) Affected
statement prepare time(s)/globals/lines/disk: 0.0065s/2020/15410/0ms
          execute time(s)/globals/lines/disk: 0.0021s/33/5048/0ms
                          cached query class: %sqlcq.USER.cls84
---------------------------------------------------------------------------
  • the next step is to honor the separators and display segments
  • and also allow groups of segments
  • As the basic functionality is there it's more a matter of chopping the streams 

Follow me on to the next chapter for the extension of this example that
will show and control more result lines.

Just a reminder:
All test data are generated using the System method %Populate
So your output will be different. I suggest you run our tests also with other parameters
than the shown examples to get the full power of this tool.

The full code example is again available on GitHub  

The Video is available now. See section Custom Class Query 

For immediate access, you can use Demo Server WebTerminal  
and the related system Management Portal on Demo Server SMP

I hope you liked it so far and I can count on your votes.

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