コード例 #1
0
        public async Task GivenFhirServer_WhenGroupDataWithNoMemberPatientIdIsExported_ThenNoDataIsExported()
        {
            // NOTE: Azure Storage Emulator is required to run these tests locally.

            // Add data for test
            string groupId = await CreateGroupWithoutPatientIds();

            // Trigger export request and check for export status
            Uri contentLocation = await _testFhirClient.ExportAsync($"Group/{groupId}/");

            IList <Uri> blobUris = await ExportTestHelper.CheckExportStatus(_testFhirClient, contentLocation);

            Assert.Empty(blobUris);

            async Task <string> CreateGroupWithoutPatientIds()
            {
                var group = new FhirGroup()
                {
                    Type   = FhirGroup.GroupType.Person,
                    Actual = true,
                };

                var groupResponse = await _testFhirClient.CreateAsync(group);

                return(groupResponse.Resource.Id);
            }
        }
コード例 #2
0
        public async Task GivenAValidConfigurationWithETag_WhenExportingGroupAnonymizedData_ResourceShouldBeAnonymized()
        {
            _metricHandler?.ResetCount();

            var patientToCreate = Samples.GetDefaultPatient().ToPoco <Patient>();
            var dateTime        = DateTimeOffset.UtcNow;

            patientToCreate.Id = Guid.NewGuid().ToString();
            var patientReponse = await _testFhirClient.UpdateAsync(patientToCreate);

            var patientId = patientReponse.Resource.Id;

            var group = new FhirGroup()
            {
                Type   = FhirGroup.GroupType.Person,
                Actual = true,
                Id     = Guid.NewGuid().ToString(),
                Member = new List <FhirGroup.MemberComponent>()
                {
                    new FhirGroup.MemberComponent()
                    {
                        Entity = new ResourceReference($"{KnownResourceTypes.Patient}/{patientId}"),
                    },
                },
            };
            var groupReponse = await _testFhirClient.UpdateAsync(group);

            var groupId = groupReponse.Resource.Id;

            (string fileName, string etag) = await UploadConfigurationAsync(RedactResourceIdAnonymizationConfiguration);

            string containerName   = Guid.NewGuid().ToString("N");
            Uri    contentLocation = await _testFhirClient.AnonymizedExportAsync(fileName, dateTime, containerName, etag, $"Group/{groupId}/");

            HttpResponseMessage response = await WaitForCompleteAsync(contentLocation);

            IList <Uri> blobUris = await CheckExportStatus(response);

            IEnumerable <string> dataFromExport = await DownloadBlobAndParse(blobUris);

            FhirJsonParser parser = new FhirJsonParser();

            foreach (string content in dataFromExport)
            {
                Resource result = parser.Parse <Resource>(content);

                Assert.Contains(result.Meta.Security, c => "REDACTED".Equals(c.Code));
            }

            Assert.Equal(2, dataFromExport.Count());

            // Only check metric for local tests
            if (_isUsingInProcTestServer)
            {
                Assert.Single(_metricHandler.NotificationMapping[typeof(ExportTaskMetricsNotification)]);
            }
        }
コード例 #3
0
        /// <summary>
        /// Parse Group
        /// </summary>
        public static Hl7.Fhir.Model.Group ParseGroup(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Group existingInstance = null)
        {
            Hl7.Fhir.Model.Group result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Group();
            string currentElementName   = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element language
                else if (atName == "language")
                {
                    result.LanguageElement = CodeParser.ParseCode(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.Text = NarrativeParser.ParseNarrative(reader, errors);
                }

                // Parse element contained
                else if (atName == "contained")
                {
                    result.Contained = new List <Hl7.Fhir.Model.Resource>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contained"))
                    {
                        result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element identifier
                else if (atName == "identifier")
                {
                    result.Identifier = IdentifierParser.ParseIdentifier(reader, errors);
                }

                // Parse element type
                else if (atName == "type")
                {
                    result.TypeElement = CodeParser.ParseCode <Hl7.Fhir.Model.Group.GroupType>(reader, errors);
                }

                // Parse element actual
                else if (atName == "actual")
                {
                    result.ActualElement = FhirBooleanParser.ParseFhirBoolean(reader, errors);
                }

                // Parse element code
                else if (atName == "code")
                {
                    result.Code = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element name
                else if (atName == "name")
                {
                    result.NameElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element quantity
                else if (atName == "quantity")
                {
                    result.QuantityElement = IntegerParser.ParseInteger(reader, errors);
                }

                // Parse element characteristic
                else if (atName == "characteristic")
                {
                    result.Characteristic = new List <Hl7.Fhir.Model.Group.GroupCharacteristicComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "characteristic"))
                    {
                        result.Characteristic.Add(GroupParser.ParseGroupCharacteristicComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element member
                else if (atName == "member")
                {
                    result.Member = new List <Hl7.Fhir.Model.ResourceReference>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "member"))
                    {
                        result.Member.Add(ResourceReferenceParser.ParseResourceReference(reader, errors));
                    }

                    reader.LeaveArray();
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
コード例 #4
0
        private async Task <(Dictionary <(string resourceType, string resourceId), Resource> serverData, string groupId)> CreateGroupWithPatient(bool includeAllResources)
        {
            // Add data for test
            var patient         = new Patient();
            var patientResponse = await _testFhirClient.CreateAsync(patient);

            var patientId = patientResponse.Resource.Id;

            var relative = new RelatedPerson()
            {
                Patient = new ResourceReference($"{KnownResourceTypes.Patient}/{patientId}"),
            };

            var relativeResponse = await _testFhirClient.CreateAsync(relative);

            var relativeId = relativeResponse.Resource.Id;

            var encounter = new Encounter()
            {
                Status = Encounter.EncounterStatus.InProgress,
                Class  = new Coding()
                {
                    Code = "test",
                },
                Subject = new ResourceReference($"{KnownResourceTypes.Patient}/{patientId}"),
            };

            var encounterResponse = await _testFhirClient.CreateAsync(encounter);

            var encounterId = encounterResponse.Resource.Id;

            var observation = new Observation()
            {
                Status = ObservationStatus.Final,
                Code   = new CodeableConcept()
                {
                    Coding = new List <Coding>()
                    {
                        new Coding()
                        {
                            Code = "test",
                        },
                    },
                },
                Subject = new ResourceReference($"{KnownResourceTypes.Patient}/{patientId}"),
            };

            var observationResponse = await _testFhirClient.CreateAsync(observation);

            var observationId = observationResponse.Resource.Id;

            var group = new FhirGroup()
            {
                Type   = FhirGroup.GroupType.Person,
                Actual = true,
                Member = new List <FhirGroup.MemberComponent>()
                {
                    new FhirGroup.MemberComponent()
                    {
                        Entity = new ResourceReference($"{KnownResourceTypes.Patient}/{patientId}"),
                    },
                },
            };

            var groupResponse = await _testFhirClient.CreateAsync(group);

            var groupId = groupResponse.Resource.Id;

            var resourceDictionary = new Dictionary <(string resourceType, string resourceId), Resource>();

            resourceDictionary.Add((KnownResourceTypes.RelatedPerson, relativeId), relativeResponse.Resource);
            resourceDictionary.Add((KnownResourceTypes.Encounter, encounterId), encounterResponse.Resource);

            if (includeAllResources)
            {
                resourceDictionary.Add((KnownResourceTypes.Patient, patientId), patientResponse.Resource);
                resourceDictionary.Add((KnownResourceTypes.Observation, observationId), observationResponse.Resource);
                resourceDictionary.Add((KnownResourceTypes.Group, groupId), groupResponse.Resource);
            }

            return(resourceDictionary, groupId);
        }
コード例 #5
0
        public static void SerializeGroup(Hl7.Fhir.Model.Group value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartRootObject("Group");
            writer.WriteStartComplexContent();

            // Serialize element _id
            if (value.LocalIdElement != null)
            {
                writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute);
            }

            // Serialize element extension
            if (value.Extension != null && !summary && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach (var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element language
            if (value.LanguageElement != null && !summary)
            {
                writer.WriteStartElement("language");
                CodeSerializer.SerializeCode(value.LanguageElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element text
            if (value.Text != null && !summary)
            {
                writer.WriteStartElement("text");
                NarrativeSerializer.SerializeNarrative(value.Text, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element contained
            if (value.Contained != null && !summary && value.Contained.Count > 0)
            {
                writer.WriteStartArrayElement("contained");
                foreach (var item in value.Contained)
                {
                    writer.WriteStartArrayMember("contained");
                    FhirSerializer.SerializeResource(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element identifier
            if (value.Identifier != null)
            {
                writer.WriteStartElement("identifier");
                IdentifierSerializer.SerializeIdentifier(value.Identifier, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element type
            if (value.TypeElement != null)
            {
                writer.WriteStartElement("type");
                CodeSerializer.SerializeCode <Hl7.Fhir.Model.Group.GroupType>(value.TypeElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element actual
            if (value.ActualElement != null)
            {
                writer.WriteStartElement("actual");
                FhirBooleanSerializer.SerializeFhirBoolean(value.ActualElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element code
            if (value.Code != null)
            {
                writer.WriteStartElement("code");
                CodeableConceptSerializer.SerializeCodeableConcept(value.Code, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element name
            if (value.NameElement != null)
            {
                writer.WriteStartElement("name");
                FhirStringSerializer.SerializeFhirString(value.NameElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element quantity
            if (value.QuantityElement != null)
            {
                writer.WriteStartElement("quantity");
                IntegerSerializer.SerializeInteger(value.QuantityElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element characteristic
            if (value.Characteristic != null && !summary && value.Characteristic.Count > 0)
            {
                writer.WriteStartArrayElement("characteristic");
                foreach (var item in value.Characteristic)
                {
                    writer.WriteStartArrayMember("characteristic");
                    GroupSerializer.SerializeGroupCharacteristicComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element member
            if (value.Member != null && !summary && value.Member.Count > 0)
            {
                writer.WriteStartArrayElement("member");
                foreach (var item in value.Member)
                {
                    writer.WriteStartArrayMember("member");
                    ResourceReferenceSerializer.SerializeResourceReference(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }


            writer.WriteEndComplexContent();
            writer.WriteEndRootObject();
        }
コード例 #6
0
      public override IDeepCopyable CopyTo(IDeepCopyable other)
      {
        var dest = other as GroupComponent;

        if (dest == null)
        {
          throw new ArgumentException("Can only copy to an object of the same type", "other");
        }

        base.CopyTo(dest);
        if(LinkIdElement != null) dest.LinkIdElement = (Hl7.Fhir.Model.FhirString)LinkIdElement.DeepCopy();
        if(TitleElement != null) dest.TitleElement = (Hl7.Fhir.Model.FhirString)TitleElement.DeepCopy();
        if(Concept != null) dest.Concept = new List<Hl7.Fhir.Model.Coding>(Concept.DeepCopy());
        if(TextElement != null) dest.TextElement = (Hl7.Fhir.Model.FhirString)TextElement.DeepCopy();
        if(RequiredElement != null) dest.RequiredElement = (Hl7.Fhir.Model.FhirBoolean)RequiredElement.DeepCopy();
        if(RepeatsElement != null) dest.RepeatsElement = (Hl7.Fhir.Model.FhirBoolean)RepeatsElement.DeepCopy();
        if(Group != null) dest.Group = new List<Hl7.Fhir.Model.Questionnaire.GroupComponent>(Group.DeepCopy());
        if(Question != null) dest.Question = new List<Hl7.Fhir.Model.Questionnaire.QuestionComponent>(Question.DeepCopy());
        return dest;
      }