HMPORRPC ;ASMR/MBS -- Orders RPCs ;01/06/2015  16:42
 ;;2.0;ENTERPRISE HEALTH MANAGEMENT PLATFORM;**2**;Dec 22, 2015;Build 28
 ;Per VA Directive 6402, this routine should not be modified.
 ; External References          DBIA#
 ; -------------------          -----
 ; ^OR(100                       5771
 ; DIQ                           2056
 
Q
RELATED(RET,IEN) ;
 
RESULT,I,HMPSIBS,HMPKIDS,PARENT
 
RESULT=$NA(^TMP($J,"HMPORRPC")) @RESULT
 
'+$G(IEN@RESULT@("error")="No order selected" JSONIFY
 
'+$$GET1^DIQ(100,IEN_",",".01","I"@RESULT@("error")="Nonexisting order" JSONIFY
 
;See if we have a parent
 
PARENT=$$GET1^DIQ(100,IEN_",",36,"I")
 
+PARENT D
 
@RESULT@("parent")=PARENT
 
;Check for siblings
 
LIST^DIC(100.002,","_PARENT_",","@;.01","I",,,,,,,"HMPSIBS")
 . 
I=1:1:+$G(HMPSIBS("DILIST",0)) D
 
. . Q:$G(HMPSIBS("DILIST",2,I))=IEN
 
. . @RESULT@("siblings",I)=$G(HMPSIBS("DILIST",2,I))
 
;Get children
 
LIST^DIC(100.002,","_IEN_",","@;.01","I",,,,,,,"HMPKIDS")
 
I=1:1:+$G(HMPKIDS("DILIST",0)) D
 
@RESULT@("children",I)=$G(HMPKIDS("DILIST",2,I))
 
;US11945 - If we're calling this from HMPDJ01, don't convert to JSON yet
 
I $G(HMPNOJS)=1 RET=RESULT Q
JSONIFY ;
 
ENCODE^HMPJSON(RESULT,"RET")
 
Q