Accessing Property within a Property
Hey Community,
I have an scenario, please advise or suggest possible ways to solve it.
So i have a persistent class to test results of a diagnostic laboratory. The properties are
- Patient name
- Type of Test
- Order ID
Type of test will values for Sugar, Urine and Thyroid. But for Thyroid which is a Profile test, should hold multiple properties like Tsh, T4, T5.
How can i design my class to be able to fetch all results in query by passing order id(proably using where clause)
Product version: Caché 2018.1
Suggestion:
add
Property Val as Serials.Value;
in your main class
and
Class Serial.Value Extends %SerialObject {
Property Single as %String;
Property Tsh as %String;
Property T4 as %String;
Property T5 as %String;
}
in SQL you see it as columns
Val_Single
Val_Tsh
Val_T4
Val_T5
Hello,
I would suggest you do the following.
I understand you have a class something like:
Class My.Test extends %Persistent { Property PatientName; Property TypeOfTest as My.TestType; Property OrderID; }
Make TypeOfTest an instance of another class My.TestType:
Class My.TestType extends %SerialObject { Property Name As %String(VALUELIST = ",Sugar,Urine,Thyroid"); Property Tsh; ... }
In this case, as Robert has mentioned, you will be able to write a query like
Another way to do it would be the following. Make TypeOfTest an array:
Class My.Test extends %Persistent { Property PatientName; Property TypeOfTest as array of %String; //%Numeric maybe? Property OrderID; }
In the array, each element is a pair of key and value. In this case, you add a key with the name of type of test and with value the result of test. And if the "Name" is "Thyroid", then you add the rest of the elements. For example:
do test.TypeOfTest.SetAt("10", "Thyriod") do test.TypefTest.SetAt("148", Tsh)
This way, for your array in SQL you will get a separate table, the name of it will be a combination of class name and property name.
You can actually write a select just to query results of the tests and then find the name of the order using the primary key (which is a link to the main table My.Test)
All answers are correct.
I personally prefer the "array of %String" approach, which is much more efficient and gives a better performance (in case your table grows to a huge size of hundreds of GBs)