public static CdaSimpleObservation CreateObservation(POCD_MT000040Observation pocdObservation)
        {
            CdaSimpleObservation returnVal = null;

            if (pocdObservation.value != null)
            {
                if (pocdObservation.value.Length > 0)
                {
                    ANY first = pocdObservation.value[0];

                    if (first is INT)
                    {
                        returnVal = new CdaIntObservation(pocdObservation);
                    }
                    else if (first is TS)
                    {
                        returnVal = new CdaDateObservation(pocdObservation);
                    }
                    else if (first is PQ)
                    {
                        returnVal = new CdaPqObservation(pocdObservation);
                    }
                    else if (first is ST)
                    {
                        returnVal = new CdaTextObservation(pocdObservation);
                    }
                }
            }

            return(returnVal);
        }
Пример #2
0
 /// MDHT operation: TBD
 public bool validateTargetOfEntryRelationship(POCD_MT000040Observation statusObservation)
 {
     if (getContainer(statusObservation) is POCD_MT000040EntryRelationship)
     {
         POCD_MT000040EntryRelationship entryRelationship = (POCD_MT000040EntryRelationship)getContainer(statusObservation);
         return(x_ActRelationshipEntryRelationship.REFR == entryRelationship.typeCode);
     }
     return(false);
 }
Пример #3
0
        public static CodeWithDateRange GetValueCodeWithDateRange(this POCD_MT000040Observation obs)
        {
            if (obs == null)
            {
                return(null);
            }

            var code = obs.GetFirstNonNullValueCode();

            var dateRange = obs.effectiveTime?.GetDateRange();

            return(new CodeWithDateRange(code, dateRange));
        }
Пример #4
0
 public CdaDateObservation(POCD_MT000040Observation pocdObs) : base(pocdObs)
 {
     if (pocdObs.value != null)
     {
         if (pocdObs.value.Length > 0)
         {
             if (pocdObs.value[0] is TS)
             {
                 TS       temp = (TS)pocdObs.value[0];
                 DateTime val  = VistaDates.ParseDateString(temp.value, RawCdaDocument.CdaDateFormat);
                 if (val != DateTime.MinValue)
                 {
                     this.Value = val;
                 }
             }
         }
     }
 }
 public CdaIntObservation(POCD_MT000040Observation pocdObs) : base(pocdObs)
 {
     if (pocdObs.value != null)
     {
         if (pocdObs.value.Length > 0)
         {
             if (pocdObs.value[0] is INT)
             {
                 INT temp = (INT)pocdObs.value[0];
                 int val  = -1;
                 if (int.TryParse(temp.value, out val))
                 {
                     this.Value = val;
                 }
             }
         }
     }
 }
        public CdaSimpleObservation(POCD_MT000040Observation pocdObs)
        {
            // *** Template Ids ***
            this.TemplateIds = new CdaTemplateIdList(pocdObs.templateId);

            // *** Observation Id ***
            if (pocdObs.id != null)
            {
                if (pocdObs.id.Length > 0)
                {
                    this.Id = pocdObs.id[0].root;
                }
            }

            // *** Code ***
            this.Code = CdaCode.FromPocd(pocdObs.code);

            // *** Negation ***
            if (pocdObs.negationIndSpecified)
            {
                this.NegationIndicator = pocdObs.negationInd;
            }

            // *** Status ***
            if (pocdObs.statusCode != null)
            {
                Hl7ProblemActStatus stat = Hl7ProblemActStatus.unknown;

                if (Enum.TryParse <Hl7ProblemActStatus>(pocdObs.statusCode.code, out stat))
                {
                    this.Status = stat;
                }
            }

            // *** Effective Time ***
            if (pocdObs.effectiveTime != null)
            {
                this.EffectiveTime = CdaEffectiveTime.FromPocd(pocdObs.effectiveTime);
            }

            this.Mood = x_ActMoodDocumentObservation.EVN;
        }
 public CdaTextObservation(POCD_MT000040Observation pocdObs) : base(pocdObs)
 {
     if (pocdObs.value != null)
     {
         if (pocdObs.value.Length > 0)
         {
             if (pocdObs.value[0] is ST)
             {
                 ST st = pocdObs.value[0] as ST;
                 if (st.Text != null)
                 {
                     if (st.Text.Length > 0)
                     {
                         this.Value = st.Text[0];
                     }
                 }
             }
         }
     }
 }
Пример #8
0
        public static Code GetFirstNonNullValueCode(this POCD_MT000040Observation obs)
        {
            if (obs == null)
            {
                return(null);
            }

            var value = (obs.value?.FirstOrDefault(v => v is CD) as CD)?.GetCode();

            if (!string.IsNullOrWhiteSpace(value?.Value))
            {
                return(value);
            }

            var childObs = obs.entryRelationship?.FirstOrDefault(r =>
                                                                 r.Item is POCD_MT000040Observation)
                           ?.Item as POCD_MT000040Observation;

            return(GetFirstNonNullValueCode(childObs));
        }
Пример #9
0
        private List <POCD_MT000040Observation> GetSupportingObservationsFromSection(POCD_MT000040Observation observation)
        {
            List <POCD_MT000040Observation> returnList = new List <POCD_MT000040Observation>();

            if (observation.entryRelationship != null)
            {
                foreach (var entryRel in observation.entryRelationship)
                {
                    if (entryRel.Item is POCD_MT000040Observation)
                    {
                        POCD_MT000040Observation subObs = entryRel.Item as POCD_MT000040Observation;
                        returnList.Add(subObs);
                        List <POCD_MT000040Observation> tempList = this.GetSupportingObservationsFromSection(subObs);
                        returnList.AddRange(tempList);
                    }
                }
            }

            return(returnList);
        }
Пример #10
0
        public CdaPqObservation(POCD_MT000040Observation pocdObservation) : base(pocdObservation)
        {
            if (pocdObservation != null)
            {
                if (pocdObservation.value != null)
                {
                    ANY[] valArray = pocdObservation.value as ANY[];

                    if (valArray != null)
                    {
                        if (valArray.Length > 0)
                        {
                            PQ val = valArray[0] as PQ;

                            if (val != null)
                            {
                                this.Value = val.value;
                                this.Unit  = val.unit;
                            }
                        }
                    }
                }
            }
        }
Пример #11
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);
        }
        public POCD_MT000040Observation ToPocd()
        {
            POCD_MT000040Observation returnObservation = new POCD_MT000040Observation();

            // *** Elements that are the same for all ***
            returnObservation.classCode = "OBS";
            returnObservation.moodCode  = this.Mood;

            returnObservation.templateId = this.TemplateIds.ToPocd();

            // *** Actual data from observation ***
            if (this.NegationIndicator)
            {
                returnObservation.negationInd          = this.NegationIndicator;
                returnObservation.negationIndSpecified = true;
            }

            returnObservation.id = new II[] { new II()
                                              {
                                                  root = this.Id
                                              } };
            returnObservation.code = this.Code.ToCE();
            returnObservation.text = new ED()
            {
                reference = new TEL()
                {
                    value = string.Format("#{0}", this.ReferenceId)
                }
            };
            returnObservation.statusCode = new CS()
            {
                code = this.Status.ToString()
            };
            returnObservation.effectiveTime = this.EffectiveTime.ToIvlTs(); //new IVL_TS() { value = this.EffectiveTime.ToString(RawCdaDocument.CdaDateFormat) };
            returnObservation.value         = this.BaseValue;

            // *** Supporting Observations ***
            if (this.SupportingObservations != null)
            {
                if (this.SupportingObservations.Count > 0)
                {
                    List <POCD_MT000040EntryRelationship> relList = new List <POCD_MT000040EntryRelationship>();

                    foreach (var item in this.SupportingObservations)
                    {
                        POCD_MT000040EntryRelationship rel = new POCD_MT000040EntryRelationship();

                        rel.typeCode = x_ActRelationshipEntryRelationship.SPRT;

                        rel.Item = item.ToPocd();

                        relList.Add(rel);
                    }

                    returnObservation.entryRelationship = relList.ToArray();
                }
            }

            if (this.Author != null)
            {
                returnObservation.author = new POCD_MT000040Author[] { this.Author.ToPocdAuthor() }
            }
            ;

            if (this.ReferenceRange != null)
            {
                returnObservation.referenceRange = new POCD_MT000040ReferenceRange[] { this.ReferenceRange.ToPocd() }
            }
            ;

            if (!string.IsNullOrWhiteSpace(this.InterpretationCode))
            {
                returnObservation.interpretationCode = new CE[] { new CE {
                                                                      code           = this.InterpretationCode,
                                                                      codeSystem     = "2.16.840.1.113883.5.83",
                                                                      codeSystemName = "ObservationInterpretation"
                                                                  } }
            }
            ;

            return(returnObservation);
        }
    }
}
Пример #13
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);
        }
Пример #14
0
        private List <CdaObservationModel> ExtractBabyObservationsFromNds()
        {
            // *** Extract section observations from the document ***

            List <CdaObservationModel> returnList = new List <CdaObservationModel>();
            int babyNumber = 0;

            if (this.Initialize())
            {
                // *** Check if we have something to work with ***
                if (this.PocdDocument != null)
                {
                    if (this.PocdDocument.component != null)
                    {
                        if (this.PocdDocument.component.Item is POCD_MT000040StructuredBody)
                        {
                            POCD_MT000040StructuredBody body = this.PocdDocument.component.Item as POCD_MT000040StructuredBody;

                            if (body.component != null)
                            {
                                if (body.component.Length > 0)
                                {
                                    foreach (var item in body.component)
                                    {
                                        if (item.section != null)
                                        {
                                            if (item.section.code != null)
                                            {
                                                if (item.section.code.code == "57075-4")
                                                {
                                                    if (item.section.component != null)
                                                    {
                                                        foreach (var comp in item.section.component)
                                                        {
                                                            if (comp.section != null)
                                                            {
                                                                if (comp.section.code.code == "10210-3")
                                                                {
                                                                    if (comp.section.entry != null)
                                                                    {
                                                                        ++babyNumber;

                                                                        List <POCD_MT000040Observation> pocdList = new List <POCD_MT000040Observation>();

                                                                        foreach (var entry in comp.section.entry)
                                                                        {
                                                                            if (entry.Item != null)
                                                                            {
                                                                                if (entry.Item is POCD_MT000040Observation)
                                                                                {
                                                                                    POCD_MT000040Observation pocdObs = entry.Item as POCD_MT000040Observation;
                                                                                    pocdList.Add(pocdObs);

                                                                                    List <POCD_MT000040Observation> tempList = this.GetSupportingObservationsFromSection(pocdObs);
                                                                                    pocdList.AddRange(tempList);
                                                                                }
                                                                            }
                                                                        }

                                                                        foreach (var pocdObs in pocdList)
                                                                        {
                                                                            // *** Create a simple observation ***
                                                                            CdaSimpleObservation cdaObs = CdaObservationFactory.CreateObservation(pocdObs);

                                                                            // *** Convert to model + add to return ***
                                                                            if ((cdaObs != null) && (cdaObs.Code != null))
                                                                            {
                                                                                CdaObservationModel tempObs = CdaObservationModel.Create(cdaObs);
                                                                                tempObs.BabyNumber = babyNumber;
                                                                                returnList.Add(tempObs);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(returnList);
        }
Пример #15
0
        private List <POCD_MT000040Observation> ExtractObservationsFromSection(string sectionCode)
        {
            // *** Extract section observations from the document ***

            List <POCD_MT000040Observation> returnList = new List <POCD_MT000040Observation>();

            if (this.Initialize())
            {
                // *** Check if we have something to work with ***
                if (this.PocdDocument != null)
                {
                    if (this.PocdDocument.component != null)
                    {
                        if (this.PocdDocument.component.Item is POCD_MT000040StructuredBody)
                        {
                            POCD_MT000040StructuredBody body = this.PocdDocument.component.Item as POCD_MT000040StructuredBody;

                            if (body.component != null)
                            {
                                if (body.component.Length > 0)
                                {
                                    foreach (var item in body.component)
                                    {
                                        if (item.section != null)
                                        {
                                            if (item.section.code != null)
                                            {
                                                if (item.section.code.code == sectionCode)
                                                {
                                                    if (item.section.entry != null)
                                                    {
                                                        foreach (var entry in item.section.entry)
                                                        {
                                                            if (entry.Item != null)
                                                            {
                                                                if (entry.Item is POCD_MT000040Observation)
                                                                {
                                                                    POCD_MT000040Observation pocdObs = entry.Item as POCD_MT000040Observation;
                                                                    returnList.Add(pocdObs);

                                                                    List <POCD_MT000040Observation> tempList = this.GetSupportingObservationsFromSection(pocdObs);
                                                                    returnList.AddRange(tempList);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(returnList);
        }