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

RORHL12.m

Go to the documentation of this file.
  1. RORHL12 ;HOIFO/BH,SG - HL7 MICROBIOLOGY DATA: OBR ;3/13/06 9:24am
  1. ;;1.5;CLINICAL CASE REGISTRIES;**1,10**;Feb 17, 2006;Build 32
  1. ;
  1. ; This routine uses the following IAs:
  1. ;
  1. ; #4335 $$GETDATA^LA7UTL1A (controlled)
  1. ; #10000 C^%DTC (supported)
  1. ; #10103 FMTHL7^XLFDT (supported)
  1. ; #2056 GET1^DIQ (supported)
  1. ;
  1. Q
  1. ;
  1. ;***** SEARCH FOR MICROBIOLOGY DATA
  1. ;
  1. ; RORDFN IEN of the patient in the PATIENT file (#2)
  1. ;
  1. ; .DXDTS Reference to a local variable where the
  1. ; data extraction time frames are stored.
  1. ;
  1. ; RORMODE The type of extract to be performed:
  1. ; 0 Nightly extract
  1. ; 1 Historical extract
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ; >0 Non-fatal error(s)
  1. ;
  1. ;-----------------------------------------------------------------------------
  1. ; NIGHTLY EXTRACT FOR A PATIENT THAT HAS NOT BEEN INCLUDED IN A PREVIOUS
  1. ; EXTRACT:
  1. ; This will consist of 1 call to the Lab API to retrieve all micro data
  1. ; collected during the extraction date range.
  1. ;
  1. ; st end
  1. ; |----------------------------------------|
  1. ; <========================================> collection date
  1. ;
  1. ;-----------------------------------------------------------------------------
  1. ; NIGHTLY EXTRACT FOR A PATIENT THAT HAS BEEN INCLUDED IN A PREVIOUS EXTRACT:
  1. ; This will consist of 3 calls to the Lab API. It will pull micro data with
  1. ; a completion date in the date range, and it also pulls micro data that was
  1. ; collected exactly 60 days before the start date but has no completion date.
  1. ;
  1. ; 1. Call using a COMPLETION date in the original date range, but only
  1. ; include records in the extract from this call that have a collection date
  1. ; on or after the start date minus 60 days.
  1. ;
  1. ; st-60 days st end
  1. ; |--------------------|----|
  1. ; <=========================> collection date
  1. ; <====> completion date
  1. ;
  1. ; 2. Call using a COMPLETION date range of 60 days prior to the extraction
  1. ; start date through the original end date. Records returned from this call
  1. ; are completed, and will be compared to the records returned in the next call.
  1. ;
  1. ; 3. Call again to get all records COLLECTED exactly 60 days from the
  1. ; extraction date range. Only send the records from call #3 that were NOT
  1. ; returned from call #2. This sends all records that were collected at
  1. ; exactly 60 days before the extraction date range, but have not yet been
  1. ; completed.
  1. ;
  1. ; st-60 end-60 st end
  1. ; |-----------|--------|----|
  1. ; ============== collection date 60 days prior to date range
  1. ; no completion date
  1. ;
  1. ;-----------------------------------------------------------------------------
  1. ; HISTORICAL EXTRACT:
  1. ; This will consist of 1 call to the Lab API to retrieve all micro data
  1. ; collected during the extraction date range.
  1. ;
  1. ; st end
  1. ; |----------------------------------------|
  1. ; <========================================> collection date
  1. ;
  1. ;-----------------------------------------------------------------------------
  1. EN1(RORDFN,DXDTS,RORMODE) ;
  1. N ERRCNT,IDX,LRDFN,RC,RCL,RORENDT,RORMIIEN,RORREF,RORSTDT,RORTMP,TMP
  1. S (ERRCNT,RC)=0
  1. ;--- Which is being requested - historical or nightly extract?
  1. S RORMODE=$S($G(RORMODE):"HIST",1:"NIGHT")
  1. ;
  1. S LRDFN=+$$LABREF^RORUTL18(RORDFN) Q:LRDFN'>0 0
  1. S RORTMP=$$ALLOC^RORTMP()
  1. ;
  1. S IDX=0
  1. F S IDX=$O(DXDTS(11,IDX)) Q:IDX'>0 D Q:RC<0
  1. . S RORSTDT=$P(DXDTS(11,IDX),U),RORENDT=$P(DXDTS(11,IDX),U,2)
  1. . K @RORTMP
  1. . ;---NIGHTLY EXTRACTION---
  1. . I RORMODE="NIGHT" D
  1. .. ;get 798 IEN (ROR REGISTRY RECORD)
  1. .. N ROR798 S ROR798=$O(^RORDATA(798,"B",RORDFN,0))
  1. .. Q:'$G(ROR798)
  1. .. ;get DATA ACKNOWLEDGED UNTIL field (#9.1) in 798
  1. .. N RORACK K RORMSG S RORACK=$$GET1^DIQ(798,ROR798_",",9.1,,,"RORMSG")
  1. .. Q:$D(RORMSG("DIERR"))
  1. .. ;--------------------------------------------------------------------------
  1. .. I $G(RORACK)="" D Q ;patient has not been included in a previous extract
  1. ... ;call lab api using 'collection date' mode
  1. ... S RCL=$$GETDATA^LA7UTL1A(LRDFN,RORSTDT,RORENDT,"CD",RORTMP)
  1. ... I RCL<0 D Q
  1. .... S TMP="$$GETDATA^LA7UTL1A"
  1. .... S RC=$$ERROR^RORERR(-56,,$P(RCL,U,2),RORDFN,+RCL,TMP)
  1. ... ;--- Process the returned data and build the message segments
  1. ... S RORMIIEN="" F S RORMIIEN=$O(@RORTMP@(LRDFN,RORMIIEN)) Q:RORMIIEN="" D
  1. .... S RORREF=$NA(@RORTMP@(LRDFN,RORMIIEN))
  1. .... S TMP=$$OBR(RORREF)
  1. .... I TMP Q:TMP<0 S ERRCNT=ERRCNT+TMP
  1. .... S TMP=$$OBX^RORHL121(RORREF)
  1. .... I TMP Q:TMP<0 S ERRCNT=ERRCNT+TMP
  1. .... Q
  1. ... Q
  1. .. ;--------------------------------------------------------------------------
  1. .. I $L(RORACK)>0 D Q ;patient has been included in a previous extract
  1. ... N X,X1,X2,RORST60
  1. ... ;subtract 60 from start date
  1. ... S X1=RORSTDT,X2=-60 D C^%DTC S RORST60=X K X,X1,X2
  1. ... ;subtract 60 from end date
  1. ... N X,X1,X2,ROREND60
  1. ... S X1=RORENDT,X2=-60 D C^%DTC S ROREND60=X K X,X1,X2
  1. ... K @RORTMP
  1. ... ;CALL #1 using 'completion date' mode
  1. ... S RCL=$$GETDATA^LA7UTL1A(LRDFN,RORSTDT,RORENDT,"RAD",RORTMP)
  1. ... I RCL<0 D Q
  1. .... S TMP="$$GETDATA^LA7UTL1A"
  1. .... S RC=$$ERROR^RORERR(-56,,$P(RCL,U,2),RORDFN,+RCL,TMP)
  1. ... ;--- Process the returned data and get the collection date
  1. ... S RORMIIEN=""
  1. ... F S RORMIIEN=$O(@RORTMP@(LRDFN,RORMIIEN)) Q:RORMIIEN="" D
  1. .... S RORREF=$NA(@RORTMP@(LRDFN,RORMIIEN))
  1. .... N RORCOLLDT S RORCOLLDT=$G(@RORREF@(0,.01,"I")) ;collection date
  1. .... Q:$G(RORCOLLDT)'>0 ;quit if collection date is null
  1. .... ;If the collection date was in the 60 days prior to the extraction start
  1. .... ;date, build the segments.
  1. .... I RORCOLLDT'<RORST60 D Q
  1. ..... S TMP=$$OBR(RORREF)
  1. ..... I TMP Q:TMP<0 S ERRCNT=ERRCNT+TMP
  1. ..... S TMP=$$OBX^RORHL121(RORREF)
  1. ..... I TMP Q:TMP<0 S ERRCNT=ERRCNT+TMP
  1. ..... Q
  1. .... Q
  1. ... N RORTMP2,RCL2
  1. ... S RORTMP2=$$ALLOC^RORTMP() K @RORTMP2
  1. ... ;CALL #2 using 'completion date' mode. Will be used further down.
  1. ... S RCL2=$$GETDATA^LA7UTL1A(LRDFN,RORST60,RORENDT,"RAD",RORTMP2)
  1. ... I RCL2<0 D Q
  1. .... S TMP="$$GETDATA^LA7UTL1A"
  1. .... S RC=$$ERROR^RORERR(-56,,$P(RCL2,U,2),RORDFN,+RCL2,TMP)
  1. ... N RORTMP3,RCL3
  1. ... S RORTMP3=$$ALLOC^RORTMP() K @RORTMP3
  1. ... ;CALL #3 using 'collection date' mode - 60 days prior to range
  1. ... S RCL3=$$GETDATA^LA7UTL1A(LRDFN,RORST60,ROREND60,"CD",RORTMP3)
  1. ... I RCL3<0 D Q
  1. .... S TMP="$$GETDATA^LA7UTL1A"
  1. .... S RC=$$ERROR^RORERR(-56,,$P(RCL2,U,2),RORDFN,+RCL2,TMP)
  1. ... ;--- Process the returned records from call #3 and compare them
  1. ... ;to the records returned from call #2
  1. ... S RORMIIEN=""
  1. ... F S RORMIIEN=$O(@RORTMP3@(LRDFN,RORMIIEN)) Q:RORMIIEN="" D
  1. .... S RORREF=$NA(@RORTMP3@(LRDFN,RORMIIEN))
  1. .... N RORCOLLDT
  1. .... S RORCOLLDT=$G(@RORREF@(0,.01,"I")) ;collection date
  1. .... ;quit if the record is on the "completed" output from call #2
  1. .... Q:$D(@RORTMP2@(LRDFN,RORMIIEN))
  1. .... ;otherwise, build message segments
  1. .... S TMP=$$OBR(RORREF)
  1. .... I TMP Q:TMP<0 S ERRCNT=ERRCNT+TMP
  1. .... S TMP=$$OBX^RORHL121(RORREF)
  1. .... I TMP Q:TMP<0 S ERRCNT=ERRCNT+TMP
  1. .... D FREE^RORTMP(RORTMP2)
  1. .... D FREE^RORTMP(RORTMP3)
  1. ... Q
  1. . ;--------------------------------------------------------------------------
  1. . I RORMODE="HIST" D ;historical extract
  1. .. ;call lab api using 'collection date' mode
  1. .. S RCL=$$GETDATA^LA7UTL1A(LRDFN,RORSTDT,RORENDT,"CD",RORTMP)
  1. .. ;--- Process the returned data and build the message segments
  1. .. S RORMIIEN=""
  1. .. F S RORMIIEN=$O(@RORTMP@(LRDFN,RORMIIEN)) Q:RORMIIEN="" D
  1. ... S RORREF=$NA(@RORTMP@(LRDFN,RORMIIEN))
  1. ... S TMP=$$OBR(RORREF) ;build OBR segment
  1. ... I TMP Q:TMP<0 S ERRCNT=ERRCNT+TMP
  1. ... S TMP=$$OBX^RORHL121(RORREF) ;build OBX segment
  1. ... I TMP Q:TMP<0 S ERRCNT=ERRCNT+TMP
  1. .. Q
  1. . Q
  1. ;
  1. D FREE^RORTMP(RORTMP)
  1. Q $S(RC<0:RC,1:ERRCNT)
  1. ;
  1. ;***** MICROBIOLOGY OBR SEGMENT BUILDER
  1. ;
  1. ; RORREF Global reference for MI entry
  1. ;
  1. ; Return Values:
  1. ; <0 Error code
  1. ; 0 Ok
  1. ; >0 Non-fatal error(s)
  1. ;
  1. OBR(RORREF) ;
  1. N CS,ERRCNT,RC,RORSEG
  1. S (ERRCNT,RC)=0
  1. D ECH^RORHL7(.CS)
  1. ;
  1. ;--- Initialize the segment
  1. S RORSEG(0)="OBR"
  1. ;
  1. ;--- OBR-3 - Accession Number
  1. S TMP=$G(@RORREF@(0,.06,"I"))
  1. I TMP="" D Q RC
  1. . S RC=$$ERROR^RORERR(-100,,,,"No accession #","$$GETDATA^LA7UTL1A")
  1. S RORSEG(3)=TMP
  1. ;
  1. ;--- OBR-4 - Universal Service ID
  1. S RORSEG(4)="87999"_CS_"MICROBIOLOGY"_CS_"C4"
  1. ;
  1. ;--- OBR-7 - Accession Date
  1. S TMP=$$FMTHL7^XLFDT($G(@RORREF@(0,.01,"I")))
  1. I TMP'>0 D Q RC
  1. . S RC=$$ERROR^RORERR(-100,,,,"No accession date","$$GETDATA^LA7UTL1A")
  1. S RORSEG(7)=TMP
  1. ;
  1. ;--- OBR-11 - Urine Screen
  1. S RORSEG(11)=$G(@RORREF@(0,11.57,"I"))
  1. ;
  1. ;--- OBR-13 - Site/Specimen
  1. S RORSEG(13)=$$ESCAPE^RORHL7($G(@RORREF@(0,.05,"E")))
  1. ;
  1. ;--- OBR-20 - Collection Sample
  1. S RORSEG(20)=$$ESCAPE^RORHL7($G(@RORREF@(0,.055,"E")))
  1. ;
  1. ;--- OBR-21 - Sputum Screen
  1. S RORSEG(21)=$$ESCAPE^RORHL7($G(@RORREF@(0,11.58,"E")))
  1. ;
  1. ;--- OBR-24 - Diagnostic Service ID
  1. S RORSEG(24)="MB"
  1. ;
  1. ;--- OBR-25 - Sterility Control
  1. S TMP=$G(@RORREF@(0,11.51,"I"))
  1. S RORSEG(25)=$S(TMP="P":"F",TMP="N":"R",1:"")
  1. ;
  1. ;--- OBR-44 - Division
  1. S RORSEG(44)=$$SITE^RORUTL03(CS)
  1. ;
  1. ;--- Store the segment
  1. D ADDSEG^RORHL7(.RORSEG)
  1. Q ERRCNT