Exemplo n.º 1
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>A <see cref="Agatha.Common.Response"/></returns>
        public override Response Handle(GetDataFromC32Request request)
        {
            // get the patient external doc
            var provenance = new ProvenanceDto();
            var patientExternalDocument = GetPatientExternalDocument(request.PatientDocumentKey, ref provenance);
            var c32Dto = GetC32Dto(patientExternalDocument);

            GetProvenanceFromC32Dto(c32Dto, ref provenance);

            var medications   = GetMedicationsFromC32Dto(c32Dto);
            var allergies     = GetAllergiesFromC32Dto(c32Dto);
            var problems      = GetProblemsFromC32Dto(c32Dto);
            var immunizations = GetImmunizationsFromC32Dto(c32Dto);
            var labSpecimen   = GetLabSpecimenFromC32Dto(c32Dto);
            var vitalSign     = GetVitalSignFromC32Dto(c32Dto);

            var response = CreateTypedResponse();

            response.Medications   = medications;
            response.Provenance    = provenance;
            response.Allergies     = allergies;
            response.Problems      = problems;
            response.Immunizations = immunizations;
            response.LabSpecimen   = labSpecimen;
            response.VitalSign     = vitalSign;

            return(response);
        }
Exemplo n.º 2
0
        private void GetProvenanceFromC32Dto(C32Dto c32Dto, ref ProvenanceDto provenance)
        {
            if (c32Dto != null && c32Dto.Header != null)
            {
                var header = c32Dto.Header;

                if (header.DocumentId != null)
                {
                    var documentId = header.DocumentId;
                    provenance.AssigningAuthority = documentId.AssigningAuthority;
                    provenance.Extension          = documentId.Extension;
                }

                if (header.DocumentTimestamp != null && !string.IsNullOrEmpty(header.DocumentTimestamp.Value))
                {
                    var signedTimestamp = DateTimeOffset.MinValue;
                    DateTimeOffset.TryParseExact(
                        header.DocumentTimestamp.Value,
                        LongDateFormat,
                        CultureInfo.InvariantCulture,
                        DateTimeStyles.AssumeUniversal,
                        out signedTimestamp);
                    provenance.SignedTimestamp = signedTimestamp;
                }

                if (header.InformationSource.Author != null && header.InformationSource.Author.AuthorName != null)
                {
                    var authorName = header.InformationSource.Author.AuthorName;
                    provenance.PrefixName = authorName.Prefix;
                    provenance.FirstName  = authorName.Given;
                    provenance.LastName   = authorName.Family;
                }

                if (header.InformationSource != null && header.InformationSource.InformationSourceName != null)
                {
                    var sourceName = header.InformationSource.InformationSourceName;

                    if (sourceName.OrganizationName != null)
                    {
                        provenance.OrganizationName = sourceName.OrganizationName.TextValue;
                    }

                    if (sourceName.OrganizationId != null)
                    {
                        var organizationId = sourceName.OrganizationId;
                        provenance.OrganizationAssigningAuthority = organizationId.AssigningAuthority;
                        provenance.OrganizationExtension          = organizationId.Extension;
                    }

                    if (sourceName.OrganizationTelecom != null)
                    {
                        provenance.PhoneNumber = sourceName.OrganizationTelecom.Value;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private Provenance CreateProvenance(ProvenanceDto provenanceDto)
        {
            var provenance = _provenanceFactory.CreateProvenance(
                new TaggedDataElement(provenanceDto.AssigningAuthority, provenanceDto.Extension), provenanceDto.SignedTimestamp);

            provenance.ReviseAssignedAuthor(
                new AssignedAuthor(
                    provenanceDto.ProviderDirectoryEntry,
                    new PersonName(provenanceDto.PrefixName, provenanceDto.FirstName, null, provenanceDto.LastName, null)));
            provenance.ReviseRepresentedOrganization(
                new RepresentedOrganization(
                    new TaggedDataElement(
                        string.IsNullOrWhiteSpace(provenanceDto.OrganizationAssigningAuthority)
                            ? "Test"
                            : provenanceDto.OrganizationAssigningAuthority,
                        provenanceDto.OrganizationExtension),
                    provenanceDto.OrganizationName,
                    new Phone(provenanceDto.PhoneNumber, null)));
            return(provenance);
        }
Exemplo n.º 4
0
        private string GetPatientExternalDocument(long patientDocumentKey, ref ProvenanceDto provenance)
        {
            var result = string.Empty;

            var patientDocument = _patientDocumentRepository.GetByKey(patientDocumentKey);

            if (patientDocument == null)
            {
                return(result);
            }

            if (patientDocument.PatientDocumentType.WellKnownName == WellKnownNames.PatientModule.PatientDocumentType.XDM)
            {
                // parse XDM doc
                var packager = XDMZipPackager.Default;
                var xdmFile  = ZipFile.Read(patientDocument.Document, null, Encoding.GetEncoding(Utf8Encoding));

                var documentPackage = packager.Unpackage(xdmFile);

                // TODO: make sure extracting the correct data from metadata
                if (documentPackage.SubmissionTime.HasValue)
                {
                    provenance.SignedTimestamp = documentPackage.SubmissionTime.Value;
                }

                //Only handle first document at this moment
                var doc = documentPackage.Documents.FirstOrDefault();
                if (doc != null)
                {
                    if (doc.PatientID != null)
                    {
                        provenance.AssigningAuthority = doc.PatientID.AssigningAuthority;
                    }

                    if (doc.Author != null)
                    {
                        if (doc.Author.Person != null)
                        {
                            provenance.FirstName  = doc.Author.Person.First;
                            provenance.LastName   = doc.Author.Person.Last;
                            provenance.PrefixName = doc.Author.Person.Prefix;
                        }

                        if (doc.Author.Institutions != null)
                        {
                            provenance.OrganizationAssigningAuthority = doc.Author.Institutions.FirstOrDefault().AssigningAuthority;
                            provenance.OrganizationName = doc.Author.Institutions.FirstOrDefault().Name;
                        }

                        if (doc.Author.TelecomAddress.Email != null)
                        {
                            provenance.Extension             = doc.Author.TelecomAddress.Email.Host;
                            provenance.OrganizationExtension = provenance.Extension;
                        }
                        provenance.PhoneNumber = doc.Author.TelecomAddress.Phone;
                    }
                    result = doc.DocumentString;
                }
            }

            if (patientDocument.PatientDocumentType.WellKnownName == WellKnownNames.PatientModule.PatientDocumentType.C32)
            {
                _patientKey = patientDocument.Patient.Key;

                if (patientDocument.Document != null && patientDocument.Document.Length > 0)
                {
                    result = Encoding.GetEncoding(Utf8Encoding).GetString(patientDocument.Document);
                }
            }

            return(result);
        }