private void WriteAssociation(BeanWrapper childBeanWrapper, Hl7Source source, XmlElement element, Relationship relationship ) { Hl7PartSource childSource = source.CreatePartSource(relationship, element); MapToTeal(childSource, childBeanWrapper, relationship); }
private object GetOrCreateCollapsedBean(Hl7Source source, Relationship relationship) { BeanProperty property = FindBeanProperty(relationship); // TM - fix for bug 13100 - will property always be null? if (property == null) { property = GetPropertyForAssociation(); } object collapsedBean = property.Get(); if (collapsedBean == null) { Relationship collapsedRelationship = GetCollapsedRelationship(source, property.GetAnnotation <Hl7XmlMappingAttribute>()); if (collapsedRelationship != null) { Hl7PartSource collapsedPartSource = source.CreatePartSource(collapsedRelationship, source.GetCurrentElement()); collapsedBean = Instantiator.GetInstance().InstantiateMessagePartBean(collapsedPartSource.GetVersion(), collapsedPartSource .Type, collapsedPartSource.GetInteraction()); property.Set(collapsedBean); } else { this.log.Info(System.String.Format("UNABLE TO SET NULL FLAVOR - Can not find bean for collapsed property {0}.{1}", this.sorter .GetBeanType().Name, this.contextName)); } } return(collapsedBean); }
internal virtual object MapPartSourceToTeal(Hl7PartSource source, Relationship relationship) { object bean = Instantiator.GetInstance().InstantiateMessagePartBean(source.GetVersion(), source.Type, source.GetInteraction ()); BeanWrapper wrapper = new BeanWrapper(bean); MapToTeal(source, wrapper, relationship); return(bean); }
// @Test // public void shouldMapMultipleCardinalityAssociationWithNullFlavor() throws Exception { // Document document1 = new DocumentFactory().createFromResource( // new ClasspathResource(this.getClass(), "findCandidatesQuery_withNullFlavor.xml")); // // Hl7MessageSource rootPartSource1 = new Hl7MessageSource(SpecificationVersion.V02R02.getVersionLiteral(), // document1, // this.service); // // FindCandidatesQueryMessageBean bean = (FindCandidatesQueryMessageBean)new Hl7SourceMapper().mapToTeal(rootPartSource1).getMessageObject(); // // assertNotNull("teal bean", bean); // assertFalse("first reason has no null flavor", bean.getReasons().get(0).hasNullFlavor()); // assertTrue("second reason has null flavor", bean.getReasons().get(1).hasNullFlavor()); // assertEquals("second reason null flavor", NullFlavor.OTHER, bean.getReasons().get(1).getNullFlavor()); // } /// <exception cref="System.IO.IOException"></exception> /// <exception cref="Platform.Xml.Sax.SAXException"></exception> /// <exception cref="System.Xml.XPath.XPathException"></exception> private object MapPartSourceToTeal(VersionNumber version, string xml, string relationshipType) { XmlDocument document1 = new DocumentFactory().CreateFromString(xml); Hl7MessageSource rootPartSource1 = new Hl7MessageSource(version, new DocumentFactory().CreateFromString("<PRPA_IN101103CA xmlns=\"urn:hl7-org:v3\" />" ), null, null, this.service); Hl7PartSource partSource1 = rootPartSource1.CreatePartSource(CreateRelationship(relationshipType), document1.DocumentElement ); return(new Hl7SourceMapper().MapPartSourceToTeal(partSource1, null)); }
public virtual void SetUp() { MockMessageBeanRegistry.Initialize(); CodeResolverRegistry.Register(new TrivialCodeResolver()); this.service = new MockTestCaseMessageDefinitionService(); this.document = GetSourceDocument(); Hl7MessageSource rootSource = new Hl7MessageSource(MockVersionNumber.MOCK_NEWFOUNDLAND, document, null, null, this.service ); this.element = document.DocumentElement; this.partSource = rootSource.CreatePartSource(CreateRelationship("MFMI_MT700711CA.Author"), element); }
public virtual void SetUp() { MockMessageBeanRegistry.Initialize(); CodeResolverRegistry.Register(new EnumBasedCodeResolver(typeof(Ca.Infoway.Messagebuilder.Domainvalue.Controlact.ActStatus ))); CodeResolverRegistry.Register(new TrivialCodeResolver()); this.service = new MockTestCaseMessageDefinitionService(); this.document = GetSourceDocument(XML); this.element = this.document.DocumentElement; Hl7MessageSource rootSource = new Hl7MessageSource(MockVersionNumber.MOCK_NEWFOUNDLAND, this.document, null, null, this.service ); this.partSource = rootSource.CreatePartSource(CreateRelationship("MCCI_MT002100CA.Sender"), element); }
public virtual void ShouldHandleIndicatorAttributesWhenNullFlavor() { this.document = GetSourceDocument(XML_NULL); this.element = this.document.DocumentElement; Hl7MessageSource rootSource = new Hl7MessageSource(MockVersionNumber.MOCK_MR2009, this.document, null, null, this.service ); this.partSource = rootSource.CreatePartSource(CreateRelationship("POIZ_MT030050CA.InFulfillmentOf"), element); InFulfillmentOfBean teal = (InFulfillmentOfBean) new Hl7SourceMapper().MapPartSourceToTeal(this.partSource, null); Assert.IsNotNull(teal, "teal"); Assert.IsTrue(((BL)teal.GetField("immunizationPlan")).Null, "null flavor"); Assert.AreEqual(2, teal.DoseNumber.Value, "dose number"); Assert.IsNull(teal.ImmunizationPlan, "indicator"); }
public virtual void ShouldMapRealmCode() { Sender senderBean = (Sender) new Hl7SourceMapper().MapPartSourceToTeal(this.partSource, null); Assert.IsNotNull(senderBean, "sender"); Assert.IsNull(senderBean.GetRealmCode(), "realm code not expected"); XmlDocument document2 = GetSourceDocument(XML3); XmlElement element2 = document2.DocumentElement; Hl7MessageSource rootSource2 = new Hl7MessageSource(MockVersionNumber.MOCK_NEWFOUNDLAND, document2, null, null, this.service ); Hl7PartSource partSource2 = rootSource2.CreatePartSource(CreateRelationship("MCCI_MT002100CA.Sender"), element2); Sender senderBeanWithRealm = (Sender) new Hl7SourceMapper().MapPartSourceToTeal(partSource2, null); Assert.IsNotNull(senderBeanWithRealm, "observation"); Assert.IsNotNull(senderBeanWithRealm.GetRealmCode(), "observation has realms"); Assert.AreEqual(2, senderBeanWithRealm.GetRealmCode().Count, "observation has two realms"); Assert.AreEqual(Realm.CANADA, senderBeanWithRealm.GetRealmCode()[0], "realm"); Assert.AreEqual(Realm.ALBERTA, senderBeanWithRealm.GetRealmCode()[1], "realm"); }
public virtual void ShouldMapObservationAttributes() { XmlDocument document2 = GetSourceDocument(XML2); XmlElement element2 = document2.DocumentElement; Hl7MessageSource rootSource2 = new Hl7MessageSource(MockVersionNumber.MOCK_NEWFOUNDLAND, document2, null, null, this.service ); Hl7PartSource partSource2 = rootSource2.CreatePartSource(CreateRelationship("PORX_MT010120CA.QuantityObservationEvent"), element2); QuantityObservationEventBean teal = (QuantityObservationEventBean) new Hl7SourceMapper().MapPartSourceToTeal(partSource2, null); Assert.IsNotNull(teal, "teal"); Assert.IsNotNull(teal.PatientMeasurementType, "code1"); Assert.IsNotNull(teal.PatientMeasuredValue, "code2"); XmlToModelResult result = partSource2.GetResult(); Assert.IsNotNull(result, "result"); Assert.AreEqual(3, result.GetHl7Errors().Count); Assert.AreEqual(Hl7ErrorCode.UNSUPPORTED_INTERACTION, result.GetHl7Errors()[0].GetHl7ErrorCode()); Assert.AreEqual(Hl7ErrorCode.MANDATORY_FIELD_NOT_PROVIDED, result.GetHl7Errors()[1].GetHl7ErrorCode()); Assert.AreEqual(Hl7ErrorCode.MANDATORY_FIELD_NOT_PROVIDED, result.GetHl7Errors()[2].GetHl7ErrorCode()); }
private IList <object> HandleCdaChoice(IList <XmlNode> nodes, string traversalName, Relationship relationship, Hl7Source source ) { IList <object> convertedBeans = new List <object>(); foreach (XmlNode node in nodes) { XmlElement childNode = (XmlElement)node; int currentNodeDepth = XmlDescriber.GetDepth(childNode); int currentErrorCount = source.GetResult().GetHl7Errors().Count; IList <Relationship> allChoiceTypes = DetermineAllChoiceTypes(relationship.Choices); Hl7SourceMapperChoiceCandidate choiceCandidate = null; Relationship choiceCandidateRelationship = null; bool foundMultipleChoiceCandidates = false; foreach (Relationship choiceType in allChoiceTypes) { Hl7PartSource childSource = source.CreatePartSourceForSpecificType(relationship, childNode, choiceType.Type); this.log.Debug("RECURSE for node=" + source.GetCurrentElement().Name + " - relationship=" + relationship.Name + ", tarversalName=" + traversalName + ", of type: " + childSource.Type); // after creating tealChild for each choiceType // - store tealChild // - store all new errors, removing them from the main error container object tealChild = MapPartSourceToTeal(childSource, relationship); Hl7SourceMapperChoiceCandidate newChoiceCandidate = new Hl7SourceMapperChoiceCandidate(tealChild); int newErrorsCount = (source.GetResult().GetHl7Errors().Count - currentErrorCount); for (int i = 0; i < newErrorsCount; i++) { IList <Hl7Error> hl7Errors = source.GetResult().GetHl7Errors(); Hl7Error removedError = hl7Errors[currentErrorCount]; hl7Errors.RemoveAt(currentErrorCount); //.NET conversion newChoiceCandidate.AddError(removedError); } if (newChoiceCandidate.IsAcceptableChoiceCandidate(currentNodeDepth)) { if (newChoiceCandidate.HasTemplateIdMatch(currentNodeDepth)) { // we'll take the first one that has a template id match, even if we found other acceptable candidates choiceCandidate = newChoiceCandidate; choiceCandidateRelationship = choiceType; foundMultipleChoiceCandidates = false; break; } else { if (choiceCandidate == null || choiceCandidateRelationship.DefaultChoice) { // we have found our first match, or we are dumping the default choice in favor of a better match choiceCandidate = newChoiceCandidate; choiceCandidateRelationship = choiceType; } else { if (!choiceType.DefaultChoice) { foundMultipleChoiceCandidates = true; } } } } } // else newChoiceCandidate is a default, and we ignore it in favor of the non-default we previously found // error if no candidates found if (choiceCandidate == null) { source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.CDA_NO_ACCEPTABLE_CHOICE_OPTION, ErrorLevel.WARNING, "Could not determine an appropriate match for a choice element: " + XmlDescriber.DescribePath(node), childNode)); } else { // error if multiple candidates found (excluding the default; but still take the first acceptable candidate) if (foundMultipleChoiceCandidates) { source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.CDA_MULTIPLE_CHOICE_OPTIONS_FOUND, ErrorLevel.WARNING, "Multiple appropriate matches for a choice element found - choosing first one: " + XmlDescriber.DescribePath(node), childNode)); } convertedBeans.Add(choiceCandidate.GetParsedBean()); source.GetResult().GetHl7Errors().AddAll(choiceCandidate.GetStoredErrors()); } } return(convertedBeans); }
private void WriteAssociation(BeanWrapper beanWrapper, Hl7Source source, IList <XmlNode> nodes, Relationship relationship, string traversalName) { this.log.Debug("Writing association: traversalName=" + traversalName + ", relationshipType=" + relationship.Type); // 1. collapsed relationship if (relationship.Cardinality.Single && beanWrapper.IsAssociationMappedToSameBean(relationship)) { this.log.Debug("COLLAPSE RECURSE : " + traversalName + " as collapsed relationship to " + beanWrapper.GetWrappedType()); BeanWrapper childBeanWrapper = beanWrapper.CreateSubWrapper(relationship); WriteSpecialAssociation(childBeanWrapper, source, nodes, relationship); } else { //1b. trivial collapsed relationship with cardinality change (e.g. "RecordId" collapsed into "Location criteria" if (relationship.Cardinality.Multiple && beanWrapper.IsAssociationMappedToSameBean(relationship) && IsTypeWithSingleNonFixedRelationship (relationship, source)) { BeanWrapper childBeanWrapper = beanWrapper.CreateSubWrapper(relationship); foreach (XmlNode node in nodes) { WriteAssociation(childBeanWrapper, source, (XmlElement)node, relationship); } } else { // 2. initialized read-only association if (relationship.Cardinality.Single && beanWrapper.IsPreInitializedDelegate(relationship)) { this.log.Debug("READ-ONLY ASSOCIATION: " + traversalName + " as collapsed relationship to " + beanWrapper.GetWrappedType( )); BeanWrapper childBeanWrapper = new BeanWrapper(beanWrapper.GetInitializedReadOnlyAssociation(relationship)); WriteSpecialAssociation(childBeanWrapper, source, nodes, relationship); } else { // 3a. non-collapsed, multiple-cardinality choice or single-cardinality choice with node name same as choice name if (IsCdaChoice(nodes, relationship, source)) { IList <object> convertedBeans = HandleCdaChoice(nodes, traversalName, relationship, source); if (relationship.Cardinality.Multiple) { this.log.Debug("Special choice handling: WRITING MULTIPLE-CARDINALITY CHOICE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - values=" + convertedBeans); beanWrapper.Write(relationship, convertedBeans); } else { if (relationship.Cardinality.Single && convertedBeans.IsEmpty()) { throw new MarshallingException("Special choice handling: Why is this empty? : " + relationship.Name + " on " + source.Type ); } else { this.log.Debug("Special choice handling: WRITING SINGLE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - value=" + convertedBeans[0]); // may need to ignore values beyond the first; an error will have been logged beanWrapper.Write(relationship, convertedBeans[0]); } } } else { // 3. non-collapsed (including choice, specializationChild, and template type, handling for which is encapsulated in // Source.createChildSource()) if (relationship.TemplateRelationship || relationship.Choice || MessageBeanRegistry.GetInstance().IsMessagePartDefined(source .GetVersion(), relationship.Type)) { IList <object> convertedBeans = new List <object>(); foreach (XmlNode node in nodes) { XmlElement childNode = (XmlElement)node; Hl7PartSource childSource = source.CreatePartSource(relationship, childNode); this.log.Debug("RECURSE for node=" + source.GetCurrentElement().Name + " - relationship=" + relationship.Name + ", tarversalName=" + traversalName + ", of type: " + childSource.Type); object tealChild = MapPartSourceToTeal(childSource, relationship); convertedBeans.Add(tealChild); } if (relationship.Cardinality.Multiple) { this.log.Debug("WRITING MULTIPLE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - values=" + convertedBeans); beanWrapper.Write(relationship, convertedBeans); } else { if (relationship.Cardinality.Single && convertedBeans.IsEmpty()) { throw new MarshallingException("Why is this empty? : " + relationship.Name + " on " + source.Type); } else { this.log.Debug("WRITING SINGLE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - value=" + convertedBeans[0]); // may need to ignore values beyond the first; an error will have been logged beanWrapper.Write(relationship, convertedBeans[0]); } } } else { if (!ConformanceLevelUtil.IsOptional(relationship) && !IsFullyFixedType(relationship, source)) { this.log.Info("IGNORING: HL7 type " + relationship.Type + " with traversalName=" + traversalName + "(" + Describer.Describe (source.GetMessagePartName(), relationship) + ") cannot be mapped to any teal bean"); } } } } } } }