@blackcode_sa/metaestetics-api 1.7.18 → 1.7.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +22 -34
- package/dist/index.d.ts +22 -34
- package/dist/index.js +40 -116
- package/dist/index.mjs +40 -116
- package/package.json +1 -1
- package/src/services/documentation-templates/filled-document.service.ts +49 -153
package/dist/index.d.mts
CHANGED
|
@@ -6804,46 +6804,34 @@ declare class FilledDocumentService extends BaseService {
|
|
|
6804
6804
|
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
6805
6805
|
}>;
|
|
6806
6806
|
/**
|
|
6807
|
-
* Upload a file
|
|
6808
|
-
*
|
|
6809
|
-
*
|
|
6810
|
-
* @param
|
|
6811
|
-
* @param
|
|
6812
|
-
* @param
|
|
6813
|
-
* @param
|
|
6814
|
-
* @returns The
|
|
6807
|
+
* Upload a file for a filled document field without updating the document.
|
|
6808
|
+
* This method only handles the upload and returns the file value to be used by the UI.
|
|
6809
|
+
*
|
|
6810
|
+
* @param appointmentId - ID of the appointment
|
|
6811
|
+
* @param formId - ID of the filled document
|
|
6812
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
6813
|
+
* @param file - The file to upload
|
|
6814
|
+
* @returns The file value object to be stored in the document
|
|
6815
6815
|
*/
|
|
6816
|
-
uploadFileForFilledDocument(appointmentId: string, formId: string, isUserForm: boolean, file: File | Blob
|
|
6816
|
+
uploadFileForFilledDocument(appointmentId: string, formId: string, isUserForm: boolean, file: File | Blob): Promise<FilledDocumentFileValue>;
|
|
6817
6817
|
/**
|
|
6818
|
-
* Upload a signature image for a filled document
|
|
6818
|
+
* Upload a signature image for a filled document.
|
|
6819
6819
|
* This is a specialized version of uploadFileForFilledDocument specifically for signatures.
|
|
6820
|
-
*
|
|
6821
|
-
* @param
|
|
6822
|
-
* @param
|
|
6823
|
-
* @param
|
|
6824
|
-
* @param
|
|
6825
|
-
* @returns The
|
|
6826
|
-
*/
|
|
6827
|
-
uploadSignatureForFilledDocument(appointmentId: string, formId: string, isUserForm: boolean, signatureBlob: Blob, fieldId: string): Promise<FilledDocument>;
|
|
6828
|
-
/**
|
|
6829
|
-
* Remove a file from a filled document field.
|
|
6830
|
-
* This will both update the document and delete the media file.
|
|
6831
|
-
* @param appointmentId - ID of the appointment.
|
|
6832
|
-
* @param formId - ID of the filled document.
|
|
6833
|
-
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
6834
|
-
* @param fieldId - The ID of the field containing the file.
|
|
6835
|
-
* @returns The updated filled document with the file removed.
|
|
6820
|
+
*
|
|
6821
|
+
* @param appointmentId - ID of the appointment
|
|
6822
|
+
* @param formId - ID of the filled document
|
|
6823
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
6824
|
+
* @param signatureBlob - The signature image as a Blob
|
|
6825
|
+
* @returns The file value object to be stored in the document
|
|
6836
6826
|
*/
|
|
6837
|
-
|
|
6827
|
+
uploadSignatureForFilledDocument(appointmentId: string, formId: string, isUserForm: boolean, signatureBlob: Blob): Promise<FilledDocumentFileValue>;
|
|
6838
6828
|
/**
|
|
6839
|
-
*
|
|
6840
|
-
*
|
|
6841
|
-
* @param
|
|
6842
|
-
* @
|
|
6843
|
-
* @param fieldId - The ID of the field containing the file.
|
|
6844
|
-
* @returns The download URL for the file, or null if not found.
|
|
6829
|
+
* Delete a file using its mediaId.
|
|
6830
|
+
*
|
|
6831
|
+
* @param mediaId - ID of the media to delete
|
|
6832
|
+
* @returns Promise resolving when the deletion is complete
|
|
6845
6833
|
*/
|
|
6846
|
-
|
|
6834
|
+
deleteFile(mediaId: string): Promise<void>;
|
|
6847
6835
|
}
|
|
6848
6836
|
|
|
6849
6837
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6804,46 +6804,34 @@ declare class FilledDocumentService extends BaseService {
|
|
|
6804
6804
|
lastDoc: QueryDocumentSnapshot<FilledDocument> | null;
|
|
6805
6805
|
}>;
|
|
6806
6806
|
/**
|
|
6807
|
-
* Upload a file
|
|
6808
|
-
*
|
|
6809
|
-
*
|
|
6810
|
-
* @param
|
|
6811
|
-
* @param
|
|
6812
|
-
* @param
|
|
6813
|
-
* @param
|
|
6814
|
-
* @returns The
|
|
6807
|
+
* Upload a file for a filled document field without updating the document.
|
|
6808
|
+
* This method only handles the upload and returns the file value to be used by the UI.
|
|
6809
|
+
*
|
|
6810
|
+
* @param appointmentId - ID of the appointment
|
|
6811
|
+
* @param formId - ID of the filled document
|
|
6812
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
6813
|
+
* @param file - The file to upload
|
|
6814
|
+
* @returns The file value object to be stored in the document
|
|
6815
6815
|
*/
|
|
6816
|
-
uploadFileForFilledDocument(appointmentId: string, formId: string, isUserForm: boolean, file: File | Blob
|
|
6816
|
+
uploadFileForFilledDocument(appointmentId: string, formId: string, isUserForm: boolean, file: File | Blob): Promise<FilledDocumentFileValue>;
|
|
6817
6817
|
/**
|
|
6818
|
-
* Upload a signature image for a filled document
|
|
6818
|
+
* Upload a signature image for a filled document.
|
|
6819
6819
|
* This is a specialized version of uploadFileForFilledDocument specifically for signatures.
|
|
6820
|
-
*
|
|
6821
|
-
* @param
|
|
6822
|
-
* @param
|
|
6823
|
-
* @param
|
|
6824
|
-
* @param
|
|
6825
|
-
* @returns The
|
|
6826
|
-
*/
|
|
6827
|
-
uploadSignatureForFilledDocument(appointmentId: string, formId: string, isUserForm: boolean, signatureBlob: Blob, fieldId: string): Promise<FilledDocument>;
|
|
6828
|
-
/**
|
|
6829
|
-
* Remove a file from a filled document field.
|
|
6830
|
-
* This will both update the document and delete the media file.
|
|
6831
|
-
* @param appointmentId - ID of the appointment.
|
|
6832
|
-
* @param formId - ID of the filled document.
|
|
6833
|
-
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
6834
|
-
* @param fieldId - The ID of the field containing the file.
|
|
6835
|
-
* @returns The updated filled document with the file removed.
|
|
6820
|
+
*
|
|
6821
|
+
* @param appointmentId - ID of the appointment
|
|
6822
|
+
* @param formId - ID of the filled document
|
|
6823
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
6824
|
+
* @param signatureBlob - The signature image as a Blob
|
|
6825
|
+
* @returns The file value object to be stored in the document
|
|
6836
6826
|
*/
|
|
6837
|
-
|
|
6827
|
+
uploadSignatureForFilledDocument(appointmentId: string, formId: string, isUserForm: boolean, signatureBlob: Blob): Promise<FilledDocumentFileValue>;
|
|
6838
6828
|
/**
|
|
6839
|
-
*
|
|
6840
|
-
*
|
|
6841
|
-
* @param
|
|
6842
|
-
* @
|
|
6843
|
-
* @param fieldId - The ID of the field containing the file.
|
|
6844
|
-
* @returns The download URL for the file, or null if not found.
|
|
6829
|
+
* Delete a file using its mediaId.
|
|
6830
|
+
*
|
|
6831
|
+
* @param mediaId - ID of the media to delete
|
|
6832
|
+
* @returns Promise resolving when the deletion is complete
|
|
6845
6833
|
*/
|
|
6846
|
-
|
|
6834
|
+
deleteFile(mediaId: string): Promise<void>;
|
|
6847
6835
|
}
|
|
6848
6836
|
|
|
6849
6837
|
/**
|
package/dist/index.js
CHANGED
|
@@ -9627,37 +9627,30 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9627
9627
|
return { documents: [], lastDoc: null };
|
|
9628
9628
|
}
|
|
9629
9629
|
/**
|
|
9630
|
-
* Upload a file
|
|
9631
|
-
*
|
|
9632
|
-
*
|
|
9633
|
-
* @param
|
|
9634
|
-
* @param
|
|
9635
|
-
* @param
|
|
9636
|
-
* @param
|
|
9637
|
-
* @returns The
|
|
9630
|
+
* Upload a file for a filled document field without updating the document.
|
|
9631
|
+
* This method only handles the upload and returns the file value to be used by the UI.
|
|
9632
|
+
*
|
|
9633
|
+
* @param appointmentId - ID of the appointment
|
|
9634
|
+
* @param formId - ID of the filled document
|
|
9635
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
9636
|
+
* @param file - The file to upload
|
|
9637
|
+
* @returns The file value object to be stored in the document
|
|
9638
9638
|
*/
|
|
9639
|
-
async uploadFileForFilledDocument(appointmentId, formId, isUserForm, file
|
|
9639
|
+
async uploadFileForFilledDocument(appointmentId, formId, isUserForm, file) {
|
|
9640
9640
|
console.log(
|
|
9641
|
-
`[FilledDocumentService] Uploading file for
|
|
9642
|
-
);
|
|
9643
|
-
const existingDoc = await this.getFilledDocumentFromAppointmentById(
|
|
9644
|
-
appointmentId,
|
|
9645
|
-
formId,
|
|
9646
|
-
isUserForm
|
|
9641
|
+
`[FilledDocumentService] Uploading file for form ${formId} in appointment ${appointmentId}`
|
|
9647
9642
|
);
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
}
|
|
9653
|
-
const ownerId = existingDoc.patientId;
|
|
9654
|
-
const collectionName = isUserForm ? "patient_forms_files" : "doctor_forms_files";
|
|
9643
|
+
const fileId = this.generateId();
|
|
9644
|
+
const formType = isUserForm ? "user-form" : "doctor-form";
|
|
9645
|
+
const collectionName = `${formType}/${formId}`;
|
|
9646
|
+
const accessLevel = "confidential" /* CONFIDENTIAL */;
|
|
9655
9647
|
const mediaMetadata = await this.mediaService.uploadMedia(
|
|
9656
9648
|
file,
|
|
9657
|
-
|
|
9649
|
+
appointmentId,
|
|
9650
|
+
// Using appointmentId as ownerId
|
|
9658
9651
|
accessLevel,
|
|
9659
9652
|
collectionName,
|
|
9660
|
-
file instanceof File ? file.name :
|
|
9653
|
+
file instanceof File ? file.name : `file_${fileId}`
|
|
9661
9654
|
);
|
|
9662
9655
|
const fileValue = {
|
|
9663
9656
|
mediaId: mediaMetadata.id,
|
|
@@ -9667,118 +9660,49 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9667
9660
|
size: mediaMetadata.size,
|
|
9668
9661
|
uploadedAt: Date.now()
|
|
9669
9662
|
};
|
|
9670
|
-
|
|
9671
|
-
[fieldId]: fileValue
|
|
9672
|
-
};
|
|
9673
|
-
return this.updateFilledDocumentInAppointment(
|
|
9674
|
-
appointmentId,
|
|
9675
|
-
formId,
|
|
9676
|
-
isUserForm,
|
|
9677
|
-
values
|
|
9678
|
-
);
|
|
9663
|
+
return fileValue;
|
|
9679
9664
|
}
|
|
9680
9665
|
/**
|
|
9681
|
-
* Upload a signature image for a filled document
|
|
9666
|
+
* Upload a signature image for a filled document.
|
|
9682
9667
|
* This is a specialized version of uploadFileForFilledDocument specifically for signatures.
|
|
9683
|
-
*
|
|
9684
|
-
* @param
|
|
9685
|
-
* @param
|
|
9686
|
-
* @param
|
|
9687
|
-
* @param
|
|
9688
|
-
* @returns The
|
|
9668
|
+
*
|
|
9669
|
+
* @param appointmentId - ID of the appointment
|
|
9670
|
+
* @param formId - ID of the filled document
|
|
9671
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
9672
|
+
* @param signatureBlob - The signature image as a Blob
|
|
9673
|
+
* @returns The file value object to be stored in the document
|
|
9689
9674
|
*/
|
|
9690
|
-
async uploadSignatureForFilledDocument(appointmentId, formId, isUserForm, signatureBlob
|
|
9675
|
+
async uploadSignatureForFilledDocument(appointmentId, formId, isUserForm, signatureBlob) {
|
|
9691
9676
|
console.log(
|
|
9692
|
-
`[FilledDocumentService] Uploading signature for
|
|
9677
|
+
`[FilledDocumentService] Uploading signature for form ${formId}`
|
|
9693
9678
|
);
|
|
9679
|
+
const signatureId = this.generateId();
|
|
9694
9680
|
const signatureFile = new File(
|
|
9695
9681
|
[signatureBlob],
|
|
9696
|
-
`signature_${
|
|
9697
|
-
{
|
|
9698
|
-
type: "image/png"
|
|
9699
|
-
}
|
|
9682
|
+
`signature_${signatureId}.png`,
|
|
9683
|
+
{ type: "image/png" }
|
|
9700
9684
|
);
|
|
9701
9685
|
return this.uploadFileForFilledDocument(
|
|
9702
9686
|
appointmentId,
|
|
9703
9687
|
formId,
|
|
9704
9688
|
isUserForm,
|
|
9705
|
-
signatureFile
|
|
9706
|
-
fieldId,
|
|
9707
|
-
"confidential" /* CONFIDENTIAL */
|
|
9708
|
-
// Signatures should be confidential
|
|
9689
|
+
signatureFile
|
|
9709
9690
|
);
|
|
9710
9691
|
}
|
|
9711
9692
|
/**
|
|
9712
|
-
*
|
|
9713
|
-
*
|
|
9714
|
-
* @param
|
|
9715
|
-
* @
|
|
9716
|
-
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
9717
|
-
* @param fieldId - The ID of the field containing the file.
|
|
9718
|
-
* @returns The updated filled document with the file removed.
|
|
9719
|
-
*/
|
|
9720
|
-
async removeFileFromFilledDocument(appointmentId, formId, isUserForm, fieldId) {
|
|
9721
|
-
var _a;
|
|
9722
|
-
console.log(
|
|
9723
|
-
`[FilledDocumentService] Removing file from field ${fieldId} in form ${formId}`
|
|
9724
|
-
);
|
|
9725
|
-
const existingDoc = await this.getFilledDocumentFromAppointmentById(
|
|
9726
|
-
appointmentId,
|
|
9727
|
-
formId,
|
|
9728
|
-
isUserForm
|
|
9729
|
-
);
|
|
9730
|
-
if (!existingDoc) {
|
|
9731
|
-
throw new Error(
|
|
9732
|
-
`Filled document with ID ${formId} not found in appointment ${appointmentId}`
|
|
9733
|
-
);
|
|
9734
|
-
}
|
|
9735
|
-
const fileValue = (_a = existingDoc.values) == null ? void 0 : _a[fieldId];
|
|
9736
|
-
if (fileValue && fileValue.mediaId) {
|
|
9737
|
-
try {
|
|
9738
|
-
await this.mediaService.deleteMedia(fileValue.mediaId);
|
|
9739
|
-
} catch (error) {
|
|
9740
|
-
console.error(
|
|
9741
|
-
`[FilledDocumentService] Error deleting media ${fileValue.mediaId}:`,
|
|
9742
|
-
error
|
|
9743
|
-
);
|
|
9744
|
-
}
|
|
9745
|
-
}
|
|
9746
|
-
const values = {
|
|
9747
|
-
[fieldId]: null
|
|
9748
|
-
};
|
|
9749
|
-
return this.updateFilledDocumentInAppointment(
|
|
9750
|
-
appointmentId,
|
|
9751
|
-
formId,
|
|
9752
|
-
isUserForm,
|
|
9753
|
-
values
|
|
9754
|
-
);
|
|
9755
|
-
}
|
|
9756
|
-
/**
|
|
9757
|
-
* Get the download URL for a file in a filled document.
|
|
9758
|
-
* @param appointmentId - ID of the appointment.
|
|
9759
|
-
* @param formId - ID of the filled document.
|
|
9760
|
-
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
9761
|
-
* @param fieldId - The ID of the field containing the file.
|
|
9762
|
-
* @returns The download URL for the file, or null if not found.
|
|
9693
|
+
* Delete a file using its mediaId.
|
|
9694
|
+
*
|
|
9695
|
+
* @param mediaId - ID of the media to delete
|
|
9696
|
+
* @returns Promise resolving when the deletion is complete
|
|
9763
9697
|
*/
|
|
9764
|
-
async
|
|
9765
|
-
var _a;
|
|
9698
|
+
async deleteFile(mediaId) {
|
|
9766
9699
|
console.log(
|
|
9767
|
-
`[FilledDocumentService]
|
|
9768
|
-
);
|
|
9769
|
-
const doc34 = await this.getFilledDocumentFromAppointmentById(
|
|
9770
|
-
appointmentId,
|
|
9771
|
-
formId,
|
|
9772
|
-
isUserForm
|
|
9700
|
+
`[FilledDocumentService] Deleting file with mediaId ${mediaId}`
|
|
9773
9701
|
);
|
|
9774
|
-
if (!
|
|
9775
|
-
|
|
9702
|
+
if (!mediaId) {
|
|
9703
|
+
throw new Error("MediaId is required to delete a file");
|
|
9776
9704
|
}
|
|
9777
|
-
|
|
9778
|
-
if (fileValue && fileValue.url) {
|
|
9779
|
-
return fileValue.url;
|
|
9780
|
-
}
|
|
9781
|
-
return null;
|
|
9705
|
+
await this.mediaService.deleteMedia(mediaId);
|
|
9782
9706
|
}
|
|
9783
9707
|
};
|
|
9784
9708
|
|
package/dist/index.mjs
CHANGED
|
@@ -9640,37 +9640,30 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9640
9640
|
return { documents: [], lastDoc: null };
|
|
9641
9641
|
}
|
|
9642
9642
|
/**
|
|
9643
|
-
* Upload a file
|
|
9644
|
-
*
|
|
9645
|
-
*
|
|
9646
|
-
* @param
|
|
9647
|
-
* @param
|
|
9648
|
-
* @param
|
|
9649
|
-
* @param
|
|
9650
|
-
* @returns The
|
|
9643
|
+
* Upload a file for a filled document field without updating the document.
|
|
9644
|
+
* This method only handles the upload and returns the file value to be used by the UI.
|
|
9645
|
+
*
|
|
9646
|
+
* @param appointmentId - ID of the appointment
|
|
9647
|
+
* @param formId - ID of the filled document
|
|
9648
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
9649
|
+
* @param file - The file to upload
|
|
9650
|
+
* @returns The file value object to be stored in the document
|
|
9651
9651
|
*/
|
|
9652
|
-
async uploadFileForFilledDocument(appointmentId, formId, isUserForm, file
|
|
9652
|
+
async uploadFileForFilledDocument(appointmentId, formId, isUserForm, file) {
|
|
9653
9653
|
console.log(
|
|
9654
|
-
`[FilledDocumentService] Uploading file for
|
|
9655
|
-
);
|
|
9656
|
-
const existingDoc = await this.getFilledDocumentFromAppointmentById(
|
|
9657
|
-
appointmentId,
|
|
9658
|
-
formId,
|
|
9659
|
-
isUserForm
|
|
9654
|
+
`[FilledDocumentService] Uploading file for form ${formId} in appointment ${appointmentId}`
|
|
9660
9655
|
);
|
|
9661
|
-
|
|
9662
|
-
|
|
9663
|
-
|
|
9664
|
-
|
|
9665
|
-
}
|
|
9666
|
-
const ownerId = existingDoc.patientId;
|
|
9667
|
-
const collectionName = isUserForm ? "patient_forms_files" : "doctor_forms_files";
|
|
9656
|
+
const fileId = this.generateId();
|
|
9657
|
+
const formType = isUserForm ? "user-form" : "doctor-form";
|
|
9658
|
+
const collectionName = `${formType}/${formId}`;
|
|
9659
|
+
const accessLevel = "confidential" /* CONFIDENTIAL */;
|
|
9668
9660
|
const mediaMetadata = await this.mediaService.uploadMedia(
|
|
9669
9661
|
file,
|
|
9670
|
-
|
|
9662
|
+
appointmentId,
|
|
9663
|
+
// Using appointmentId as ownerId
|
|
9671
9664
|
accessLevel,
|
|
9672
9665
|
collectionName,
|
|
9673
|
-
file instanceof File ? file.name :
|
|
9666
|
+
file instanceof File ? file.name : `file_${fileId}`
|
|
9674
9667
|
);
|
|
9675
9668
|
const fileValue = {
|
|
9676
9669
|
mediaId: mediaMetadata.id,
|
|
@@ -9680,118 +9673,49 @@ var FilledDocumentService = class extends BaseService {
|
|
|
9680
9673
|
size: mediaMetadata.size,
|
|
9681
9674
|
uploadedAt: Date.now()
|
|
9682
9675
|
};
|
|
9683
|
-
|
|
9684
|
-
[fieldId]: fileValue
|
|
9685
|
-
};
|
|
9686
|
-
return this.updateFilledDocumentInAppointment(
|
|
9687
|
-
appointmentId,
|
|
9688
|
-
formId,
|
|
9689
|
-
isUserForm,
|
|
9690
|
-
values
|
|
9691
|
-
);
|
|
9676
|
+
return fileValue;
|
|
9692
9677
|
}
|
|
9693
9678
|
/**
|
|
9694
|
-
* Upload a signature image for a filled document
|
|
9679
|
+
* Upload a signature image for a filled document.
|
|
9695
9680
|
* This is a specialized version of uploadFileForFilledDocument specifically for signatures.
|
|
9696
|
-
*
|
|
9697
|
-
* @param
|
|
9698
|
-
* @param
|
|
9699
|
-
* @param
|
|
9700
|
-
* @param
|
|
9701
|
-
* @returns The
|
|
9681
|
+
*
|
|
9682
|
+
* @param appointmentId - ID of the appointment
|
|
9683
|
+
* @param formId - ID of the filled document
|
|
9684
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
9685
|
+
* @param signatureBlob - The signature image as a Blob
|
|
9686
|
+
* @returns The file value object to be stored in the document
|
|
9702
9687
|
*/
|
|
9703
|
-
async uploadSignatureForFilledDocument(appointmentId, formId, isUserForm, signatureBlob
|
|
9688
|
+
async uploadSignatureForFilledDocument(appointmentId, formId, isUserForm, signatureBlob) {
|
|
9704
9689
|
console.log(
|
|
9705
|
-
`[FilledDocumentService] Uploading signature for
|
|
9690
|
+
`[FilledDocumentService] Uploading signature for form ${formId}`
|
|
9706
9691
|
);
|
|
9692
|
+
const signatureId = this.generateId();
|
|
9707
9693
|
const signatureFile = new File(
|
|
9708
9694
|
[signatureBlob],
|
|
9709
|
-
`signature_${
|
|
9710
|
-
{
|
|
9711
|
-
type: "image/png"
|
|
9712
|
-
}
|
|
9695
|
+
`signature_${signatureId}.png`,
|
|
9696
|
+
{ type: "image/png" }
|
|
9713
9697
|
);
|
|
9714
9698
|
return this.uploadFileForFilledDocument(
|
|
9715
9699
|
appointmentId,
|
|
9716
9700
|
formId,
|
|
9717
9701
|
isUserForm,
|
|
9718
|
-
signatureFile
|
|
9719
|
-
fieldId,
|
|
9720
|
-
"confidential" /* CONFIDENTIAL */
|
|
9721
|
-
// Signatures should be confidential
|
|
9702
|
+
signatureFile
|
|
9722
9703
|
);
|
|
9723
9704
|
}
|
|
9724
9705
|
/**
|
|
9725
|
-
*
|
|
9726
|
-
*
|
|
9727
|
-
* @param
|
|
9728
|
-
* @
|
|
9729
|
-
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
9730
|
-
* @param fieldId - The ID of the field containing the file.
|
|
9731
|
-
* @returns The updated filled document with the file removed.
|
|
9732
|
-
*/
|
|
9733
|
-
async removeFileFromFilledDocument(appointmentId, formId, isUserForm, fieldId) {
|
|
9734
|
-
var _a;
|
|
9735
|
-
console.log(
|
|
9736
|
-
`[FilledDocumentService] Removing file from field ${fieldId} in form ${formId}`
|
|
9737
|
-
);
|
|
9738
|
-
const existingDoc = await this.getFilledDocumentFromAppointmentById(
|
|
9739
|
-
appointmentId,
|
|
9740
|
-
formId,
|
|
9741
|
-
isUserForm
|
|
9742
|
-
);
|
|
9743
|
-
if (!existingDoc) {
|
|
9744
|
-
throw new Error(
|
|
9745
|
-
`Filled document with ID ${formId} not found in appointment ${appointmentId}`
|
|
9746
|
-
);
|
|
9747
|
-
}
|
|
9748
|
-
const fileValue = (_a = existingDoc.values) == null ? void 0 : _a[fieldId];
|
|
9749
|
-
if (fileValue && fileValue.mediaId) {
|
|
9750
|
-
try {
|
|
9751
|
-
await this.mediaService.deleteMedia(fileValue.mediaId);
|
|
9752
|
-
} catch (error) {
|
|
9753
|
-
console.error(
|
|
9754
|
-
`[FilledDocumentService] Error deleting media ${fileValue.mediaId}:`,
|
|
9755
|
-
error
|
|
9756
|
-
);
|
|
9757
|
-
}
|
|
9758
|
-
}
|
|
9759
|
-
const values = {
|
|
9760
|
-
[fieldId]: null
|
|
9761
|
-
};
|
|
9762
|
-
return this.updateFilledDocumentInAppointment(
|
|
9763
|
-
appointmentId,
|
|
9764
|
-
formId,
|
|
9765
|
-
isUserForm,
|
|
9766
|
-
values
|
|
9767
|
-
);
|
|
9768
|
-
}
|
|
9769
|
-
/**
|
|
9770
|
-
* Get the download URL for a file in a filled document.
|
|
9771
|
-
* @param appointmentId - ID of the appointment.
|
|
9772
|
-
* @param formId - ID of the filled document.
|
|
9773
|
-
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
9774
|
-
* @param fieldId - The ID of the field containing the file.
|
|
9775
|
-
* @returns The download URL for the file, or null if not found.
|
|
9706
|
+
* Delete a file using its mediaId.
|
|
9707
|
+
*
|
|
9708
|
+
* @param mediaId - ID of the media to delete
|
|
9709
|
+
* @returns Promise resolving when the deletion is complete
|
|
9776
9710
|
*/
|
|
9777
|
-
async
|
|
9778
|
-
var _a;
|
|
9711
|
+
async deleteFile(mediaId) {
|
|
9779
9712
|
console.log(
|
|
9780
|
-
`[FilledDocumentService]
|
|
9781
|
-
);
|
|
9782
|
-
const doc34 = await this.getFilledDocumentFromAppointmentById(
|
|
9783
|
-
appointmentId,
|
|
9784
|
-
formId,
|
|
9785
|
-
isUserForm
|
|
9713
|
+
`[FilledDocumentService] Deleting file with mediaId ${mediaId}`
|
|
9786
9714
|
);
|
|
9787
|
-
if (!
|
|
9788
|
-
|
|
9715
|
+
if (!mediaId) {
|
|
9716
|
+
throw new Error("MediaId is required to delete a file");
|
|
9789
9717
|
}
|
|
9790
|
-
|
|
9791
|
-
if (fileValue && fileValue.url) {
|
|
9792
|
-
return fileValue.url;
|
|
9793
|
-
}
|
|
9794
|
-
return null;
|
|
9718
|
+
await this.mediaService.deleteMedia(mediaId);
|
|
9795
9719
|
}
|
|
9796
9720
|
};
|
|
9797
9721
|
|
package/package.json
CHANGED
|
@@ -478,55 +478,45 @@ export class FilledDocumentService extends BaseService {
|
|
|
478
478
|
}
|
|
479
479
|
|
|
480
480
|
/**
|
|
481
|
-
* Upload a file
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* @param
|
|
485
|
-
* @param
|
|
486
|
-
* @param
|
|
487
|
-
* @param
|
|
488
|
-
* @returns The
|
|
481
|
+
* Upload a file for a filled document field without updating the document.
|
|
482
|
+
* This method only handles the upload and returns the file value to be used by the UI.
|
|
483
|
+
*
|
|
484
|
+
* @param appointmentId - ID of the appointment
|
|
485
|
+
* @param formId - ID of the filled document
|
|
486
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
487
|
+
* @param file - The file to upload
|
|
488
|
+
* @returns The file value object to be stored in the document
|
|
489
489
|
*/
|
|
490
490
|
async uploadFileForFilledDocument(
|
|
491
491
|
appointmentId: string,
|
|
492
492
|
formId: string,
|
|
493
493
|
isUserForm: boolean,
|
|
494
|
-
file: File | Blob
|
|
495
|
-
|
|
496
|
-
accessLevel: MediaAccessLevel = MediaAccessLevel.PRIVATE
|
|
497
|
-
): Promise<FilledDocument> {
|
|
494
|
+
file: File | Blob
|
|
495
|
+
): Promise<FilledDocumentFileValue> {
|
|
498
496
|
console.log(
|
|
499
|
-
`[FilledDocumentService] Uploading file for
|
|
497
|
+
`[FilledDocumentService] Uploading file for form ${formId} in appointment ${appointmentId}`
|
|
500
498
|
);
|
|
501
499
|
|
|
502
|
-
//
|
|
503
|
-
const
|
|
504
|
-
appointmentId,
|
|
505
|
-
formId,
|
|
506
|
-
isUserForm
|
|
507
|
-
);
|
|
500
|
+
// Generate a unique file ID
|
|
501
|
+
const fileId = this.generateId();
|
|
508
502
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
);
|
|
513
|
-
}
|
|
503
|
+
// Set the path according to the specified structure
|
|
504
|
+
const formType = isUserForm ? "user-form" : "doctor-form";
|
|
505
|
+
const collectionName = `${formType}/${formId}`;
|
|
514
506
|
|
|
515
|
-
//
|
|
516
|
-
const
|
|
517
|
-
const collectionName = isUserForm
|
|
518
|
-
? "patient_forms_files"
|
|
519
|
-
: "doctor_forms_files";
|
|
507
|
+
// Always use CONFIDENTIAL access level
|
|
508
|
+
const accessLevel = MediaAccessLevel.CONFIDENTIAL;
|
|
520
509
|
|
|
510
|
+
// Upload the file using MediaService
|
|
521
511
|
const mediaMetadata = await this.mediaService.uploadMedia(
|
|
522
512
|
file,
|
|
523
|
-
ownerId
|
|
513
|
+
appointmentId, // Using appointmentId as ownerId
|
|
524
514
|
accessLevel,
|
|
525
515
|
collectionName,
|
|
526
|
-
file instanceof File ? file.name :
|
|
516
|
+
file instanceof File ? file.name : `file_${fileId}`
|
|
527
517
|
);
|
|
528
518
|
|
|
529
|
-
//
|
|
519
|
+
// Create and return a file value object
|
|
530
520
|
const fileValue: FilledDocumentFileValue = {
|
|
531
521
|
mediaId: mediaMetadata.id,
|
|
532
522
|
url: mediaMetadata.url,
|
|
@@ -536,156 +526,62 @@ export class FilledDocumentService extends BaseService {
|
|
|
536
526
|
uploadedAt: Date.now(),
|
|
537
527
|
};
|
|
538
528
|
|
|
539
|
-
|
|
540
|
-
const values = {
|
|
541
|
-
[fieldId]: fileValue,
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
// 5. Use the existing update method to save the file reference
|
|
545
|
-
return this.updateFilledDocumentInAppointment(
|
|
546
|
-
appointmentId,
|
|
547
|
-
formId,
|
|
548
|
-
isUserForm,
|
|
549
|
-
values
|
|
550
|
-
);
|
|
529
|
+
return fileValue;
|
|
551
530
|
}
|
|
552
531
|
|
|
553
532
|
/**
|
|
554
|
-
* Upload a signature image for a filled document
|
|
533
|
+
* Upload a signature image for a filled document.
|
|
555
534
|
* This is a specialized version of uploadFileForFilledDocument specifically for signatures.
|
|
556
|
-
*
|
|
557
|
-
* @param
|
|
558
|
-
* @param
|
|
559
|
-
* @param
|
|
560
|
-
* @param
|
|
561
|
-
* @returns The
|
|
535
|
+
*
|
|
536
|
+
* @param appointmentId - ID of the appointment
|
|
537
|
+
* @param formId - ID of the filled document
|
|
538
|
+
* @param isUserForm - Boolean indicating if it's a user form or doctor form
|
|
539
|
+
* @param signatureBlob - The signature image as a Blob
|
|
540
|
+
* @returns The file value object to be stored in the document
|
|
562
541
|
*/
|
|
563
542
|
async uploadSignatureForFilledDocument(
|
|
564
543
|
appointmentId: string,
|
|
565
544
|
formId: string,
|
|
566
545
|
isUserForm: boolean,
|
|
567
|
-
signatureBlob: Blob
|
|
568
|
-
|
|
569
|
-
): Promise<FilledDocument> {
|
|
546
|
+
signatureBlob: Blob
|
|
547
|
+
): Promise<FilledDocumentFileValue> {
|
|
570
548
|
console.log(
|
|
571
|
-
`[FilledDocumentService] Uploading signature for
|
|
549
|
+
`[FilledDocumentService] Uploading signature for form ${formId}`
|
|
572
550
|
);
|
|
573
551
|
|
|
574
|
-
//
|
|
552
|
+
// Generate a filename for the signature
|
|
553
|
+
const signatureId = this.generateId();
|
|
575
554
|
const signatureFile = new File(
|
|
576
555
|
[signatureBlob],
|
|
577
|
-
`signature_${
|
|
578
|
-
{
|
|
579
|
-
type: "image/png",
|
|
580
|
-
}
|
|
556
|
+
`signature_${signatureId}.png`,
|
|
557
|
+
{ type: "image/png" }
|
|
581
558
|
);
|
|
582
559
|
|
|
560
|
+
// Use the general file upload method
|
|
583
561
|
return this.uploadFileForFilledDocument(
|
|
584
562
|
appointmentId,
|
|
585
563
|
formId,
|
|
586
564
|
isUserForm,
|
|
587
|
-
signatureFile
|
|
588
|
-
fieldId,
|
|
589
|
-
MediaAccessLevel.CONFIDENTIAL // Signatures should be confidential
|
|
590
|
-
);
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
/**
|
|
594
|
-
* Remove a file from a filled document field.
|
|
595
|
-
* This will both update the document and delete the media file.
|
|
596
|
-
* @param appointmentId - ID of the appointment.
|
|
597
|
-
* @param formId - ID of the filled document.
|
|
598
|
-
* @param isUserForm - Boolean indicating if it's a user form or doctor form.
|
|
599
|
-
* @param fieldId - The ID of the field containing the file.
|
|
600
|
-
* @returns The updated filled document with the file removed.
|
|
601
|
-
*/
|
|
602
|
-
async removeFileFromFilledDocument(
|
|
603
|
-
appointmentId: string,
|
|
604
|
-
formId: string,
|
|
605
|
-
isUserForm: boolean,
|
|
606
|
-
fieldId: string
|
|
607
|
-
): Promise<FilledDocument> {
|
|
608
|
-
console.log(
|
|
609
|
-
`[FilledDocumentService] Removing file from field ${fieldId} in form ${formId}`
|
|
610
|
-
);
|
|
611
|
-
|
|
612
|
-
// 1. Get the existing document to verify it exists and to get the file info
|
|
613
|
-
const existingDoc = await this.getFilledDocumentFromAppointmentById(
|
|
614
|
-
appointmentId,
|
|
615
|
-
formId,
|
|
616
|
-
isUserForm
|
|
617
|
-
);
|
|
618
|
-
|
|
619
|
-
if (!existingDoc) {
|
|
620
|
-
throw new Error(
|
|
621
|
-
`Filled document with ID ${formId} not found in appointment ${appointmentId}`
|
|
622
|
-
);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
// 2. Check if the field has a file value
|
|
626
|
-
const fileValue = existingDoc.values?.[fieldId] as FilledDocumentFileValue;
|
|
627
|
-
if (fileValue && fileValue.mediaId) {
|
|
628
|
-
// 3. Delete the file using MediaService
|
|
629
|
-
try {
|
|
630
|
-
await this.mediaService.deleteMedia(fileValue.mediaId);
|
|
631
|
-
} catch (error) {
|
|
632
|
-
console.error(
|
|
633
|
-
`[FilledDocumentService] Error deleting media ${fileValue.mediaId}:`,
|
|
634
|
-
error
|
|
635
|
-
);
|
|
636
|
-
// Continue with document update even if media deletion fails
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
// 4. Update the document to remove the file reference
|
|
641
|
-
const values = {
|
|
642
|
-
[fieldId]: null,
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
// 5. Use the existing update method to save the changes
|
|
646
|
-
return this.updateFilledDocumentInAppointment(
|
|
647
|
-
appointmentId,
|
|
648
|
-
formId,
|
|
649
|
-
isUserForm,
|
|
650
|
-
values
|
|
565
|
+
signatureFile
|
|
651
566
|
);
|
|
652
567
|
}
|
|
653
568
|
|
|
654
569
|
/**
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* @param
|
|
658
|
-
* @
|
|
659
|
-
* @param fieldId - The ID of the field containing the file.
|
|
660
|
-
* @returns The download URL for the file, or null if not found.
|
|
570
|
+
* Delete a file using its mediaId.
|
|
571
|
+
*
|
|
572
|
+
* @param mediaId - ID of the media to delete
|
|
573
|
+
* @returns Promise resolving when the deletion is complete
|
|
661
574
|
*/
|
|
662
|
-
async
|
|
663
|
-
appointmentId: string,
|
|
664
|
-
formId: string,
|
|
665
|
-
isUserForm: boolean,
|
|
666
|
-
fieldId: string
|
|
667
|
-
): Promise<string | null> {
|
|
575
|
+
async deleteFile(mediaId: string): Promise<void> {
|
|
668
576
|
console.log(
|
|
669
|
-
`[FilledDocumentService]
|
|
577
|
+
`[FilledDocumentService] Deleting file with mediaId ${mediaId}`
|
|
670
578
|
);
|
|
671
579
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
appointmentId,
|
|
675
|
-
formId,
|
|
676
|
-
isUserForm
|
|
677
|
-
);
|
|
678
|
-
|
|
679
|
-
if (!doc) {
|
|
680
|
-
return null;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
// 2. Check if the field has a file value
|
|
684
|
-
const fileValue = doc.values?.[fieldId] as FilledDocumentFileValue;
|
|
685
|
-
if (fileValue && fileValue.url) {
|
|
686
|
-
return fileValue.url;
|
|
580
|
+
if (!mediaId) {
|
|
581
|
+
throw new Error("MediaId is required to delete a file");
|
|
687
582
|
}
|
|
688
583
|
|
|
689
|
-
|
|
584
|
+
// Delete the file using MediaService
|
|
585
|
+
await this.mediaService.deleteMedia(mediaId);
|
|
690
586
|
}
|
|
691
587
|
}
|