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

BJPNAPI2.m

Go to the documentation of this file.
  1. BJPNAPI2 ;GDIT/HS/BEE-Prenatal Care Module V2.0 API Calls ; 08 May 2012 12:00 PM
  1. ;;2.0;PRENATAL CARE MODULE;**8**;Feb 24, 2015;Build 25
  1. ;
  1. Q
  1. ;
  1. PIP(TARGET,DFN,TYPE,ASTS,VIEN,VONLY,VLAST,PARM,XICG) ;Returns PIPA/PIPN - PIP-Active/Inactive Information
  1. ;
  1. ;Input:
  1. ; DFN - Patient IEN
  1. ; TYPE - "C" - Returns list of problem entries on the PIP.
  1. ; For each problem entry, returns any information for each entry
  1. ; entered within the date range for the current pregnancy.
  1. ; "A" - Returns list of problem entries on the PIP.
  1. ; For each problem entry, returns ALL information for each entry,
  1. ; regardless of whether they apply to the current pregnancy
  1. ; or to prior pregnancies.
  1. ; ASTS - All Statuses - (Optional) If 1, return both Active and Inactive
  1. ; Problems. Otherwise, just return Active problems.
  1. ; VIEN - Visit IEN - If populated, only return problems that were set as the POV
  1. ; for that visit. Return only visit instructions associated with that visit
  1. ; VONLY - 1 - (Optional) Used with VIEN, return only visit instructions/OB Notes for the
  1. ; specified visit
  1. ; VLAST - 1 - (Optional) Used with VIEN and VONLY. If 1, get previous instruction/OB Notes if
  1. ; there is no instruction on current visit
  1. ; PARM - (Optional) - Formatting parameter which can contain one or more of the following codes
  1. ; - 'V' - Do NOT display the date beside visit instructions/OB Notes
  1. ; - 'P' - Do NOT display the date entered for the problem
  1. ; - 'H' - Do Not display a hyphen next to each care plan, goal, and visit instruction
  1. ; - 'O' - Include OB Notes
  1. ; - So as an example, passing "VP" would not display either date listed, but the hyphen
  1. ; would still display
  1. ; XICG - 1 - (Optional) - Exclude Inactive Care Plans and Goals regardles of TYPE
  1. ;
  1. ;Input validation
  1. S ASTS=$G(ASTS)
  1. I $G(DFN)="" S @TARGET@(1,0)="Invalid DFN" Q "~@"_$NA(@TARGET)
  1. I $G(TYPE)="" S @TARGET@(1,0)="Invalid TYPE" Q "~@"_$NA(@TARGET)
  1. ;
  1. I (",C,A,")'[TYPE D Q "~@"_$NA(@TARGET)
  1. . S @TARGET@(1,0)="Invalid TYPE - Must be C or A"
  1. S VIEN=$G(VIEN) I VIEN]"",$$GET1^DIQ(9000010,VIEN_",",.01,"I")="" D Q "~@"_$NA(@TARGET)
  1. . S @TARGET@(1,0)="Invalid VIEN"
  1. ;
  1. S VONLY=$G(VONLY) S:VIEN="" VONLY=""
  1. S VLAST=$G(VLAST) S:VIEN="" VLAST=""
  1. S XICG=$G(XICG)
  1. S PARM=$G(PARM)
  1. ;
  1. NEW II,CNT,RESULT,PRBIEN,PCNT,UID,TMP,NEDT
  1. ;
  1. ;Reset output
  1. K @TARGET
  1. ;
  1. ;Define task id
  1. S UID=$S($G(ZTSK):"Z"_ZTSK,1:$J)
  1. ;
  1. ;Definitive EDD date range check
  1. D GETPAR^CIAVMRPC(.NEDT,"BJPN POST DEDD DAYS","SYS",1,"I","")
  1. ;
  1. ;If blank default to 70
  1. I +$G(NEDT)<1 S NEDT=70
  1. ;
  1. ;Call EHR API and format results into usable data
  1. D COMP^BJPNUTIL(DFN,UID,VIEN)
  1. S TMP=$NA(^TMP("BJPNIPL",UID)) ;Define compiled data reference
  1. ;
  1. ;Loop through PIP - Process each entry
  1. S PRBIEN="",II=0,PCNT=0 F S PRBIEN=$O(^BJPNPL("F",DFN,PRBIEN)) Q:PRBIEN="" D
  1. . NEW BPIEN
  1. . S BPIEN="" F S BPIEN=$O(^BJPNPL("F",DFN,PRBIEN,BPIEN)) Q:BPIEN="" D
  1. .. D PROC(PRBIEN,BPIEN,ASTS,TMP,VIEN,VONLY,VLAST,PARM)
  1. ;
  1. ;Clear out scratch global
  1. K ^TMP("BJPNPRL",$J)
  1. ;
  1. ;Define Output
  1. S (II,CNT)=0 F S II=$O(RESULT(II)) Q:'II D
  1. .S CNT=CNT+1
  1. .S @TARGET@(CNT,0)=RESULT(II)
  1. I 'CNT S @TARGET@(1,0)="No Active Problems for Current Pregnanacy"
  1. Q "~@"_$NA(@TARGET)
  1. ;
  1. PROC(PRBIEN,BPIEN,ASTS,TMP,VIEN,VONLY,VLAST,PARM) ;EP - Process one entry
  1. ;
  1. NEW DEL,PNR,OEDT,OEBY,CNT,WRAP,PDSP,STS,LINE,SPACE,BGO,API,IVOB
  1. NEW X1,X2,X,DEDD,BRNG,ERNG,GOAL,VISIT,CARE,VSTDT,NVDT,NPDT,NHYP,OBN
  1. ;
  1. ;Define formatting parameters
  1. S NVDT=$S(PARM["V":1,1:"")
  1. S NPDT=$S(PARM["P":1,1:"")
  1. S NHYP=$S(PARM["H":1,1:"")
  1. S IVOB=$S(PARM["O":1,1:"")
  1. ;
  1. ;Get the visit date
  1. S VSTDT="" S:VIEN]"" VSTDT=$$GET1^DIQ(9000010,VIEN_",",.01,"I")
  1. ;
  1. S $P(SPACE," ",80)=" "
  1. ;
  1. ;Skip deletes
  1. S DEL=$$GET1^DIQ(90680.01,BPIEN_",",2.01,"I") Q:DEL]"" ;PIP Delete
  1. S DEL=$$GET1^DIQ(9000011,PRBIEN_",",2.02,"I") I DEL]"" Q ;IPL Delete
  1. ;
  1. ;Retrieve the entry from the API results
  1. S BGO=$O(@TMP@("P",PRBIEN,"")) Q:BGO="" ;Quit if no IPL entry
  1. S API=$G(@TMP@("P",PRBIEN,BGO)) Q:API=""
  1. ;
  1. ;If passed in only return POV problems
  1. I VIEN]"",$P(API,U,31)="" Q
  1. ;
  1. ;Status - Active Only
  1. S STS=$$GET1^DIQ(90680.01,BPIEN_",",.08,"I")
  1. I '$G(ASTS),STS'="A" Q
  1. ;
  1. ;Provider Text
  1. S PNR=$P(API,U,8)
  1. ;
  1. ;Tack on Inactive
  1. I STS'="A" S PNR="(i)"_PNR
  1. ;
  1. ;Original Entry Date
  1. S OEDT=$$FMTE^XLFDT($$GET1^DIQ(9000011,PRBIEN_",",.08,"I"),"2D")
  1. ;
  1. ;Original Entry By
  1. S OEBY=$$GET1^DIQ(9000011,PRBIEN_",",1.03,"E")
  1. ;
  1. ;Problem Count
  1. S PCNT=PCNT+1 I PCNT>1 S II=II+1,RESULT(II)=" "
  1. S PDSP=PCNT_") ",PDSP=$E(PDSP,1,4)
  1. ;
  1. ;Handle Wrapping
  1. D WRAP^BJPNPRNT(.WRAP,PNR,76)
  1. ;
  1. ;Process each wrapped line
  1. S WRAP="" F LINE=1:1 S WRAP=$O(WRAP(WRAP)) Q:WRAP="" D
  1. . S II=II+1,RESULT(II)=$S(LINE=1:PDSP,1:($E(SPACE,1,4)))_WRAP(WRAP)
  1. ;
  1. ;Tack on Date/By
  1. S II=II+1,RESULT(II)=$E(SPACE,1,4)_"(Entered"_$S(NPDT:"",1:" "_OEDT)_$S(OEBY]"":" by ",1:"")_OEBY_")"
  1. ;
  1. ;Pull Definitive EDD
  1. S DEDD=$$GET1^DIQ(90680.01,BPIEN_",",.09,"I")
  1. S X1=DEDD,X2=-280 D C^%DTC S BRNG=X
  1. S X1=DEDD,X2=NEDT D C^%DTC S ERNG=X
  1. ;
  1. ;Reset Notes Entries
  1. S (GOAL,CARE,VISIT,OBN)=""
  1. ;
  1. ;Loop through goals
  1. I 'VONLY S BGO="" F S BGO=$O(@TMP@("G",PRBIEN,BGO)) Q:BGO="" D
  1. . ;
  1. . NEW APIRES,VISIT,NIEN,IENS,DA,SCO,WRAP
  1. . NEW DTTM,MDBY,ILMBY,NOTE,NSTS,SIGN
  1. . ;
  1. . S SIGN=""
  1. . S APIRES=$G(@TMP@("G",PRBIEN,BGO,0)) Q:APIRES=""
  1. . ;
  1. . ;Skip Inactive Goals for Current Display
  1. . S NSTS=$P(APIRES,U,6),NSTS=$S(NSTS="A":"a",1:"i")
  1. . I TYPE="C",NSTS'="a" Q
  1. . ;
  1. . ;Skip Inactive Goals if override set
  1. . I XICG=1,NSTS'="a" Q
  1. . ;
  1. . ;Get note date/time entered and by
  1. . S (DTTM,ILMBY)=""
  1. . ;
  1. . ;Note IEN
  1. . S NIEN=$P(APIRES,U,2) Q:NIEN=""
  1. . ;
  1. . ;Get note date/time entered and by - Goal
  1. . S DA=$O(^AUPNCPL(NIEN,11,"B","A",""),-1) Q:DA=""
  1. . S DA(1)=NIEN,IENS=$$IENS^DILF(.DA)
  1. . S DTTM=$$GET1^DIQ(9000092.11,IENS,".03","I")
  1. . S ILMBY=$$GET1^DIQ(9000092.11,IENS,".02","I")
  1. . S SIGN=$P(APIRES,U,7)
  1. . ;
  1. . Q:DTTM=""
  1. . S MDBY=$$GET1^DIQ(200,ILMBY_",",".01","E")
  1. . ;
  1. . ;Get Note
  1. . S NOTE=$P($G(@TMP@("G",PRBIEN,BGO,1)),U,2)
  1. . Q:NOTE=""
  1. . ;
  1. . ;Note Status
  1. . S NSTS=$S(VIEN]"":" ",TYPE="C":" ",XICG=1:" ",1:" ("_NSTS_") ")
  1. . ;
  1. . ;Determined signed/unsigned
  1. . S SIGN=$S(SIGN]"":"S",1:"U")
  1. . ;
  1. . ;Set up record
  1. . ;
  1. . ;Display Header
  1. . I 'GOAL D
  1. .. NEW WRAP
  1. .. D WRAP^BJPNPRNT(.WRAP,"Goal Notes",75,2)
  1. .. S II=II+1,RESULT(II)=$E(SPACE,1,6)_$G(WRAP(1))
  1. .. S GOAL=1
  1. . ;
  1. . ;Handle Wrapping
  1. . D WRAP^BJPNPRNT(.WRAP,$S(NHYP:"",1:"-")_NSTS_NOTE_" ("_$$FMTE^XLFDT(DTTM,"2D")_$S(MDBY]"":" by ",1:"")_MDBY_")",72,2)
  1. . ;
  1. . ;Process each wrapped line
  1. . S WRAP="" F LINE=1:1 S WRAP=$O(WRAP(WRAP)) Q:WRAP="" D
  1. .. S II=II+1,RESULT(II)=$E(SPACE,1,8)_WRAP(WRAP)
  1. ;
  1. ;Loop through care plans
  1. I 'VONLY S BGO="" F S BGO=$O(@TMP@("C",PRBIEN,BGO)) Q:BGO="" D
  1. . ;
  1. . NEW APIRES,VISIT,NIEN,IENS,DA,SCO,WRAP
  1. . NEW DTTM,MDBY,ILMBY,NOTE,NSTS,SIGN
  1. . ;
  1. . S SIGN=""
  1. . S APIRES=$G(@TMP@("C",PRBIEN,BGO,0)) Q:APIRES=""
  1. . ;
  1. . ;Skip Inactive Care Plans for Current Display
  1. . S NSTS=$P(APIRES,U,6),NSTS=$S(NSTS="A":"a",1:"i")
  1. . I TYPE="C",NSTS'="a" Q
  1. . ;
  1. . ;Skip Inactive Care Plans if override set
  1. . I XICG=1,NSTS'="a" Q
  1. . ;
  1. . ;Get note date/time entered and by
  1. . S (DTTM,ILMBY)=""
  1. . ;
  1. . ;Note IEN
  1. . S NIEN=$P(APIRES,U,2) Q:NIEN=""
  1. . ;
  1. . ;Get note date/time entered and by - Goal
  1. . S DA=$O(^AUPNCPL(NIEN,11,"B","A",""),-1) Q:DA=""
  1. . S DA(1)=NIEN,IENS=$$IENS^DILF(.DA)
  1. . S DTTM=$$GET1^DIQ(9000092.11,IENS,".03","I")
  1. . S ILMBY=$$GET1^DIQ(9000092.11,IENS,".02","I")
  1. . S SIGN=$P(APIRES,U,7)
  1. . ;
  1. . Q:DTTM=""
  1. . S MDBY=$$GET1^DIQ(200,ILMBY_",",".01","E")
  1. . ;
  1. . ;Get Note
  1. . S NOTE=$P($G(@TMP@("C",PRBIEN,BGO,1)),U,2)
  1. . Q:NOTE=""
  1. . ;
  1. . ;Note Status
  1. . S NSTS=$S(VIEN]"":" ",TYPE="C":" ",XICG=1:" ",1:" ("_NSTS_") ")
  1. . ;
  1. . ;Determined signed/unsigned
  1. . S SIGN=$S(SIGN]"":"S",1:"U")
  1. . ;
  1. . ;Set up record
  1. . ;
  1. . ;Display Header
  1. . I 'CARE D
  1. .. ;
  1. .. ;Skip a line if there were goals
  1. .. I GOAL S II=II+1,RESULT(II)=" "
  1. .. ;
  1. .. NEW WRAP
  1. .. D WRAP^BJPNPRNT(.WRAP,"Care Plan",75,2)
  1. .. S II=II+1,RESULT(II)=$E(SPACE,1,6)_$G(WRAP(1))
  1. .. S CARE=1
  1. . ;
  1. . ;Handle Wrapping
  1. . D WRAP^BJPNPRNT(.WRAP,$S(NHYP:"",1:"-")_NSTS_NOTE_" ("_$$FMTE^XLFDT(DTTM,"2D")_$S(MDBY]"":" by ",1:"")_MDBY_")",72,2)
  1. . ;
  1. . ;Process each wrapped line
  1. . S WRAP="" F LINE=1:1 S WRAP=$O(WRAP(WRAP)) Q:WRAP="" D
  1. .. S II=II+1,RESULT(II)=$E(SPACE,1,8)_WRAP(WRAP)
  1. ;
  1. ;Loop through OB Notes (Return All)
  1. I IVOB S BGO="" F S BGO=$O(@TMP@("O",PRBIEN,BGO)) Q:BGO="" D
  1. . ;
  1. . NEW APIRES,NIEN,IENS,DA,SCO,WRAP,SKIP
  1. . NEW DTTM,MDBY,ILMBY,NOTE,NSTS,SIGN,VSIT
  1. . ;
  1. . S SIGN=""
  1. . S APIRES=$G(@TMP@("O",PRBIEN,BGO,0)) Q:APIRES=""
  1. . ;
  1. . ;Filter out unmatch visits, if desired
  1. . S VSIT=$P(APIRES,U,9)
  1. . I 'VLAST,VIEN]"",VSIT'=VIEN Q
  1. . ;
  1. . ;See if only last note should be displayed
  1. . S SKIP="" I VLAST D Q:SKIP
  1. .. NEW VDT
  1. .. S VDT=$$GET1^DIQ(9000010,VSIT_",",.01,"I")
  1. .. I VDT>VSTDT S SKIP=1
  1. .. I VSIT'=VIEN,VISIT S SKIP=1
  1. . ;
  1. . ;Get note date/time entered and by
  1. . S (DTTM,ILMBY)=""
  1. . ;
  1. . ;Note IEN
  1. . S NIEN=$P(APIRES,U,2) Q:NIEN=""
  1. . ;
  1. . ;Get note date/time entered and by - V VISIT INSTRUCTIONS
  1. . S (DTTM,ILMBY)=""
  1. . S DTTM=$$GET1^DIQ(9000010.43,NIEN_",",1216,"I")
  1. . S ILMBY=$$GET1^DIQ(9000010.43,NIEN_",",1217,"I")
  1. . S SIGN=$P(APIRES,U,13)
  1. . ;
  1. . Q:DTTM=""
  1. . S MDBY=$$GET1^DIQ(200,ILMBY_",",".01","E")
  1. . ;
  1. . ;Get Note
  1. . S NOTE=$P($G(@TMP@("O",PRBIEN,BGO,1)),U,2)
  1. . Q:NOTE=""
  1. . ;
  1. . ;Note Status
  1. . S NSTS="i"
  1. . I DEDD]"",DTTM'<BRNG,DTTM'>ERNG S NSTS="a"
  1. . ;
  1. . ;Quit if current display and out of pregnancy range
  1. . I TYPE="C",NSTS="i" Q
  1. . ;
  1. . S NSTS=$S(VIEN]"":" ",TYPE="C":" ",1:" ("_NSTS_") ")
  1. . ;
  1. . ;Determined signed/unsigned
  1. . S SIGN=$S(SIGN]"":"S",1:"U")
  1. . ;
  1. . ;Set up record
  1. . ;
  1. . ;Display Header
  1. . I 'OBN D
  1. .. ;
  1. .. ;Skip a line if there were goals
  1. .. I GOAL!CARE S II=II+1,RESULT(II)=" "
  1. .. ;
  1. .. NEW WRAP
  1. .. D WRAP^BJPNPRNT(.WRAP,"OB Brief Note",75,2)
  1. .. S II=II+1,RESULT(II)=$E(SPACE,1,6)_$G(WRAP(1))
  1. .. S OBN=1
  1. . ;
  1. . ;Handle Wrapping
  1. . D WRAP^BJPNPRNT(.WRAP,$S(NHYP:"",1:"-")_NSTS_NOTE_" ("_$S('NVDT:$$FMTE^XLFDT(DTTM,"2D")_" ",1:"")_$S(MDBY]"":"by ",1:"")_MDBY_")",72,2)
  1. . ;
  1. . ;Process each wrapped line
  1. . S WRAP="" F LINE=1:1 S WRAP=$O(WRAP(WRAP)) Q:WRAP="" D
  1. .. S II=II+1,RESULT(II)=$E(SPACE,1,8)_WRAP(WRAP)
  1. ;
  1. ;Loop through Visit Instructions (Return All)
  1. S BGO="" F S BGO=$O(@TMP@("I",PRBIEN,BGO)) Q:BGO="" D
  1. . ;
  1. . NEW APIRES,NIEN,IENS,DA,SCO,WRAP,SKIP
  1. . NEW DTTM,MDBY,ILMBY,NOTE,NSTS,SIGN,VSIT
  1. . ;
  1. . S SIGN=""
  1. . S APIRES=$G(@TMP@("I",PRBIEN,BGO,0)) Q:APIRES=""
  1. . ;
  1. . ;Filter out unmatch visits, if desired
  1. . S VSIT=$P(APIRES,U,9)
  1. . I 'VLAST,VIEN]"",VSIT'=VIEN Q
  1. . ;
  1. . ;See if only last note should be displayed
  1. . S SKIP="" I VLAST D Q:SKIP
  1. .. NEW VDT
  1. .. S VDT=$$GET1^DIQ(9000010,VSIT_",",.01,"I")
  1. .. I VDT>VSTDT S SKIP=1
  1. .. I VSIT'=VIEN,VISIT S SKIP=1
  1. . ;
  1. . ;Get note date/time entered and by
  1. . S (DTTM,ILMBY)=""
  1. . ;
  1. . ;Note IEN
  1. . S NIEN=$P(APIRES,U,2) Q:NIEN=""
  1. . ;
  1. . ;Get note date/time entered and by - V VISIT INSTRUCTIONS
  1. . S (DTTM,ILMBY)=""
  1. . S DTTM=$$GET1^DIQ(9000010.58,NIEN_",",1216,"I")
  1. . S ILMBY=$$GET1^DIQ(9000010.58,NIEN_",",1217,"I")
  1. . S SIGN=$P(APIRES,U,13)
  1. . ;
  1. . Q:DTTM=""
  1. . S MDBY=$$GET1^DIQ(200,ILMBY_",",".01","E")
  1. . ;
  1. . ;Get Note
  1. . S NOTE=$P($G(@TMP@("I",PRBIEN,BGO,1)),U,2)
  1. . Q:NOTE=""
  1. . ;
  1. . ;Note Status
  1. . S NSTS="i"
  1. . I DEDD]"",DTTM'<BRNG,DTTM'>ERNG S NSTS="a"
  1. . ;
  1. . ;Quit if current display and out of pregnancy range
  1. . I TYPE="C",NSTS="i" Q
  1. . ;
  1. . S NSTS=$S(VIEN]"":" ",TYPE="C":" ",1:" ("_NSTS_") ")
  1. . ;
  1. . ;Determined signed/unsigned
  1. . S SIGN=$S(SIGN]"":"S",1:"U")
  1. . ;
  1. . ;Set up record
  1. . ;
  1. . ;Display Header
  1. . I 'VISIT D
  1. .. ;
  1. .. ;Skip a line if there were goals
  1. .. I GOAL!CARE!OBN S II=II+1,RESULT(II)=" "
  1. .. ;
  1. .. NEW WRAP
  1. .. D WRAP^BJPNPRNT(.WRAP,"Visit Instructions",75,2)
  1. .. S II=II+1,RESULT(II)=$E(SPACE,1,6)_$G(WRAP(1))
  1. .. S VISIT=1
  1. . ;
  1. . ;Handle Wrapping
  1. . D WRAP^BJPNPRNT(.WRAP,$S(NHYP:"",1:"-")_NSTS_NOTE_" ("_$S('NVDT:$$FMTE^XLFDT(DTTM,"2D")_" ",1:"")_$S(MDBY]"":"by ",1:"")_MDBY_")",72,2)
  1. . ;
  1. . ;Process each wrapped line
  1. . S WRAP="" F LINE=1:1 S WRAP=$O(WRAP(WRAP)) Q:WRAP="" D
  1. .. S II=II+1,RESULT(II)=$E(SPACE,1,8)_WRAP(WRAP)
  1. ;
  1. Q