Changeset 1604 for fmts/trunk/p/C0XPT0.m


Ignore:
Timestamp:
Feb 4, 2013, 6:26:26 PM (12 years ago)
Author:
Sam Habiel
Message:

Further work on importing patients. Now implementing allergies. Implemented relational navigation for predicate in C0XGET3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fmts/trunk/p/C0XPT0.m

    r1603 r1604  
    1 C0XPT0 ; VEN/SMH - Get patient data and do something about it ;2013-01-28  4:24 PM
     1C0XPT0 ; VEN/SMH - Get patient data and do something about it ;2013-02-04  3:41 PM
    22 ;;1.1;FILEMAN TRIPLE STORE;;
    33 ;
     
    2727 NEW RETURN
    2828 D ADDPT(.RETURN,.PARAM)
    29  ZWRITE RETURN
    3029 N DFN S DFN=$P(RETURN(1),U,2)
    31  D VITALS(G,DFN)
     30 I DFN<1 S $EC=",U1," ; Debug.Assert that patient is added.
     31 ; D VITALS(G,DFN)
    3232 D PROBLEMS(G,DFN)
     33 D ADR(G,DFN) ; Adverse Drug Reactions
    3334 ;
    3435 QUIT
     
    177178 N S F S=0:0 S S=$O(^TMP($J,"VS",S)) Q:S=""  D
    178179 . N ENC S ENC=$$GSPO1^C0XGET3(G,^TMP($J,"VS",S),"sp:encounter")
    179  . ZWRITE ENC
    180180 ;
    181181 ; D EN1^GMVDCSAV(.RESULT,DATA)
     
    267267        I '$D(DA) S $EC=",U1," ; Fail here if API fails.
    268268        QUIT
     269        ;
     270        ;
     271ADR(G,DFN) ;  Private Proc; Extract Allergies and ADRs from Graph and add to Patient's Record
     272        ; Input: G, Patient Graph, DFN, you should know that that is; Both by value.
     273        ;
     274        ; Try No known allergies first.
     275        N NKA S NKA=$$ONETYPE1^C0XGET3(G,"sp:AllergyExclusion") ; Get NKA node
     276        ;
     277        ; Add allergies to record.
     278        ; We don't really care about the return value. If patient already has
     279        ; allergies, we just keep them.
     280        I $L(NKA) N % S %=$$NKA^C0XPT0(DFN) QUIT  ; If it exists, let's try to file it into VISTA
     281        ;
     282        ; If we are here, it means that the patient has allergies. Fun!
     283        ; Process incoming allergies
     284        N RETURN ; Local return variable. I don't expect a patient to have more than 50 allergies.
     285        D ONETYPE^C0XGET3($NA(RETURN),G,"sp:Allergy") ; Get all allergies for patient
     286        ;
     287        N S F S=0:0 S S=$O(RETURN(S)) Q:'S  D  ; For each allergy
     288        . ; Get the SNOMED code for the category
     289        . N ALLERGYTYPE
     290        . N SNOCAT S SNOCAT=$$GSPO1^C0XGET3(G,RETURN(S),"sp:category.sp:code"),SNOCAT=$P(SNOCAT,"/",$L(SNOCAT,"/"))
     291        . I SNOCAT=414285001 S ALLERGYTYPE="F" ; Food
     292        . E  I SNOCAT=416098002 S ALLERGYTYPE="D" ; Drug
     293        . I '$D(ALLERGYTYPE) S $EC=",U1," ; Crash if neither of these is true.
     294        . ;
     295        . N ALLERGEN,ALLERGENI ; Allergen, Internal Allergen
     296        . I ALLERGYTYPE="F" D  ; Food
     297        . . S ALLERGEN=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:otherAllergen.dcterms:title")) ; uppercase the allergen
     298        . . I ALLERGEN="PEANUT" S ALLERGEN="PEANUTS" ; temporary fix
     299        . . S ALLERGENI=$$GMRA^C0XPT0(ALLERGEN) ; Get internal representation for GMRA call
     300        . ;
     301        . ; Otherwise, it's a drug. But we need to find out if it's a class,
     302        . ; ingredient, canonical drug, etc. Unfortunately, Smart examples don't
     303        . ; show such variety. The only one specified is a drug class.
     304        . ; Therefore
     305        . ; TODO: Handle other drug items besides drug class
     306        . ;
     307        . E  D  ; Drug
     308        . . N DC S DC=$$GSPO1^C0XGET3(G,RETURN(S),"sp:drugClassAllergen.sp:code") ; drug class
     309        . . I '$L(DC) QUIT  ; edit this line out when handling other items
     310        . . S ALLERGEN=$P(DC,"/",$L(DC,"/")) ; Get last piece
     311        . . ; TODO: Resolve drug class properly. Need all of RxNorm for that.
     312        . . I ALLERGEN="N0000175503"
     313        QUIT
     314        ;
     315NKA(DFN) ; Public $$; Add no known allergies to patient record
     316        N ORDFN S ORDFN=DFN ; CPRS API requires this one
     317        N ORY ; Return value: 0 - Everything is okay; -1^msg: Patient already has allergies
     318        D NKA^GMRAGUI1 ; API
     319        QUIT $G(ORY) ; Not always returned
     320        ;
     321GMRA(NAME)      ; $$ Private - Retrieve GMRAGNT for food allergy from 120.82
     322        ; Input: Brand Name, By Value
     323        ; Output: Entry Name^IEN;File Root for IEN
     324        N C0PIEN S C0PIEN=$$FIND1^DIC(120.82,"","O",NAME,"B")
     325        Q:C0PIEN $$GET1^DIQ(120.82,C0PIEN,.01)_"^"_C0PIEN_";GMRD(120.82,"
     326        QUIT "" ; no match otherwise
     327        ;
     328TYPE(GMRAGNT)   ; $$ Private - Get allergy Type (Drug, food, or other)
     329        ; Input: Allergen, formatted as Allergen^IEN;File Root
     330        ; Output: Type (internal)^Type (external) e.g. D^Drug
     331        N C0PIEN S C0PIEN=+$P(GMRAGNT,U,2)
     332        I GMRAGNT["GMRD(120.82," Q $$GET1^DIQ(120.82,C0PIEN,"ALLERGY TYPE","I")_U_$$GET1^DIQ(120.82,C0PIEN,"ALLERGY TYPE","E")
     333        Q "D^Drug" ; otherwise, it's a drug
Note: See TracChangeset for help on using the changeset viewer.