go to post Elize VdRiet · Apr 1, 2019 Good day,I would very much like to install this example on my local instance. However, I cannot find installer.xml on "corrresponding page". Which is the "corresponding page" please? I downloaded the solution from Github, but also there is no installer.xml. I will apprecitae it if you can point me to the "corresponding page" where the installer.xml is please.Thank you in advance.
go to post Elize VdRiet · Feb 24, 2019 Thank you for posting Eduard, you are absolutely right, I scratched around and was just about to post here the solution I found, but it is the same as you are suggesting, so I sovled it by covnerting the date sting to Caché date format with:Set consumerRecord.ActivePeriod.StartDate = $ZDATEH(obj.activePeriod.startDate, 15)But the IsValid check I did not know about and will be very handy, because yes, if the date is empty string or not valid the above conversion threw an error as well and I do not want an error since the date may be empty, so I have to test it first, so will add that now. And yes, we are using IRIS, so the %PosicTime tip is handy too.
go to post Elize VdRiet · Feb 24, 2019 Apologies, I forgot to add the REST service code, the POST "AddConsumer" uses "CopyToConsumerFromJSON" and this is the one where the de-serialized dynamic object is assigned to the Consumer record: SpoilerClass REST.ConsumerRestService Extends %CSP.REST{ ///============================================================================================ /// UrlMap ///============================================================================================ XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ] { <Routes> <!-- Return the list of all Consumers --> <Route Url="/consumers" Method="GET" Call="GetAllConsumers" /> <!-- Add a new Consumer --> <Route Url="/consumer" Method="POST" Call="AddConsumer" /> <!-- Return the details for a single Consumer --> <Route Url="/consumer/:id" Method="GET" Call="GetConsumer" /> <!-- Update the details for the specified Consumer --> <Route Url="/consumer/:id" Method="PUT" Call="UpdateConsumer" /> <!-- Delete the specified Consumer --> <Route Url="/consumer/:id" Method="DELETE" Call="DeleteConsumer" /> </Routes> } ///-------------------------------------------------------------------------------------------- /// Return the list of all Consumers ///-------------------------------------------------------------------------------------------- ClassMethod GetAllConsumers() As %Status { Set tArr = [] Set rs = ##class(%SQL.Statement).%ExecDirect(,"SELECT * FROM Consumer.Consumer") While rs.%Next() { Do tArr.%Push({ "familyName": (rs.%Get("FamilyName")), "firstNames" : (rs.%Get("FirstNames")), "dateOfBirth": (rs.%Get("DateOfBirth")), "isDateOfBirthApproximate": (rs.%Get("IsDateOfBirthApproximate")), "isDeceased": (rs.%Get("IsDeceased")), "deceasedDateTime": (rs.%Get("DeceasedDateTime")), "activePeriod": { "startDate": (rs.%Get("ActivePeriod.StartDate")), "endDate": (rs.%Get("ActivePeriod.EndDate")), "isActive": (rs.%Get("ActivePeriod.IsActive")), "reasonChangedOrDeleted": (rs.%Get("ActivePeriod.ReasonChangedOrDeleted")) }, "am": { "createdBy": (rs.%Get("AM.CreatedBy")), "createdDateTime": (rs.%Get("AM.CreatedDateTime")), "modifiedBy": (rs.%Get("AM.ModifiedBy")), "modifiedDateTime": (rs.%Get("AM.ModifiedDateTime")) } }) } Write tArr.%ToJSON() Quit $$$OK } ///-------------------------------------------------------------------------------------------- /// Get record for a Consumer ///-------------------------------------------------------------------------------------------- ClassMethod GetConsumer(id As %Integer = 0) As %Status { Set consumer = ##class(Consumer.Consumer).%OpenId(id) If '$IsObject(consumer) { Set %response.Status = ..#HTTP204NOCONTENT } Else { Set obj = { "familyName": (consumer.FamilyName), "firstNames" : (consumer.FirstNames), "dateOfBirth": (consumer.DateOfBirth), "isDateOfBirthApproximate": (consumer.IsDateOfBirthApproximate), "isDeceased": (consumer.IsDeceased), "deceasedDateTime": (consumer.DeceasedDateTime), "activePeriod": { "startDate": (consumer.ActivePeriod.StartDate), "endDate": (consumer.ActivePeriod.EndDate), "isActive": (consumer.ActivePeriod.IsActive), "reasonChangedOrDeleted": (consumer.ActivePeriod.ReasonChangedOrDeleted) }, "am": { "createdBy": (consumer.AM.CreatedBy), "createdDateTime": (consumer.AM.CreatedDateTime), "modifiedBy": (consumer.AM.ModifiedBy), "modifiedDateTime": (consumer.AM.ModifiedDateTime) } } Write obj.%ToJSON() } Quit $$$OK } ///-------------------------------------------------------------------------------------------- /// Update the details for the specified Consumer ///-------------------------------------------------------------------------------------------- ClassMethod UpdateConsumer(id As %Integer = 0) As %Status { If '..GetJSONFromRequest(.obj) { Set %response.Status = ..#HTTP400BADREQUEST Set error = {"errormessage": "JSON not found"} Write error.%ToJSON() Quit $$$OK } If '..ValidateJSON(obj,.error) { Set %response.Status = ..#HTTP400BADREQUEST Write error.%ToJSON() Quit $$$OK } Set consumerRecord = ##class(Consumer.Consumer).%OpenId(id) If consumerRecord = "" { Set %response.Status = ..#HTTP404NOTFOUND Set error = {"errormessage": "Consumer does not exist"} Write error.%ToJSON() Quit $$$OK } Do ..CopyToConsumerFromJSON(.consumerRecord,obj) Set sc = consumerRecord.%Save() Set result={} Do result.%Set("Status",$s($$$ISERR(sc):$system.Status.GetOneErrorText(sc),1:"OK")) Write result.%ToJSON() Quit sc } ///-------------------------------------------------------------------------------------------- /// Add a new Consumer ///-------------------------------------------------------------------------------------------- ClassMethod AddConsumer(id As %Integer = 0) As %Status { If '..GetJSONFromRequest(.obj) { Set %response.Status = ..#HTTP400BADREQUEST Set error = {"errormessage": "JSON not found"} Write error.%ToJSON() Quit $$$OK } If '..ValidateJSON(obj,.error) { Set %response.Status = ..#HTTP400BADREQUEST Write error.%ToJSON() Quit $$$OK } Set consumerNew = ##class(Consumer.Consumer).%New() Do ..CopyToConsumerFromJSON(.consumerNew, obj) Set sc = consumerNew.%Save() Set result = {} do result.%Set("Status",$s($$$ISERR(sc):$system.Status.GetOneErrorText(sc),1:"OK")) write result.%ToJSON() Quit sc } ///-------------------------------------------------------------------------------------------- /// Delete a Consumer ///-------------------------------------------------------------------------------------------- ClassMethod DeleteConsumer(id As %Integer = 0) As %Status { Set result={} Set sc=0 If id '= "", ##class(Consumer.Consumer).%ExistsId(id) { Set sc = ##class(Consumer.Consumer).%DeleteId(id) Do result.%Set("Status",$s($$$ISERR(sc):$system.Status.GetOneErrorText(sc),1:"OK")) } Else { Do result.%Set("Status","") } Write result.%ToJSON() Quit sc } ///-------------------------------------------------------------------------------------------- /// Helper method ///-------------------------------------------------------------------------------------------- ClassMethod CopyToConsumerFromJSON(ByRef consumerRecord As Consumer.Consumer, obj As %DynamicObject) [ Private ] { Set consumerRecord.FamilyName = obj.familyName Set consumerRecord.FirstNames = obj.firstNames Set consumerRecord.DateOfBirth = obj.dateOfBirth Set consumerRecord.IsDateOfBirthApproximate = obj.isDateOfBirthApproximate Set consumerRecord.IsDeceased = obj.isDeceased Set consumerRecord.DeceasedDateTime = obj.deceasedDateTime Set consumerRecord.ActivePeriod.StartDate = obj.activePeriod.startDate Set consumerRecord.ActivePeriod.EndDate = obj.activePeriod.endDate Set consumerRecord.ActivePeriod.IsActive = obj.activePeriod.isActive Set consumerRecord.ActivePeriod.ReasonChangedOrDeleted = obj.activePeriod.reasonChangedOrDeleted Set consumerRecord.AM.CreatedBy = obj.am.createdBy Set consumerRecord.AM.CreatedDateTime = obj.am.createdDateTime Set consumerRecord.AM.ModifiedBy = obj.am.modifiedBy Set consumerRecord.AM.ModifiedDateTime = obj.am.modifiedDateTime } /// Helper method ClassMethod GetJSONFromRequest(Output obj As %DynamicObject) As %Boolean { Set ok = 1 Try { Set jsonData = %request.Content.Read() Set obj = ##class(%DynamicObject).%FromJSON(jsonData) } Catch ex { Set ok = 0 } Quit ok } ///-------------------------------------------------------------------------------------------- /// Helper method ///-------------------------------------------------------------------------------------------- ClassMethod ValidateJSON(obj As %DynamicObject, Output error As %DynamicObject) As %Boolean { Set error = {} If obj.%Get("familyName") = "" { Set error.errormessage = "familyName was blank" Quit 0 } If obj.%Get("firstNames") = "" { Set error.errormessage = "firstNames was blank" Quit 0 } Quit 1 } }