adding support for rtf files

fixes #321
This commit is contained in:
Jason Kulatunga 2023-12-06 13:39:45 -08:00
parent 80336a1775
commit 36bf113336
No known key found for this signature in database
9 changed files with 95 additions and 0 deletions

View File

@ -52,6 +52,7 @@
"ngx-infinite-scroll": "^14.0.0", "ngx-infinite-scroll": "^14.0.0",
"ngx-moment": "^6.0.2", "ngx-moment": "^6.0.2",
"parse-full-name": "^1.2.6", "parse-full-name": "^1.2.6",
"rtf.js": "^3.0.9",
"rxjs": "~6.5.4", "rxjs": "~6.5.4",
"tslib": "^2.0.0", "tslib": "^2.0.0",
"uuid": "^9.0.0", "uuid": "^9.0.0",

View File

@ -0,0 +1,3 @@
<div>
<div id="rtfContent"></div>
</div>

View File

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RtfComponent } from './rtf.component';
describe('RtfComponent', () => {
let component: RtfComponent;
let fixture: ComponentFixture<RtfComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ RtfComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(RtfComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,47 @@
import {Component, Input, OnInit} from '@angular/core';
import {CommonModule} from '@angular/common';
import {BinaryModel} from '../../../../../lib/models/resources/binary-model';
import {EMFJS, RTFJS, WMFJS} from 'rtf.js';
@Component({
standalone: true,
imports: [CommonModule],
selector: 'fhir-rtf',
templateUrl: './rtf.component.html',
styleUrls: ['./rtf.component.scss']
})
export class RtfComponent implements OnInit {
@Input() displayModel: BinaryModel
constructor() { }
ngOnInit(): void {
let doc = new RTFJS.Document(this.stringToArrayBuffer(this.displayModel.content), null);
doc.render().then(function(htmlElements) {
const parent: HTMLElement = document.getElementById('rtfContent');
for(let i = 0; i < htmlElements.length; i++){
parent.appendChild(htmlElements[i])
}
}).catch(e => {
if (e instanceof RTFJS.Error) {
console.error("Error: " + e.message);
document.getElementById('rtfContent').innerHTML = e.message;
}
else {
throw e;
}
});
}
private stringToArrayBuffer(string): ArrayBuffer {
const buffer = new ArrayBuffer(string.length);
const bufferView = new Uint8Array(buffer);
for (let i = 0; i < string.length; i++) {
bufferView[i] = string.charCodeAt(i);
}
return buffer;
}
}

View File

@ -27,6 +27,7 @@ import {ProcedureComponent} from './resources/procedure/procedure.component';
import {FhirCardComponent} from './fhir-card/fhir-card.component'; import {FhirCardComponent} from './fhir-card/fhir-card.component';
import {FhirCardOutletDirective} from './fhir-card/fhir-card-outlet.directive'; import {FhirCardOutletDirective} from './fhir-card/fhir-card-outlet.directive';
import { EncounterComponent } from './resources/encounter/encounter.component'; import { EncounterComponent } from './resources/encounter/encounter.component';
import { RtfComponent } from './datatypes/rtf/rtf.component';
@ -45,6 +46,7 @@ import { EncounterComponent } from './resources/encounter/encounter.component';
ImgComponent, ImgComponent,
MarkdownComponent, MarkdownComponent,
PdfComponent, PdfComponent,
RtfComponent,
//resources //resources
AllergyIntoleranceComponent, AllergyIntoleranceComponent,
BinaryComponent, BinaryComponent,
@ -82,6 +84,7 @@ import { EncounterComponent } from './resources/encounter/encounter.component';
ImgComponent, ImgComponent,
MarkdownComponent, MarkdownComponent,
PdfComponent, PdfComponent,
RtfComponent,
//resources //resources
AllergyIntoleranceComponent, AllergyIntoleranceComponent,
BinaryComponent, BinaryComponent,

View File

@ -13,6 +13,7 @@
displayModel?.content_type == 'text/markdown' ? showMarkdown : displayModel?.content_type == 'text/markdown' ? showMarkdown :
displayModel?.content_type == 'text/plain' ? showText : displayModel?.content_type == 'text/plain' ? showText :
displayModel?.content_type == 'application/dicom' ? showDicom : displayModel?.content_type == 'application/dicom' ? showDicom :
displayModel?.content_type == 'text/rtf' ? showRtf :
(displayModel?.content_type == 'text/html' || displayModel?.content_type == 'application/html') ? showHtml : (displayModel?.content_type == 'text/html' || displayModel?.content_type == 'application/html') ? showHtml :
(displayModel?.content_type == 'application/xml' || displayModel?.content_type == 'application/json') ? showHighlight : (displayModel?.content_type == 'application/xml' || displayModel?.content_type == 'application/json') ? showHighlight :
(displayModel?.content_type == 'image/jpeg' || displayModel?.content_type == 'image/png') ? showImg : (displayModel?.content_type == 'image/jpeg' || displayModel?.content_type == 'image/png') ? showImg :
@ -40,6 +41,9 @@
<ng-template #showDicom> <ng-template #showDicom>
<fhir-dicom [displayModel]="displayModel"></fhir-dicom> <fhir-dicom [displayModel]="displayModel"></fhir-dicom>
</ng-template> </ng-template>
<ng-template #showRtf>
<fhir-rtf [displayModel]="displayModel"></fhir-rtf>
</ng-template>
<ng-template #showEmpty> <ng-template #showEmpty>
Unknown Binary content type {{displayModel?.content_type}} Unknown Binary content type {{displayModel?.content_type}}
</ng-template> </ng-template>

View File

@ -17,6 +17,7 @@ import {DicomComponent} from "../../datatypes/dicom/dicom.component";
import {HighlightModule} from "ngx-highlightjs"; import {HighlightModule} from "ngx-highlightjs";
import {HttpClient, HttpClientModule} from "@angular/common/http"; import {HttpClient, HttpClientModule} from "@angular/common/http";
import {AuthService} from "../../../../services/auth.service"; import {AuthService} from "../../../../services/auth.service";
import {RtfComponent} from '../../datatypes/rtf/rtf.component';
@Component({ @Component({
standalone: true, standalone: true,
@ -27,6 +28,7 @@ import {AuthService} from "../../../../services/auth.service";
ImgComponent, ImgComponent,
HtmlComponent, HtmlComponent,
MarkdownComponent, MarkdownComponent,
RtfComponent,
BinaryTextComponent, BinaryTextComponent,
DicomComponent, DicomComponent,
HighlightModule, HighlightModule,

View File

@ -5074,6 +5074,11 @@ codelyzer@^5.1.2:
source-map "^0.5.7" source-map "^0.5.7"
sprintf-js "^1.1.2" sprintf-js "^1.1.2"
codepage@^1.15.0:
version "1.15.0"
resolved "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz#2e00519024b39424ec66eeb3ec07227e692618ab"
integrity sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==
coffeescript@^2.7.0: coffeescript@^2.7.0:
version "2.7.0" version "2.7.0"
resolved "https://registry.npmjs.org/coffeescript/-/coffeescript-2.7.0.tgz#a43ec03be6885d6d1454850ea70b9409c391279c" resolved "https://registry.npmjs.org/coffeescript/-/coffeescript-2.7.0.tgz#a43ec03be6885d6d1454850ea70b9409c391279c"
@ -10827,6 +10832,13 @@ rimraf@~2.6.2:
dependencies: dependencies:
glob "^7.1.3" glob "^7.1.3"
rtf.js@^3.0.9:
version "3.0.9"
resolved "https://registry.npmjs.org/rtf.js/-/rtf.js-3.0.9.tgz#27d4f4e26372ba080b945ee48293347346de943e"
integrity sha512-I1GpDat4i548WzmeZXv27f/743984fvEeeBS8BC01/Sop17pMlUl3M7DYcdcB3PUvOZTrFIMxGZx8qw7cSMAKQ==
dependencies:
codepage "^1.15.0"
run-async@^2.4.0: run-async@^2.4.0:
version "2.4.1" version "2.4.1"
resolved "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455" resolved "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455"