Esempio n. 1
0
        public void RenderPeriod()
        {
            var p = new Period { Start = "200401" };
            Assert.AreEqual("[200401,∞]", p.ForDisplay());

            p.End = "20050212";
            Assert.AreEqual("[200401,20050212]", p.ForDisplay());

            p.Start = null;
            Assert.AreEqual("[∞,20050212]", p.ForDisplay());
        }
        /// <summary>
        /// Parse Period
        /// </summary>
        public static Hl7.Fhir.Model.Period ParsePeriod(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Period existingInstance = null)
        {
            Hl7.Fhir.Model.Period result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Period();
            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 _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element start
                else if (atName == "start")
                {
                    result.StartElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                }

                // Parse element end
                else if (atName == "end")
                {
                    result.EndElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors);
                }

                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);
        }
Esempio n. 3
0
        public static void SerializePeriod(Hl7.Fhir.Model.Period value, IFhirWriter writer, bool summary)
        {
            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 start
            if (value.StartElement != null)
            {
                writer.WriteStartElement("start");
                FhirDateTimeSerializer.SerializeFhirDateTime(value.StartElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element end
            if (value.EndElement != null)
            {
                writer.WriteStartElement("end");
                FhirDateTimeSerializer.SerializeFhirDateTime(value.EndElement, writer, summary);
                writer.WriteEndElement();
            }


            writer.WriteEndComplexContent();
        }
Esempio n. 4
0
        public static Period ToPeriod(this FhirDateTime fdt)
        {
            var result = new Period();
            var dtoStart = fdt.ToDateTimeOffset();
            result.StartElement = new FhirDateTime(dtoStart);
            var dtoEnd = dtoStart;

            switch (fdt.Precision())
            {
                case FhirDateTimePrecision.Year: dtoEnd = dtoStart.AddYears(1); break;
                case FhirDateTimePrecision.Month: dtoEnd = dtoStart.AddMonths(1); break;
                case FhirDateTimePrecision.Day: dtoEnd = dtoStart.AddDays(1); break;
                case FhirDateTimePrecision.Minute: dtoEnd = dtoStart.AddMinutes(1); break;
                case FhirDateTimePrecision.Second: dtoEnd = dtoStart.AddSeconds(1); break;
                default: dtoEnd = dtoStart; break;
            }

            result.EndElement = new FhirDateTime(dtoEnd);
            return result;
        }
Esempio n. 5
0
        /// <summary>
        /// { start : lowerbound-of-period-start, end : upperbound-of-period-end }
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>

        private List <Expression> ToExpressions(FhirModel.Period element)
        {
            if (element == null || (element.StartElement == null && element.EndElement == null))
            {
                return(null);
            }

            var bounds = new List <IndexValue>();

            if (element.StartElement != null)
            {
                bounds.Add(new IndexValue("start", new DateTimeValue(element.StartElement.LowerBound())));
            }
            if (element.EndElement != null)
            {
                bounds.Add(new IndexValue("end", new DateTimeValue(element.EndElement.UpperBound())));
            }

            return(ListOf(new CompositeValue(bounds)));
        }
        public void Write(Definition definition, Period period)
        {
            string start = definition.Argument.GroomElement(period.Start);
            string end = definition.Argument.GroomElement(period.End);

            BsonDocument value = new BsonDocument()
                {
                    { "start", start },
                    { "end", end }
                };
            document.Write(definition.ParamName, value);
        }
Esempio n. 7
0
 public void PeriodWithStartAndEndMapTest()
 {
     var input = new Period();
     input.StartElement = new FhirDateTime("2015-02");
     input.EndElement = new FhirDateTime("2015-03");
     var result = sut.Map(input);
     CheckPeriod(result, "2015-02-01T00:00:00+01:00", "2015-04-01T00:00:00+01:00");
 }
Esempio n. 8
0
 public void PeriodWithJustEndMapTest()
 {
     var input = new Period();
     input.EndElement = new FhirDateTime("2015-03");
     var result = sut.Map(input);
     CheckPeriod(result, null, "2015-04-01T00:00:00+01:00");
 }
Esempio n. 9
0
 public void PeriodWithJustStartMapTest()
 {
     var input = new Period();
     input.StartElement = new FhirDateTime("2015-02");
     var result = sut.Map(input);
     CheckPeriod(result, "2015-02-01T00:00:00+01:00", null);
 }
Esempio n. 10
0
        /// <summary>
        /// Deserialize JSON into a FHIR Appointment
        /// </summary>
        public static void DeserializeJsonProperty(this Appointment current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "identifier":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"Appointment 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($"Appointment 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 "status":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.StatusElement = new Code <Hl7.Fhir.Model.Appointment.AppointmentStatus>();
                    reader.Skip();
                }
                else
                {
                    current.StatusElement = new Code <Hl7.Fhir.Model.Appointment.AppointmentStatus>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.Appointment.AppointmentStatus>(reader.GetString()));
                }
                break;

            case "_status":
                if (current.StatusElement == null)
                {
                    current.StatusElement = new Code <Hl7.Fhir.Model.Appointment.AppointmentStatus>();
                }
                ((Hl7.Fhir.Model.Element)current.StatusElement).DeserializeJson(ref reader, options);
                break;

            case "cancelationReason":
                current.CancelationReason = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.CancelationReason).DeserializeJson(ref reader, options);
                break;

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

                current.ServiceCategory = new List <CodeableConcept>();

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

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

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

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

                current.ServiceType = new List <CodeableConcept>();

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

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

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

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

                current.Specialty = new List <CodeableConcept>();

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

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

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

            case "appointmentType":
                current.AppointmentType = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.AppointmentType).DeserializeJson(ref reader, options);
                break;

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

                current.ReasonCode = new List <CodeableConcept>();

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

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

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

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

                current.ReasonReference = new List <ResourceReference>();

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

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

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

            case "priority":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.PriorityElement = new UnsignedInt();
                    reader.Skip();
                }
                else
                {
                    current.PriorityElement = new UnsignedInt(reader.GetInt32());
                }
                break;

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

            case "description":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.DescriptionElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.DescriptionElement = new FhirString(reader.GetString());
                }
                break;

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

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

                current.SupportingInformation = new List <ResourceReference>();

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

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

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

            case "start":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.StartElement = new Instant();
                    reader.Skip();
                }
                else
                {
                    current.StartElement = new Instant(DateTimeOffset.Parse(reader.GetString()));
                }
                break;

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

            case "end":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.EndElement = new Instant();
                    reader.Skip();
                }
                else
                {
                    current.EndElement = new Instant(DateTimeOffset.Parse(reader.GetString()));
                }
                break;

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

            case "minutesDuration":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.MinutesDurationElement = new PositiveInt();
                    reader.Skip();
                }
                else
                {
                    current.MinutesDurationElement = new PositiveInt(reader.GetInt32());
                }
                break;

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

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

                current.Slot = new List <ResourceReference>();

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

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

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

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

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

            case "comment":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.CommentElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.CommentElement = new FhirString(reader.GetString());
                }
                break;

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

            case "patientInstruction":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.PatientInstructionElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.PatientInstructionElement = new FhirString(reader.GetString());
                }
                break;

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

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

                current.BasedOn = new List <ResourceReference>();

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

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

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

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

                current.Participant = new List <Appointment.ParticipantComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Appointment.ParticipantComponent v_Participant = new Hl7.Fhir.Model.Appointment.ParticipantComponent();
                    v_Participant.DeserializeJson(ref reader, options);
                    current.Participant.Add(v_Participant);

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

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

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

                current.RequestedPeriod = new List <Period>();

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

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

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

            // Complex: Appointment, Export: Appointment, Base: DomainResource
            default:
                ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }