private static void ProcessEncounters(List<TimelineEntry> timeline, Bundle matchingEncounters) { foreach (var encounter in matchingEncounters.Entries.Select(x => (ResourceEntry<Encounter>)x)) { DateTimeOffset? startTime; DateTimeOffset? endTime; if (encounter.Resource.Hospitalization != null) { startTime = DateTimeOffset.Parse(encounter.Resource.Hospitalization.Period.Start); endTime = DateTimeOffset.Parse(encounter.Resource.Hospitalization.Period.End); } else { startTime = encounter.Published; endTime = encounter.Published; } timeline.Add(new TimelineEntry { StartTime = startTime, EndTime = endTime, TypeOfEntry = TimelineEntryType.Encounter, Summary = encounter.Resource.Reason.ToString() }); } }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { var result = new List<ValidationResult>(); if (String.IsNullOrWhiteSpace(Title)) result.Add(new ValidationResult("Feed must contain a title")); if (!UriHasValue(Id)) result.Add(new ValidationResult("Feed must have an id")); else if (!Id.IsAbsoluteUri) result.Add(new ValidationResult("Feed id must be an absolute URI")); if (LastUpdated == null) result.Add(new ValidationResult("Feed must have a updated date")); if (Links.SearchLink != null) result.Add(new ValidationResult("Links with rel='search' can only be used on feed entries")); bool feedHasAuthor = !String.IsNullOrEmpty(this.AuthorName); if (Entries != null) { foreach (var entry in Entries.Where(e => e != null)) { if (!feedHasAuthor && entry is ResourceEntry && String.IsNullOrEmpty(((ResourceEntry)entry).AuthorName)) result.Add(new ValidationResult("Bundle's author and Entry author cannot both be empty")); Validator.TryValidateObject(entry, ValidationContextFactory.Create(entry, null), result, true); } } return result; }
public Import(ILocalhost localhost, IGenerator generator) { this.localhost = localhost; this.generator = generator; mapper = new Mapper<Key, Key>(); interactions = new List<Interaction>(); }
public static ICollection<Tag> ParseCategoryHeader(string value) { if (String.IsNullOrEmpty(value)) return new List<Tag>(); var result = new List<Tag>(); var categories = value.SplitNotInQuotes(',').Where(s => !String.IsNullOrEmpty(s)); foreach (var category in categories) { var values = category.SplitNotInQuotes(';').Where(s => !String.IsNullOrEmpty(s)); if (values.Count() >= 1) { var term = values.First(); var pars = values.Skip(1).Select( v => { var vsplit = v.Split('='); var item1 = vsplit[0].Trim(); var item2 = vsplit.Length > 1 ? vsplit[1].Trim() : null; return new Tuple<string,string>(item1,item2); }); var scheme = new Uri(pars.Where(t => t.Item1 == "scheme").Select(t => t.Item2.Trim('\"')).FirstOrDefault(), UriKind.RelativeOrAbsolute); var label = pars.Where(t => t.Item1 == "label").Select(t => t.Item2.Trim('\"')).FirstOrDefault(); result.Add(new Tag(term,scheme,label)); } } return result; }
public void UpdateTagsOnUpdate() { if (original == null) TestResult.Skipped(); // Update one tag, add another var tags = new List<Tag>() { new Tag(NUTAG, Tag.FHIRTAGNS, "readTagTest2"), new Tag(OTHERTAG, Tag.FHIRTAGNS, "dummy") }; HttpTests.AssertSuccess(client, () => latest = client.Fetch<Patient>(original.Id)); latest.Tags = tags; HttpTests.AssertSuccess(client, () => client.Update<Patient>(latest)); var read = client.Fetch<Patient>(latest.Id); if (read.Tags == null) TestResult.Fail("fetch after update did not return any tags"); if (read.Tags.Count() != 2) TestResult.Fail(String.Format("Wrong number of tags after update: {0}, expected 2", read.Tags.Count())); var nutags = read.Tags.FindByTerm(NUTAG,Tag.FHIRTAGNS); if (nutags.Count() != 1 || nutags.First().Label != "readTagTest2") TestResult.Fail("update did not replace value in tag"); var othertags = read.Tags.FindByTerm(OTHERTAG,Tag.FHIRTAGNS); if(othertags.Count() != 1 || othertags.First().Label != "dummy") TestResult.Fail("update failed to add new tag"); latest = read; }
public void TestTagsOnCreateAndRead() { var tags = new List<Tag>() { new Tag(NUTAG, Tag.FHIRTAGNS, "readTagTest") }; HttpTests.AssertSuccess(client, () => latest = client.Create<Patient>(DemoData.GetDemoPatient(),tags)); if(latest.Tags == null) TestResult.Fail("create did not return any tags"); var nutags = latest.Tags.FindByTerm(NUTAG, Tag.FHIRTAGNS); if (nutags.Count() != 1 || nutags.First().Label != "readTagTest") TestResult.Fail("create did not return specified tag"); var read = client.Fetch<Patient>(latest.Id); if (read.Tags == null) TestResult.Fail("read did not return any tags"); nutags = latest.Tags.FindByTerm(NUTAG, Tag.FHIRTAGNS); if (nutags.Count() != 1 || nutags.First().Label != "readTagTest") TestResult.Fail("read did not return specified tag"); var vread = client.Fetch<Patient>(latest.SelfLink); if (vread.Tags == null) TestResult.Fail("vread did not return any tags"); nutags = latest.Tags.FindByTerm(NUTAG, Tag.FHIRTAGNS); if (nutags.Count() != 1 || nutags.First().Label != "readTagTest") TestResult.Fail("vread did not return specified tag"); original = latest; }
public SearchParams() { Include = new List<string>(); RevInclude = new List<string>(); Sort = new List<Tuple<string, SortOrder>>(); Parameters = new List<Tuple<string, string>>(); }
public IEnumerable<Patient> GetAllPatients() { var patients = new List<Patient>(); var patientsExist = true; var i = 1; while (patientsExist) { try { var patient = _client.Read<Patient>(i.ToString()); patients.Add(patient.Resource); i++; } catch (FhirOperationException) { patientsExist = false; } } return patients; }
public static void AddHistoryKeys(this IGenerator generator, List<Interaction> interactions) { // PERF: this needs a performance improvement. foreach (Interaction interaction in interactions) { interaction.Key = generator.NextHistoryKey(interaction.Key); } }
public InitializeHub(FhirService fhirService, ILocalhost localhost, IFhirStore fhirStore, IFhirIndex fhirIndex) { this.localhost = localhost; this.fhirService = fhirService; this.fhirStore = fhirStore; this.fhirIndex = fhirIndex; this.resources = null; }
static CustomModelInfo() { searchParameters = new List<SearchParamDefinition> { new SearchParamDefinition() { Resource = "Practitioner", Name = "roleid", Description = @"Search by role identifier extension", Type = SearchParamType.Token, Path = new string[] { @"Practitioner.practitionerRole.Extension[url=http://hl7.no/fhir/StructureDefinition/practitonerRole-identifier].ValueIdentifier" } } }; // searchParameters.AddRange(ModelInfo.SearchParameters); }
public Pager(IFhirStore fhirStore, ISnapshotStore snapshotstore, ILocalhost localhost, Transfer transfer, List<ModelInfo.SearchParamDefinition> searchParameters) { this.fhirStore = fhirStore; this.snapshotstore = snapshotstore; this.localhost = localhost; this.transfer = transfer; this.searchParameters = searchParameters; }
private IMongoQuery ParametersToQuery(IEnumerable<IParameter> parameters) { List<IMongoQuery> queries = new List<IMongoQuery>(); queries.Add(M.Query.EQ(InternalField.LEVEL, 0)); // geindexeerde contained documents overslaan IEnumerable<IMongoQuery> q = parameters.Select(p => ParameterToQuery(p)); queries.AddRange(q); return M.Query.And(queries); }
public static Conformance AddMultipleResourceComponents(this Conformance conformance, List<String> resourcetypes, Boolean readhistory, Boolean updatecreate, Conformance.ResourceVersionPolicy versioning) { foreach (var type in resourcetypes) { AddSingleResourceComponent(conformance, type, readhistory, updatecreate, versioning); } return conformance; }
public InitializeHub() { this.localhost = InfrastructureProvider.Mongo.Localhost; this.service = InfrastructureProvider.Mongo.CreateService(); this.store = InfrastructureProvider.Mongo.Store; this.index = InfrastructureProvider.Mongo.Index; this.resources = null; }
internal static IMongoQuery ResourceFilter(string resourceType) { var queries = new List<IMongoQuery>(); queries.Add(M.Query.EQ(InternalField.LEVEL, 0)); queries.Add(M.Query.EQ(InternalField.RESOURCE, resourceType)); return M.Query.And(queries); }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { var result = new List<ValidationResult>(); foreach (var tag in Category) result.AddRange(tag.Validate(validationContext)); return result; }
public IEnumerable<Tuple<string, IFhirReader>> GetMembers() { if (_current is XElement) { var rootElem = (XElement)_current; var result = new List<Tuple<string, IFhirReader>>(); // First, any attributes foreach(var attr in rootElem.Attributes()) //.Where(xattr => xattr.Name.LocalName != "xmlns")) { if (attr.Name == XName.Get("xmlns", "")) continue; // skip xmlns declarations if (attr.Name == XName.Get("{http://www.w3.org/2000/xmlns/}xsi") && !SerializationConfig.EnforceNoXsiAttributesOnRoot ) continue; // skip xmlns:xsi declaration if (attr.Name == XName.Get("{http://www.w3.org/2001/XMLSchema-instance}schemaLocation") && !SerializationConfig.EnforceNoXsiAttributesOnRoot) continue; // skip schemaLocation if (attr.Name.NamespaceName == "") result.Add(Tuple.Create(attr.Name.LocalName, (IFhirReader)new XmlDomFhirReader(attr))); else throw Error.Format("Encountered unsupported attribute {0}", this, attr.Name); } foreach(var node in rootElem.Nodes()) { if(node is XText) { // A nested text node (the content attribute of a Binary) result.Add(Tuple.Create(SerializationConfig.BINARY_CONTENT_MEMBER_NAME, (IFhirReader)new XmlDomFhirReader(node))); } else if(node is XElement) { var elem = (XElement)node; // All normal elements if(elem.Name.NamespaceName == SerializationUtil.FHIRNS) result.Add(Tuple.Create(elem.Name.LocalName, (IFhirReader)new XmlDomFhirReader(elem))); // The special xhtml div element else if(elem.Name == XHTMLDIV) result.Add(Tuple.Create(XHTMLDIV.LocalName, (IFhirReader)new XmlDomFhirReader(buildDivXText(elem)))); else throw Error.Format("Encountered element '{0}' from unsupported namespace '{1}'", this, elem.Name.LocalName, elem.Name.NamespaceName); } else if(node is XComment) { // nothing } else throw Error.Format("Encountered unexpected element member of type {0}", this, node.GetType().Name); } return result; } else throw Error.Format("Cannot get members: reader not at an element", this); }
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { var result = new List<ValidationResult>(); result.AddRange(base.Validate(validationContext)); if (!result.Any()) result.Add(ValidationResult.Success); return result; }
public Chain(string path) { List<string> chain = SplitPath(path); // Keep the typename separate. var typeName = chain.First(); chain.RemoveAt(0); segments = BuildSegments(typeName, chain); }
public IEnumerable<Patient> GetPatientsByName(string firstName, string lastName) { var searchParameters = new SearchParams(); searchParameters.Add("Given", firstName); searchParameters.Add("Family", lastName); var matches = new List<Patient>(); var result = _client.Search(searchParameters, ResourceType.Patient.ToString()); return result.Entry.Select(x => (Patient) x.Resource); }
public static IList<Interaction> GetInteractions(this ILocalhost localhost, Bundle bundle) { var interactions = new List<Interaction>(); foreach(var entry in bundle.Entry) { Interaction interaction = localhost.ToInteraction(entry); interaction.SupplementBase(bundle.Base); interactions.Add(interaction); } return interactions; }
public static void SetBundleType(this Bundle bundle, BundleType type) { List<Tag> result = new List<Tag>(bundle.Tags.Exclude(new Tag[] { MESSAGE_TAG, DOCUMENT_TAG })); if (type == BundleType.Document) result.Add(DOCUMENT_TAG); else if (type == BundleType.Message) result.Add(MESSAGE_TAG); bundle.Tags = result; }
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { var result = new List<ValidationResult>(); result.AddRange(base.Validate(validationContext)); if (When == null) result.Add(new ValidationResult("A DeletedEntry must have a non-null deletion time (When)")); if (!result.Any()) result.Add(ValidationResult.Success); return result; }
public IEnumerable<TimelineEntry> GetTimelineForPatient(string patientIdentifier) { var timeline = new List<TimelineEntry>(); var matchingEncounters = _client.Search(ResourceType.Encounter, "subject.identifier", patientIdentifier); var matchingAlerts = _client.Search(ResourceType.Alert, "subject.identifier", patientIdentifier); ProcessAlerts(timeline, matchingAlerts); ProcessEncounters(timeline, matchingEncounters); return timeline.OrderBy(x => x.StartTime).ThenBy(x => x.EndTime); }
private static IEnumerable<Type> LoadSupportedTypesFromAssembly(Assembly fhirAssembly) { var result = new List<Type>(); foreach (Type fhirType in fhirAssembly.GetTypes()) { if (typeof(Resource).IsAssignableFrom(fhirType) || typeof(Element).IsAssignableFrom(fhirType)) //It is derived of Resource or Element, so we should support it. { result.Add(fhirType); } } return result; }
public RestUrl(Uri url) { if (!url.IsAbsoluteUri) throw Error.Argument("url", "Must be an absolute url"); if (url.Scheme != "http") Error.Argument("uri", "RestUrl must be a http url"); _builder = new UriBuilder(url); if (!String.IsNullOrEmpty(_builder.Query)) _parameters = new List<Tuple<string,string>>( HttpUtil.SplitParams(_builder.Query) ); }
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { var result = new List<ValidationResult>(); result.AddRange(base.Validate(validationContext)); if (Content == null) result.Add(new ValidationResult("Entry must contain (possibly 0-length) data in Content element")); if (ContentType == null) result.Add(new ValidationResult("Entry must contain a ContentType")); return result; }
public static Expression ToExpression(this Quantity quantity) { quantity = System.Canonical(quantity); string searchable = quantity.LeftSearchableString(); var values = new List<ValueExpression>(); values.Add(new IndexValue("system", new StringValue(UCUM.Uri.ToString()))); values.Add(new IndexValue("value", new NumberValue(quantity.Value.ToDecimal()))); values.Add(new IndexValue("decimals", new StringValue(searchable))); values.Add(new IndexValue("unit", new StringValue(quantity.Metric.ToString()))); return new CompositeValue(values); }
public static void SetTextTag(this BundleEntry entry, string text) { var result = new List<Tag>(); if (entry.Tags != null) result.AddRange(entry.Tags); result.RemoveAll(t => Equals(t.Scheme,Tag.FHIRTAGSCHEME_GENERAL) && (t.Term != null && t.Term.StartsWith(TAG_TERM_TEXT))); result.Add(new Tag(TAG_TERM_TEXT + Uri.EscapeUriString(text), Tag.FHIRTAGSCHEME_GENERAL, text)); entry.Tags = result; }
public static void SerializeList(Hl7.Fhir.Model.List value, IFhirWriter writer, bool summary) { writer.WriteStartRootObject("List"); 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 code if (value.Code != null && !summary) { writer.WriteStartElement("code"); CodeableConceptSerializer.SerializeCodeableConcept(value.Code, writer, summary); writer.WriteEndElement(); } // Serialize element source if (value.Source != null && !summary) { writer.WriteStartElement("source"); ResourceReferenceSerializer.SerializeResourceReference(value.Source, writer, summary); writer.WriteEndElement(); } // Serialize element date if (value.DateElement != null && !summary) { writer.WriteStartElement("date"); FhirDateTimeSerializer.SerializeFhirDateTime(value.DateElement, writer, summary); writer.WriteEndElement(); } // Serialize element ordered if (value.OrderedElement != null && !summary) { writer.WriteStartElement("ordered"); FhirBooleanSerializer.SerializeFhirBoolean(value.OrderedElement, writer, summary); writer.WriteEndElement(); } // Serialize element mode if (value.ModeElement != null && !summary) { writer.WriteStartElement("mode"); CodeSerializer.SerializeCode <Hl7.Fhir.Model.List.ListMode>(value.ModeElement, writer, summary); writer.WriteEndElement(); } // Serialize element entry if (value.Entry != null && !summary && value.Entry.Count > 0) { writer.WriteStartArrayElement("entry"); foreach (var item in value.Entry) { writer.WriteStartArrayMember("entry"); ListSerializer.SerializeListEntryComponent(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element emptyReason if (value.EmptyReason != null && !summary) { writer.WriteStartElement("emptyReason"); CodeableConceptSerializer.SerializeCodeableConcept(value.EmptyReason, writer, summary); writer.WriteEndElement(); } writer.WriteEndComplexContent(); writer.WriteEndRootObject(); }
/// <summary> /// Parse List /// </summary> public static Hl7.Fhir.Model.List ParseList(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.List existingInstance = null) { Hl7.Fhir.Model.List result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.List(); 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 code else if (atName == "code") { result.Code = CodeableConceptParser.ParseCodeableConcept(reader, errors); } // Parse element source else if (atName == "source") { result.Source = ResourceReferenceParser.ParseResourceReference(reader, errors); } // Parse element date else if (atName == "date") { result.DateElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors); } // Parse element ordered else if (atName == "ordered") { result.OrderedElement = FhirBooleanParser.ParseFhirBoolean(reader, errors); } // Parse element mode else if (atName == "mode") { result.ModeElement = CodeParser.ParseCode <Hl7.Fhir.Model.List.ListMode>(reader, errors); } // Parse element entry else if (atName == "entry") { result.Entry = new List <Hl7.Fhir.Model.List.ListEntryComponent>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "entry")) { result.Entry.Add(ListParser.ParseListEntryComponent(reader, errors)); } reader.LeaveArray(); } // Parse element emptyReason else if (atName == "emptyReason") { result.EmptyReason = CodeableConceptParser.ParseCodeableConcept(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); }