public static void SerializeCode(Hl7.Fhir.Model.Code value, IFhirWriter writer, bool summary) { writer.WriteStartComplexContent(); // Serialize element value if (value.Value != null) { writer.WritePrimitiveContents("value", value, XmlSerializationHint.Attribute); } // 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(); } writer.WriteEndComplexContent(); }
private static Profile.ProfileStructureComponent locate(Profile profile, string anchor, Code type) { if(String.IsNullOrEmpty(anchor)) anchor = null; IEnumerable<Profile.ProfileStructureComponent> results = null; if (anchor == null && type == null) { // We have NO structure name and NO type hint. This is only unambiguous if there's just 1 structure in the profile results = profile.Structure; } else if(anchor != null && type == null) { // We have a structure name but NO specific type. This is normally unambiguous, since the name should be unique results = profile.Structure.Where(str => str.Name == anchor); } else if (anchor == null && type != null) { // We don't know the structure name but have it's type. This is unambiguous if there's just one structure of the given type results = profile.Structure.Where(str => str.Type == type.Value); } else { // We have both the name and the type, this should also normally be unique results = profile.Structure.Where(str => str.Name == anchor && str.Type == type.Value); } if (results.Count() <= 1) return results.SingleOrDefault(); else throw Error.InvalidOperation("Cannot unambiguously determine structure to locate based on the given combination of url, anchor and structure type"); }
/// <summary> /// Parse code /// </summary> public static Hl7.Fhir.Model.Code ParseCode(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Code existingInstance = null) { Hl7.Fhir.Model.Code result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Code(); 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 value else if (atName == "value") { result.Value = Code.Parse(reader.ReadPrimitiveContents(typeof(Code))).Value; } 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); }
/// <summary> /// Locate a structures within a profile given by an uri /// </summary> /// <param name="structureUri">An Uri pointing to a profile or a structure within a profile</param> /// <param name="type">Resource or Datatype that the structure is constraining</param> /// <returns>The structure as indicated by the uri or null if it was not found</returns> /// <remarks>This function accepts an uri that has only the profile's address, or a uri that has both the /// address and an achor indicating the name of the structure to locate (e.g. http://someplace.org/fhir/Profiles/myprofile#somestructure). /// </remarks> public Profile.ProfileStructureComponent Locate(Uri structureUri, Code type = null) { if (structureUri == null) throw Error.ArgumentNull("structureUri"); if (!structureUri.IsAbsoluteUri) throw Error.Argument("Reference to structure must be an absolute url"); // The structure Uri might be of the form <url-to-profile>#<structure name> // First split off the <url-to-profile> and load the profile var uriWithoutAnchor = new UriBuilder(structureUri); uriWithoutAnchor.Fragment = null; var profile = loadProfile(uriWithoutAnchor.Uri); // If the profile was not found, return without doing work if (profile == null || profile.Structure == null || profile.Structure.Count == 0) return null; // Determine the anchor, which we use to locate the structure by comparing it to Structure.name var anchor = structureUri.Fragment.TrimStart('#'); return locate(profile, anchor, type); }
public void Write(Definition definition, Code code) { if (code != null) { Write(definition, code.Value); } }
private static ElementNavigator resolveStructureReference(StructureLoader loader, Code code) { var result = loader.LocateBaseStructure(code); return result != null ? new ElementNavigator(result) : null; }
public void ExtensionManagement() { Patient p = new Patient(); var u1 = "http://fhir.org/ext/ext-test"; Assert.IsNull(p.GetExtension("http://fhir.org/ext/ext-test")); Extension newEx = p.SetExtension(u1, new FhirBoolean(true)); Assert.AreSame(newEx, p.GetExtension(u1)); p.AddExtension("http://fhir.org/ext/ext-test2", new FhirString("Ewout")); Assert.AreSame(newEx, p.GetExtension(u1)); p.RemoveExtension(u1); Assert.IsNull(p.GetExtension(u1)); p.SetExtension("http://fhir.org/ext/ext-test2", new FhirString("Ewout Kramer")); var ew = p.GetExtensions("http://fhir.org/ext/ext-test2"); Assert.AreEqual(1, ew.Count()); p.AddExtension("http://fhir.org/ext/ext-test2", new FhirString("Wouter Kramer")); ew = p.GetExtensions("http://fhir.org/ext/ext-test2"); Assert.AreEqual(2, ew.Count()); Assert.AreEqual(0, p.ModifierExtension.Count()); var me = p.AddExtension("http://fhir.org/ext/ext-test3", new FhirString("bla"), isModifier:true); Assert.AreEqual(1, p.ModifierExtension.Count()); Assert.AreEqual(me, p.GetExtension("http://fhir.org/ext/ext-test3")); Assert.AreEqual(me, p.GetExtensions("http://fhir.org/ext/ext-test3").Single()); Assert.AreEqual(3, p.AllExtensions().Count()); var code = new Code("test"); p.AddExtension("http://fhir.org/ext/code", code); Assert.AreEqual(code, p.GetExtensionValue<Code>("http://fhir.org/ext/code")); var text = new FhirString("test"); p.AddExtension("http://fhir.org/ext/string", text); Assert.AreEqual(text, p.GetExtensionValue<FhirString>("http://fhir.org/ext/string")); var fhirbool = new FhirBoolean(true); p.AddExtension("http://fhir.org/ext/bool", fhirbool); Assert.AreEqual(fhirbool, p.GetExtensionValue<FhirBoolean>("http://fhir.org/ext/bool")); }
public void CodedEnumMapTest() { var input = new Code<AdministrativeGender>(AdministrativeGender.Male); var result = sut.Map(input); Assert.AreEqual(1, result.Count()); Assert.IsInstanceOfType(result[0], typeof(StringValue)); Assert.AreEqual("male", (result[0] as StringValue).Value); }
public void CodeMapTest() { var input = new Code("bla"); var result = sut.Map(input); Assert.AreEqual(1, result.Count()); Assert.IsInstanceOfType(result[0], typeof(StringValue)); Assert.AreEqual("bla", (result[0] as StringValue).Value); }
private List <Expression> ToExpressions(FhirModel.Code element) { return(element != null?ListOf(new StringValue(element.Value)) : null); }
/// <summary> /// Locate base structures for a given FHIR core type /// </summary> /// <param name="type">The Resource or Datatype to locate</param> /// <returns></returns> public Profile.ProfileStructureComponent LocateBaseStructure(Code type) { return Locate(BuildBaseStructureUri(type),type); }
/// <summary> /// All base structures (resources + datatypes) that come with the spec have a specific pre-defined /// (but currently symbolic) url where they can be found. This function constructs this Url, given the /// core Resource or Datatype code. /// </summary> /// <param name="type">Resource or Datatype to build the Uri for</param> /// <returns></returns> public static Uri BuildBaseStructureUri(Code type) { //string fullReference = CoreZipArtifactSource.CORE_SPEC_PROFILE_URI_PREFIX + type.Value.ToLower(); string fullReference = CoreZipArtifactSource.CORE_SPEC_PROFILE_URI_PREFIX + type.Value; return new Uri(fullReference); }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as DiagnosticReport; if (dest != null) { base.CopyTo(dest); if (Identifier != null) { dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy()); } if (StatusElement != null) { dest.StatusElement = (Code <Hl7.Fhir.Model.DiagnosticReport.DiagnosticReportStatus>)StatusElement.DeepCopy(); } if (Category != null) { dest.Category = (Hl7.Fhir.Model.CodeableConcept)Category.DeepCopy(); } if (Code != null) { dest.Code = (Hl7.Fhir.Model.CodeableConcept)Code.DeepCopy(); } if (Subject != null) { dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy(); } if (Encounter != null) { dest.Encounter = (Hl7.Fhir.Model.ResourceReference)Encounter.DeepCopy(); } if (Effective != null) { dest.Effective = (Hl7.Fhir.Model.Element)Effective.DeepCopy(); } if (IssuedElement != null) { dest.IssuedElement = (Hl7.Fhir.Model.Instant)IssuedElement.DeepCopy(); } if (Performer != null) { dest.Performer = (Hl7.Fhir.Model.ResourceReference)Performer.DeepCopy(); } if (Request != null) { dest.Request = new List <Hl7.Fhir.Model.ResourceReference>(Request.DeepCopy()); } if (Specimen != null) { dest.Specimen = new List <Hl7.Fhir.Model.ResourceReference>(Specimen.DeepCopy()); } if (Result != null) { dest.Result = new List <Hl7.Fhir.Model.ResourceReference>(Result.DeepCopy()); } if (ImagingStudy != null) { dest.ImagingStudy = new List <Hl7.Fhir.Model.ResourceReference>(ImagingStudy.DeepCopy()); } if (Image != null) { dest.Image = new List <Hl7.Fhir.Model.DiagnosticReport.ImageComponent>(Image.DeepCopy()); } if (ConclusionElement != null) { dest.ConclusionElement = (Hl7.Fhir.Model.FhirString)ConclusionElement.DeepCopy(); } if (CodedDiagnosis != null) { dest.CodedDiagnosis = new List <Hl7.Fhir.Model.CodeableConcept>(CodedDiagnosis.DeepCopy()); } if (PresentedForm != null) { dest.PresentedForm = new List <Hl7.Fhir.Model.Attachment>(PresentedForm.DeepCopy()); } return(dest); } else { throw new ArgumentException("Can only copy to an object of the same type", "other"); } }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as Condition; if (dest == null) { throw new ArgumentException("Can only copy to an object of the same type", "other"); } base.CopyTo(dest); if (Identifier != null) { dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy()); } if (ClinicalStatusElement != null) { dest.ClinicalStatusElement = (Code <Hl7.Fhir.Model.Condition.ConditionClinicalStatusCodes>)ClinicalStatusElement.DeepCopy(); } if (VerificationStatusElement != null) { dest.VerificationStatusElement = (Code <Hl7.Fhir.Model.Condition.ConditionVerificationStatus>)VerificationStatusElement.DeepCopy(); } if (Category != null) { dest.Category = new List <Hl7.Fhir.Model.CodeableConcept>(Category.DeepCopy()); } if (Severity != null) { dest.Severity = (Hl7.Fhir.Model.CodeableConcept)Severity.DeepCopy(); } if (Code != null) { dest.Code = (Hl7.Fhir.Model.CodeableConcept)Code.DeepCopy(); } if (BodySite != null) { dest.BodySite = new List <Hl7.Fhir.Model.CodeableConcept>(BodySite.DeepCopy()); } if (Subject != null) { dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy(); } if (Context != null) { dest.Context = (Hl7.Fhir.Model.ResourceReference)Context.DeepCopy(); } if (Onset != null) { dest.Onset = (Hl7.Fhir.Model.DataType)Onset.DeepCopy(); } if (Abatement != null) { dest.Abatement = (Hl7.Fhir.Model.DataType)Abatement.DeepCopy(); } if (AssertedDateElement != null) { dest.AssertedDateElement = (Hl7.Fhir.Model.FhirDateTime)AssertedDateElement.DeepCopy(); } if (Asserter != null) { dest.Asserter = (Hl7.Fhir.Model.ResourceReference)Asserter.DeepCopy(); } if (Stage != null) { dest.Stage = (Hl7.Fhir.Model.Condition.StageComponent)Stage.DeepCopy(); } if (Evidence != null) { dest.Evidence = new List <Hl7.Fhir.Model.Condition.EvidenceComponent>(Evidence.DeepCopy()); } if (Note != null) { dest.Note = new List <Hl7.Fhir.Model.Annotation>(Note.DeepCopy()); } return(dest); }
public override IDeepCopyable CopyTo(IDeepCopyable other) { var dest = other as Procedure; if (dest != null) { base.CopyTo(dest); if (Identifier != null) { dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy()); } if (Subject != null) { dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy(); } if (StatusElement != null) { dest.StatusElement = (Code <Hl7.Fhir.Model.Procedure.ProcedureStatus>)StatusElement.DeepCopy(); } if (Category != null) { dest.Category = (Hl7.Fhir.Model.CodeableConcept)Category.DeepCopy(); } if (Code != null) { dest.Code = (Hl7.Fhir.Model.CodeableConcept)Code.DeepCopy(); } if (NotPerformedElement != null) { dest.NotPerformedElement = (Hl7.Fhir.Model.FhirBoolean)NotPerformedElement.DeepCopy(); } if (ReasonNotPerformed != null) { dest.ReasonNotPerformed = new List <Hl7.Fhir.Model.CodeableConcept>(ReasonNotPerformed.DeepCopy()); } if (BodySite != null) { dest.BodySite = new List <Hl7.Fhir.Model.CodeableConcept>(BodySite.DeepCopy()); } if (Reason != null) { dest.Reason = (Hl7.Fhir.Model.Element)Reason.DeepCopy(); } if (Performer != null) { dest.Performer = new List <Hl7.Fhir.Model.Procedure.PerformerComponent>(Performer.DeepCopy()); } if (Performed != null) { dest.Performed = (Hl7.Fhir.Model.Element)Performed.DeepCopy(); } if (Encounter != null) { dest.Encounter = (Hl7.Fhir.Model.ResourceReference)Encounter.DeepCopy(); } if (Location != null) { dest.Location = (Hl7.Fhir.Model.ResourceReference)Location.DeepCopy(); } if (Outcome != null) { dest.Outcome = (Hl7.Fhir.Model.CodeableConcept)Outcome.DeepCopy(); } if (Report != null) { dest.Report = new List <Hl7.Fhir.Model.ResourceReference>(Report.DeepCopy()); } if (Complication != null) { dest.Complication = new List <Hl7.Fhir.Model.CodeableConcept>(Complication.DeepCopy()); } if (FollowUp != null) { dest.FollowUp = new List <Hl7.Fhir.Model.CodeableConcept>(FollowUp.DeepCopy()); } if (Request != null) { dest.Request = (Hl7.Fhir.Model.ResourceReference)Request.DeepCopy(); } if (Notes != null) { dest.Notes = new List <Hl7.Fhir.Model.Annotation>(Notes.DeepCopy()); } if (FocalDevice != null) { dest.FocalDevice = new List <Hl7.Fhir.Model.Procedure.FocalDeviceComponent>(FocalDevice.DeepCopy()); } if (Used != null) { dest.Used = new List <Hl7.Fhir.Model.ResourceReference>(Used.DeepCopy()); } return(dest); } else { throw new ArgumentException("Can only copy to an object of the same type", "other"); } }