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

RORX024.m

Go to the documentation of this file.
  1. RORX024 ;ALB/TK,MAF - HEP A VACCINE OR IMMUNITY REPORT ; 27 Jul 2016 3:03 PM
  1. ;;1.5;CLINICAL CASE REGISTRIES;**29,31,32,33,34**;Feb 17, 2006;Build 45
  1. ;
  1. ;******************************************************************************
  1. ; This routine uses the following IAs:
  1. ;
  1. ; #10103 HL7TFM^XLFDT
  1. ;
  1. ;******************************************************************************
  1. ;******************************************************************************
  1. ; --- ROUTINE MODIFICATION LOG ---
  1. ;
  1. ;PKG/PATCH DATE DEVELOPER MODIFICATION
  1. ;----------- ---------- ----------- ---------------------------------------
  1. ;ROR*1.5*29 APR 2016 T KOPP Added 'Hep A vaccine or immunity report'
  1. ;ROR*1.5*31 MAY 2017 M FERRARESE Adding PACT, PCP, and AGE/DOB as additional
  1. ; identifiers.
  1. ;ROR*1.5*32 11/01/17 S ALSAHHAR Print the most recent Immunity result
  1. ;ROR*1.5*33 MAR 2018 M FERRARESE Adding FUTURE APPOINTMENT as additional identifiers.
  1. ;ROR*1.5*34 SEP 2018 M FERRARESE Adding Future Appointment clinic name ; Fix LOINC code table for HEP A/B
  1. ;******************************************************************************
  1. ;******************************************************************************
  1. ;
  1. Q
  1. ;
  1. ;***** COMPILES THE "HEP A VACCINE OR IMMUNITY" REPORT
  1. ; REPORT CODE: 024
  1. ;
  1. ; .RORTSK Task number and task parameters
  1. ;
  1. ; The ^TMP("RORX024",$J) global node is used by this function.
  1. ;
  1. ; ^TMP("RORX024",$J,
  1. ; "PAT",
  1. ; DFN, Patient descriptor
  1. ; ^01: Last 4 digits of SSN
  1. ; ^02: Patient name
  1. ; ^03: Date of Death
  1. ; ^04: ICN
  1. ; ^05: Patient Care Team
  1. ; ^06: Priamary Care Provider
  1. ; ^07: Age/DOB
  1. ; "IMM") Result if positive test found or "" if no positive test found
  1. ; ^01: Local lab test name
  1. ; ^02: Collected date (FM)
  1. ; ^03: Lab test result
  1. ;
  1. ; "VAC", Number of results
  1. ; ^01: #
  1. ; VaccineName,
  1. ; VaccineDate) Always null if node exists
  1. ; ^01: Null
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ;
  1. HEPARPT(RORTSK) ;
  1. N RORIMM ; Immunity wanted mode (-1|0|1) no|not selected|yes (verified by lab test)
  1. N RORVAC ; Vaccination (-1|0|1) not received|not selected|received (verified by immunization record)
  1. N RORREG ; Registry IEN
  1. N RORVEDT ; Vaccination end date
  1. N RORVSDT ; Vaccination start date
  1. N RORLEDT ; Lab test/LOINC end date
  1. N RORLSDT ; Lab test/LOINC start date
  1. N RORRTN ; Routine to invoke for hep A processing
  1. N RORDAYS ; Future Days patch 33
  1. N RORFUT ; Future Appointment patch 33
  1. ;
  1. N NSPT,RC,REPORT,SFLAGS,TMP
  1. S RC=0,RORRTN="RORX024"
  1. K ^TMP(RORRTN,$J)
  1. ;--- Root node of the report
  1. S REPORT=$$ADDVAL^RORTSK11(RORTSK,"REPORT")
  1. Q:REPORT<0 REPORT
  1. ;
  1. D
  1. . ;--- Get and prepare the report parameters
  1. . S RORREG=$$PARAM^RORTSK01("REGIEN") ; Registry IEN
  1. . S RORVAC=$$RPTMODE("HEPAVAC") ; Vaccination option chosen
  1. . S RORIMM=$$RPTMODE("HEPAIMM") ; Immunity option chosen
  1. . S RC=$$PARAMS(REPORT,.RORVSDT,.RORVEDT,.SFLAGS) Q:RC<0
  1. . ;--- Report header
  1. . S RC=$$HEADER(REPORT) Q:RC<0
  1. . ;--- Query the registry
  1. . D TPPSETUP^RORTSK01(80)
  1. . S RC=$$QUERY^RORX024A(SFLAGS,.NSPT,RORRTN)
  1. . I RC Q:RC<0
  1. . ;--- Store the results
  1. . D TPPSETUP^RORTSK01(20)
  1. . S RC=$$STORE^RORX024A(REPORT,NSPT,RORRTN)
  1. . I RC Q:RC<0
  1. ;
  1. ;--- Cleanup
  1. K ^TMP(RORRTN,$J)
  1. Q $S(RC<0:RC,1:0)
  1. ;
  1. ;
  1. ;
  1. ;***** OUTPUTS THE REPORT HEADER
  1. ;
  1. ; PARTAG Reference (IEN) to the parent tag
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; >0 IEN of the HEADER element
  1. ;
  1. ;;PATIENTS(#,NAME,LAST4,AGE,DOD,VAC_NAME,VAC_DATE,LTNAME,DATE,RESULT,ICN,PACT,PCP,FUT_APPT,FUT_CLIN)^I $$PARAM^RORTSK01("AGE_RANGE","TYPE")="AGE"
  1. ;;PATIENTS(#,NAME,LAST4,DOB,DOD,VAC_NAME,VAC_DATE,LTNAME,DATE,RESULT,ICN,PACT,PCP,FUT_APPT,FUT_CLIN)^I $$PARAM^RORTSK01("AGE_RANGE","TYPE")="DOB"
  1. ;;PATIENTS(#,NAME,LAST4,DOD,VAC_NAME,VAC_DATE,LTNAME,DATE,RESULT,ICN,PACT,PCP,FUT_APPT,FUT_CLIN)^I $$PARAM^RORTSK01("AGE_RANGE","TYPE")="ALL"
  1. ;
  1. N HEADER,LN,RC,CTAG,LTAG
  1. S HEADER=$$HEADER^RORXU002(.RORTSK,PARTAG)
  1. Q:HEADER<0 HEADER
  1. ;automatically build the table defintion(s) listed under the header tag above PATCH 33
  1. ;--- LOINC codes output
  1. I $G(RORIMM) D
  1. . S LTAG=$$ADDVAL^RORTSK11(RORTSK,"LOINC_CODES",,PARTAG)
  1. . S LN=0 F S LN=$O(^TMP("RORX024",$J,"IMM","TYPE",LN)) Q:'LN D
  1. . . S CTAG=$$ADDVAL^RORTSK11(RORTSK,"CODE",,LTAG)
  1. . . D ADDATTR^RORTSK11(RORTSK,CTAG,"CODE",^TMP("RORX024",$J,"IMM","TYPE",LN))
  1. S RC=$$TBLDEF^RORXU002("HEADER^RORX024",HEADER)
  1. Q $S(RC<0:RC,1:HEADER)
  1. ;
  1. ;***** OUTPUTS THE PARAMETERS TO THE REPORT
  1. ;
  1. ; PARTAG Reference (IEN) to the parent tag
  1. ;
  1. ; [.STDT] Start and end dates of the report
  1. ; [.ENDT] are returned via these parameters
  1. ;
  1. ; [.FLAGS] Flags for the $$SKIP^RORXU005 are
  1. ; returned via this parameter
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; >0 IEN of the PARAMETERS element
  1. ;
  1. PARAMS(PARTAG,STDT,ENDT,FLAGS) ;
  1. N PARAMS,TMP
  1. S PARAMS=$$PARAMS^RORXU002(.RORTSK,PARTAG,,,.FLAGS)
  1. Q:PARAMS<0 PARAMS
  1. ;--- Process the list of Lab tests/LOINC codes
  1. I $G(RORIMM) D
  1. . D GETIMM("RORX024") ;extract the immunity criteria for HEP A
  1. ;--- Process the list of vaccinations
  1. I $G(RORVAC) D
  1. . D GETVAC("RORX024") ;extract the vaccine criteria for HEP A
  1. ;---
  1. Q PARAMS
  1. ;
  1. ;
  1. ; -- Extract immunity (lab) data for a patient
  1. ;
  1. ; PATIEN IEN of the patient (DFN)
  1. ;
  1. ; RORLOINC Closed root of a variable, which contains a list
  1. ; of LOINC codes for HEP A or HEPB in the format
  1. ; @RORLOINC@("VALID",i,
  1. ; ^01: LOINC code
  1. ; @("PRIORITY",LOINC code,priority)=""
  1. ;
  1. ; HEPA priority [0 for Ab Total or 1 for IgG]
  1. ; HEPB priority [0 for Surface AB or 1 for Core AB]
  1. ;
  1. ; RORLRES Closed root of an array where the data will be
  1. ; returned.
  1. ; The data will be stored into the destination
  1. ; array in following format:
  1. ;
  1. ; @RORLRES
  1. ; ^01: Local lab test name
  1. ; ^02: Collected date (FM)
  1. ; ^03: Lab test result
  1. ;
  1. ; LTSDT Lab test start date (FileMan)
  1. ; LTEDT Lab test end date (FileMan)
  1. ;
  1. ; The function should return the following values:
  1. ;
  1. ; <0 Error code (the search will be aborted)
  1. ; 0 No immunity found
  1. ; 1 At least 1 immunity found
  1. ;
  1. LAB(PATIEN,RORLOINC,RORLRES,LTSDT,LTEDT) ;
  1. N RC1,DFN,RORID,RORENDT,RORSTDT,ROR1,RESDT,RESULT,RORLRC,RORLAB,RORMSG,Z,Z0
  1. ;
  1. S DFN=PATIEN
  1. ;
  1. ; Search for specific LOINC codes and positive results
  1. S RORLAB=$NA(^TMP("ROROUT",$J)) ;lab API output global
  1. K RORMSG,@RORLAB ;initialize prior to call
  1. ;---CALL LAB API---
  1. M RORLRC=@RORLOINC@("VALID")
  1. S RORLRC="CH,MI",RORLRES="",RORID=$$PTID^RORUTL02(DFN)
  1. S RC1=$$GCPR^LA7QRY(RORID,LTSDT,LTEDT,.RORLRC,"*",.RORMSG,RORLAB)
  1. I RC1<0 Q -1
  1. Q:$D(@RORLAB)<10 0
  1. ;Note: the Lab API returns data in the form of HL7 segments
  1. N FS,TMP,LOINC,RESULT,RORLTN,RORVAL,RORNODE,RORSEG,SEGTYPE,RORDATE,RORX,RORX1
  1. S FS="|" ;HL7 field separator for lab data
  1. S (RORNODE,RESULT)=0
  1. F S RORNODE=$O(^TMP("ROROUT",$J,RORNODE)) Q:RORNODE="" D
  1. . S RORSEG=$G(^TMP("ROROUT",$J,RORNODE)) ;get entire HL7 segment
  1. . S SEGTYPE=$P(RORSEG,FS,1) ;get segment type (PID,OBR,OBX,etc.)
  1. . Q:SEGTYPE'="OBX" ;we want OBX segments only
  1. . S LOINC=$P($P(RORSEG,FS,4),U,1) ;get LOINC code for test
  1. . Q:$S(LOINC="":1,1:'$D(@RORLOINC@("PRIORITY",LOINC))) ; Call to lab does not filter out unwanted LOINCs
  1. . S RORLTN=$P($P($P(RORSEG,FS,4),U,9),FS) ;local test name
  1. . S RORVAL=$P(RORSEG,FS,6) ;test result value
  1. . S RORVAL=$TR(RORVAL,"""","") ;get rid of double quotes around values
  1. . Q:RORVAL="" ;quit if no value
  1. . ;Check if value meets the positive result criteria selected for immunity
  1. . Q:'$$POS^RORX024A(RORVAL)
  1. . S RORDATE=$$HL7TFM^XLFDT($E($P(RORSEG,FS,15),1,8)) ;get date collected
  1. . ;S RORDATE=RORDATE\1
  1. . ;Output the record into RORX by priority, date, LOINC Code if positive result
  1. . S RORX(+$O(@RORLOINC@("PRIORITY",LOINC,0)),(9999999-RORDATE),LOINC)=RORVAL_U_RORLTN
  1. ; Find the result as the earliest date in priority 0 tests and if none, earliest in priority 1
  1. F Z=1,2 S Z0=$O(RORX(Z,0)) I Z0 D Q:RESULT
  1. . S RORX1=$O(RORX(Z,Z0,0))
  1. . Q:RORX1=""
  1. . S RESULT=1,RORLRES=$P(RORX(Z,Z0,RORX1),U,2)_U_(9999999-Z0)_U_$P(RORX(Z,Z0,RORX1),U)
  1. K @RORLAB
  1. Q RESULT
  1. ;
  1. ;***** DETERMINES THE REPORT MODE FOR IMMUNITY OR VACCINATION
  1. ;
  1. ; NAME Base name of the attribute ("HEPAIMM" or "HEPAVAC")
  1. ; OR ("HEPBIMM" or "HEPBVAC")
  1. ; Return Values:
  1. ; <0 "No"
  1. ; 0 Not selected
  1. ; >0 "Yes"
  1. ;
  1. RPTMODE(NAME) ;
  1. Q:$$PARAM^RORTSK01("PATIENTS",NAME) 1 ; "Yes"
  1. Q:$$PARAM^RORTSK01("PATIENTS","NO"_NAME) -1 ; "No"
  1. Q 0
  1. ;
  1. ; ******* EXTRACT LOINC CODES FOR IMMUNITY ********
  1. ; RORRTN = the name of the report routine where the IMMUNITY data should be extracted from
  1. ;
  1. ; Returns ^TMP(RORRTN,$J,"IMM","VALID",n)=LOINC code^LN and
  1. ; ^TMP(RORRTN,$J,"IMM","PRIORITY",LOINC code,[0 for Total Ab or 1 for IgG])=""
  1. ; ^TMP(RORRTN,$J,"IMM","TYPE",n)=Type of LOINC: list of LOINC codes for type (used for header output)
  1. ;
  1. ;
  1. GETIMM(RORRTN) ;
  1. N RORDATA,RORI,RORI1,COM,CT,Z
  1. K ^TMP(RORRTN,$J,"IMM")
  1. ;
  1. I $E(RORRTN)=U S RORRTN=$P(RORRTN,U,2)
  1. S CT=0
  1. F RORI=1:1 S RORDATA=$P($T(@("IMMUNITY+"_RORI_U_RORRTN)),";;",2) Q:RORDATA="" D
  1. . S ^TMP(RORRTN,$J,"IMM","TYPE",RORI)=$P(RORDATA,U)_": ",COM=0
  1. . F RORI1=2:1 S Z=$P(RORDATA,U,RORI1) Q:Z="" D
  1. . . S CT=CT+1,^TMP(RORRTN,$J,"IMM","VALID",CT)=Z_"^LN"
  1. . . S ^TMP(RORRTN,$J,"IMM","PRIORITY",Z,RORI)=""
  1. . . S ^TMP(RORRTN,$J,"IMM","TYPE",RORI)=^TMP(RORRTN,$J,"IMM","TYPE",RORI)_$S('COM:"",1:";")_Z,COM=1
  1. ;
  1. Q
  1. ;
  1. ; -- LOINC codes to check for HEP A immunity
  1. IMMUNITY ; List of LOINC codes indicating HEP A immunity results by type Line +1 = Total AB (priority), Line +2 = IgG
  1. ;;Hepatitis A Ab Total^20575-7^13951-9^22312-3^5183-9^5184-7
  1. ;;Hepatitis A IgG^32018-4^22313-1^5179-7
  1. ;;
  1. Q
  1. ; ******* EXTRACT VACCINE NAMES ********
  1. ; RORRTN = the name of the report routine where the IMMUNITY data should be extracted from
  1. ;
  1. ; Returns ^TMP(RORRTN,$J,"VAC",seq #)=pattern to match
  1. ;
  1. GETVAC(RORRTN) ; Extract pertinent vaccine names to match
  1. N CT,CHAR,QUOTE,POS,RORDATA,RORI,RORI1,RESULT,VACNM,Z
  1. ;
  1. I $E(RORRTN="^") S RORRTN=$P(RORRTN,U,2)
  1. S CT=0
  1. F RORI=1:1 S RORDATA=$P($T(@("VACCINE+"_RORI_U_RORRTN)),";;",2) Q:RORDATA="" D
  1. . F RORI1=1:1 S VACNM=$P(RORDATA,U,RORI1) Q:VACNM="" D
  1. .. S RESULT=""
  1. .. ; determine pattern
  1. .. S QUOTE=0
  1. .. F POS=1:1:$L(VACNM) S CHAR=$E(VACNM,POS) D
  1. ... I POS=1,CHAR="%" S RESULT=".E" Q
  1. ... I CHAR'="%" S RESULT=RESULT_$S('QUOTE:"1""",1:"")_CHAR,QUOTE=1 Q
  1. ... I CHAR="%" D
  1. .... I QUOTE S RESULT=RESULT_""""
  1. .... S RESULT=RESULT_".E",QUOTE=0
  1. .. I RESULT'="",QUOTE S RESULT=RESULT_""""
  1. .. S CT=CT+1,^TMP(RORRTN,$J,"VAC",CT)=RESULT
  1. ;
  1. Q
  1. ;
  1. ; -- List of vaccines to include
  1. ; Business owner also requested (HEPATITIS A&B%, HEPATITIS A/B, HEPATITIS AB) that are the same as %HEPATITIS A%
  1. ; (HEP A/HEP B%, HEP A&B, HEP A/HEP B) that are the same as HEP A%
  1. VACCINE ; Hepatitis A vaccine names (% = wild card)
  1. ;;HEP A%^%HEPATITIS A%^HEPATITIS-A%^HEPAADULT^HEPAADLT1^HEPA,%^HEPA/HEPB%^%HEP A/B%^HEPAB%^TWINRIX%
  1. ;;
  1. Q
  1. ;