Example #1
0
        private static string GetOrCreateStructureDefinition(string structureDefinitionName)
        {
            var sdSearchParams = new SearchParams();

            sdSearchParams.Add("name", structureDefinitionName);
            var sd = FhirClient.Search <Hl7.Fhir.Model.StructureDefinition>(sdSearchParams);

            var sdReference = sd
                              .With(x => x.Entry)
                              .With(x => x.FirstOrDefault())
                              .With(x => FhirHelper.CreateReference(x.Resource));

            if (sdReference == null)
            {
                var structureDefinition = new Hl7.Fhir.Model.StructureDefinition {
                    Name = structureDefinitionName
                };
                var createdSd = FhirClient.Create(structureDefinition);
                return(FhirHelper.CreateReference(createdSd).Reference);
            }
            else
            {
                return(sdReference.Reference);
            }
        }
Example #2
0
        public static Order GetOrder(Patient patient, Practitioner orderPractitioner,
                                     Organization orderOrganization,
                                     Resource diagnosticOrder)
        {
            var order = new Order
            {
                Identifier = new List <Identifier>
                {
                    new Identifier(Systems.ORGANIZATIONS, GetCodeBySystem(Systems.ORGANIZATIONS))
                    {
                        Assigner = FhirHelper.CreateReference(orderOrganization)
                    },
                },
                Date = DateTime.Today.ToString(CultureInfo.CurrentCulture),
                When = new Order.OrderWhenComponent
                {
                    Code = new CodeableConcept
                    {
                        Coding = new List <Coding>
                        {
                            new Coding(Systems.PRIORIRY, GetCodeBySystem(Systems.PRIORIRY))
                        }
                    }
                },
                Subject = FhirHelper.CreateReference(patient),
                Source  = FhirHelper.CreateReference(orderPractitioner),
                Target  = FhirHelper.CreateReference(orderOrganization),
                Detail  = new List <ResourceReference> {
                    FhirHelper.CreateBundleReference(diagnosticOrder)
                },
            };

            return(order);
        }
Example #3
0
 public static DiagnosticReport GetDiagnosticReport(ResourceReference orderSubject, Practitioner practitioner1,
                                                    Observation observation1, Observation observation2, ResourceReference detail)
 {
     return(new DiagnosticReport
     {
         Id = Guid.NewGuid().ToString(),
         Name = new CodeableConcept(Systems.DIAGNOSTIC_REPORT_CODE, GetCodeBySystem(Systems.DIAGNOSTIC_ORDER_CODE)),
         Status = DiagnosticReport.DiagnosticReportStatus.Final,
         Issued = DateTime.Today.AddDays(-1).ToString(CultureInfo.CurrentCulture),
         Subject = orderSubject,
         Performer = FhirHelper.CreateBundleReference(practitioner1),
         RequestDetail = new List <ResourceReference> {
             detail
         },
         //RequestDetail = new List<ResourceReference> { new ResourceReference { Reference = "/DiagnosticOrder/41b2a8eb-2447-47d6-92a1-286995276841" } },
         Conclusion = "Заключение",
         PresentedForm = new List <Attachment>
         {
             new Attachment {
                 Hash = Encoding.UTF8.GetBytes("hash"), Data = LoadSignedData()
             }
         },
         Result = new List <ResourceReference>
         {
             FhirHelper.CreateBundleReference(observation1),
             FhirHelper.CreateBundleReference(observation2),
         }
     });
 }
Example #4
0
        public static Encounter CreateEncounter(Patient patient, Condition condition, Organization orderOrganization)
        {
            var encounter = new Encounter
            {
                Identifier = new List <Identifier>
                {
                    new Identifier(Systems.ORGANIZATIONS, GetCodeBySystem(Systems.ORGANIZATIONS))
                    {
                        Assigner = FhirHelper.CreateReference(orderOrganization)
                    }
                },
                Type = new List <CodeableConcept>
                {
                    new CodeableConcept(Systems.ENCOUNTER_TYPE, GetCodeBySystem(Systems.ENCOUNTER_TYPE))
                },
                Class      = Encounter.EncounterClass.Outpatient,
                Status     = Encounter.EncounterState.Arrived,
                Patient    = FhirHelper.CreateReference(patient),
                Indication = new List <ResourceReference> {
                    new ResourceReference {
                        Reference = condition.Id
                    }
                },
                Reason = new List <CodeableConcept>
                {
                    new CodeableConcept(Systems.REASON_CODE, GetCodeBySystem(Systems.REASON_CODE))
                },
                ServiceProvider = FhirHelper.CreateReference(orderOrganization),
            };

            return(FhirClient.Create(encounter));
        }
Example #5
0
        public static Specimen GetSpecimen(Patient patient, Organization orderOrganization)
        {
            var specimen = new Specimen
            {
                Id         = Guid.NewGuid().ToString(),
                Collection = new Specimen.SpecimenCollectionComponent
                {
                    Collected = new Date(DateTime.Today.ToString(CultureInfo.CurrentCulture))
                },
                Type      = new CodeableConcept(Systems.BIOMATERIAL, Guid.NewGuid().ToString()),
                Container = new List <Specimen.SpecimenContainerComponent>
                {
                    new Specimen.SpecimenContainerComponent
                    {
                        Identifier = new List <Identifier>
                        {
                            new Identifier(Systems.ORGANIZATIONS, GetCodeBySystem(Systems.ORGANIZATIONS))
                            {
                                Assigner = FhirHelper.CreateReference(orderOrganization)
                            }
                        },
                        Type = new CodeableConcept(Systems.CONTAINER_TYPE, Guid.NewGuid().ToString())
                    }
                },
                Subject = FhirHelper.CreateReference(patient)
            };

            return(specimen);
        }
Example #6
0
 public static Resource GetOrderResponse(Order order, DiagnosticReport[] reports)
 {
     return(new OrderResponse
     {
         Identifier = new List <Identifier> {
             new Identifier(Systems.ORGANIZATIONS, GetCodeBySystem(Systems.ORGANIZATIONS))
         },
         Request = FhirHelper.CreateReference(order),
         Date = DateTime.Now.ToString(CultureInfo.CurrentCulture),
         Who = order.Source,
         OrderStatus_ = OrderResponse.OrderStatus.Completed,
         Description = "Комментарий к заказу",
         Fulfillment = reports.Select(FhirHelper.CreateBundleReference).ToList()
     });
 }
Example #7
0
        public static Practitioner CreatePractitioner(Organization orderOrganization)
        {
            var practitioner = new Practitioner
            {
                Identifier = new List <Identifier>
                {
                    new Identifier(Systems.ORGANIZATIONS, GetCodeBySystem(Systems.ORGANIZATIONS))
                    {
                        Assigner = FhirHelper.CreateReference(orderOrganization)
                    }
                },
                Name = new HumanName
                {
                    Family = new List <string> {
                        "Врач"
                    },
                    Given = new List <string> {
                        "Врач"
                    }
                },
                PractitionerRole = new List <Practitioner.PractitionerPractitionerRoleComponent>
                {
                    new Practitioner.PractitionerPractitionerRoleComponent
                    {
                        ManagingOrganization = FhirHelper.CreateReference(orderOrganization),
                        Role      = new CodeableConcept(Systems.PRACTITIONER_ROLE, GetCodeBySystem(Systems.PRACTITIONER_ROLE)),
                        Specialty = new List <CodeableConcept>
                        {
                            new CodeableConcept(Systems.PRACTITIONER_SPECIALITY, GetCodeBySystem(Systems.PRACTITIONER_SPECIALITY))
                        }
                    }
                }
            };

            try
            {
                return(FhirClient.Create(practitioner));
            }
            catch (FhirOperationException ex)
            {
                var st = ex.StackTrace;
                foreach (var operationOutcomeIssueComponent in ex.Outcome.Issue)
                {
                }
            }

            return(null);
        }
Example #8
0
        public static Condition GetCondition(Patient patient)
        {
            var condition = new Condition
            {
                Id         = Guid.NewGuid().ToString(),
                Identifier = new List <Identifier>
                {
                    new Identifier(Systems.MES, GetCodeBySystem(Systems.MES))
                },
                Patient        = FhirHelper.CreateReference(patient),
                DateAsserted   = DateTime.Now.ToString(CultureInfo.CurrentCulture),
                Code           = new CodeableConcept(Systems.MKB10, GetCodeBySystem(Systems.MKB10)),
                Category       = new CodeableConcept(Systems.CONDITION_CATEGORY, GetCodeBySystem(Systems.CONDITION_CATEGORY)),
                ClinicalStatus = Condition.ConditionClinicalStatus.Confirmed,
                Notes          = "Condition notes",
            };

            return(condition);
        }
Example #9
0
 public static Observation GetObservation(Practitioner practitioner)
 {
     return(new Observation
     {
         Id = Guid.NewGuid().ToString(),
         Code = new CodeableConcept(Systems.OBSERVATION_LOINC, Guid.NewGuid().ToString()),
         Comments = "Комментарии",
         Issued = DateTime.Now,
         Status = Observation.ObservationStatus.Final,
         Method = new CodeableConcept(Systems.ORGANIZATIONS, GetCodeBySystem(Systems.ORGANIZATIONS)),
         Performer = new List <ResourceReference> {
             FhirHelper.CreateBundleReference(practitioner)
         },
         ReferenceRange = new List <Observation.ObservationReferenceRangeComponent>
         {
             new Observation.ObservationReferenceRangeComponent
             {
                 Low = new Quantity(),
                 High = new Quantity()
             }
         }
     });
 }
Example #10
0
        public static Order GetOrderByDiagnosticOrder(DiagnosticOrder diagnosticOrder)
        {
            var result = FhirClient.Search <Order>(new[] { string.Format("detail={0}", FhirHelper.CreateReference(diagnosticOrder).Reference) });

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Entry, Is.Not.Null);
            Assert.That(result.Entry.Count, Is.GreaterThanOrEqualTo(1));

            return((Order)result.Entry.First().Resource);
        }
Example #11
0
        public static DiagnosticOrder SearchDiagnosticOrderBySpecimen(Specimen specimen)
        {
            var result = FhirClient.Search <DiagnosticOrder>(new[] { string.Format("specimen={0}", FhirHelper.CreateReference(specimen).Reference) });

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Entry, Is.Not.Null);
            Assert.That(result.Entry.Count, Is.GreaterThanOrEqualTo(1));

            return((DiagnosticOrder)result.Entry.First().Resource);
        }
Example #12
0
        public static DiagnosticOrder GetDiagnosticOrder(Patient patient, Practitioner diagnosticOrderPractitioner,
                                                         Encounter encounter,
                                                         Observation observation, Observation observation1,
                                                         Specimen specimen, Specimen specimen1)
        {
            var diagnosticOrder = new DiagnosticOrder
            {
                Id                    = Guid.NewGuid().ToString(),
                Subject               = FhirHelper.CreateReference(patient),
                Orderer               = FhirHelper.CreateReference(diagnosticOrderPractitioner),
                Encounter             = FhirHelper.CreateReference(encounter),
                SupportingInformation = new List <ResourceReference>
                {
                    FhirHelper.CreateBundleReference(observation),
                    FhirHelper.CreateBundleReference(observation1),
                },
                Specimen = new List <ResourceReference>
                {
                    FhirHelper.CreateBundleReference(specimen),
                    FhirHelper.CreateBundleReference(specimen1)
                },
                Status = DiagnosticOrder.DiagnosticOrderStatus.Requested,
                Item   = new List <DiagnosticOrder.DiagnosticOrderItemComponent>
                {
                    new DiagnosticOrder.DiagnosticOrderItemComponent
                    {
                        Code = new CodeableConcept
                        {
                            Text   = "Услуга 1",
                            Coding = new List <Coding>
                            {
                                new Coding(Systems.DIAGNOSTIC_ORDER_CODE, Systems.DIAGNOSTIC_ORDER_CODE),
                            },
                            Extension = new List <Extension>
                            {
                                new Extension(Systems.DIAGNOSTIC_ORDER_FINANCIAL_EXTENSION, new CodeableConcept(Systems.FINANCIAL, GetCodeBySystem(Systems.FINANCIAL))),
                                new Extension(Systems.DIAGNOSTIC_ORDER_INSURANCE_EXTENSION, new ResourceReference {
                                    Reference = Guid.NewGuid().ToString()
                                })
                            }
                        },
                    },
                    new DiagnosticOrder.DiagnosticOrderItemComponent
                    {
                        Code = new CodeableConcept
                        {
                            Text   = "Услуга 2",
                            Coding = new List <Coding>
                            {
                                new Coding(Systems.DIAGNOSTIC_ORDER_CODE, Guid.NewGuid().ToString()),
                            },
                            Extension = new List <Extension>
                            {
                                new Extension(Systems.DIAGNOSTIC_ORDER_FINANCIAL_EXTENSION, new CodeableConcept(Systems.FINANCIAL, GetCodeBySystem(Systems.FINANCIAL))),
                                new Extension(Systems.DIAGNOSTIC_ORDER_INSURANCE_EXTENSION, new ResourceReference {
                                    Reference = Guid.NewGuid().ToString()
                                })
                            }
                        },
                    }
                }
            };

            return(diagnosticOrder);
        }