Need help creation enumeration like data structure in Cache

482 views
Skip to first unread message

Laavanya

unread,
Feb 19, 2014, 2:24:46 AM2/19/14
to intersystems...@googlegroups.com

Hey Guys, 

 

Coming from a .Net background I'm fairly new to the world of cache. I'd like to emulate an enum like behaviour in cache. 

 

For Instance, 

 

I'd like to do something to this effect

 

MyCacheObject.MyProperty = MyEnumType.Enum

 

So if i had a class as follows

 

Class MedicareClaim.Service Extends (%RegisteredObject, %XML.Adaptor)

{

                Property ServiceTypeCode As ClaimEnum.ServiceTypeCodeEnum (MAXLEN = 2, XMLNAME = "serviceTypeCde", XMLPROJECTION = "ATTRIBUTE");

}

 

Class EasyClaimEnum.ServiceTypeCodeEnum Extends %String
{
       /*Definition of the enum here*/

       /*Possible enum values o,s,d,p*/

       /*DisplayList: GeneralPractitioner, Specialist, Diagnostic Imaging,Pathology */
}

 

In the method that service class, I'd like to do something like this:

 

Set Service = ##class(MedicareClaim.Service).%New()

Set Service.ServiceTypeCode = ##class(ClaimEnum.ServiceTypeCodeEnum ).DiagnosticImaging 

 

(ServiceTypeCode should now hold the value d)

 

Is there any way to achieve this or something similar to this?

 

Any help is greatly appreciated.

Thanks and Regards,

Laavanya


David Whitten

unread,
Feb 19, 2014, 7:15:35 AM2/19/14
to intersystems...@googlegroups.com
In VistA FileMan, this would be a SET OF CODES

I'm not familiar with the Cache Object Class to do the same thing.


--
--
Caché, Ensemble, DeepSee
 
---
You received this message because you are subscribed to the Google Groups "Caché, Ensemble, DeepSee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to intersystems-publi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Rob Van Looke

unread,
Feb 19, 2014, 3:41:20 PM2/19/14
to intersystems...@googlegroups.com
I've had the same problem. I think i solved it using read only classmethods returning the string. The signature is almost the same. Your "enum" call just would end with ().

Maybe there is a better solution but i have not found it (yet).

Laavanya

unread,
Feb 19, 2014, 6:10:02 PM2/19/14
to intersystems...@googlegroups.com
Thanks Rob, 

I did think of that method, but kept it as my last resort.

Does cache support the concept of 'Class Property' similar to Class Methods, in which case you'd just have to call the class property.

Keith Avery

unread,
Feb 20, 2014, 1:21:15 PM2/20/14
to intersystems...@googlegroups.com

Laavanya,

 

You might have success with using Parameters in a DataType class.

Class Hack.EnumString Extends %String
{
Parameter DiagnosticImaging = "d";

...

}

Please take a look at my sample classes: http://pastebin.com/93bGMxBC

In the Test() method of my Hack.EnumTest class, Caché Studio apparently only uses intellisense for the first property, which is a %String type. (I don’t know why it doesn’t happen with the other two properties that are user-defined types.) But it looks something like this as soon as you enter “.#” at the end of the line, allowing you to select the code description:

 

set obj.MyEnum=##class(Hack.EnumType).#

                                       DiagnosticImaging

                                       GeneralPractitioner

                                       Pathology

                                       Specialist

-Keith

--

--
Caché, Ensemble, DeepSee
 
---
You received this message because you are subscribed to the Google Groups "Caché, Ensemble, DeepSee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to intersystems-publi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



The information contained in this email may be confidential and/or may be covered under the Privacy Act, 5 USC 552(a), and/or the Health Insurance Portability and Accountability Act (PL 104-191) and its various implementing regulations and must be protected in accordance with those provisions.. It has been sent for the sole use of the intended recipient(s). If the reader of this message is not an intended recipient, you are hereby notified that any unauthorized review, use, disclosure, dissemination, distribution, or copying of this communication, or any of its contents, is strictly prohibited. If you have received this communication in error, please contact the sender by reply email and destroy all copies of the original message. To contact our email administrator directly, send an email message to help...@medsphere.com. Thank you.

Laavanya

unread,
Feb 27, 2014, 4:46:25 PM2/27/14
to intersystems...@googlegroups.com
Keith, 

This is fantastic mate !! love it! however I can only do this as .%GetParameter("DiagnosticImaging"). Using Cache 2012.
But this works, and I'm ok using this. However, it's not strictly object oriented, but I guess it'll do for the moment.

Thanks a lot. Much appreciated.

-Laavanya


To unsubscribe from this group and stop receiving emails from it, send an email to intersystems-public-cache+unsub...@googlegroups.com.

Jo Claes

unread,
Feb 28, 2014, 4:52:57 AM2/28/14
to intersystems...@googlegroups.com
Hi,

In 2013 the .#DiagnosticImaging still works ( only the class completion is not working ) 

btw  :
We are using ClassMethods iso Parameters btw  ( also no code completion :(:(:(:( )
Also define the VALUELIST parameter then you have also validation in the %ValidateObject.

Regards

Jo


Op donderdag 27 februari 2014 22:46:25 UTC+1 schreef Laavanya:

Laavanya

unread,
Mar 12, 2014, 8:59:41 AM3/12/14
to intersystems...@googlegroups.com
Hey Keith,

I know I've closed this post but i realised that I couldn't achieve this via the %GetParameter if I simply had my class extend a data type(for instance %String). The class that I want to call a %GetParameter on has to necessarily extend the %RegisterdObject class as well.

So even for your example to work your class definition should have been

Class Hack.EnumString Extends (%RegisteredObject,%String)
{
Parameter DiagnosticImaging = "d";

...

}

Unless you could get this to work with having to extend the %RegisteredObject class, in which case I am very curious to know how.

Laavanya

On Friday, February 21, 2014 5:21:15 AM UTC+11, Crash Avery wrote:

To unsubscribe from this group and stop receiving emails from it, send an email to intersystems-public-cache+unsub...@googlegroups.com.

Sasi

unread,
May 1, 2014, 9:56:11 AM5/1/14
to intersystems...@googlegroups.com
Hi

This could be achieved using %RegisteredClass

Class FD.Enum Extends %RegisteredObject
{

Property GeneralPractitioner As %String [ InitialExpression = "O", ReadOnly  ];
}
in someMethod()
{
diagnosticImaging=##class(FD.Enum).%New().DiagnosticImaging
}

Please have a look at my post http://www.forgedreams.com/enumeration-intersystems-cache/

Regards
Sasi
http://www.forgedreams.com

Jo Claes

unread,
May 11, 2014, 5:14:34 AM5/11/14
to intersystems...@googlegroups.com
Sasi,

Sorry i have to mention it even it looks like a good solution using the readonly property thing but it isn't an enumeration at all, you can not use it as a datatype and it doesn't have validation. 

A better solution would be something like this ( the only missing thing is the class completion on the ClassMethod )

Class enu.Alignment Extends %EnumString [ ClassType = datatype ]
{

Parameter VALUELIST = ",L,R,C";

Parameter DISPLAYLIST = ",Left,Right,Center";

ClassMethod Left() As enu.Alignment
{
quit "L"
}

ClassMethod Right() As enu.Alignment
{
quit "R"
}

ClassMethod Center() As enu.Alignment
{
quit "C"
}

Class enu.AlignmentUsage Extends %RegisteredObject
{

Property Alignment As enu.Alignment;

ClassMethod Test()
{
set Usage = ..%New()
set Usage.Alignment = ##class(enu.Alignment).Right()
do Usage.Validate()

set Usage.Alignment = ##class(enu.Alignment).Left()
do Usage.Validate()

set Usage.Alignment = "InvalidValue"
do Usage.Validate()
}

Method Validate(Value As enu.Alignment)
{
write !,..Alignment
#dim Status As %Status = ..%ValidateObject()
if $$$ISERR(Status) write !,$$Parse(Status)
Parse(Status)
#dim arr As %String
do DecomposeStatus^%apiOBJ(Status ,.arr)
quit $get(arr(1))
}

}

do ##class(enu.AlignmentUsage).Test()

R
L
InvalidValue
FOUT #7205: Gegevenstypewaarde 'InvalidValue' niet in VALUELIST ',L,R,C'
  > FOUT #5802: Bevestiging van gegevenstype mislukt voor eigenschap 'enu.AlignmentUsage:Alignment' met waarde gelijk aan "InvalidValue"


Op donderdag 1 mei 2014 15:56:11 UTC+2 schreef Sasi:
Reply all
Reply to author
Forward
0 new messages