public List <Encounters> FillEncounters(IEntryCollection entryCollection, string name)
        {
            List <Encounters> encounters = new List <Encounters>();

            foreach (IEntry entryitem in entryCollection)
            {
                Encounters         ptEncounters      = new Encounters();
                IEncounter         entryEncounter    = entryitem.AsEncounter;
                IEntryRelationship entryRelationItem = entryEncounter.EntryRelationship.FirstOrDefault();
                if (entryRelationItem != null)
                {
                    IObservation observation = entryRelationItem.AsObservation;
                    IIVL_TS      efftime     = observation.EffectiveTime;
                    if (efftime == null)
                    {
                        throw new InvalidOperationException();
                    }
                    IANY   observationvalue = observation.Value.FirstOrDefault();
                    ICD    str      = (ICD)observationvalue;
                    string location = observation.Participant.Count > 0 ? observation.Participant[0].ParticipantRole.AsPlayingEntity.Name[0].Text : null;
                    ptEncounters.Code = str.Code;
                    ptEncounters.EncounterDescription = str.DisplayName;
                    ptEncounters.PerformerName        = name;
                    //ptEncounters.EncounterDate = efftime != null ? efftime.Low != null ? efftime.Low.Value != null ? new DateTime?(Convert.ToDateTime(efftime.Low.AsDateTime)) : null : null : efftime.Value != null ? new DateTime?(Convert.ToDateTime(efftime.AsDateTime)) : null;
                }
                encounters.Add(ptEncounters);
            }

            return(encounters);
        }
        public List <PatientProblemes> FillProblems(IEntryCollection entryCollection)
        {
            List <PatientProblemes> Problemes = new List <PatientProblemes>();

            foreach (IEntry singleentry in entryCollection)
            {
                IObservation     probObservation = singleentry.AsAct.EntryRelationship.FirstOrDefault().AsObservation;
                IIVL_TS          effectivetime   = probObservation.EffectiveTime;
                IANY             probValue       = probObservation.Value[0];
                ICD              itemVlues       = (ICD)probValue;
                PatientProblemes ptproblem       = new PatientProblemes();
                ptproblem.ProblemCode = itemVlues.Code != null ? itemVlues.Code : null;
                IEntryRelationship ObserentryRelation = probObservation.EntryRelationship.Where(e => e.AsObservation.Code.Code.ToString() == "33999-4").FirstOrDefault();
                if (ObserentryRelation != null)
                {
                    IANY probStatusVal = ObserentryRelation.AsObservation.Value.FirstOrDefault();
                    ICD  StatusVlues   = (ICD)probStatusVal;
                    ptproblem.Status = StatusVlues.DisplayName;
                }
                else
                {
                    ptproblem.Status = null;
                }
                ptproblem.DateDiagnosed = effectivetime.Low != null ? effectivetime.Low.Value != null?effectivetime.Low.AsDateTime.ToString() : null : null;

                ptproblem.Description = itemVlues.DisplayName != null ? itemVlues.DisplayName : null;
                Problemes.Add(ptproblem);
            }
            return(Problemes);
        }
        public void GenerateProblemEntryEmpty(string refId, III hl7III, Factory hl7Factory)
        {
            IEntry entry = functionalStatus.Section.Entry.Append();

            entry.TypeCode        = x_ActRelationshipEntry.DRIV;
            entry.AsAct.ClassCode = x_ActClassDocumentEntryAct.ACT;
            entry.AsAct.MoodCode  = x_DocumentActMood.EVN;
            IIVXB_TS TS = hl7Factory.CreateIVXB_TS();

            hl7III = entry.AsAct.Id.Append();
            hl7III.Init(Convert.ToString(Guid.NewGuid()));
            hl7III = entry.AsAct.TemplateId.Append();
            hl7III.Init("2.16.840.1.113883.10.20.22.4.3");
            entry.AsAct.Code.Code           = "CONC";
            entry.AsAct.Code.CodeSystem     = "2.16.840.1.113883.5.6";
            entry.AsAct.Code.CodeSystemName = "HL7ActClass";
            entry.AsAct.Code.DisplayName    = "Concern";
            entry.AsAct.StatusCode.Init("completed");
            entry.AsAct.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
            IEntryRelationship entryRel = entry.AsAct.EntryRelationship.Append();

            entryRel.TypeCode = x_ActRelationshipEntryRelationship.SUBJ;
            entryRel.AsObservation.ClassCode            = "OBS";
            entryRel.AsObservation.MoodCode             = x_ActMoodDocumentObservation.EVN;
            entryRel.AsObservation.NegationInd          = true;
            entryRel.AsObservation.NegationIndSpecified = true;
            III TempId = entryRel.AsObservation.TemplateId.Append();

            TempId.Root = "2.16.840.1.113883.10.20.22.4.4";
            hl7III      = entryRel.AsObservation.Id.Append();
            hl7III.Root = Guid.NewGuid().ToString();
            entryRel.AsObservation.Code.Code           = "55607006";
            entryRel.AsObservation.Code.CodeSystem     = "2.16.840.1.113883.6.96";
            entryRel.AsObservation.Code.DisplayName    = "Problem";
            entryRel.AsObservation.Code.CodeSystemName = "SNOMED CT";
            IED ED = hl7Factory.CreateED();

            ED.Reference.Value          = refId;
            entryRel.AsObservation.Text = ED;
            ICS CS = hl7Factory.CreateCS();

            CS.Init("completed");
            entryRel.AsObservation.StatusCode    = CS;
            entryRel.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS(), high: new IVXB_TS());
            ICD CD = hl7Factory.CreateCD();

            CD.Code           = "55607006";
            CD.CodeSystem     = "2.16.840.1.113883.6.96";
            CD.CodeSystemName = "SNOMED CT";
            CD.DisplayName    = Convert.ToString("Problem");
            entryRel.AsObservation.Value.Add(CD);
        }
        public void CreateEncounterEmptyEntry(III hl7III, Factory hl7factory)
        {
            IEntry entry = functionalStatus.Section.Entry.Append();

            entry.TypeCode        = x_ActRelationshipEntry.DRIV;
            entry.AsAct.ClassCode = x_ActClassDocumentEntryAct.ACT;
            entry.AsAct.MoodCode  = x_DocumentActMood.EVN;
            hl7III            = entry.AsAct.Id.Append();
            hl7III.NullFlavor = "UNK";
            hl7III            = entry.AsAct.TemplateId.Append();
            hl7III.Init("2.16.840.1.113883.10.20.22.4.30");
            entry.AsAct.Code.Code           = "48765-2";
            entry.AsAct.Code.CodeSystem     = "2.16.840.1.113883.6.1";
            entry.AsAct.Code.CodeSystemName = "LOINC";
            entry.AsAct.Code.DisplayName    = "Allergies, adverse reactions, alerts";
            entry.AsAct.StatusCode.Code     = "completed";
            entry.AsAct.EffectiveTime       = new IVL_TS().Init(low: new IVXB_TS(), high: new IVXB_TS());
            // If Status Complete

            IEntryRelationship entryRel = entry.AsAct.EntryRelationship.Append();

            entryRel.TypeCode = x_ActRelationshipEntryRelationship.SUBJ;
            entryRel.AsObservation.ClassCode = "OBS";
            entryRel.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
            III TempId = entryRel.AsObservation.TemplateId.Append();

            TempId.Root = "2.16.840.1.113883.10.20.22.4.7";
            entryRel.AsObservation.StatusCode.Code = "completed";
            hl7III           = entryRel.AsObservation.Id.Append();
            hl7III.Root      = "1.3.6.1.4.1.22812.11.0.100610.4.10.2";
            hl7III.Extension = "41700060";
            entryRel.AsObservation.Code.Code       = "ASSERTION";
            entryRel.AsObservation.Code.CodeSystem = "2.16.840.1.113883.5.4";
            entryRel.AsObservation.EffectiveTime   = new IVL_TS().Init(low: new IVXB_TS());
            CD obsValueAsCD = new CD();

            obsValueAsCD.NullFlavor = "UNK";
            entryRel.AsObservation.Value.Add(obsValueAsCD);
            PN pn = new PN();

            pn.Text = "N/A";
            IParticipant2 parti = hl7factory.CreateParticipant2();

            parti.TypeCode = "CSM";
            parti.ParticipantRole.ClassCode = "MANU";
            parti.ParticipantRole.AsPlayingEntity.ClassCode       = "MMAT";
            parti.ParticipantRole.AsPlayingEntity.Code.NullFlavor = "UNK";
            parti.ParticipantRole.AsPlayingEntity.Name.Add(pn);
            entryRel.AsObservation.Participant.Add(parti);
        }
        public List <PatientMedication> FillMedication(IEntryCollection entryCollection)
        {
            List <PatientMedication> Medication = new List <PatientMedication>();

            foreach (IEntry entryitem in entryCollection)
            {
                ISubstanceAdministration entrySubstanceAdministration = entryitem.AsSubstanceAdministration;
                foreach (var timeitem in entrySubstanceAdministration.EffectiveTime)
                {
                    var    obj     = timeitem.GetType();
                    string objname = obj.Name;
                    switch (objname)
                    {
                    case "IVL_TS":
                        datetime = (IIVL_TS)timeitem;
                        break;

                    case "PIVL_TS":
                        timeduration = (IPIVL_TS)timeitem;
                        break;
                    }
                }
                IIVL_PQ            doseQuantity      = entrySubstanceAdministration.DoseQuantity;
                IIVL_PQ            rateQuantity      = entrySubstanceAdministration.RateQuantity;
                ICE                meterialCode      = entrySubstanceAdministration.Consumable.ManufacturedProduct.AsMaterial.Code;
                IEntryRelationship entryRelationShip = entrySubstanceAdministration.EntryRelationship.Where(e => e.TypeCode.ToString() == "RSON").FirstOrDefault();
                if (entryRelationShip != null)
                {
                    IANY entryvalue      = entryRelationShip.AsObservation.Value.FirstOrDefault();
                    ICE  valueCollection = (ICE)entryvalue;
                }
                PatientMedication ptMedication = new PatientMedication();
                ptMedication.Medication = meterialCode.Translation.FirstOrDefault() != null?meterialCode.Translation.FirstOrDefault().DisplayName : meterialCode.DisplayName != null ? meterialCode.DisplayName : null;

                ptMedication.RxNorm    = meterialCode.Code != null ? meterialCode.Code : null;
                ptMedication.Frequency = timeduration != null ? timeduration.Value != null?timeduration.Value.ToString() : null : null;

                ptMedication.doseUnit = doseQuantity.Value.ToString() + " " + doseQuantity.Unit != null?doseQuantity.Unit.ToString() : "";

                ptMedication.StartDate = datetime.Low != null ? datetime.Low.Value != null ? new DateTime?(datetime.Low.AsDateTime) : null : null;
                ptMedication.EndDate   = datetime.High != null ? datetime.High.Value != null ? new DateTime?(datetime.High.AsDateTime) : null : null;
                Medication.Add(ptMedication);
            }

            return(Medication);
        }
        public List <PatientAllergies> FillAllergies(IEntryCollection entryCollection)
        {
            List <PatientAllergies> alleryies = new List <PatientAllergies>();

            foreach (IEntry entryitem in entryCollection)
            {
                IAct entryact = entryitem.AsAct;
                IEntryRelationship entryRelationship  = entryact.EntryRelationship[0];
                IObservation       entryobservation   = entryRelationship.AsObservation;
                IIVL_TS            effectivetime      = entryact.EffectiveTime;
                IParticipant2      allergyParticipant = entryobservation.Participant[0];
                IParticipantRole   participantRole    = allergyParticipant.ParticipantRole;
                IPlayingEntity     playingEntity      = participantRole.AsPlayingEntity;
                ICE              code        = playingEntity.Code;
                IPNCollection    name        = playingEntity.Name;
                string           substance   = name != null && name.Count() > 0 ? name[0].Text : code.DisplayName;
                PatientAllergies ptallergies = new PatientAllergies();
                ptallergies.substance = substance;
                IEntryRelationship entryRelationshipMFST = entryobservation.EntryRelationship.Where(r => r.TypeCode.ToString() == "MFST").FirstOrDefault();
                if (entryRelationshipMFST != null && entryRelationshipMFST.AsObservation.Value != null)
                {
                    IANY Reactionvaluecollection = entryRelationshipMFST.AsObservation.Value.FirstOrDefault();
                    CD   valuesReaction          = (CD)Reactionvaluecollection;
                    ptallergies.reaction = valuesReaction.DisplayName;
                }
                ptallergies.rxNorm = code.Code;
                IEntryRelationship entryRelationshipSUBJ = entryobservation.EntryRelationship.Where(r => r.TypeCode.ToString() == "SUBJ").FirstOrDefault();
                if (entryRelationshipSUBJ != null && entryRelationshipSUBJ.AsObservation.Value != null)
                {
                    IANY Statusvaluecollection = entryRelationshipSUBJ.AsObservation.Value.FirstOrDefault();
                    ICE  values = (ICE)Statusvaluecollection;
                    ptallergies.status = values.DisplayName;
                }
                if (effectivetime != null && effectivetime.Value != null)
                {
                    ptallergies.allergyDate = effectivetime.AsDateTime.ToString();
                }
                alleryies.Add(ptallergies);
            }

            return(alleryies);
        }
        public void GenerateProblemEntry(PatientProblemes patientProblem, string refId, DateTime dateofbirth, III hl7III, Factory hl7Factory)
        {
            IEntry entry = functionalStatus.Section.Entry.Append();

            entry.TypeCode        = x_ActRelationshipEntry.DRIV;
            entry.AsAct.ClassCode = x_ActClassDocumentEntryAct.ACT;
            entry.AsAct.MoodCode  = x_DocumentActMood.EVN;
            IIVXB_TS TS = hl7Factory.CreateIVXB_TS();

            hl7III = entry.AsAct.Id.Append();

            hl7III.Init(Convert.ToString(patientProblem.PatientGuid));
            hl7III = entry.AsAct.TemplateId.Append();
            hl7III.Init("2.16.840.1.113883.10.20.22.4.3");
            entry.AsAct.Code.Code           = "CONC";
            entry.AsAct.Code.CodeSystem     = "2.16.840.1.113883.5.6";
            entry.AsAct.Code.CodeSystemName = "LOINC";

            entry.AsAct.StatusCode.Init((Convert.ToString(patientProblem.Status) == "Active" ? "active" : "completed"));
            if (patientProblem.DateDiagnosed != null)
            {
                entry.AsAct.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
            }
            else
            {
                entry.AsAct.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
                //entry.AsAct.EffectiveTime.NullFlavor = "UNK";

                /* Not Compiled
                 * entry.AsAct.EffectiveTime = new IVL_TS().Init(Value:null, low:new IVXB_TS().Init(Convert.ToDateTime(patientProblem.DateDiagnosed)),high:null,width:null,center:null);*/
                // Setting the DateTime.
            }

            IEntryRelationship entryRel = entry.AsAct.EntryRelationship.Append();

            entryRel.TypeCode = x_ActRelationshipEntryRelationship.SUBJ;
            entryRel.AsObservation.ClassCode = "OBS";
            entryRel.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
            III TempId = entryRel.AsObservation.TemplateId.Append();

            TempId.Root = "2.16.840.1.113883.10.20.22.4.4";
            hl7III      = entryRel.AsObservation.Id.Append();
            hl7III.Root = Guid.NewGuid().ToString();

            entryRel.AsObservation.Code.Code        = Convert.ToString(patientProblem.Description).ToLower().Contains("finding") ? "404684003" : Convert.ToString(patientProblem.Description).ToLower().Contains("disease") ? "282291009" : "409586006";
            entryRel.AsObservation.Code.CodeSystem  = "2.16.840.1.113883.6.96";
            entryRel.AsObservation.Code.DisplayName = Convert.ToString(patientProblem.Description).ToLower().Contains("finding") ? "Finding" : Convert.ToString(patientProblem.Description).ToLower().Contains("disease") ? "Diagnosis" : "Complaint";


            IED ED = hl7Factory.CreateED();

            ED.Reference.Value          = refId;
            entryRel.AsObservation.Text = ED;
            ICS CS = hl7Factory.CreateCS();

            CS.Init("completed");
            entryRel.AsObservation.StatusCode = CS;

            if (Convert.ToString(patientProblem.Status) == "Resolved")
            {
                if (object.ReferenceEquals(patientProblem.DateDiagnosed, DBNull.Value))
                {
                    entry.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
                }
                else
                {
                    entry.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
                    //entryRel.AsObservation.EffectiveTime.NullFlavor = "UNK";

                    /* Not Compiled
                     * entryRel.AsObservation.EffectiveTime.Init(low: new IVXB_TS().Init(Convert.ToDateTime(patientProblem.DateDiagnosed)), high: new IVXB_TS());
                     * // Because Allergy Start Date is Missing.
                     *
                     * entryRel.AsObservation.EffectiveTime.High.NullFlavor = "UNK";*/
                }
            }
            else
            {
                if (object.ReferenceEquals(patientProblem.DateDiagnosed, DBNull.Value))
                {
                    entryRel.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
                    //entryRel.AsObservation.EffectiveTime.NullFlavor = "UNK";
                }
                else
                {
                    entryRel.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
                    //entryRel.AsObservation.EffectiveTime.NullFlavor = "UNK";

                    /* Not Compiled
                     * entryRel.AsObservation.EffectiveTime.Init(low: new IVXB_TS().Init(Convert.ToDateTime(patientProblem.DateDiagnosed)), high: new IVXB_TS());
                     * entryRel.AsObservation.EffectiveTime.High.NullFlavor = "UNK";*/
                }
            }

            ICD CD = hl7Factory.CreateCD();

            string snomedCode = GetSNOMED(Convert.ToString(patientProblem.Description));

            if (string.IsNullOrEmpty(snomedCode))
            {
                CD.NullFlavor = "UNK";
            }
            else
            {
                CD.Code           = snomedCode;
                CD.CodeSystem     = "2.16.840.1.113883.6.96";
                CD.CodeSystemName = "SNOMED CT";
                CD.DisplayName    = Convert.ToString(patientProblem.Description);
            }

            entryRel.AsObservation.Value.Add(CD);

            ///''''''''''''Problem Observation''''''''''''''''''
            IEntryRelationship entryProblemObs = entryRel.AsObservation.EntryRelationship.Append();

            entryProblemObs.TypeCode = x_ActRelationshipEntryRelationship.SUBJ;
            entryProblemObs.AsObservation.ClassCode = "OBS";
            entryProblemObs.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
            TempId      = entryProblemObs.AsObservation.TemplateId.Append();
            TempId.Root = "2.16.840.1.113883.10.20.22.4.4";
            hl7III      = entryProblemObs.AsObservation.Id.Append();
            hl7III.Root = Guid.NewGuid().ToString();

            entryProblemObs.AsObservation.Code.Code        = Convert.ToString(patientProblem.Description).ToLower().Contains("finding") ? "404684003" : Convert.ToString(patientProblem.Description).ToLower().Contains("disease") ? "282291009" : "409586006";
            entryProblemObs.AsObservation.Code.CodeSystem  = "2.16.840.1.113883.6.96";
            entryProblemObs.AsObservation.Code.DisplayName = Convert.ToString(patientProblem.Description).ToLower().Contains("finding") ? "Finding" : Convert.ToString(patientProblem.Description).ToLower().Contains("disease") ? "Diagnosis" : "Complaint";

            ED = hl7Factory.CreateED();
            ED.Reference.Value = refId;
            entryProblemObs.AsObservation.Text = ED;
            CS = hl7Factory.CreateCS();
            CS.Init("completed");
            entryProblemObs.AsObservation.StatusCode = CS;

            if (Convert.ToString(patientProblem.Status) == "Resolved")
            {
                if (object.ReferenceEquals(patientProblem.DateDiagnosed, DBNull.Value))
                {
                    entryProblemObs.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
                    //entryProblemObs.AsObservation.EffectiveTime.NullFlavor = "UNK";
                }
                else
                {
                    entryProblemObs.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());

                    /* Not Compiled
                     * entryProblemObs.AsObservation.EffectiveTime.Init(low: new IVXB_TS().Init(Convert.ToDateTime(patientProblem.DateDiagnosed)), high: new IVXB_TS());
                     * // Because Allergy Start Date is Missing.
                     * entryProblemObs.AsObservation.EffectiveTime.High.NullFlavor = "UNK";*/
                }
            }
            else
            {
                if (object.ReferenceEquals(patientProblem.DateDiagnosed, DBNull.Value))
                {
                    entryProblemObs.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
                }
                else
                {
                    entryProblemObs.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());

                    /* Not Compiled
                     * entryProblemObs.AsObservation.EffectiveTime.Init(low: new IVXB_TS().Init(Convert.ToDateTime(patientProblem.DateDiagnosed)), high: new IVXB_TS());
                     * entryProblemObs.AsObservation.EffectiveTime.High.NullFlavor = "UNK";*/
                }
            }

            CD         = hl7Factory.CreateCD();
            snomedCode = GetSNOMED(Convert.ToString(patientProblem.Description));
            if (string.IsNullOrEmpty(snomedCode))
            {
                CD.NullFlavor = "UNK";
            }
            else
            {
                CD.Code        = snomedCode;
                CD.CodeSystem  = "2.16.840.1.113883.6.96";
                CD.DisplayName = Convert.ToString(patientProblem.Description);
            }

            entryProblemObs.AsObservation.Value.Add(CD);


            ///'''''''''''' Age Observation''''''''''''''''''

            if ((!object.ReferenceEquals(patientProblem.DateDiagnosed, DBNull.Value)))
            {
                IEntryRelationship age_EntryRel = entryRel.AsObservation.EntryRelationship.Append();
                age_EntryRel.TypeCode                = x_ActRelationshipEntryRelationship.SUBJ;
                age_EntryRel.InversionInd            = true;
                age_EntryRel.InversionIndSpecified   = true;
                age_EntryRel.AsObservation.ClassCode = "OBS";
                age_EntryRel.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
                hl7III = age_EntryRel.AsObservation.TemplateId.Append();
                hl7III.Init("2.16.840.1.113883.10.20.22.4.31");
                CD = hl7Factory.CreateCD();
                CD.Init("445518008", "2.16.840.1.113883.6.96", "", "Age");
                age_EntryRel.AsObservation.Code = CD;
                age_EntryRel.AsObservation.StatusCode.Init("completed");
                IPQ PQ = hl7Factory.CreatePQ();
                PQ.Value = calcYear(Convert.ToDateTime(patientProblem.DateDiagnosed), dateofbirth);
                PQ.Unit  = "a";
                age_EntryRel.AsObservation.Value.Add(PQ);
            }

            ///'''''''''''' Problem Status Observation'''''''''''''
            IEntryRelationship problemStatus_EntryRel = entryRel.AsObservation.EntryRelationship.Append();

            problemStatus_EntryRel.TypeCode                = x_ActRelationshipEntryRelationship.REFR;
            problemStatus_EntryRel.InversionInd            = true;
            problemStatus_EntryRel.InversionIndSpecified   = true;
            problemStatus_EntryRel.AsObservation.ClassCode = "OBS";
            problemStatus_EntryRel.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
            hl7III = problemStatus_EntryRel.AsObservation.TemplateId.Append();
            hl7III.Init("2.16.840.1.113883.10.20.22.4.6");

            CD = hl7Factory.CreateCD();
            CD.Init("33999-4", "2.16.840.1.113883.6.1", "LOINC", "Status");
            problemStatus_EntryRel.AsObservation.Code = CD;
            problemStatus_EntryRel.AsObservation.StatusCode.Init("completed");
            //55561003-Active, 73425007-Inactive, 413322009- Resolved
            CD = hl7Factory.CreateCD();

            CD.Init((Convert.ToString(patientProblem.Status) == "Active" ? "55561003" : (Convert.ToString(patientProblem.Status) == "Inactive" ? "73425007" : "413322009")), "2.16.840.1.113883.6.96", "SNOMED CT", Convert.ToString(patientProblem.Status));
            problemStatus_EntryRel.AsObservation.Value.Add(CD);
        }
Ejemplo n.º 8
0
        public void GenerateAllergyEntry(PatientAllergies patientAllergies, III hl7III, Factory hl7factory)
        {
            IEntry entry = functionalStatus.Section.Entry.Append();

            entry.TypeCode        = x_ActRelationshipEntry.DRIV;
            entry.AsAct.ClassCode = x_ActClassDocumentEntryAct.ACT;
            entry.AsAct.MoodCode  = x_DocumentActMood.EVN;
            hl7III = entry.AsAct.Id.Append();
            hl7III.Init("36e3e930-7b14-11db-9fe1-0800200c9a66");
            hl7III = entry.AsAct.TemplateId.Append();
            hl7III.Init("2.16.840.1.113883.10.20.22.4.30");
            entry.AsAct.Code.Code           = "48765-2";
            entry.AsAct.Code.CodeSystem     = "2.16.840.1.113883.6.1";
            entry.AsAct.Code.CodeSystemName = "LOINC";

            entry.AsAct.Code.DisplayName = "Allergies, adverse reactions, alerts";

            entry.AsAct.StatusCode.Code = Convert.ToString(patientAllergies.status).ToLower();

            if (Convert.ToString(patientAllergies.status) == "Active")
            {
                entry.AsAct.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS());
                // If Status Active
            }
            else
            {
                entry.AsAct.EffectiveTime = new IVL_TS().Init(high: new IVXB_TS());
                // If Status is Not Active
            }

            IEntryRelationship entryRel = entry.AsAct.EntryRelationship.Append();

            entryRel.TypeCode = x_ActRelationshipEntryRelationship.SUBJ;
            entryRel.AsObservation.ClassCode = "OBS";
            entryRel.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
            III TempId = entryRel.AsObservation.TemplateId.Append();

            TempId.Root = "2.16.840.1.113883.10.20.22.4.7";
            entryRel.AsObservation.StatusCode.Code = "completed";
            hl7III      = entryRel.AsObservation.Id.Append();
            hl7III.Root = "4adc1020-7b14-11db-9fe1-0800200c9a66";
            entryRel.AsObservation.Code.Code       = "ASSERTION";
            entryRel.AsObservation.Code.CodeSystem = "2.16.840.1.113883.5.4";
            ICS CS = hl7factory.CreateCS();

            CS.Init("completed");

            entryRel.AsObservation.EffectiveTime.NullFlavor = "UNK";
            // Because Allergy Start Date is Missing.
            CD obsValueAsCD = new CD();
            CE obsValueAsCE = new CE();

            //obsValueAsCD.Code = patientAllergies.AllergyType == "Medication" ? "416098002" : patientAllergies.AllergyType == "Food" ? "414285001" : patientAllergies.AllergyType == "Environmental" ? "419199007" : "420134006";//(patientAllergies.AllergyType == "Medication" ? "416098002" : (patientAllergies.AllergyType == "Food" ? "414285001" : (patientAllergies.AllergyType == "Environmental" ? "426232007" : "106190000")));
            //// Allergy Type SNOMED Code(Environmental Alergy:426232007, Food Allergy: 414285001, Medication Allergy: 416098002, Other Allergy: 106190000)
            //obsValueAsCD.DisplayName = (patientAllergies.AllergyType == "Medication" ? "Drug allergy" : (patientAllergies.AllergyType == "Food" ? "Food allergy" : (patientAllergies.AllergyType == "Environmental" ? "Environmental allergy" : "Other allergy")));

            obsValueAsCD.CodeSystem     = "2.16.840.1.113883.6.96";
            obsValueAsCD.CodeSystemName = "SNOMED CT";
            obsValueAsCD.OriginalText.Reference.Value = "#" + Convert.ToString(patientAllergies.allergyId);
            // "#reaction1" ' Dynamic Value
            entryRel.AsObservation.Value.Add(obsValueAsCD);
            PN pn = new PN();

            pn.Text = patientAllergies.substance;
            IParticipant2 parti = hl7factory.CreateParticipant2();

            parti.TypeCode = "CSM";
            parti.ParticipantRole.ClassCode = "MANU";
            parti.ParticipantRole.AsPlayingEntity.ClassCode = "MMAT";
            parti.ParticipantRole.AsPlayingEntity.Code.Code = Convert.ToString(patientAllergies.rxNorm);
            //"314422" ' Dynamic Value
            parti.ParticipantRole.AsPlayingEntity.Code.DisplayName = patientAllergies.substance;
            //"ALLERGENIC EXTRACT, PENICILLIN" ' Dynamic Value
            parti.ParticipantRole.AsPlayingEntity.Code.CodeSystem     = "2.16.840.1.113883.6.88";
            parti.ParticipantRole.AsPlayingEntity.Code.CodeSystemName = "RxNorm";
            parti.ParticipantRole.AsPlayingEntity.Code.OriginalText.Reference.Value = "";
            //"#" & Convert.ToString(dtRow("ReactionID"))
            parti.ParticipantRole.AsPlayingEntity.Name.Add(pn);
            entryRel.AsObservation.Participant.Add(parti);

            ///'' Allergy Status Observation '''''''''''
            IEntryRelationship obs_EntryRel = entryRel.AsObservation.EntryRelationship.Append();

            obs_EntryRel.TypeCode                = x_ActRelationshipEntryRelationship.SUBJ;
            obs_EntryRel.InversionInd            = true;
            obs_EntryRel.InversionIndSpecified   = true;
            obs_EntryRel.AsObservation.ClassCode = "OBS";
            obs_EntryRel.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
            hl7III      = obs_EntryRel.AsObservation.TemplateId.Append();
            hl7III.Root = "2.16.840.1.113883.10.20.22.4.28";
            obs_EntryRel.AsObservation.Code.Code           = "33999-4";
            obs_EntryRel.AsObservation.Code.CodeSystem     = "2.16.840.1.113883.6.1";
            obs_EntryRel.AsObservation.Code.CodeSystemName = "LOINC";
            obs_EntryRel.AsObservation.Code.DisplayName    = "Status";
            obs_EntryRel.AsObservation.StatusCode.Code     = "completed";


            obsValueAsCE             = new CE();
            obsValueAsCE.Code        = Convert.ToString(patientAllergies.status) == "Active" ? "55561003" : patientAllergies.status == "Inactive" ? "73425007" : "413322009";
            obsValueAsCE.DisplayName = Convert.ToString(patientAllergies.status);
            obsValueAsCE.CodeSystem  = "2.16.840.1.113883.6.96";

            obs_EntryRel.AsObservation.Value.Add(obsValueAsCE);
            obs_EntryRel.InversionInd          = true;
            obs_EntryRel.InversionIndSpecified = true;
            ///' Allergy Reaction Observation
            if (!string.IsNullOrEmpty(patientAllergies.reaction))
            {
                obs_EntryRel                         = entryRel.AsObservation.EntryRelationship.Append();
                obs_EntryRel.TypeCode                = x_ActRelationshipEntryRelationship.MFST;
                obs_EntryRel.InversionInd            = true;
                obs_EntryRel.InversionIndSpecified   = true;
                obs_EntryRel.AsObservation.ClassCode = "OBS";
                obs_EntryRel.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
                hl7III = obs_EntryRel.AsObservation.TemplateId.Append();
                hl7III.Init("2.16.840.1.113883.10.20.22.4.9");
                hl7III = obs_EntryRel.AsObservation.Id.Append();
                hl7III.Init("4adc1020-7b14-11db-9fe1-0800200c9a64");
                obs_EntryRel.AsObservation.Code.NullFlavor = "UNK";
                //obs_EntryRel.AsObservation.Text.Reference.Value = "#" & Convert.ToString(dtRow("ReactionID")) '"#reaction1"
                obs_EntryRel.AsObservation.StatusCode.Code = "completed";
                obs_EntryRel.AsObservation.EffectiveTime   = new IVL_TS().Init(low: new IVXB_TS(), high: new IVXB_TS());
                obsValueAsCD = new CD();
                if (!string.IsNullOrEmpty(GetSNOMED(patientAllergies.reaction)))
                {
                    obsValueAsCD.Code = GetSNOMED(patientAllergies.reaction);
                    // Dynamic Value ''
                }

                obsValueAsCD.DisplayName = patientAllergies.reaction;
                //"Hives"
                obsValueAsCD.CodeSystem = "2.16.840.1.113883.6.96";
                obsValueAsCD.OriginalText.Reference.Value = "#" + Convert.ToString(patientAllergies.allergyId);
                obs_EntryRel.AsObservation.Value.Add(obsValueAsCD);
            }

            ///' Allergy Severity Observation
            if (!string.IsNullOrEmpty(patientAllergies.reaction))
            {
                obs_EntryRel                         = entryRel.AsObservation.EntryRelationship.Append();
                obs_EntryRel.TypeCode                = x_ActRelationshipEntryRelationship.SUBJ;
                obs_EntryRel.InversionInd            = true;
                obs_EntryRel.InversionIndSpecified   = true;
                obs_EntryRel.AsObservation.ClassCode = "OBS";
                obs_EntryRel.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
                hl7III = obs_EntryRel.AsObservation.TemplateId.Append();
                hl7III.Init("2.16.840.1.113883.10.20.22.4.8");
                obs_EntryRel.AsObservation.Code.Code           = "SEV";
                obs_EntryRel.AsObservation.Code.DisplayName    = "Severity Observation";
                obs_EntryRel.AsObservation.Code.CodeSystem     = "2.16.840.1.113883.5.4";
                obs_EntryRel.AsObservation.Code.CodeSystemName = "ActCode";
                //obs_EntryRel.AsObservation.Text.Reference.Value = "#severity1"
                obs_EntryRel.AsObservation.StatusCode.Code = "completed";
                obsValueAsCD             = new CD();
                obsValueAsCD.Code        = (Convert.ToString(patientAllergies.reaction) == "Mild" ? "255604002" : (Convert.ToString(patientAllergies.reaction) == "Moderate" ? "6736007" : "24484000"));
                obsValueAsCD.DisplayName = patientAllergies.reaction;
                // Moderate or Mild or severe"
                obsValueAsCD.CodeSystem     = "2.16.840.1.113883.6.96";
                obsValueAsCD.CodeSystemName = "SNOMED CT";
                obsValueAsCD.OriginalText.Reference.Value = "#" + Convert.ToString(patientAllergies.allergyId);
                obs_EntryRel.AsObservation.Value.Add(obsValueAsCD);
            }
        }