Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: ORRDI1

ORRDI1.m

Go to the documentation of this file.
  1. ORRDI1 ;SLC/JMH - RDI ROUTINES FOR API SUPPORTING CDS DATA ;Nov 16, 2022@13:03:49
  1. ;;3.0;ORDER ENTRY/RESULTS REPORTING;**232,294,306,269,591,588**;Dec 17, 1997;Build 29
  1. ; SAC EXEMPTION 202211140901-03 : Non-standard $Z special variable used
  1. ;
  1. GET(DFN,DOMAIN) ;API for packages to call in order to get data from HDR for
  1. I '$L($G(DOMAIN)) S DOMAIN="ART"
  1. ; check if in OUTAGE state and quit if so
  1. I $$DOWNXVAL^ORRDI2 D Q -1
  1. .K ^XTMP("ORRDI",DOMAIN,DFN)
  1. .S ^XTMP("ORRDI",DOMAIN,DFN,0)="^^-1"
  1. ; order checking purposes
  1. N I,ORCACHE,ORRET,ORRECDT
  1. ;check if data was just retrieved a short time ago and if so return
  1. S ORRECDT=$P($G(^XTMP("ORRDI",DOMAIN,DFN,0)),U) I 'ORRECDT S ORRECDT=3000101
  1. S ORCACHE=$$GET^XPAR("SYS","OR RDI CACHE TIME")
  1. I $$FMDIFF^XLFDT($$NOW^XLFDT,ORRECDT,2)<(60*ORCACHE),$P(^XTMP("ORRDI",DOMAIN,DFN,0),U,3)>-1 S ORRET=$P(^XTMP("ORRDI",DOMAIN,DFN,0),U,3)
  1. ;check if there has been an HDR down condition within last minute
  1. I $$FMDIFF^XLFDT($$NOW^XLFDT,$P($G(^XTMP("ORRDI","PSOO",DFN,0)),U),2)<60,$P($G(^XTMP("ORRDI","PSOO",DFN,0)),U,3)<0 S ORRET=$P($G(^XTMP("ORRDI","PSOO",DFN,0)),U,3)
  1. I $$FMDIFF^XLFDT($$NOW^XLFDT,$P($G(^XTMP("ORRDI","ART",DFN,0)),U),2)<60,$P($G(^XTMP("ORRDI","ART",DFN,0)),U,3)<0 S ORRET=$P($G(^XTMP("ORRDI","ART",DFN,0)),U,3)
  1. ;if data is not "fresh" then go get it
  1. I '$L($G(ORRET)) D
  1. .S ORRET=$$RETRIEVE(DFN,DOMAIN)
  1. .I ORRET>-1 S ^XTMP("ORRDI","OUTAGE INFO","FAILURES")=0
  1. .I ORRET'>-1 D
  1. ..Q:$P(ORRET,U,2)="PATIENT ICN NOT FOUND"
  1. ..I ORRET=-9 S ORRET="-1^PROCESSING ERROR" Q
  1. ..S ^XTMP("ORRDI","OUTAGE INFO","FAILURES")=$$FAILXVAL^ORRDI2+1
  1. ..I $$FAILXVAL^ORRDI2'<$$FAILPVAL^ORRDI2 D
  1. ...S ^XTMP("ORRDI","OUTAGE INFO","DOWN")=1
  1. ...D SPAWN^ORRDI2
  1. S $P(^XTMP("ORRDI",DOMAIN,DFN,0),U,3,4)=ORRET
  1. Q ORRET
  1. ;
  1. RETRIEVE(DFN,DOMAIN) ;GET DATA
  1. N $ES,$ET
  1. S $ET="D ERRHNDL^ORRDI1(DFN) Q -1"
  1. N Y,ORCSTART,ORPSTART,ORCDIF,ORPDIF,ORALNUM,ORPSNUM,ORREQ,ORXML,ORERR,ORRET,ORY,START,FACIL,ICN
  1. K ^TMP($J,"ORRDI")
  1. S ORY=-1
  1. I '$L($G(DOMAIN)) S DOMAIN="ART"
  1. ;GET ICN
  1. S ICN=$$GETICN^MPIF001(DFN)
  1. I +ICN<0 Q -1_"^PATIENT ICN NOT FOUND"
  1. S START=$$FMADD^XLFDT($P($$NOW^XLFDT,"."),-30)
  1. S START=$$FMTHL7^XLFDT(START)
  1. S START=$E(START,1,4)_"-"_$E(START,5,6)_"-"_$E(START,7,8)
  1. S FACIL=$P($$SITE^VASITE,U,3)
  1. ;format request XML
  1. S ORREQ="/readClinicalData1?&templateId=RDIAllergiesPharmacyRead40013&"
  1. S ORREQ=ORREQ_"filterRequest=<?xml version=""1.0"" encoding=""UTF-8""?>"
  1. S ORREQ=ORREQ_"<filter:filter vhimVersion=""Vhim_4_00"" xmlns:filter=""Filter"" "
  1. S ORREQ=ORREQ_"xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"
  1. S ORREQ=ORREQ_"<filterId>RDI_ALLERGY_RX_SINGLE_PATIENT_FILTER</filterId>"
  1. S ORREQ=ORREQ_"<clientName>RDI</clientName><patients><NationalId>"_ICN_"</NationalId>"
  1. S ORREQ=ORREQ_"<excludeIdentifiers><assigningAuthority>USVHA</assigningAuthority>"
  1. S ORREQ=ORREQ_"<assigningFacility>"_FACIL_"</assigningFacility></excludeIdentifiers></patients>"
  1. S ORREQ=ORREQ_"<entryPointFilter queryName=""IC-Standardized""><domainEntryPoint>IntoleranceCondition</domainEntryPoint>"
  1. S ORREQ=ORREQ_"<xpathQuery><xpath>intoleranceConditions[((gmrAllergyAgent[(code!='') and (codingSystem = '99"
  1. S ORREQ=ORREQ_"VHA_ERT' or contains(.,'99VA'))]) or (drugClass/code[(code!='') and (codingSystem = '99VHA_ERT' or co"
  1. S ORREQ=ORREQ_"ntains(.,'99VA'))]) or (drugIngredient/code[(code!='') and (codingSystem = '99VHA_ERT' or contain"
  1. S ORREQ=ORREQ_"s(.,'99VA'))])) and (status = 'F')]</xpath></xpathQuery></entryPointFilter>"
  1. S ORREQ=ORREQ_"<entryPointFilter queryName=""OMP-Standardized"">"
  1. S ORREQ=ORREQ_"<domainEntryPoint>OutpatientMedicationPromise</domainEntryPoint>"
  1. S ORREQ=ORREQ_"<startDate>"_START_"</startDate><xpathQuery><xpath>outpatientMedicationPromises[pharmacyRe"
  1. S ORREQ=ORREQ_"quest/orderedMedication/medicationCode[(code!='') and (codingSystem = '99VHA_ERT' or contain"
  1. S ORREQ=ORREQ_"s(.,'99VA'))]]</xpath></xpathQuery></entryPointFilter><entryPointFilter queryName=""AA-Standardized"">"
  1. S ORREQ=ORREQ_"<domainEntryPoint>AllergyAssessment</domainEntryPoint></entryPointFilter></filter:filter>"
  1. S ORCSTART=$ZH
  1. S ORREQ=ORREQ_"&filterId=RDI_ALLERGY_RX_SINGLE_PATIENT_FILTER&requestId="_FACIL_"RDI"_$$NOW^XLFDT_";"_ORCSTART
  1. ;make call to HDR
  1. S ORXML=$$GETREST^XOBWLIB("CDS WEB SERVICE","CDS SERVER")
  1. S ORRET=$$GET^XOBWLIB(ORXML,ORREQ,.ORERR,0)
  1. S ORCDIF=$ZH-ORCSTART
  1. I ORRET D Q ORY
  1. .;parse out xml into temp global
  1. .S ORPSTART=$ZH
  1. .D PARSE(ORXML.HttpResponse.Data)
  1. .S ORPDIF=$ZH-ORCSTART-ORCDIF
  1. .;move from temp global into ^XTMP("ORRDI" domain globals
  1. .S ORALNUM=$$AL(DFN)
  1. .S ORPSNUM=$$PS(DFN)
  1. .S ^XTMP("ORRDI","ART",DFN,0)=$$NOW^XLFDT_U_U_ORALNUM
  1. .S ^XTMP("ORRDI","PSOO",DFN,0)=$$NOW^XLFDT_U_U_ORPSNUM
  1. .S ^XTMP("ORRDI",0)=$$FMADD^XLFDT($$NOW^XLFDT,2)_U_$$NOW^XLFDT
  1. .I DOMAIN="ART" S ORY=ORALNUM
  1. .I DOMAIN="PSOO" S ORY=ORPSNUM
  1. .I +ORY>-1 S ^XTMP("ORRDI","TESTREQ")=ORREQ
  1. .;set metrics for data retrieval and parsing
  1. .S ^XTMP("ORRDI","METRICS",$$NOW^XLFDT,ORCSTART)=DFN_U_ORCDIF_U_ORPDIF_U_ORALNUM_U_ORPSNUM
  1. .K ^TMP($J,"ORRDI")
  1. I 'ORRET!(ORERR) S ^XTMP("ORRDI","METRICS",$$NOW^XLFDT,ORCSTART)=DFN_U_"ERROR" D Q "-1^"_ORERR
  1. .S ^XTMP("ORRDI","ART",DFN,0)=U_U_"-1^"_ORERR
  1. .S ^XTMP("ORRDI","PSOO",DFN,0)=U_U_"-1^"_ORERR
  1. Q -1
  1. ;
  1. PS(DFN) ;expects ^TMP($J,"ORRDI")
  1. K ^XTMP("ORRDI","PSOO",DFN)
  1. N ORQ S ORQ=$$MSGERR Q:($L(ORQ)>0) -1_U_ORQ
  1. N I,GL,CNT
  1. S CNT=0,GL=$NA(^TMP($J,"ORRDI","ClinicalData",0,"patient",0,"outpatientMedicationPromises"))
  1. S I="" F S I=$O(@GL@(I)) Q:'$L(I) D
  1. .S CNT=CNT+1
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,1,0)=$G(@GL@(I,"pharmacyRequest",0,"orderingInstitutionIdentifier",0,"name",0))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,2,0)=$G(@GL@(I,"pharmacyRequest",0,"orderedMedication",0,"medicationCode",0,"displayText",0))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,3,0)=$G(@GL@(I,"pharmacyRequest",0,"orderedMedication",0,"medicationCode",0,"code",0))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,4,0)=$G(@GL@(I,"prescriptionId",0))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,5,0)=$G(@GL@(I,"pharmacyRequest",0,"statusModifier",0,"displayText",0))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,6,0)=$G(@GL@(I,"originalDispense",0,"quantityDispensed",0,"value",0))_";"_$G(@GL@(I,"originalDispense",0,"daysSupply",0))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,7,0)=$$DTCONV($G(@GL@(I,"expirationDate",0,"literal",0)))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,8,0)=$$DTCONV($G(@GL@(I,"pharmacyRequest",0,"orderDate",0,"literal",0)))
  1. .N K S K="" F S K=$O(@GL@(I,"refillDispense",K)) Q:'$L(K) D
  1. ..I $G(@GL@(I,"refillDispense",K,"fillDate",0,"literal",0)) D
  1. ...S ^XTMP("ORRDI","PSOO",DFN,I+1,9,0)=$$DTCONV($G(@GL@(I,"refillDispense",K,"fillDate",0,"literal",0)))
  1. .I '$G(^XTMP("ORRDI","PSOO",DFN,I+1,9,0)) S ^XTMP("ORRDI","PSOO",DFN,I+1,9,0)=$$DTCONV($G(@GL@(I,"originalDispense",0,"fillDate",0,"literal",0)))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,10,0)=$G(@GL@(I,"numberOfRefillsAuthorized",0))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,11,0)=$G(@GL@(I,"originalDispense",0,"currentProvider",0,"name",0,"family",0))_","_$G(@GL@(I,"originalDispense",0,"currentProvider",0,"name",0,"given",0))
  1. .S ^XTMP("ORRDI","PSOO",DFN,I+1,12,0)=$G(@GL@(I,"originalDispense",0,"dispensedDrug",0,"drugUnitPrice",0,"value",0))
  1. .N L S L="" F S L=$O(@GL@(I,"sig",L)) Q:'$L(L) S ^XTMP("ORRDI","PSOO",DFN,I+1,14,0)=$G(^XTMP("ORRDI","PSOO",DFN,I+1,14,0))_" "_$G(@GL@(I,"sig",L))
  1. .I '$D(^XTMP("ORRDI","PSOO",DFN,I+1,14,0)) S ^XTMP("ORRDI","PSOO",DFN,I+1,14,0)=""
  1. .;S ^XTMP("ORRDI","PSOO",DFN,I+1,14,0)=$G(@GL@(I,"sig",0))
  1. Q CNT
  1. ;
  1. AL(DFN) ;expects ^TMP($J,"ORRDI")
  1. K ^XTMP("ORRDI","ART",DFN)
  1. N ORQ S ORQ=$$MSGERR Q:($L(ORQ)>0) -1_U_ORQ
  1. N I,GL,CNT
  1. S CNT=0,GL=$NA(^TMP($J,"ORRDI","ClinicalData",0,"patient",0,"intoleranceConditions"))
  1. S I="" F S I=$O(@GL@(I)) Q:'$L(I) D
  1. .S CNT=CNT+1
  1. .I $D(@GL@(I,"patient",0,"identifier",0,"assigningFacility",0)) D
  1. ..N RETURN
  1. ..D F4^XUAF4($G(@GL@(I,"patient",0,"identifier",0,"assigningFacility",0)),.RETURN)
  1. ..I +RETURN>0 D
  1. ...S ^XTMP("ORRDI","ART",DFN,I+1,"FACILITY",0)=RETURN_U_$S(RETURN("VA NAME")'="":RETURN("VA NAME"),1:RETURN("NAME"))_U_RETURN("STATION NUMBER")
  1. ..I +RETURN=0 D
  1. ...S ^XTMP("ORRDI","ART",DFN,I+1,"FACILITY",0)=U_U_$G(@GL@(I,"patient",0,"identifier",0,"assigningFacility",0))
  1. .I $G(@GL@(I,"gmrAllergyAgent",0,"code",0)),$E($G(@GL@(I,"gmrAllergyAgent",0,"codingSystem",0)),1,4)="99VA" D
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"GMRALLERGY",0)=@GL@(I,"gmrAllergyAgent",0,"code",0)_U_@GL@(I,"gmrAllergyAgent",0,"displayText",0)_U_@GL@(I,"gmrAllergyAgent",0,"codingSystem",0)
  1. .I $D(@GL@(I,"agent",0,"code",0))#2 D
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"REACTANT",0)=$G(@GL@(I,"agent",0,"code",0))
  1. .I $D(@GL@(I,"reaction")) D
  1. ..N J S J="" F S J=$O(@GL@(I,"reaction",J)) Q:'$L(J) D
  1. ...I $E($G(@GL@(I,"reaction",J,"reaction",0,"codingSystem",0)),1,4)="99VA" D
  1. ....S ^XTMP("ORRDI","ART",DFN,I+1,"SIGNS/SYMPTOMS",J+1)=$G(@GL@(I,"reaction",J,"reaction",0,"code",0))_U_@GL@(I,"reaction",J,"reaction",0,"displayText",0)_U_@GL@(I,"reaction",J,"reaction",0,"codingSystem",0)
  1. ...I $E($G(@GL@(I,"reaction",J,"reaction",0,"codingSystem",0)),1,4)'="99VA" D
  1. ....S ^XTMP("ORRDI","ART",DFN,I+1,"SIGNS/SYMPTOMS",J+1)=U_@GL@(I,"reaction",J,"reaction",0,"displayText",0)_U_$TR(@GL@(I,"reaction",J,"reaction",0,"codingSystem",0),"`~!@#$%^&*()-_=+[{]}\|;:'"",<.>/?")
  1. ...I $G(@GL@(I,"reaction",J,"observationTime",0,"literal",0))'="" D
  1. ....S ^XTMP("ORRDI","ART",DFN,I+1,"SIGNS/SYMPTOMS",J+1,"DATE_ENTERED",0)=@GL@(I,"reaction",J,"observationTime",0,"literal",0)
  1. .I $D(@GL@(I,"informationSourceCategory")) D
  1. ..Q:$E($G(@GL@(I,"informationSourceCategory",0,"codingSystem",0)),1,4)'="99VA"
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"OBS/HISTORICAL",0)=$G(@GL@(I,"informationSourceCategory",0,"code",0))_U_@GL@(I,"informationSourceCategory",0,"displayText",0)_U_@GL@(I,"informationSourceCategory",0,"codingSystem",0)
  1. .I $D(@GL@(I,"mechanism",0)) D
  1. ..Q:$E($G(@GL@(I,"mechanism",0,"codingSystem",0)),1,4)'="99VA"
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"MECHANISM",0)=$G(@GL@(I,"mechanism",0,"code",0))_U_@GL@(I,"mechanism",0,"displayText",0)_U_@GL@(I,"mechanism",0,"codingSystem",0)
  1. .I $D(@GL@(I,"severity",0)) D
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"SEVERITY",0)=$G(@GL@(I,"severity",0,"value",0,"code",0))_U_$G(@GL@(I,"severity",0,"value",0,"displayText",0))
  1. .I $D(@GL@(I,"verified",0)) D
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"VERIFIED",0)=$G(@GL@(I,"verified",0))
  1. .I $D(@GL@(I,"allergyType",0)) D
  1. ..Q:$E($G(@GL@(I,"allergyType",0,"codingSystem",0)),1,4)'="L"
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"TYPE",0)=$G(@GL@(I,"allergyType",0,"code",0))_U_@GL@(I,"allergyType",0,"displayText",0)_U_@GL@(I,"allergyType",0,"codingSystem",0)
  1. .I $D(@GL@(I,"observationTime",0,"literal",0)) D
  1. ..;observationTime is mapped to ORIGINATION DATE/TIME field in file #120.8
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"ORIGINATION DATE/TIME",0)=$G(@GL@(I,"observationTime",0,"literal",0))
  1. .I $D(@GL@(I,"author",0)) D
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"AUTHOR",0)=$G(@GL@(I,"author",0,"practitioner",0,"name",0,"family",0))_U
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"AUTHOR",0)=^XTMP("ORRDI","ART",DFN,I+1,"AUTHOR",0)_$G(@GL@(I,"author",0,"practitioner",0,"name",0,"given",0))_U
  1. ..S ^XTMP("ORRDI","ART",DFN,I+1,"AUTHOR",0)=^XTMP("ORRDI","ART",DFN,I+1,"AUTHOR",0)_$G(@GL@(I,"author",0,"practitioner",0,"name",0,"middle",0))
  1. .I $D(@GL@(I,"drugIngredient")) D
  1. ..N J S J="" F S J=$O(@GL@(I,"drugIngredient",J)) Q:'$L(J) D
  1. ...I $G(@GL@(I,"drugIngredient",J,"code",0,"code",0)),$E($G(@GL@(I,"drugIngredient",J,"code",0,"codingSystem",0)),1,4)="99VA" D
  1. ....S ^XTMP("ORRDI","ART",DFN,I+1,"DRUG INGREDIENTS",J+1)=@GL@(I,"drugIngredient",J,"code",0,"code",0)_U_@GL@(I,"drugIngredient",J,"code",0,"displayText",0)_U_@GL@(I,"drugIngredient",J,"code",0,"codingSystem",0)
  1. .I $D(@GL@(I,"drugClass")) D
  1. ..N J S J="" F S J=$O(@GL@(I,"drugClass",J)) Q:'$L(J) D
  1. ...Q:$E($G(@GL@(I,"drugClass",0,"code",0,"codingSystem",0)),1,4)'="99VA"
  1. ...S ^XTMP("ORRDI","ART",DFN,I+1,"DRUG CLASSES",J+1)=@GL@(I,"drugClass",J,"code",0,"code",0)_U_@GL@(I,"drugClass",J,"code",0,"displayText",0)_U_$G(@GL@(I,"drugClass",J,"code",0,"codingSystem",0))
  1. ...S ^XTMP("ORRDI","ART",DFN,I+1,"DRUG CLASSES",J+1)=^XTMP("ORRDI","ART",DFN,I+1,"DRUG CLASSES",J+1)_U_$G(@GL@(I,"drugClass",J,"code",0,"alternateCode",0))
  1. S GL=$NA(^TMP($J,"ORRDI","ClinicalData",0,"patient",0,"allergyAssessments"))
  1. S I="" F S I=$O(@GL@(I)) Q:'$L(I) D
  1. .S ^XTMP("ORRDI","ART",DFN,"ASSESSMENT",I+1)=$G(@GL@(I,"assessmentValue",0,"code",0))_U_$G(@GL@(I,"assessmentValue",0,"displayText",0))_U_$G(@GL@(I,"assessmentValue",0,"codingSystem",0))
  1. .N RETURN
  1. .D F4^XUAF4($G(@GL@(I,"patient",0,"identifier",0,"assigningFacility",0)),.RETURN)
  1. .I +RETURN>0 D
  1. ..S ^XTMP("ORRDI","ART",DFN,"ASSESSMENT",I+1,"FACILITY",0)=RETURN_U_$S(RETURN("VA NAME")'="":RETURN("VA NAME"),1:RETURN("NAME"))_U_RETURN("STATION NUMBER")
  1. .I +RETURN=0 D
  1. ..S ^XTMP("ORRDI","ART",DFN,"ASSESSMENT",I+1,"FACILITY",0)=U_U_$G(@GL@(I,"patient",0,"identifier",0,"assigningFacility",0))
  1. Q CNT
  1. ;
  1. HAVEHDR() ;call to check if this system has an HDR to perform order checks
  1. ; against
  1. ;check parameter to see if there is an HDR and returns positive if so
  1. I $$GET^XPAR("SYS","OR RDI HAVE HDR") Q 1
  1. ;returns negative because the parameter indicates there is no HDR
  1. Q 0
  1. ;
  1. DTCONV(DATE) ;convert date in hl7 format to mm/dd/yy
  1. I '$L(DATE) Q ""
  1. Q $E(DATE,5,6)_"/"_$E(DATE,7,8)_"/"_$E(DATE,3,4)
  1. ;
  1. PARSE(STREAM) ;
  1. N %XML,GL
  1. S GL=$NA(^TMP($J,"ORRDI"))
  1. K @GL
  1. N STATUS,READER,XOBERR,S
  1. S STATUS=##class(%XML.TextReader).ParseStream(STREAM,.READER,,,,,1)
  1. I $$STATCHK^XOBWLIB(STATUS,.XOBERR,1) D
  1. .N BREAK
  1. .S BREAK=0 F Q:BREAK||READER.EOF||'READER.Read() D
  1. ..N X
  1. ..I READER.NodeType="element" D SPUSH(.S,READER.LocalName)
  1. ..I READER.NodeType="endelement" D SPOP(.S,.X)
  1. ..I READER.NodeType="chars" D SPUT(.S,READER.Value)
  1. Q
  1. ;
  1. SPUSH(S,X) ;places X on the stack S and returns the current level of the stack
  1. N I S I=$O(S(""),-1)+1,S(I)=X
  1. Q I
  1. ;
  1. SPOP(S,X) ;removes the top item from the stack S and put it into the variable X and returns the level that X was at
  1. N I S I=$O(S(""),-1)
  1. I I S X=S(I) K S(I)
  1. N J S J=$O(S(I),-1) I J S S(J,X)=$G(S(J,X))+1
  1. Q I
  1. ;
  1. SPEEK(S,X) ;same as SPOP except the top item is not removed
  1. N I S I=$O(S(""),-1)
  1. I I S X=S(I)
  1. Q I
  1. ;
  1. SPUT(S,X) ;implementation specific, uses the stack to form a global node
  1. N I,STR
  1. S STR=$P(GL,")")
  1. S I=0 F S I=$O(S(I)) Q:'I D
  1. .S STR=STR_","_""""_S(I)_""""_","
  1. .N NUM S NUM=0
  1. .I $D(S(I-1,S(I))) S NUM=+$G(S(I-1,S(I)))
  1. .S STR=STR_NUM
  1. S STR=STR_")"
  1. I $D(@STR) S @STR=@STR_X
  1. I '$D(@STR) S @STR=X
  1. Q STR
  1. ;
  1. MSGERR() ;check errors from XML return
  1. ;returns empty string "" if there was no error
  1. ;returns empty string "" if the only error was "ALL_PATIENT_IDS_EXCLUDED"
  1. ;otherwise returns the exceptionMessage string from the errorSection
  1. N ORRET S ORRET=""
  1. I $D(^TMP($J,"ORRDI","ClinicalData",0,"errorSection")) D
  1. .N I F I="fatalErrors","errors","warnings" D
  1. ..N J S J="" F S J=$O(^TMP($J,"ORRDI","ClinicalData",0,"errorSection",0,I,J)) Q:J="" D
  1. ...N ORSTR S ORSTR=$G(^TMP($J,"ORRDI","ClinicalData",0,"errorSection",0,I,J,"errorCode",0))
  1. ...I ORSTR'="ALL_PATIENT_IDS_EXCLUDED" S ORRET=ORSTR
  1. Q ORRET
  1. ERRHNDL(DFN) ;handle any errors that may get thrown in call to GET^ORRDI1
  1. K ^TMP($J,"ORRDI"),^XTMP("ORRDI","PSOO",DFN),^XTMP("ORRDI","ART",DFN)
  1. D UNWIND^%ZTER
  1. Q