예제 #1
0
        /// <inheritdoc/>
        public async Task <RequestResult <ImmunizationResult> > GetImmunizations(string bearerToken, int pageIndex = 0)
        {
            RequestResult <PHSAResult <ImmunizationResponse> > delegateResult = await this.immunizationDelegate.GetImmunizations(bearerToken, pageIndex).ConfigureAwait(true);

            if (delegateResult.ResultStatus == ResultType.Success)
            {
                return(new RequestResult <ImmunizationResult>()
                {
                    ResultStatus = delegateResult.ResultStatus,
                    ResourcePayload = new ImmunizationResult()
                    {
                        LoadState = LoadStateModel.FromPHSAModel(delegateResult.ResourcePayload.LoadState),
                        Immunizations = ImmunizationEvent.FromPHSAModelList(delegateResult.ResourcePayload.Result.ImmunizationViews),
                        Recommendations = ImmunizationRecommendation.FromPHSAModelList(delegateResult.ResourcePayload.Result.Recommendations),
                    },
                    PageIndex = delegateResult.PageIndex,
                    PageSize = delegateResult.PageSize,
                    TotalResultCount = delegateResult.TotalResultCount,
                });
            }
            else
            {
                return(new RequestResult <ImmunizationResult>()
                {
                    ResultStatus = delegateResult.ResultStatus,
                    ResultError = delegateResult.ResultError,
                });
            }
        }
예제 #2
0
        /// <summary>
        /// Deserialize JSON into a FHIR ImmunizationRecommendation
        /// </summary>
        public static void DeserializeJson(this ImmunizationRecommendation current, ref Utf8JsonReader reader, JsonSerializerOptions options)
        {
            string propertyName;

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    return;
                }

                if (reader.TokenType == JsonTokenType.PropertyName)
                {
                    propertyName = reader.GetString();
                    if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug)
                    {
                        Console.WriteLine($"ImmunizationRecommendation >>> ImmunizationRecommendation.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"ImmunizationRecommendation: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
예제 #3
0
        /// <summary>
        /// Serialize a FHIR ImmunizationRecommendation into JSON
        /// </summary>
        public static void SerializeJson(this ImmunizationRecommendation current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            writer.WriteString("resourceType", "ImmunizationRecommendation");
            // Complex: ImmunizationRecommendation, Export: ImmunizationRecommendation, Base: DomainResource (DomainResource)
            ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false);

            if ((current.Identifier != null) && (current.Identifier.Count != 0))
            {
                writer.WritePropertyName("identifier");
                writer.WriteStartArray();
                foreach (Identifier val in current.Identifier)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            writer.WritePropertyName("patient");
            current.Patient.SerializeJson(writer, options);

            writer.WriteString("date", current.DateElement.Value);

            if (current.Authority != null)
            {
                writer.WritePropertyName("authority");
                current.Authority.SerializeJson(writer, options);
            }

            if ((current.Recommendation != null) && (current.Recommendation.Count != 0))
            {
                writer.WritePropertyName("recommendation");
                writer.WriteStartArray();
                foreach (ImmunizationRecommendation.RecommendationComponent val in current.Recommendation)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
예제 #4
0
        /// <summary>
        /// Deserialize JSON into a FHIR ImmunizationRecommendation
        /// </summary>
        public static void DeserializeJsonProperty(this ImmunizationRecommendation current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "identifier":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"ImmunizationRecommendation error reading 'identifier' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Identifier = new List <Identifier>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Identifier v_Identifier = new Hl7.Fhir.Model.Identifier();
                    v_Identifier.DeserializeJson(ref reader, options);
                    current.Identifier.Add(v_Identifier);

                    if (!reader.Read())
                    {
                        throw new JsonException($"ImmunizationRecommendation error reading 'identifier' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Identifier.Count == 0)
                {
                    current.Identifier = null;
                }
                break;

            case "patient":
                current.Patient = new Hl7.Fhir.Model.ResourceReference();
                ((Hl7.Fhir.Model.ResourceReference)current.Patient).DeserializeJson(ref reader, options);
                break;

            case "date":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.DateElement = new FhirDateTime();
                    reader.Skip();
                }
                else
                {
                    current.DateElement = new FhirDateTime(reader.GetString());
                }
                break;

            case "_date":
                if (current.DateElement == null)
                {
                    current.DateElement = new FhirDateTime();
                }
                ((Hl7.Fhir.Model.Element)current.DateElement).DeserializeJson(ref reader, options);
                break;

            case "authority":
                current.Authority = new Hl7.Fhir.Model.ResourceReference();
                ((Hl7.Fhir.Model.ResourceReference)current.Authority).DeserializeJson(ref reader, options);
                break;

            case "recommendation":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"ImmunizationRecommendation error reading 'recommendation' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Recommendation = new List <ImmunizationRecommendation.RecommendationComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ImmunizationRecommendation.RecommendationComponent v_Recommendation = new Hl7.Fhir.Model.ImmunizationRecommendation.RecommendationComponent();
                    v_Recommendation.DeserializeJson(ref reader, options);
                    current.Recommendation.Add(v_Recommendation);

                    if (!reader.Read())
                    {
                        throw new JsonException($"ImmunizationRecommendation error reading 'recommendation' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Recommendation.Count == 0)
                {
                    current.Recommendation = null;
                }
                break;

            // Complex: ImmunizationRecommendation, Export: ImmunizationRecommendation, Base: DomainResource
            default:
                ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
예제 #5
0
        public void ValidateRecomendation()
        {
            string recomendationSetId        = "set-recomendation-id";
            string diseaseEligibleDateString = "2021-02-02";
            string diseaseName = "Human papillomavirus infection";
            string vaccineName = "Human Papillomavirus-HPV9 Vaccine";
            string antigenName = "HPV-9";

            var mockDelegate = new Mock <IImmunizationDelegate>();
            RequestResult <PHSAResult <ImmunizationResponse> > delegateResult = new RequestResult <PHSAResult <ImmunizationResponse> >()
            {
                ResultStatus    = Common.Constants.ResultType.Success,
                ResourcePayload = new PHSAResult <ImmunizationResponse>()
                {
                    LoadState = new PHSALoadState()
                    {
                        RefreshInProgress = false,
                    },
                    Result = new ImmunizationResponse()
                    {
                        Recommendations = new List <ImmunizationRecommendationResponse>()
                        {
                            new ImmunizationRecommendationResponse()
                            {
                                ForecastCreationDate         = DateTime.Now,
                                RecommendationId             = recomendationSetId,
                                RecommendationSourceSystem   = "MockSourceSystem",
                                RecommendationSourceSystemId = "MockSourceID",
                                Recommendations = new List <RecommendationResponse>()
                                {
                                    new RecommendationResponse()
                                    {
                                        DateCriterions = new List <DateCriterion>()
                                        {
                                            new DateCriterion()
                                            {
                                                DateCriterionCode = new DateCriterionCode()
                                                {
                                                    text = "Forecast by Disease Eligible Date"
                                                },
                                                Value = diseaseEligibleDateString
                                            }
                                        },
                                        ForecastStatus = new ForecastStatusModel()
                                        {
                                            ForecastStatusText = "Eligible"
                                        },
                                        TargetDisease = new TargetDiseaseResponse()
                                        {
                                            targetDiseaseCodes = new List <SystemCode>()
                                            {
                                                new SystemCode()
                                                {
                                                    Code       = "240532009",
                                                    CommonType = "DiseaseCode",
                                                    Display    = diseaseName,
                                                    System     = "https://ehealthbc.ca/NamingSystem/ca-bc-panorama-immunization-disease-code"
                                                }
                                            }
                                        },
                                        VaccineCode = new VaccineCode()
                                        {
                                            VaccineCodeText = vaccineName,
                                            VaccineCodes    = new List <SystemCode>()
                                            {
                                                new SystemCode()
                                                {
                                                    Code       = "BCYSCT_AN032",
                                                    CommonType = "AntiGenCode",
                                                    Display    = antigenName,
                                                    System     = "https://ehealthbc.ca/NamingSystem/ca-bc-panorama-immunization-antigen-code"
                                                }
                                            }
                                        },
                                    }
                                },
                            }
                        },
                    },
                },
                PageIndex        = 0,
                PageSize         = 5,
                TotalResultCount = 1,
            };
            RequestResult <ImmunizationResult> expectedResult = new RequestResult <ImmunizationResult>()
            {
                ResultStatus    = delegateResult.ResultStatus,
                ResourcePayload = new ImmunizationResult()
                {
                    LoadState       = LoadStateModel.FromPHSAModel(delegateResult.ResourcePayload.LoadState),
                    Recommendations = ImmunizationRecommendation.FromPHSAModelList(delegateResult.ResourcePayload.Result.Recommendations),
                },
                PageIndex        = delegateResult.PageIndex,
                PageSize         = delegateResult.PageSize,
                TotalResultCount = delegateResult.TotalResultCount,
            };

            mockDelegate.Setup(s => s.GetImmunizations(It.IsAny <string>(), It.IsAny <int>())).Returns(Task.FromResult(delegateResult));
            IImmunizationService service = new ImmunizationService(new Mock <ILogger <ImmunizationService> >().Object, mockDelegate.Object);

            var actualResult = service.GetImmunizations(string.Empty, 0);

            Assert.True(expectedResult.IsDeepEqual(actualResult.Result));
            Assert.Equal(1, expectedResult.ResourcePayload.Recommendations.Count);
            var recomendationResult = expectedResult.ResourcePayload.Recommendations[0];

            Assert.Equal(recomendationSetId, recomendationResult.RecommendationSetId);
            Assert.Equal(vaccineName, recomendationResult.Immunization.Name);
            Assert.Equal(1, recomendationResult.Immunization.ImmunizationAgents.Count());
            Assert.Equal(antigenName, recomendationResult.Immunization.ImmunizationAgents.First().Name);
            Assert.Equal(1, recomendationResult.TargetDiseases.Count());
            Assert.Equal(diseaseName, recomendationResult.TargetDiseases.First().Name);
            Assert.Equal(DateTime.Parse(diseaseEligibleDateString), recomendationResult.DisseaseEligibleDate);
            Assert.Null(recomendationResult.DiseaseDueDate);
            Assert.Null(recomendationResult.AgentDueDate);
            Assert.Null(recomendationResult.AgentEligibleDate);
        }