private static PersonItem GetProvider(Hl7.Fhir.Model.Immunization fhirImmunization) { var practitionerComponent = fhirImmunization.Practitioner.First(); //Let's take only the first one if (practitionerComponent.Actor.IsContainedReference) { var containedReference = fhirImmunization.Contained.SingleOrDefault(resouce => resouce.Id.Equals(practitionerComponent.Actor.Reference) && resouce.GetType().Equals(typeof(Practitioner))); if (containedReference == null) { return(null); } return((containedReference as Practitioner).ToHealthVault()); } if (string.IsNullOrEmpty(practitionerComponent.Actor.Display)) { return(null); } return(new PersonItem() { Name = new Name(practitionerComponent.Actor.Display) }); }
public static ItemTypes.Immunization ToHealthVault(this Hl7.Fhir.Model.Immunization fhirImmunization) { ItemTypes.Immunization hvImmunization = fhirImmunization.ToThingBase <ItemTypes.Immunization>(); hvImmunization.Name = fhirImmunization.VaccineCode.ToCodableValue(); if (!fhirImmunization.DateElement.IsNullOrEmpty()) { hvImmunization.DateAdministrated = fhirImmunization.DateElement.ToAproximateDateTime(); } if (!fhirImmunization.Practitioner.IsNullOrEmpty()) { hvImmunization.Administrator = GetProvider(fhirImmunization); } if (!fhirImmunization.Manufacturer.IsNullOrEmpty()) { hvImmunization.Manufacturer = GetManufacturer(fhirImmunization); } hvImmunization.Lot = fhirImmunization.LotNumber; hvImmunization.Route = fhirImmunization.Route.ToCodableValue(); if (fhirImmunization.ExpirationDateElement != null) { hvImmunization.ExpirationDate = fhirImmunization.ExpirationDateElement.ToAproximateDateTime().ApproximateDate; } hvImmunization.AnatomicSurface = fhirImmunization.Site.ToCodableValue(); Extension immunizationExtension = fhirImmunization.GetExtension(HealthVaultExtensions.ImmunizationDetail); if (immunizationExtension != null) { hvImmunization.Sequence = immunizationExtension.GetStringExtension(HealthVaultExtensions.ImmunizationDetailSequence); hvImmunization.Consent = immunizationExtension.GetStringExtension(HealthVaultExtensions.ImmunizationDetailConcent); hvImmunization.AdverseEvent = immunizationExtension.GetStringExtension(HealthVaultExtensions.ImmunizationDetailAdverseEvent); } if (!fhirImmunization.Note.IsNullOrEmpty()) { fhirImmunization.Note.ForEach(note => { string separator = string.Empty; if (!string.IsNullOrEmpty(hvImmunization.CommonData.Note)) { separator = Environment.NewLine; //Let's separate each note with new line } hvImmunization.CommonData.Note += $"{separator}{note.Text}"; }); } return(hvImmunization); }
private static CodableValue GetManufacturer(Hl7.Fhir.Model.Immunization fhirImmunization) { var manufacturerComponent = fhirImmunization.Manufacturer; if (manufacturerComponent.IsContainedReference) { var containedReference = fhirImmunization.Contained.SingleOrDefault(resouce => resouce.Id.Equals(manufacturerComponent.Reference) && resouce.GetType().Equals(typeof(Hl7.Fhir.Model.Organization))); if (containedReference == null) { return(null); } return(new CodableValue((containedReference as Hl7.Fhir.Model.Organization).Name)); } if (string.IsNullOrEmpty(manufacturerComponent.Display)) { return(null); } return(new CodableValue(manufacturerComponent.Display)); }
/// <summary> /// Parse Immunization /// </summary> public static Hl7.Fhir.Model.Immunization ParseImmunization(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Immunization existingInstance = null) { Hl7.Fhir.Model.Immunization result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Immunization(); 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 date else if (atName == "date") { result.DateElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors); } // Parse element vaccineType else if (atName == "vaccineType") { result.VaccineType = CodeableConceptParser.ParseCodeableConcept(reader, errors); } // Parse element subject else if (atName == "subject") { result.Subject = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element refusedIndicator else if (atName == "refusedIndicator") { result.RefusedIndicatorElement = FhirBooleanParser.ParseFhirBoolean(reader, errors); } // Parse element reported else if (atName == "reported") { result.ReportedElement = FhirBooleanParser.ParseFhirBoolean(reader, errors); } // Parse element performer else if (atName == "performer") { result.Performer = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element requester else if (atName == "requester") { result.Requester = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element manufacturer else if (atName == "manufacturer") { result.Manufacturer = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element location else if (atName == "location") { result.Location = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element lotNumber else if (atName == "lotNumber") { result.LotNumberElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element expirationDate else if (atName == "expirationDate") { result.ExpirationDateElement = DateParser.ParseDate(reader, errors); } // Parse element site else if (atName == "site") { result.Site = CodeableConceptParser.ParseCodeableConcept(reader, errors); } // Parse element route else if (atName == "route") { result.Route = CodeableConceptParser.ParseCodeableConcept(reader, errors); } // Parse element doseQuantity else if (atName == "doseQuantity") { result.DoseQuantity = QuantityParser.ParseQuantity(reader, errors); } // Parse element explanation else if (atName == "explanation") { result.Explanation = ImmunizationParser.ParseImmunizationExplanationComponent(reader, errors); } // Parse element reaction else if (atName == "reaction") { result.Reaction = new List <Hl7.Fhir.Model.Immunization.ImmunizationReactionComponent>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "reaction")) { result.Reaction.Add(ImmunizationParser.ParseImmunizationReactionComponent(reader, errors)); } reader.LeaveArray(); } // Parse element vaccinationProtocol else if (atName == "vaccinationProtocol") { result.VaccinationProtocol = ImmunizationParser.ParseImmunizationVaccinationProtocolComponent(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); }
public void WhenImmunizationTransformedToFhir_ThenValuesAreEqual() { var now = new LocalDateTime(2017, 9, 21, 18, 55, 10, 100); var afterOneMonth = new LocalDate(2017, 10, 20); var immunization = new ItemTypes.Immunization { Name = new CodableValue("cholera vaccine", new CodedValue { Value = "26", Family = "HL7", VocabularyName = "vaccines-cvx", Version = "2.3 09_2008" }), DateAdministrated = new ApproximateDateTime(now), Administrator = new PersonItem { Name = new Name { Full = "Justin Case" } }, Manufacturer = new CodableValue("Baxter Healthcare Corporation", new CodedValue { Value = "BA", Family = "HL7", VocabularyName = "vaccine-manufacturers-mvx", Version = "2.3 07_2008" }), Lot = "AAJN11K", Route = new CodableValue("By mouth", new CodedValue { Value = "po", Family = "wc", VocabularyName = "medication-routes", Version = "2" }), ExpirationDate = new ApproximateDate(afterOneMonth), Sequence = "Last", AnatomicSurface = new CodableValue("Metacarpophalangeal joint structure of index finger", new CodedValue { Value = "289002", VocabularyName = "SnomedBodyLocation", Family = "Snomed", Version = "Jan2008" }), AdverseEvent = "Something bad happened", Consent = "A concent from parent goes here" }; immunization.CommonData.Note = "Some note goes here"; Hl7.Fhir.Model.Immunization fhirImmunization = immunization.ToFhir(); Assert.IsNotNull(fhirImmunization); Assert.AreEqual(immunization.Name.Text, fhirImmunization.VaccineCode.Text); Assert.AreEqual(now.ToDateTimeUnspecified(), fhirImmunization.DateElement.ToDateTimeOffset()); var containedPractitioner = fhirImmunization.Contained.Where(resource => resource.GetType().Equals(typeof(Practitioner))).SingleOrDefault() as Practitioner; Assert.IsNotNull(containedPractitioner); Assert.AreEqual(immunization.Administrator.Name.Full, containedPractitioner.Name.Single().Text); var containedOrganization = fhirImmunization.Contained.Where(resource => resource.GetType().Equals(typeof(FhirOrganization))).SingleOrDefault() as FhirOrganization; Assert.IsNotNull(containedOrganization); Assert.AreEqual(immunization.Manufacturer.Text, containedOrganization.Name); Assert.AreEqual(immunization.Lot, fhirImmunization.LotNumber); Assert.AreEqual(immunization.Route.Text, fhirImmunization.Route.Text); Assert.AreEqual(afterOneMonth.ToDateTimeUnspecified().ToUniversalTime(), fhirImmunization.ExpirationDateElement.ToPartialDateTime().Value.ToUniversalTime()); Assert.AreEqual(immunization.AnatomicSurface.Text, fhirImmunization.Site.Text); var immunizationExtension = fhirImmunization.GetExtension(HealthVaultExtensions.ImmunizationDetail); Assert.AreEqual(immunization.AdverseEvent, immunizationExtension.GetStringExtension(HealthVaultExtensions.ImmunizationDetailAdverseEvent)); Assert.AreEqual(immunization.Consent, immunizationExtension.GetStringExtension(HealthVaultExtensions.ImmunizationDetailConcent)); Assert.AreEqual(immunization.Sequence, immunizationExtension.GetStringExtension(HealthVaultExtensions.ImmunizationDetailSequence)); Assert.IsFalse(fhirImmunization.Note.IsNullOrEmpty()); Assert.AreEqual(immunization.CommonData.Note, fhirImmunization.Note.First().Text); }
public static void SerializeImmunization(Hl7.Fhir.Model.Immunization value, IFhirWriter writer, bool summary) { writer.WriteStartRootObject("Immunization"); 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 date if (value.DateElement != null && !summary) { writer.WriteStartElement("date"); FhirDateTimeSerializer.SerializeFhirDateTime(value.DateElement, writer, summary); writer.WriteEndElement(); } // Serialize element vaccineType if (value.VaccineType != null && !summary) { writer.WriteStartElement("vaccineType"); CodeableConceptSerializer.SerializeCodeableConcept(value.VaccineType, writer, summary); writer.WriteEndElement(); } // Serialize element subject if (value.Subject != null && !summary) { writer.WriteStartElement("subject"); ResourceReferenceSerializer.SerializeResourceReference(value.Subject, writer, summary); writer.WriteEndElement(); } // Serialize element refusedIndicator if (value.RefusedIndicatorElement != null && !summary) { writer.WriteStartElement("refusedIndicator"); FhirBooleanSerializer.SerializeFhirBoolean(value.RefusedIndicatorElement, writer, summary); writer.WriteEndElement(); } // Serialize element reported if (value.ReportedElement != null && !summary) { writer.WriteStartElement("reported"); FhirBooleanSerializer.SerializeFhirBoolean(value.ReportedElement, writer, summary); writer.WriteEndElement(); } // Serialize element performer if (value.Performer != null && !summary) { writer.WriteStartElement("performer"); ResourceReferenceSerializer.SerializeResourceReference(value.Performer, writer, summary); writer.WriteEndElement(); } // Serialize element requester if (value.Requester != null && !summary) { writer.WriteStartElement("requester"); ResourceReferenceSerializer.SerializeResourceReference(value.Requester, writer, summary); writer.WriteEndElement(); } // Serialize element manufacturer if (value.Manufacturer != null && !summary) { writer.WriteStartElement("manufacturer"); ResourceReferenceSerializer.SerializeResourceReference(value.Manufacturer, writer, summary); writer.WriteEndElement(); } // Serialize element location if (value.Location != null && !summary) { writer.WriteStartElement("location"); ResourceReferenceSerializer.SerializeResourceReference(value.Location, writer, summary); writer.WriteEndElement(); } // Serialize element lotNumber if (value.LotNumberElement != null && !summary) { writer.WriteStartElement("lotNumber"); FhirStringSerializer.SerializeFhirString(value.LotNumberElement, writer, summary); writer.WriteEndElement(); } // Serialize element expirationDate if (value.ExpirationDateElement != null && !summary) { writer.WriteStartElement("expirationDate"); DateSerializer.SerializeDate(value.ExpirationDateElement, writer, summary); writer.WriteEndElement(); } // Serialize element site if (value.Site != null && !summary) { writer.WriteStartElement("site"); CodeableConceptSerializer.SerializeCodeableConcept(value.Site, writer, summary); writer.WriteEndElement(); } // Serialize element route if (value.Route != null && !summary) { writer.WriteStartElement("route"); CodeableConceptSerializer.SerializeCodeableConcept(value.Route, writer, summary); writer.WriteEndElement(); } // Serialize element doseQuantity if (value.DoseQuantity != null && !summary) { writer.WriteStartElement("doseQuantity"); QuantitySerializer.SerializeQuantity(value.DoseQuantity, writer, summary); writer.WriteEndElement(); } // Serialize element explanation if (value.Explanation != null && !summary) { writer.WriteStartElement("explanation"); ImmunizationSerializer.SerializeImmunizationExplanationComponent(value.Explanation, writer, summary); writer.WriteEndElement(); } // Serialize element reaction if (value.Reaction != null && !summary && value.Reaction.Count > 0) { writer.WriteStartArrayElement("reaction"); foreach (var item in value.Reaction) { writer.WriteStartArrayMember("reaction"); ImmunizationSerializer.SerializeImmunizationReactionComponent(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element vaccinationProtocol if (value.VaccinationProtocol != null && !summary) { writer.WriteStartElement("vaccinationProtocol"); ImmunizationSerializer.SerializeImmunizationVaccinationProtocolComponent(value.VaccinationProtocol, writer, summary); writer.WriteEndElement(); } writer.WriteEndComplexContent(); writer.WriteEndRootObject(); }
internal static Hl7.Fhir.Model.Immunization ToFhirInternal(ItemTypes.Immunization hvImmunization, Hl7.Fhir.Model.Immunization fhirImmunization) { fhirImmunization.VaccineCode = hvImmunization.Name.ToFhir(); fhirImmunization.DateElement = hvImmunization.DateAdministrated.ToFhir(); if (hvImmunization.Administrator != null) { fhirImmunization.Practitioner.Add(new Hl7.Fhir.Model.Immunization.PractitionerComponent { Actor = AddContainedResource(fhirImmunization, hvImmunization.Administrator.ToFhir()) }); } if (hvImmunization.Manufacturer != null) { fhirImmunization.Manufacturer = AddContainedResource(fhirImmunization, new Hl7.Fhir.Model.Organization { Name = hvImmunization.Manufacturer.Text }); } fhirImmunization.LotNumber = hvImmunization.Lot; fhirImmunization.Route = hvImmunization.Route.ToFhir(); fhirImmunization.ExpirationDateElement = hvImmunization.ExpirationDate.ToFhir(); if (!string.IsNullOrEmpty(hvImmunization.Sequence) || !string.IsNullOrEmpty(hvImmunization.AdverseEvent) || !string.IsNullOrEmpty(hvImmunization.Consent)) { var immunizationExtension = new Extension { Url = HealthVaultExtensions.ImmunizationDetail }; if (!string.IsNullOrEmpty(hvImmunization.Sequence)) { immunizationExtension.AddExtension(HealthVaultExtensions.ImmunizationDetailSequence, new FhirString(hvImmunization.Sequence)); } if (!string.IsNullOrEmpty(hvImmunization.Consent)) { immunizationExtension.AddExtension(HealthVaultExtensions.ImmunizationDetailConcent, new FhirString(hvImmunization.Consent)); } if (!string.IsNullOrEmpty(hvImmunization.AdverseEvent)) { immunizationExtension.AddExtension(HealthVaultExtensions.ImmunizationDetailAdverseEvent, new FhirString(hvImmunization.AdverseEvent)); } fhirImmunization.Extension.Add(immunizationExtension); } fhirImmunization.Site = hvImmunization.AnatomicSurface.ToFhir(); fhirImmunization.Note.Add(new Hl7.Fhir.Model.Annotation { Text = hvImmunization.CommonData.Note }); //Setting default values that is not available in HealthVault. Let's revisit when a good //approach is found for better fidelity between Fhir & HV fhirImmunization.Status = Hl7.Fhir.Model.Immunization.ImmunizationStatusCodes.Completed; fhirImmunization.NotGiven = false; fhirImmunization.PrimarySource = true; return(fhirImmunization); }