C0PALGY3	  ; ERX/GPL - eRx Allergy utilities ; 5/8/12 9:11pm
	;;1.0;C0P;;Apr 25, 2012;Build 103
	;Copyright 2009 George Lilly.  Licensed under the terms of the GNU
	;General Public License See attached copy of the License.
	;
	;This program is free software; you can redistribute it and/or modify
	;it under the terms of the GNU General Public License as published by
	;the Free Software Foundation; either version 2 of the License, or
	;(at your option) any later version.
	;
	;This program is distributed in the hope that it will be useful,
	;but WITHOUT ANY WARRANTY; without even the implied warranty of
	;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	;GNU General Public License for more details.
	;
	;You should have received a copy of the GNU General Public License along
	;with this program; if not, write to the Free Software Foundation, Inc.,
	;51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
	;
	Q
	;
ADDALGY(RTNXML,ZDUZ,ZDFN,ZFILE)	; ADDS PATIENT ALLERGIES TO NCSCRIPT
	; CLICK-THROUGH HTLM FILE FOR
	; MAPPING ALLERGIES , XML IS RETURNED IN RTN,PASSED BY NAME
	; IF ZFILE IS 1, THE FILE IS WRITTEN TO AN XML FILE
	;D EN^C0PMAIN("G1","G2",ZDUZ,ZDFN) ; GET THE NCSCRIPT
	;S @RTNURL=G2
	;D GETXML^C0PWS1("G3",14) ; GET BEGINNING OF FILE
	;D GETXML^C0PWS1("G4",15) ; GET END OF FILE
	N G1,G2,G3,G4,G5,G6,GBLD
	D GETALGY("G6",ZDFN) ;GET ALLERGIES
	;D QUEUE^C0CXPATH("GBLD","G3",1,$O(G3(""),-1)) ;BUILD LIST BEGINNING OF FILE
	;;D QUEUE^C0CXPATH("GBLD","G1",1,$O(G1(""),-1)) ; NCSCRIPT
	M G1=@RTNXML
	S GEND=$O(G1(""),-1)-2
	D QUEUE^C0CXPATH("GBLD","G1",1,GEND) ; NCSCRIPT.. UP TO </Patient>
	D QUEUE^C0CXPATH("GBLD","G6",1,$O(G6(""),-1)) ; ADD THE ALLERGIES
	D QUEUE^C0CXPATH("GBLD","G1",GEND+1,$O(G1(""),-1)) ;END OF NCSCRIPT
	D QUEUE^C0CXPATH("GBLD","G4",1,$O(G4(""),-1)) ; END OF FILE
	D BUILD^C0CXPATH("GBLD","G5") ; BUILD THE CONTENTS FROM THE BUILD LIST
	K @RTNXML
	M @RTNXML=G5 ;
	I $G(ZFILE)=1 W $$OUTPUT^C0CXPATH("G5(1)","ALLERGY-"_ZDFN_".html","/home/dev/CCR/")
	Q
	;
GENTEST(RTNXML,RTNURL,ZDUZ,ZDFN,ZFILE)	; GENERATE A TEST 
	; CLICK-THROUGH HTLM FILE FOR
	; MAPPING ALLERGIES , XML IS RETURNED IN RTN,PASSED BY NAME
	; IF ZFILE IS 1, THE FILE IS WRITTEN TO HOST FILE
	D EN^C0PMAIN("G1","G2",ZDUZ,ZDFN) ; GET THE NCSCRIPT
	;S @RTNURL=G2
	D GETXML^C0PWS1("G3",14) ; GET BEGINNING OF FILE
	D GETXML^C0PWS1("G4",15) ; GET END OF FILE
	D GETALGY("G6",ZDFN) ;GET ALLERGIES
	D QUEUE^C0CXPATH("GBLD","G3",1,$O(G3(""),-1)) ;BUILD LIST BEGINNING OF FILE
	;D QUEUE^C0CXPATH("GBLD","G1",1,$O(G1(""),-1)) ; NCSCRIPT
	D QUEUE^C0CXPATH("GBLD","G1",1,76) ; NCSCRIPT.. UP TO </Patient>
	D QUEUE^C0CXPATH("GBLD","G6",1,$O(G6(""),-1)) ; ADD THE ALLERGIES
	D QUEUE^C0CXPATH("GBLD","G1",77,$O(G1(""),-1)) ;END OF NCSCRIPT
	D QUEUE^C0CXPATH("GBLD","G4",1,$O(G4(""),-1)) ; END OF FILE
	D BUILD^C0CXPATH("GBLD","G5") ; BUILD THE CONTENTS FROM THE BUILD LIST
	M @RTNXML=G5 ;
	I $G(ZFILE)=1 W $$OUTPUT^C0CXPATH("G5(1)","ALLERGY-"_ZDFN_".html","/home/dev/CCR/")
	Q
	;
GETALGY(OUTARY,ZDFN)	;
	;
	N ZG,ZG2,ZB,ZN
	S DEBUG=0
	D GETTEMP^C0PWS1("ZG",16) ;GET THE ALLERGY TEMPLATE
	D EXTRACT^C0CALERT("ZG",ZDFN,"ZG2","ALGYCBK^C0PALGY3(ALTVMAP,A1)")
	S ZN=$O(ZG2(""),-1) ;NUMBER OF LINES IN OUTPUT
	D QUEUE^C0CXPATH("ZB","ZG2",2,ZN-1)
	D BUILD^C0CXPATH("ZB",OUTARY)
	Q
	; 
ALGYCBK(ZRTN,ZIN)	;CALLBACK ROUTINE FOR C0CALERT USED TO SET FDB CONCEPT
	; ID IF FOUND. ZIN IS PASSED BY NAME AND IS ONE ALLERGY
	N ZI,ZJ
	S ZI=$P(ZIN,"^",9) ;THIS IS THE VARIABLE POINTER OF THE GMR ALLERGY
	I ZI="" Q
	S ZJ=$O(^C0PALGY("VA",ZI,""))
	I ZJ'="" D  ; CONCEPT WAS FOUND
	. S ZK=$$GET1^DIQ(113059005,ZJ_",",.05) ;COMPOSIT ALLERGY ID (NOT CONCEPT)
	. S @ZRTN@("ALERTFDBCONCEPTID")=ZK
	. S @ZRTN@("ALERTFDB")="FDB"
	E  D  ;
	. S @ZRTN@("ALERTFDBCONCEPTID")=""
	. S @ZRTN@("ALERTFDB")=""
	Q
	;
UPDIE	  ; INTERNAL ROUTINE TO CALL UPDATE^DIE AND CHECK FOR ERRORS
	K ZERR
	D CLEAN^DILF
	D UPDATE^DIE("","C0PFDA","","ZERR")
	I $D(ZERR) D ERROR^C0PMAIN(",U113059008,",$ST($ST,"PLACE"),"ERX-UPDIE-FAIL","Fileman Data Update Failure") QUIT
	K C0PFDA
	Q
