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

VPSRPC21.m

Go to the documentation of this file.
  1. VPSRPC21 ;;DALOI/KML,WOIFO/BT - Update of Patient Demographics RPC (Continue from VPSRPC2) ;11/20/11 15:30
  1. ;;1.0;VA POINT OF SERVICE (KIOSKS);**2**;Oct 21, 2011;Build 41
  1. ;;Per VHA Directive 2004-038, this routine should not be modified.
  1. ;
  1. ; External Reference DBIA#
  1. ; ------------------------
  1. ; ICR# 3618 - Postal Code and County Code APIs (Supported)
  1. Q
  1. ;
  1. ADDRVAL(PTIEN,REC,REQLST,ILST,VRES) ; validate for required fields for address sets
  1. ; INPUT - all input parameters except PTIEN passed in by reference
  1. ; PTIEN = DFN
  1. ; REC = incremental number assigned to each subscript built in the OUTPUT array
  1. ; REQLST = array to be used when validating the required address sets
  1. ; ILST = data passed in by Vecna (VPSLST array)
  1. ; OUTPUT
  1. ; VRES = the array to return the results of ADDRESS validation processing. Exceptions (only) made available as RPC output for client
  1. ;
  1. N OK,ER
  1. ; validate country and zip code for permanent address
  1. S OK=$$PERMVAL(.REQLST,.ILST,.ER)
  1. I 'OK D ADDERR(.REC,.VRES,.ER) ;Add errors to the result array
  1. I 'OK D CLRPERM(.REQLST,.ILST) ; did not pass validation; clear permanet address fields
  1. ;
  1. ; validate foreign/temporary address
  1. S OK=$$TEMPVAL(PTIEN,.REQLST,.ILST,.ER)
  1. I 'OK D ADDERR(.REC,.VRES,.ER) ;Add errors to the result array
  1. I 'OK D CLRTEMP(.REQLST,.ILST) ; did not pass validation; clear permanet address fields
  1. Q
  1. ;
  1. PERMVAL(REQLST,ILST,ER) ;validate country and zip code for permanent address
  1. ; INPUT - all input parameters passed in by reference
  1. ; REQLST = array to be used when validating the required address sets
  1. ; ILST = data passed in by Vecna (VPSLST array)
  1. ; OUTPUT
  1. ; ER = array of Error Message or Empty (No error)
  1. ; RETURN
  1. ; 1 = success
  1. ; 0 = failed
  1. ;
  1. ; country must exist. The cross reference validation will happen during filing
  1. K ER
  1. ; check if Vecna sent permanent address
  1. N PERM S PERM=0
  1. N FLD F FLD=.111,.114,.115,.117,.1112,.1173 I $P(REQLST(FLD),U,3)]"" S PERM=1 Q ;determine if vecna sent permanent address fields
  1. Q:'PERM 1 ; permanent address fields not sent, no error
  1. ;
  1. ; country must exist to update permanent address fields
  1. N COUNTRY S COUNTRY=$P(REQLST(.1173),U,3) ;Country sent by Vecna
  1. I COUNTRY="" S ER(1)="COUNTRY is needed for PERMANENT address fields. Write to Patient record for the ADDRESS fields did not get performed"
  1. Q:$D(ER) 0
  1. N USAADDR S USAADDR=(COUNTRY="USA")!(COUNTRY="UNITED STATES")!(COUNTRY?1N.N)
  1. Q:'USAADDR 1 ; no zip code validation for non US address
  1. ;
  1. ; Validate Zip Code. Changing City, County or State must be accompanied by Zip Code
  1. N ZIP S ZIP=$P(REQLST(.1112),U,3) ;Zip Code sent by Vecna
  1. I ZIP="" D CLRCCS(.REQLST,.ILST) ;if zip code was not sent, clear city, county, state from processing. This is to guard someone for entering invalid City/County/State
  1. Q:ZIP="" 1 ; no city,county,state update, no error
  1. ;
  1. N XIP D POSTALB^XIPUTIL(ZIP,.XIP) ;IA #3618 (Supported)
  1. I 'XIP S ER(1)=XIP("ERROR")_". Write to Patient record for the ADDRESS fields did not get performed" ;can't find zipcode
  1. Q:'XIP 0
  1. ;
  1. ; validate city,county,state,country for the zipcode
  1. N CITY S CITY=$P(REQLST(.114),U,3)
  1. N STATE S STATE=$P(REQLST(.115),U,3)
  1. N COUNTY S COUNTY=$P(REQLST(.117),U,3)
  1. N EFLG S EFLG=$$GETZIP(CITY,COUNTY,STATE,.XIP,.ZIPIDX) ;get the index of XIP
  1. I EFLG=-1 S ER(1)="Invalid STATE for the ZIPCODE of PERMANENT address. Write to Patient record for the ADDRESS fields did not get performed"
  1. I EFLG=-2 S ER(1)="Cannot find DEFAULT CITY for the ZIPCODE OF PERMANENT address. Write to Patient record for the ADDRESS fields did not get performed"
  1. I EFLG=1 D UPDZIP(ZIPIDX,.XIP,.REQLST,.ILST) ; Change city, county, state, country to match VistA
  1. ;
  1. Q '$D(ER)
  1. ;
  1. GETZIP(CITY,COUNTY,STATE,XIP,ZIPIDX) ;get the index of XIP of permanent address
  1. ; INPUT
  1. ; CITY = City sent by VecNa
  1. ; COUNTY = County sent by VecNa
  1. ; STATE = State sent by VecNa
  1. ; XIP = VistA Zip Code information in array (multiple entries could exist for a zipcode)
  1. ; OUTPUT
  1. ; ZIPIDX = The selected Index of XIP containing the ZIP CODE information
  1. ; RETURN
  1. ; 0 = City, State, County, Country have perfect match between Vecna and Vista
  1. ; 1 = City/County/state/country doesn't match, require update
  1. ; -1 = State sent by Vecna doesn't match VistA based on the ZipCode
  1. ; -2 = Can't find default city for the zipcode
  1. ;
  1. N RET S RET=-2 ; can't find default address
  1. S ZIPIDX=0
  1. ;
  1. ; find the city in the XIP array
  1. N IDX F IDX=1:1:XIP I $$UP^XLFSTR($P(XIP(IDX,"CITY"),"*"))=$$UP^XLFSTR(CITY) S ZIPIDX=IDX Q
  1. ;
  1. ; if city found, use the index of the XIP as the result
  1. I ZIPIDX D ; check other address fields
  1. . I $P(XIP(ZIPIDX,"CITY"),"*")=CITY,XIP(ZIPIDX,"STATE")=STATE,XIP(ZIPIDX,"COUNTY")=COUNTY S RET=0 Q ;perfect match
  1. . I STATE]"",$$UP^XLFSTR(XIP(ZIPIDX,"STATE"))'=$$UP^XLFSTR(STATE) S RET=-1 Q ;error out, state must match
  1. . S RET=1 ;require update
  1. ;
  1. ; if city not found, use the default address
  1. I 'ZIPIDX D
  1. . F IDX=1:1:XIP I XIP(IDX,"CITY KEY")=XIP(IDX,"PREFERRED CITY KEY") S ZIPIDX=IDX,RET=1 Q ;require update
  1. . I ZIPIDX,STATE]"",$$UP^XLFSTR(XIP(ZIPIDX,"STATE"))'=$$UP^XLFSTR(STATE) S RET=-1 Q ;error out, state must match
  1. ;
  1. Q RET
  1. ;
  1. UPDZIP(ZIPIDX,XIP,REQLST,ILST) ; Change city, county, state, country of permanent address to match VistA
  1. ; INPUT
  1. ; ZIPIDX = The selected Index of XIP containing the ZIP CODE information
  1. ; XIP = VistA Zip Code information in array (multiple entries could exist for a zipcode)
  1. ; OUTPUT
  1. ; REQLST = array to be used when validating the required address sets - will be updated based on VistA ZIP Code
  1. ; ILST = data passed in by Vecna (VPSLST array) - will be updated based on VistA ZIP Code
  1. ;
  1. S $P(REQLST(.114),U,3)=$P(XIP(ZIPIDX,"CITY"),"*")
  1. S $P(REQLST(.115),U,3)=XIP(ZIPIDX,"STATE")
  1. S $P(REQLST(.117),U,3)=XIP(ZIPIDX,"COUNTY")
  1. ;
  1. N FLD
  1. F FLD=.114,.115,.117 D
  1. . N RECNO S RECNO=$P(REQLST(FLD),U)
  1. . I 'RECNO D
  1. . . S RECNO=$O(ILST(""),-1)+1
  1. . . S $P(REQLST(FLD),U)=RECNO
  1. . S ILST(RECNO)=$P(REQLST(FLD),U,2,3)
  1. Q
  1. ;
  1. CLRPERM(REQLST,ILST) ;clear permanent address
  1. ; INPUT - all input parameters passed in by reference
  1. ; REQLST = array to be used when validating the required address sets
  1. ; OUTPUT
  1. ; ILST = data passed in by Vecna (VPSLST array) to be cleared so no update will happen
  1. ;
  1. N FLD,RECNO
  1. F FLD=.111,.112,.113,.114,.115,.117,.121,.1171,.1172,.1173,.1112 S RECNO=$P(REQLST(FLD),U) I RECNO]"" K ILST(RECNO) ; remove from input array so they are not processed for filing into patient record
  1. Q
  1. ;
  1. CLRCCS(REQLST,ILST) ;clear zipcode, city, state, county from processing
  1. ; INPUT - all input parameters passed in by reference
  1. ; REQLST = array to be used when validating the required address sets
  1. ; OUTPUT
  1. ; ILST = data passed in by Vecna (VPSLST array) to be cleared so no update will happen
  1. ;
  1. N FLD,RECNO
  1. F FLD=.1112,.114,.115,.117 S RECNO=$P(REQLST(FLD),U) I RECNO]"" K ILST(RECNO) ; remove from input array so they are not processed for filing into patient record
  1. Q
  1. ;
  1. ADDERR(REC,VRES,ER) ;Add error to the result array
  1. ; INPUT - all input parameters passed in by reference
  1. ; ER = Error Message to be returned to vecna
  1. ; REC = incremental number assigned to each subscript built in the OUTPUT array
  1. ; OUTPUT
  1. ; VRES = the array to return the results of ADDRESS validation processing. Exceptions (only) made available as RPC output for client
  1. ;
  1. N IDX S IDX=""
  1. F S IDX=$O(ER(IDX)) Q:IDX="" S REC=REC+1,VRES(REC)="^^99^"_ER(IDX)
  1. Q
  1. ;
  1. TEMPVAL(PTIEN,REQLST,ILIST,ER) ; validate temporary address
  1. ; INPUT - all input parameters except PTIEN passed in by reference
  1. ; PTIEN = DFN
  1. ; REQLST = array to be used when validating data
  1. ; ILIST = data passed in by Vecna (VPSLST array)
  1. ; OUTPUT
  1. ; ER = array of Error Message or Empty (No error)
  1. ; RETURN
  1. ; 1 = success
  1. ; 0 = failed
  1. ;
  1. K ER
  1. N TEMP S TEMP=0
  1. ; check if Vecna sent temp address
  1. N NUM F NUM=.1211,.1214,.1215,.1217,.1218,.12111,.12112,.1223 Q:TEMP I $P(REQLST(NUM),U,3)]"" S TEMP=1 ;determine if any required temp address fields are sent
  1. Q:'TEMP 1 ; temporary address fields not sent
  1. ;
  1. ; validate country fields
  1. N COUNTRY S COUNTRY=$P(REQLST(.1223),U,3)
  1. I COUNTRY="" S ER(1)=$P(REQLST(.1223),U,2)_" is needed for TEMPORARY (USA and FOREIGN) address fields. Write to Patient record not performed"
  1. Q:COUNTRY="" 0
  1. ;
  1. ; validate temporarty address
  1. N USAADDR S USAADDR=(COUNTRY="USA")!(COUNTRY="UNITED STATES")!(COUNTRY?1N.N)
  1. I USAADDR D USVAL(.REQLST,.ER) ;validate US Address
  1. I 'USAADDR D NONUSVAL(.REQLST,.ER) ; validate foreign address
  1. Q:$D(ER) 0
  1. ;
  1. ; update TEMPORARY ADDRESS ACTIVE? field to yes when all required TEMPORARY address fields (USA or FOREIGN) are submitted.
  1. N VPSFDA S VPSFDA(2,PTIEN_",",.12105)="Y"
  1. D FILE^DIE("","VPSFDA","")
  1. Q 1
  1. ;
  1. USVAL(REQLST,ER) ;validate US Address
  1. ; INPUT - all input parameters except PTIEN passed in by reference
  1. ; REQLST = array to be used when validating data
  1. ; OUTPUT
  1. ; ER = array of Error Message or Empty (No error)
  1. ;
  1. N IDX S IDX=0
  1. ;
  1. ; validate required fields
  1. N FLD
  1. F FLD=.1211,.1214,.1215,.1217,.1218,.12111,.12112 I $P(REQLST(FLD),U,3)="" D
  1. . S IDX=IDX+1
  1. . S ER(IDX)=$P(REQLST(FLD),U,2)_" is needed for TEMPORARY (USA) address fields. Write to Patient record for TEMPORARY ADDRESS fields did not get performed"
  1. Q
  1. ;
  1. NONUSVAL(REQLST,ER) ; validate foreign address
  1. ; INPUT - all input parameters except PTIEN passed in by reference
  1. ; REQLST = array to be used when validating data
  1. ; OUTPUT
  1. ; ER = array of Error Message or Empty (No error)
  1. ;
  1. N IDX S IDX=0
  1. ;
  1. ; validate required fields
  1. N FLD
  1. F FLD=.1211,.1214,.1217,.1218 I $P(REQLST(FLD),U,3)="" D
  1. . S IDX=IDX+1
  1. . S ER(IDX)=$P(REQLST(FLD),U,2)_" is needed for TEMPORARY (foreign) address fields. Write to Patient record not performed"
  1. Q
  1. ;
  1. CLRTEMP(REQLST,ILST) ;clear temporary address
  1. ; INPUT - all input parameters passed in by reference
  1. ; REQLST = array to be used when validating the required address sets
  1. ; OUTPUT
  1. ; ILST = data passed in by Vecna (VPSLST array) to be cleared so no update will happen
  1. ;
  1. N FLD,RECNO
  1. F FLD=.1211,.1212,.1213,.1214,.1215,.1217,.1218,.1219,.1221,.1222,.1223,.12111,.12112 S RECNO=$P(REQLST(FLD),U) I RECNO]"" K ILST(RECNO) ; remove from input array so they are not processed for filing into patient record
  1. Q