public static DiagnosisProblem GetDiagnosisProblemFromDiagnosisProblemAct(this POCD_MT000040Act act, Client client)
        {
            //TODO: Can there be many observations under an act?  The schema definition says there can, but I can't find any examples?
            var problemObservation = act?.entryRelationship?.FirstOrDefault(r =>
                                                                            r.Item is POCD_MT000040Observation)
                                     ?.Item as POCD_MT000040Observation;

            var invertedChildObservations = problemObservation?.entryRelationship?
                                            .Where(r => r.Item is POCD_MT000040Observation && r.inversionInd &&
                                                   r.typeCode == x_ActRelationshipEntryRelationship.SUBJ)
                                            .Select(r => r.Item as POCD_MT000040Observation);

            var severityObservation = invertedChildObservations?.FirstOrDefault(ico => ico?.code?.code == "SEV");

            var diagnosisProblem = new DiagnosisProblem(client)
            {
                ProblemResult = problemObservation?.value?.GetResultValue(),
                DateRange     = problemObservation?.effectiveTime?.GetDateRange(), //use the date on the observation (which is the date of biological onset),
                //NOT the date on the act (which is the date the concern was authored in the patient's chart)
                //TODO: but does that ^ make sense if there are multiple observations under the same concern act??
                Status = act?.statusCode?.GetCode(),                    //use the status code on the act (which is the overall concern status),
                                                                        //NOT the statusCode on the observation
                TargetSite = problemObservation?.targetSiteCode?.FirstOrDefault()?.qualifier?.FirstOrDefault()?.value?.GetCode(),
                Severity   = severityObservation?.GetFirstNonNullValueCode(),
                NotPresent = problemObservation != null && problemObservation.negationInd
            };

            return(diagnosisProblem);
        }
        public static AllergyAdverseEvent GetAllergyAdverseEventFromAct(this POCD_MT000040Act act, Client client)
        {
            var observation = act?.entryRelationship?.FirstOrDefault(r =>
                                                                     r.Item is POCD_MT000040Observation)
                              ?.Item as POCD_MT000040Observation;

            var playingEntity = observation?.participant?.FirstOrDefault(p =>
                                                                         p.typeCode == "CSM" && p.participantRole?.Item is POCD_MT000040PlayingEntity)
                                ?.participantRole?.Item as POCD_MT000040PlayingEntity;

            var allergyAdverseEvent = new AllergyAdverseEvent(client)
            {
                Cause       = playingEntity?.code?.GetCode(),
                AllergyType = observation?.GetFirstNonNullValueCode(),
                DateRange   = act?.effectiveTime?.GetDateRange(),
                NotPresent  = observation != null && observation.negationInd
            };

            return(allergyAdverseEvent);
        }
Exemple #3
0
        public POCD_MT000040Entry ToPocdEntry()
        {
            // *** Create allergy section ***
            POCD_MT000040Entry entry = new POCD_MT000040Entry();

            // *** Required Allergies and Intolerances Concern element ***
            //entry.templateId = new II[] {
            //    new II { root = "1.3.6.1.4.1.19376.1.5.3.1.4.5.3" },
            //    new II { root = "2.16.840.1.113883.10.20.1.27" },
            //    new II { root = "1.3.6.1.4.1.19376.1.5.3.1.4.5.1" },
            //};

            POCD_MT000040Act act = new POCD_MT000040Act();

            act.id = new II[] { new II {
                                    root = Guid.NewGuid().ToString()
                                } };

            act.classCode = x_ActClassDocumentEntryAct.ACT;
            act.moodCode  = x_DocumentActMood.EVN;

            act.templateId = new II[] {
                new II {
                    root = "2.16.840.1.113883.10.20.1.27"
                },
                new II {
                    root = "1.3.6.1.4.1.19376.1.5.3.1.4.5.1"
                },
                new II {
                    root = "1.3.6.1.4.1.19376.1.5.3.1.4.5.3"
                }
            };

            act.code = new CD()
            {
                nullFlavor = "NA"
            };

            act.statusCode = GetStatusCode();

            List <POCD_MT000040EntryRelationship> entryRelationships = new List <POCD_MT000040EntryRelationship>();


            POCD_MT000040EntryRelationship entryRel = new POCD_MT000040EntryRelationship();

            entryRel.typeCode = x_ActRelationshipEntryRelationship.SUBJ;

            entryRel.inversionInd          = false;
            entryRel.inversionIndSpecified = true;

            POCD_MT000040Observation obs = new POCD_MT000040Observation();

            obs.id = new II[] { new II {
                                    root = Guid.NewGuid().ToString()
                                } };

            obs.classCode  = "OBS";
            obs.moodCode   = x_ActMoodDocumentObservation.EVN;
            obs.templateId = new II[] {
                new II()
                {
                    root = "1.3.6.1.4.1.19376.1.5.3.1.4.5"
                },
                new II()
                {
                    root = "1.3.6.1.4.1.19376.1.5.3.1.4.6"
                },
                new II()
                {
                    root = "2.16.840.1.113883.10.20.1.28"
                }
            };

            obs.negationInd          = this.NegationIndicator;
            obs.negationIndSpecified = true;

            string intoleranceTypeCode = GetIntoleranceType();

            obs.code = new CD()
            {
                code           = intoleranceTypeCode,
                codeSystem     = "2.16.840.1.113883.5.4",
                codeSystemName = "ObservationIntoleranceType"
            };

            obs.text = new ED()
            {
                Text = new string[] { this.Id }
            };

            if (this.Value == null)
            {
                obs.value = new ANY[] { new CD()
                                        {
                                            originalText = new ED()
                                            {
                                                Text = new string[] { this.AllergyText }
                                            }
                                        } }
            }
            ;
            else
            {
                obs.value = new ANY[] { this.Value.ToCD() }
            };

            obs.participant = new POCD_MT000040Participant2[] {
                new POCD_MT000040Participant2()
                {
                    typeCode        = "CSM",
                    participantRole = new POCD_MT000040ParticipantRole()
                    {
                        classCode = "MANU",
                        Item      = new POCD_MT000040PlayingEntity()
                        {
                            classCode = "MMAT",
                            code      = new CE()
                            {
                                code           = this.Id,
                                codeSystemName = CdaCode.VhaSystemName,
                                codeSystem     = CdaCode.VhaSystemId,
                                originalText   = new ED()
                                {
                                    reference = new TEL()
                                    {
                                        value = this.Substance
                                    }
                                }
                            }
                        }
                    }
                }
            };

            if (this.EffectiveTime != null)
            {
                act.effectiveTime = this.EffectiveTime.ToIvlTs();
                obs.effectiveTime = act.effectiveTime;
            }

            obs.statusCode = new CS()
            {
                code = "completed"
            };

            // TODO: Optional entry relationships for reactions
            // TODO: Optional entry relationships for severity

            entryRel.Item = obs;

            entryRelationships.Add(entryRel);

            // *** Add entry relationships ***
            act.entryRelationship = entryRelationships.ToArray();

            // ** Add act ***
            entry.Item = act;

            return(entry);
        }
Exemple #4
0
        public List <POCD_MT000040Entry> ToPocdEntryList()
        {
            List <POCD_MT000040Entry> entryList = new List <POCD_MT000040Entry>();

            if (this.Observations != null)
            {
                foreach (CdaCodeObservation cdaObservation in this.Observations)
                {
                    // *** Create the entry ***
                    POCD_MT000040Entry tempEntry = new POCD_MT000040Entry();

                    // *** Create an act ***
                    POCD_MT000040Act act = new POCD_MT000040Act();

                    act.id = new II[] { new II {
                                            root = Guid.NewGuid().ToString()
                                        } };

                    act.classCode = x_ActClassDocumentEntryAct.ACT;
                    act.moodCode  = x_DocumentActMood.EVN;

                    // *** Add template ids for this act ***
                    CdaTemplateIdList templateIdList =
                        new CdaTemplateIdList(
                            "1.3.6.1.4.1.19376.1.5.3.1.4.5.2",
                            "1.3.6.1.4.1.19376.1.5.3.1.4.5.1",
                            "2.16.840.1.113883.10.20.1.27");

                    act.templateId = templateIdList.ToPocd();

                    // *** No code here ***
                    act.code = new CD()
                    {
                        nullFlavor = "NA"
                    };

                    // *** The concern is active, even though the problem itself may be resolved or inactive ***
                    act.statusCode = new CS()
                    {
                        code = "active"
                    };

                    // *** This concern uses the observation date/time ***
                    //CdaEffectiveTime effTime = new CdaEffectiveTime() { Low = cdaObservation.EffectiveTime };
                    //act.effectiveTime = effTime.ToIvlTs();
                    act.effectiveTime = cdaObservation.EffectiveTime.ToIvlTs();

                    // *** Create entry relationship ***
                    List <POCD_MT000040EntryRelationship> entryRelationships = new List <POCD_MT000040EntryRelationship>();

                    POCD_MT000040EntryRelationship tempEntryRelationship = new POCD_MT000040EntryRelationship();

                    tempEntryRelationship.typeCode              = x_ActRelationshipEntryRelationship.SUBJ;
                    tempEntryRelationship.inversionInd          = false;
                    tempEntryRelationship.inversionIndSpecified = true;

                    // *** Create pocd observation ***
                    POCD_MT000040Observation observation = cdaObservation.ToPocd();

                    // *** Add the observation to the entry relationship ***
                    tempEntryRelationship.Item = observation;

                    // *** Add the entry relationship to the list ***
                    entryRelationships.Add(tempEntryRelationship);

                    // *** Add entry relationships to the act ***
                    act.entryRelationship = entryRelationships.ToArray();

                    // *** Add act to entry ***
                    tempEntry.Item = act;

                    // *** Add entry to list ***
                    entryList.Add(tempEntry);
                }
            }

            return(entryList);
        }