%SYS>w $H //date, time 秒计
65352,35669
%SYS>w $p("a b c"," ",1)
a
%SYS>w $p("a b c"," ",2)
b
%SYS>w $p($H,",",1)
65352
%SYS>w $zd($p($H,",",1))
12/05/2019
%SYS>w $zdt($p($h,",",1),1)
12/05/2019
%SYS>w $zdt($p($h,",",1),3)
2019-12-05
2, 类与对象
在studio中创建一个类: Demo命名空间–>new cache class (默认继承%Persistent类): 写入属性 -->编译
Class com.eyeof.Test1 Extends %Persistent
{
Property age As %Integer;
Property name As %String;
//普通方法
Method f1()
{
w "hello world, Method f1 "
}
ClassMethod f2()
{
w "hello world, ClassMethod f1 "
}
//方法传参
Method info(salary1 As %Integer, profile1 As %Integer, name, state As %String = "CA")
{
w name_"/"_state_"/"_"total salary="_(salary1+profile1)
}
//方法返回值
ClassMethod returnObj(name As %String, age As %Integer) As Test1
{
Set person = ##class(Test1).%New()
set person.name= name
set person.age=age
Quit person
}
//以下是编译后,生成的代码段
Storage Default
{
<Data name="Test1DefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>count1</Value>
</Value>
<Value name="3">
<Value>count2</Value>
</Value>
<Value name="4">
<Value>age</Value>
</Value>
<Value name="5">
<Value>name</Value>
</Value>
</Data>
<DataLocation>^com.eyeof.Test1D</DataLocation>
<DefaultData>Test1DefaultData</DefaultData>
<IdLocation>^com.eyeof.Test1D</IdLocation>
<IndexLocation>^com.eyeof.Test1I</IndexLocation>
<StreamLocation>^com.eyeof.Test1S</StreamLocation>
<Type>%Library.CacheStorage</Type>
}
}
Class T1.Patient Extends (%Persistent, %XML.Adaptor, %Populate)
{
Property IDCard As %String;
Property PatNo As %String;
Property Name As %String;
Property Gender As %String;
Property DOB As %Date;
Property Citizenship As %String;
Property PhoneNumber As %String;
ClassMethod FindPatient(id As %String) As T1.Patient
{ Set patient= ##class(T1.Patien).%OpenId(id)
Quit patient
}
ClassMethod GetPatientsByName(name As %String) As %ListOfObjects
{
set queryStr = "SELECT * FROM T1.Patient WHERE Name like ?"
set nameParameter = "%"_name_"%"
SET tStatement = ##class(%SQL.Statement).%New()
SET qStatus = tStatement.%Prepare(queryStr)
IF qStatus'=1 {WRITE "%Prepare failed:" DO $System.Status.DisplayError(qStatus) QUIT ""}
#Dim rset As %SQL.StatementResult = tStatement.%Execute(nameParameter)
if 0'=rset.SQLCODE{quit ""}
Write "Counts: ", rset.%ROWCOUNT,!
#Dim rtnList as %Library.ListOfObjects = ##class(%Library.ListOfObjects).%New()
WHILE rset.%Next() {
#dim patInst As T1.Patient = ##class(T1.Patient).%New()
set patInst.Name = rset.%Get("Name")
set patInst.Gender = rset.%Get("Gender")
set patInst.DOB = rset.%Get("DOB")
do rtnList.Insert(patInst)
}
quit rtnList
}
}