public void GenerateSocialHistoryEmpty(III hl7III, Factory hl7Factory)
        {
            IEntry entry = functionalStatus.Section.Entry.Append();

            entry.AsObservation.ClassCode = "OBS";
            entry.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
            IIVXB_TS TS = hl7Factory.CreateIVXB_TS();

            hl7III = entry.AsObservation.Id.Append();
            hl7III.Init(Guid.NewGuid().ToString());
            hl7III = entry.AsObservation.TemplateId.Append();
            hl7III.Init("2.16.840.1.113883.10.20.22.4.78");
            IED ED = hl7Factory.CreateED();

            entry.AsObservation.Code.Code           = "ASSERTION";
            entry.AsObservation.Code.DisplayName    = "Assertion";
            entry.AsObservation.Code.CodeSystem     = "2.16.840.1.113883.5.4";
            entry.AsObservation.Code.CodeSystemName = "ActCode";
            entry.AsObservation.StatusCode.Init("completed");
            entry.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS(), high: new IVXB_TS());
            ICD CD = hl7Factory.CreateCD();

            CD.NullFlavor = "UNK";
            entry.AsObservation.Value.Add(CD);
        }
        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 GenerateSocialHistoryEntry(string observerValue, ref int refId, string obsrvType, III hl7III, Factory hl7Factory)
        {
            if (obsrvType == "Smoking")
            {
                IEntry entry = functionalStatus.Section.Entry.Append();
                //GetSNOMED(obsrvType)
                entry.AsObservation.ClassCode = "OBS";
                entry.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
                IIVXB_TS TS = hl7Factory.CreateIVXB_TS();
                hl7III = entry.AsObservation.Id.Append();
                hl7III.Init(Guid.NewGuid().ToString());
                hl7III = entry.AsObservation.TemplateId.Append();
                hl7III.Init("2.16.840.1.113883.10.20.22.4.78");
                //entry.AsObservation.Code.Code = IIf(obsrvType = "Smoking", "230056004", IIf(obsrvType = "Alcohol", "160573003", IIf(obsrvType = "Drugs", "228423003", "229819007")))
                IED ED = hl7Factory.CreateED();
                entry.AsObservation.Code.Code           = "ASSERTION";
                entry.AsObservation.Code.DisplayName    = "Assertion";
                entry.AsObservation.Code.CodeSystem     = "2.16.840.1.113883.5.4";
                entry.AsObservation.Code.CodeSystemName = "ActCode";
                //ED.Reference.Value = "#Sec" + refId
                //entry.AsObservation.Code.OriginalText = ED
                //entry.AsObservation.Code.CodeSystem = "2.16.840.1.113883.6.96"
                //entry.AsObservation.Code.DisplayName = IIf(obsrvType = "Smoking", "Cigarette smoking", IIf(obsrvType = "Alcohol", "Alcohol consumption", IIf(obsrvType = "Drugs", "Drugs consumption", "Tobacoo consumption")))

                entry.AsObservation.StatusCode.Init("completed");
                entry.AsObservation.EffectiveTime = new IVL_TS().Init(low: new IVXB_TS(), high: new IVXB_TS());
                //entry.AsObservation.EffectiveTime.High.Value = "UNK"
                ICD CD = hl7Factory.CreateCD();
                CD.CodeSystemName = "SNOMED CT";
                //= observerValue
                CD.CodeSystem  = "2.16.840.1.113883.6.96";
                CD.Code        = "77176002";
                CD.DisplayName = "Cigarette smoking";
                CD.OriginalText.Reference.Value = "#Sec" + refId;
                entry.AsObservation.Value.Add(CD);
                refId = refId + 1;
            }
            else
            {
                IEntry entry = functionalStatus.Section.Entry.Append();
                GetSNOMED(obsrvType);
                entry.TypeCode = x_ActRelationshipEntry.DRIV;
                entry.AsObservation.ClassCode = "OBS";
                entry.AsObservation.MoodCode  = x_ActMoodDocumentObservation.EVN;
                IIVXB_TS TS = hl7Factory.CreateIVXB_TS();
                hl7III = entry.AsObservation.Id.Append();
                hl7III.Init(Guid.NewGuid().ToString());
                hl7III = entry.AsObservation.TemplateId.Append();
                hl7III.Init("2.16.840.1.113883.10.20.22.4.38");
                entry.AsObservation.Code.Code = (obsrvType == "Smoking" ? "230056004" : (obsrvType == "Alcohol" ? "160573003" : (obsrvType == "Drugs" ? "228423003" : "229819007")));
                IED ED = hl7Factory.CreateED();
                ED.Reference.Value = "#Sec" + refId;
                entry.AsObservation.Code.OriginalText = ED;
                entry.AsObservation.Code.CodeSystem   = "2.16.840.1.113883.6.96";
                entry.AsObservation.Code.DisplayName  = (obsrvType == "Smoking" ? "Cigarette smoking" : (obsrvType == "Alcohol" ? "Alcohol consumption" : (obsrvType == "Drugs" ? "Drugs consumption" : "Tobacoo consumption")));

                entry.AsObservation.StatusCode.Init("completed");
                entry.AsObservation.EffectiveTime.NullFlavor = "UNK";
                IST ST = hl7Factory.CreateST();
                ST.Text = observerValue;
                entry.AsObservation.Value.Add(ST);
                refId = refId + 1;
            }
        }
        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);
        }