Beispiel #1
0
        /// <summary>
        /// Creates a document from an XML XElement representation
        /// </summary>
        public static DocumentMetadata ConsumeDocument(XElement docXEl)
        {
            DocumentMetadata doc = new DocumentMetadata();
            doc.Author = ConsumeAuthor(docXEl.Classification(XDMetadataStandard.UUIDs.DocumentAuthor));
            doc.Class = ConsumeCodedValue(docXEl.Classification(XDMetadataStandard.UUIDs.DocumentClass));
            doc.Comments = docXEl.DescriptionValue();
            doc.Confidentiality = ConsumeCodedValue(docXEl.Classification(XDMetadataStandard.UUIDs.DocumentConfidentiality));
            doc.CreatedOn = docXEl.SlotValue<DateTime?>(XDMetadataStandard.Slots.CreationTime, s => HL7Util.DateTimeFromHL7Value(s));
            doc.EventCodes = docXEl.Classifications(XDMetadataStandard.UUIDs.EventCode).Select(c => ConsumeCodedValue(c));
            doc.FormatCode = ConsumeCodedValue(docXEl.Classification(XDMetadataStandard.UUIDs.FormatCode));
            doc.FacilityCode = ConsumeCodedValue(docXEl.Classification(XDMetadataStandard.UUIDs.FacilityCode));
            doc.Hash = docXEl.SlotValue(XDMetadataStandard.Slots.Hash);
            doc.LanguageCode = docXEl.SlotValue(XDMetadataStandard.Slots.LanguageCode);
            doc.LegalAuthenticator = docXEl.SlotValue<Person>(XDMetadataStandard.Slots.LegalAuthenticator, s => Person.FromXCN(s));
            doc.MediaType = docXEl.AttributeValue(XDMetadataStandard.Attrs.MimeType);
            doc.PatientID = docXEl.ExternalIdentifierValue(XDMetadataStandard.UUIDs.DocumentEntryPatientIdentityScheme, s => PatientID.FromEscapedCx(s));
            doc.ServiceStart = docXEl.SlotValue<DateTime?>(XDMetadataStandard.Slots.ServiceStart, s => HL7Util.DateTimeFromHL7Value(s));
            doc.ServiceStop = docXEl.SlotValue<DateTime?>(XDMetadataStandard.Slots.ServiceStop, s => HL7Util.DateTimeFromHL7Value(s));
            doc.PracticeSetting = ConsumeCodedValue(docXEl.Classification(XDMetadataStandard.UUIDs.PracticeSetting));
            doc.Size = docXEl.SlotValue<int?>(XDMetadataStandard.Slots.Size, s => Parse(s));
            doc.SourcePtId = docXEl.SlotValue<PatientID>(XDMetadataStandard.Slots.SourcePatientID, s => PatientID.FromEscapedCx(s));
            doc.Patient = Person.FromSourcePatientInfoValues(docXEl.SlotValues(XDMetadataStandard.Slots.SourcePatientInfo));
            doc.Title = docXEl.NameValue();
            // Ignore TypeCode
            doc.UniqueId = docXEl.ExternalIdentifierValue(XDMetadataStandard.UUIDs.DocumentUniqueIdIdentityScheme);
            doc.Uri = ConsumeUriValues(docXEl.SlotValues(XDMetadataStandard.Slots.Uri));

            return doc;
        }
Beispiel #2
0
 public void SetDocumentWithStream()
 {
     DocumentMetadata m = new DocumentMetadata();
     using (MemoryStream stream = new MemoryStream(new byte[] { 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 }))
     {
         m.SetDocument(stream);
     }
     Assert.Equal(11, m.Size);                
 }
Beispiel #3
0
 public void SetDocumentSetsHash()
 {
     DocumentMetadata m = new DocumentMetadata();
     m.SetDocument("abc");
     SHA1 sha = new SHA1CryptoServiceProvider();
     byte[] bytes = (new UTF8Encoding()).GetBytes("abc");
     string hash = BitConverter.ToString(sha.ComputeHash(bytes)).Replace("-", "");
     Assert.Equal(hash, m.Hash);
 }
Beispiel #4
0
 public void SetDocumentWithExistingRightSizeWorks()
 {
     DocumentMetadata m = new DocumentMetadata();
     byte[] bytes = (new UTF8Encoding()).GetBytes("abc");
     m.Size = bytes.Length;
     m.SetDocument("abc");
     Assert.Equal(bytes.Length, m.Size);
 }
Beispiel #5
0
 public void SetDocumentWithExistingWrongSizeThrowsError()
 {
     DocumentMetadata m = new DocumentMetadata();
     m.Size = 1000000000;
     Assert.Throws<FormatException>(() => m.SetDocument("abc"));
 }
Beispiel #6
0
 public void SetDocumentWithExistingWrongHashThrowsError()
 {
     DocumentMetadata m = new DocumentMetadata();
     m.Hash = "abc123";
     Assert.Throws<FormatException>(() => m.SetDocument("abc"));
 }
Beispiel #7
0
 public void SetDocumentSetsSize()
 {
     DocumentMetadata m = new DocumentMetadata();
     m.SetDocument(new byte[] { 72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100 });
     Assert.Equal(11, m.Size);
 }
Beispiel #8
0
 public void DocumentStringHasStringRepresentation()
 {
     DocumentMetadata m = new DocumentMetadata();
     m.SetDocument("abc123");
     Assert.Equal("abc123", m.DocumentString);
 }
Beispiel #9
0
        public static ExtrinsicObjectType CreateDocumentEntry(DocumentMetadata document, string documentId)
        {
            ExtrinsicObjectType eo = new ExtrinsicObjectType();
            eo.Id = documentId;
            eo.ObjectType = GlobalValues.XDSDocumentEntryUUID; //ClassificationNode?
            eo.MimeType = document.MediaType;

            eo.Name = new InternationalStringType();
            eo.Name.LocalizedString = new LocalizedStringType[1];
            eo.Name.LocalizedString[0] = new LocalizedStringType();
            eo.Name.LocalizedString[0].Value = document.Title;

            SlotType[] slots = new SlotType[6];

            string[] values = new string[1];
            values[0] = Extensions.ToHL7Date(document.CreatedOn);
         
            slots[0] = new SlotType(SlotNameType.creationTime, values);

            values = new string[1];
            values[0] = document.LanguageCode;
            slots[1] = new SlotType(SlotNameType.languageCode, values);

            values = new string[1];
            values[0] = document.SourcePtId.ToCx();
            slots[2] = new SlotType(SlotNameType.sourcePatientId, values);

            //values = new string[5];
            //values[0] = "PID-3|" + _patID
            //values[1] = "PID-5|" + _patName;
            //values[2] = "PID-7|" + _patDOB;
            //values[3] = "PID-8|" + _patSex;
            //values[4] = "PID-11|" + _patAddress;
            values = (string[])document.Patient.ToSourcePatientInfoValues(document.SourcePtId);
            slots[3] = new SlotType(SlotNameType.sourcePatientInfo, values);

            values = new string[1];
            values[0] = document.Size.ToString();
            slots[4] = new SlotType(SlotNameType.size, values);

            values = new string[1];
            values[0] = document.Hash.ToString();
            slots[5] = new SlotType(SlotNameType.hash, values);

            eo.Slot = slots;

            string[] eiScheme = new string[2];
            string[] eiValue = new string[2];
            string[] eiName = new string[2];
            string[] eiId = new string[2];
            string[] registryObject = new string[2];
            eiScheme[0] = GlobalValues.XDSDocumentEntry_patientIdUUID;
            eiScheme[1] = GlobalValues.XDSDocumentEntry_uniqueIdUUID;
            eiValue[0] = document.PatientID.ToCx();
            eiValue[1] = document.UniqueId;
            eiName[0] = "XDSDocumentEntry.patientId";
            eiName[1] = "XDSDocumentEntry.uniqueId";
            eiId[0] = documentId + "ei01";
            eiId[1] = documentId + "ei02";
            registryObject[0] = eo.Id;
            registryObject[1] = eo.Id;

            eo.ExternalIdentifier = CreateEIDs(eiScheme, eiValue, eiName, eiId, registryObject);

            //Create Classifications for authorInstitution/authorPerson, class code, and type code
            eo.Classification = new ClassificationType[7];

            //Author Institution and Author Person
            //<rim:Classification id="cl01" classificationScheme="urn:uuid:93606bcf-9494-43ec-9b4e-a7748d1a838d" classifiedObject="Document01">
            //    <rim:Slot name="authorPerson">
            //        <rim:ValueList>
            //            <rim:Value>Gerald Smitty</rim:Value>
            //        </rim:ValueList>
            //    </rim:Slot>
            //    <rim:Slot name="authorInstitution">
            //        <rim:ValueList>
            //            <rim:Value>Cleveland Clinic</rim:Value>
            //            <rim:Value>Parma Community</rim:Value>
            //        </rim:ValueList>
            //    </rim:Slot>
            //</rim:Classification>
            slots = new SlotType[3];
            values = new string[document.Author.Institutions.Count];
            for (int i = 0; i < document.Author.Institutions.Count; i++)
            {
                values[i] = document.Author.Institutions[i].ToXON();
            }
            slots[0] = new SlotType(SlotNameType.authorInstitution, values);

            values = new string[1];
            values[0] = document.Author.Person.ToXCN();
            slots[1] = new SlotType(SlotNameType.authorPerson, values);

            values = new string[1];
            values[0] = document.Author.TelecomAddress.ToXTN();
            slots[2] = new SlotType(SlotNameType.authorTelecom, values);

            eo.Classification[0] = new ClassificationType(GlobalValues.XDSDocumentEntry_authorDescriptionUUID,
                eo.Id, null, null, documentId + "cl01", null, slots);

            //Class Code
            slots = new SlotType[1];
            values = new string[1];
            values[0] = document.Class.Scheme;
            slots[0] = new SlotType(SlotNameType.codingScheme, values);
            eo.Classification[1] = new ClassificationType(GlobalValues.XDSDocumentEntry_classCodeUUID,
                eo.Id, null, document.Class.Code, documentId + "cl02", document.Class.Label, slots);

            //Confidentiality Code
            slots = new SlotType[1];
            values = new string[1];
            values[0] = document.Confidentiality.Scheme;
            slots[0] = new SlotType(SlotNameType.codingScheme, values);
            eo.Classification[2] = new ClassificationType(GlobalValues.XDSDocumentEntry_confidentialityCodeUUID,
                eo.Id, null, document.Confidentiality.Code, documentId + "cl03", document.Confidentiality.Label, slots);

            //Format Code
            slots = new SlotType[1];
            values = new string[1];
            values[0] = document.FormatCode.Scheme;
            slots[0] = new SlotType(SlotNameType.codingScheme, values);
            eo.Classification[3] = new ClassificationType(GlobalValues.XDSDocumentEntry_formatCodeUUID,
                eo.Id, null, document.FormatCode.Code, documentId + "cl04",
                document.FormatCode.Label, slots);

            //HealthCare Facility type code
            slots = new SlotType[1];
            values = new string[1];
            values[0] = document.FacilityCode.Scheme;
            slots[0] = new SlotType(SlotNameType.codingScheme, values);
            eo.Classification[4] = new ClassificationType(GlobalValues.XDSDocumentEntry_healthCareFacilityTypeCodeUUID,
                eo.Id, null, document.FacilityCode.Code, documentId + "cl05",
                document.FacilityCode.Label, slots);

            //Practice Setting Code
            slots = new SlotType[1];
            values = new string[1];
            values[0] = document.PracticeSetting.Scheme;
            slots[0] = new SlotType(SlotNameType.codingScheme, values);
            eo.Classification[5] = new ClassificationType(GlobalValues.XDSDocumentEntry_practiceSettingCodeUUID,
                eo.Id, null, document.PracticeSetting.Code, documentId + "cl06",
                document.PracticeSetting.Label, slots);

            //Type Code
            slots = new SlotType[1];
            values = new string[1];
            values[0] = document.Type.Scheme;
            slots[0] = new SlotType(SlotNameType.codingScheme, values);
            eo.Classification[6] = new ClassificationType(GlobalValues.XDSDocumentEntry_typeCodeUUID,
                eo.Id, null, document.Type.Code, documentId + "cl07",
                document.Type.Label, slots);

            return eo;
        }
 public void EmptyMetadataDocumentHasNoDescendents()
 {
     XElement empty = new DocumentMetadata().Generate();
     Assert.Empty(empty.Descendants());
 }
 public void NoDocumentMetadata()
 {
     DocumentMetadata empty = new DocumentMetadata();
     Assert.DoesNotThrow(() => empty.Generate());
 }