Changeset 1606 for fmts/trunk/p/C0XPT0.m
- Timestamp:
- Feb 19, 2013, 3:58:54 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fmts/trunk/p/C0XPT0.m
r1605 r1606 1 C0XPT0 ; VEN/SMH - Get patient data and do something about it ;2013-02- 06 3:08PM1 C0XPT0 ; VEN/SMH - Get patient data and do something about it ;2013-02-19 12:01 PM 2 2 ;;1.1;FILEMAN TRIPLE STORE;; 3 3 ; … … 30 30 I DFN<1 S $EC=",U1," ; Debug.Assert that patient is added. 31 31 ; D VITALS(G,DFN) 32 D PROBLEMS (G,DFN)33 D ADR (G,DFN) ; Adverse Drug Reactions32 D PROBLEMS^C0XPT1(G,DFN) ; Extract Problems and File 33 D ADR^C0XPT2(G,DFN) ; Extract Allergies and File 34 34 ; 35 35 QUIT … … 182 182 QUIT 183 183 ; 184 PROBLEMS(G,DFN) ; Private EP; Process Problems for a patient graph185 ; Delete existing problems if they are present186 ; PS: This is a risky operation if somebody points to the original data.187 ; PS2: Another idea is just to quit here if Patient has problems already.188 I $D(^AUPNPROB("AC",DFN)) DO ; Patient already has problems.189 . N DIK S DIK="^AUPNPROB(" ; Global to kill190 . N DA F DA=0:0 S DA=$O(^AUPNPROB("AC",DFN,DA)) Q:'DA D ^DIK ; Kill each entry191 ;192 ; Process incoming problems193 N RETURN ; Local return variable. I don't expect a patient to have more than 50 problems.194 D ONETYPE^C0XGET3($NA(RETURN),G,"sp:Problem") ; Get all problems for patient195 N S F S=0:0 S S=$O(RETURN(S)) Q:'S D ; For each problem196 . N PROBNM S PROBNM=$$GSPO1^C0XGET3(G,RETURN(S),"sp:problemName") ; Snomed-CT coding info197 . N CODEURL S CODEURL=$$GSPO1^C0XGET3(G,PROBNM,"sp:code") ; Snomed-CT Code URL198 . N TEXT S TEXT=$$GSPO1^C0XGET3(G,PROBNM,"dcterms:title") ; Snomed-CT Code description199 . ;200 . N CODE ; Actual Snomed code rather than URL201 . S CODE=$P(CODEURL,"/",$L(CODEURL,"/")) ; Get last / piece202 . N EXPIEN ; IEN in the EXPESSION file203 . N LEXS ; Return from Lex call204 . D EN^LEXCODE(CODE) ; Lex API205 . S EXPIEN=$P(LEXS("SCT",1),U) ; First match on Snomed CT. Crash if isn't present.206 . ;207 . N STARTDT S STARTDT=$$GSPO1^C0XGET3(G,RETURN(S),"sp:startDate") ; Start Date208 . N X,Y,%DT S X=STARTDT D ^%DT S STARTDT=Y ; Convert STARTDT to internal format209 . D PROBADD(DFN,CODE,TEXT,EXPIEN,STARTDT) ; Add problem to VISTA.210 QUIT211 ;212 184 NP() ; New Person Entry 213 185 N C0XFDA,C0XIEN,C0XERR … … 220 192 Q C0XIEN(1) ;Provider IEN 221 193 ; 222 PROBADD(DFN,CODE,TEXT,EXPIEN,STARTDT) ; Add a problem to a patient's record.223 ; Input224 ; DFN - you know what that is225 ; CODE - SNOMED code; not used alas; for the future.226 ; TEXT - SNOMED Text227 ; EXPIEN - IEN of Snomed CT Expression in the Expressions File (757.01)228 ; STARTDT - Internal Date of when the problem was first noted.229 ;230 ; Output:231 ; NONE232 ; Crash expected if code fails to add a problem.233 ;234 ;235 ;236 N GMPDFN S GMPDFN=DFN ; patient dfn237 ;238 ; Add unknown provider to database239 N GMPPROV S GMPPROV=$$NP^C0XPT0() ;Smart Provider IEN240 ;241 N GMPVAMC S GMPVAMC=$$KSP^XUPARAM("INST") ; Problem Institution. Ideally, the external one. But we are taking a shortcut here.242 ;243 N GMPFLD ; Input array244 S GMPFLD(".01")="" ;Code IEN - API will assign 799.9.245 ; .02 field (Patient IEN) not used. Pass variable GMPDFN instead.246 S GMPFLD(".03")=DT ;Date Last Modified247 S GMPFLD(".05")="^"_TEXT ;Expression text248 S GMPFLD(".08")=DT ; today's date (entry?)249 S GMPFLD(".12")="A" ;Active/Inactive250 S GMPFLD(".13")=STARTDT ;Onset date251 S GMPFLD("1.01")=EXPIEN_U_TEXT ;^LEX(757.01 ien,descip252 S GMPFLD("1.03")=GMPPROV ;Entered by253 S GMPFLD("1.04")=GMPPROV ;Recording provider254 S GMPFLD("1.05")=GMPPROV ;Responsible provider255 S GMPFLD("1.06")="" ; SERVICE FILE - LEAVE BLANK(#49)256 S GMPFLD("1.07")="" ; Date resolved257 S GMPFLD("1.08")="" ; Clinic (#44)258 S GMPFLD("1.09")=DT ;entry date259 S GMPFLD("1.1")=0 ;Service Connected260 S GMPFLD("1.11")=0 ;Agent Orange exposure261 S GMPFLD("1.12")=0 ;Ionizing radiation exposure262 S GMPFLD("1.13")=0 ;Persian Gulf exposure263 S GMPFLD("1.14")="C" ;Accute/Chronic (A,C)264 S GMPFLD("1.15")="" ;Head/neck cancer265 S GMPFLD("1.16")="" ;Military sexual trauma266 S GMPFLD("10",0)=0 ; Note. No note.267 ;268 ;269 N DA ; Return variable270 D NEW^GMPLSAVE ; API call271 I '$D(DA) S $EC=",U1," ; Fail here if API fails.272 QUIT273 ;274 ;275 ADR(G,DFN) ; Private Proc; Extract Allergies and ADRs from Graph and add to Patient's Record276 ; Input: G, Patient Graph, DFN, you should know that that is; Both by value.277 ;278 ; Try No known allergies first.279 N NKA S NKA=$$ONETYPE1^C0XGET3(G,"sp:AllergyExclusion") ; Get NKA node280 ;281 ; Add allergies to record.282 ; We don't really care about the return value. If patient already has283 ; allergies, we just keep them.284 I $L(NKA) N % S %=$$NKA^C0XPT0(DFN) QUIT ; If it exists, let's try to file it into VISTA285 ;286 ; If we are here, it means that the patient has allergies. Fun!287 ; Process incoming allergies288 N RETURN ; Local return variable. I don't expect a patient to have more than 50 allergies.289 D ONETYPE^C0XGET3($NA(RETURN),G,"sp:Allergy") ; Get all allergies for patient290 ;291 N S F S=0:0 S S=$O(RETURN(S)) Q:'S D ; For each allergy292 . ; Get the SNOMED code for the category293 . N ALLERGYTYPE294 . N SNOCAT S SNOCAT=$$GSPO1^C0XGET3(G,RETURN(S),"sp:category.sp:code"),SNOCAT=$P(SNOCAT,"/",$L(SNOCAT,"/"))295 . I SNOCAT=414285001 S ALLERGYTYPE="F" ; Food296 . E I SNOCAT=416098002 S ALLERGYTYPE="D" ; Drug297 . I '$D(ALLERGYTYPE) S $EC=",U1," ; Crash if neither of these is true.298 . ;299 . N ALLERGEN,ALLERGENI ; Allergen, Internal Allergen300 . I ALLERGYTYPE="F" D ; Food301 . . S ALLERGEN=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:otherAllergen.dcterms:title")) ; uppercase the allergen302 . . I ALLERGEN="PEANUT" S ALLERGEN="PEANUTS" ; TODO: temporary fix303 . . S ALLERGENI=$$GMRA^C0XPT0(ALLERGEN) ; Get internal representation for GMRA call304 . ;305 . ; Otherwise, it's a drug. But we need to find out if it's a class,306 . ; ingredient, canonical drug, etc. Unfortunately, Smart examples don't307 . ; show such variety. The only one specified is a drug class.308 . ; Therefore309 . ; TODO: Handle other drug items besides drug class310 . ;311 . E D ; Drug312 . . N DC S DC=$$GSPO1^C0XGET3(G,RETURN(S),"sp:drugClassAllergen.sp:code") ; drug class313 . . I '$L(DC) QUIT ; edit this line out when handling other items314 . . S ALLERGEN=$P(DC,"/",$L(DC,"/")) ; Get last piece315 . . ; TODO: Resolve drug class properly. Need all of RxNorm for that.316 . . N STR S STR=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:drugClassAllergen.dcterms:title"))317 . . I ALLERGEN="N0000175503" S ALLERGENI=STR_U_"23;PS(50.605," ; hard codeded for sulfonamides318 . . ;319 . ; DEBUG.ASSERT THAT allergen Internal isn't empty320 . I '$L(ALLERGENI) S $EC=",U1,"321 . ;322 . ; Get Severity (Mild or Severe) - We get free text rather than SNOMED323 . N SEVERITY S SEVERITY=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:severity.dcterms:title"))324 . I '$L(SEVERITY) S $EC=",U1,"325 . ;326 . ; Get Reaction - We get free text rather than SNOMED327 . N REACTION S REACTION=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:allergicReaction.dcterms:title"))328 . I '$L(REACTION) S $EC=",U1,"329 . ;330 . ; Now that we have determined the allergy, add it331 . D FILEADR^C0XPT0(DFN,ALLERGENI,REACTION,SEVERITY,ALLERGYTYPE) ; Internal API332 QUIT333 ;334 NKA(DFN) ; Public $$; Add no known allergies to patient record335 N ORDFN S ORDFN=DFN ; CPRS API requires this one336 N ORY ; Return value: 0 - Everything is okay; -1^msg: Patient already has allergies337 D NKA^GMRAGUI1 ; API338 QUIT $G(ORY) ; Not always returned339 ;340 GMRA(NAME) ; $$ Private - Retrieve GMRAGNT for food allergy from 120.82341 ; Input: Brand Name, By Value342 ; Output: Entry Name^IEN;File Root for IEN343 N C0PIEN S C0PIEN=$$FIND1^DIC(120.82,"","O",NAME,"B")344 Q:C0PIEN $$GET1^DIQ(120.82,C0PIEN,.01)_"^"_C0PIEN_";GMRD(120.82,"345 QUIT "" ; no match otherwise346 ;347 TYPE(GMRAGNT) ; $$ Private - Get allergy Type (Drug, food, or other)348 ; Input: Allergen, formatted as Allergen^IEN;File Root349 ; Output: Type (internal)^Type (external) e.g. D^Drug350 N C0PIEN S C0PIEN=+$P(GMRAGNT,U,2)351 I GMRAGNT["GMRD(120.82," Q $$GET1^DIQ(120.82,C0PIEN,"ALLERGY TYPE","I")_U_$$GET1^DIQ(120.82,C0PIEN,"ALLERGY TYPE","E")352 Q "D^Drug" ; otherwise, it's a drug353 ;354 FILEADR(DFN,AGENT,REACTION,SEVERITY,TYPE) ; Private Proc - File Drug Reaction355 N C0XRXN356 S C0XRXN("GMRAGNT")=AGENT ; Agent^Agent in variable pointer format357 S C0XRXN("GMRATYPE")=TYPE ; F(ood), D(rug), or O(ther) or combination.358 S C0XRXN("GMRANATR")="U^Unknown" ; Allergic, Pharmacologic, or Unknown359 S C0XRXN("GMRAORIG")=$$NP^C0XPT0 ; New Person generated for SMART360 ; S C0XRXN("GMRACHT",0)=1 ; Mark Chart as allergy document - commented out b/c depends on Paper Docs361 ; S C0XRXN("GMRACHT",1)=$$NOW^XLFDT ; Chart documentation date - commented out depends on Paper Docs362 S C0XRXN("GMRAORDT")=$$NOW^XLFDT363 S C0XRXN("GMRAOBHX")="h^HISTORICAL"364 S C0XRXN("GMRACMTS",0)=1 ; Comments365 S C0XRXN("GMRACMTS",1)=SEVERITY ; Store severity in the comments366 N ORY ; Return value 0: success; -1: failure; discarded.367 D UPDATE^GMRAGUI1("",DFN,$NA(C0XRXN))368 QUIT
Note:
See TracChangeset
for help on using the changeset viewer.