Пример #1
0
    protected bool LetterExists(int letterID)
    {
        Letter letter         = LetterDB.GetByID(letterID);
        bool   useDefaultDocs = letter.Organisation == null ? true : !LetterDB.OrgHasdocs(letter.Organisation.OrganisationID);

        string dir = Letter.GetLettersDirectory();

        return(File.Exists(dir + (useDefaultDocs ? "" : letter.Organisation.OrganisationID + @"\") + letter.Docname));
    }
    public static BulkLetterSendingQueueAdditionalLetter GetFileInfo(Letter.FileFormat fileFormat, Booking booking, Patient patient, HealthCard hc, Letter.TreatmentLetterType treatmentLetterType, Booking.InvoiceType invType, int fieldID, int siteID, int staffID, Referrer referrer, bool keepInHistory, int letterPrintHistorySendMethodID)
    {
        // 1. Add to healthcardaction
        int healthCardActionID = -1;

        if (treatmentLetterType == Letter.TreatmentLetterType.First || treatmentLetterType == Letter.TreatmentLetterType.Last || treatmentLetterType == Letter.TreatmentLetterType.LastWhenReplacingEPC)
        {
            healthCardActionID = HealthCardActionDB.Insert(hc.HealthCardID, Letter.GetHealthCardActionTypeID(treatmentLetterType), DateTime.Now);
        }

        // 2.create document and put it in history
        int letterID = Letter.GetLetterIDByTreatmentLetterTypeAndInvoiceType(treatmentLetterType, invType, fieldID, siteID);

        if (letterID == -1)
        {
            return(null);
        }


        string lettersDir = Letter.GetLettersDirectory();

        if (!Directory.Exists(lettersDir))
        {
            throw new CustomMessageException("Letters directory doesn't exist");
        }

        Letter letter             = LetterDB.GetByID(letterID);
        bool   useDefaultDocs     = letter.Organisation == null ? true : !LetterDB.OrgHasdocs(letter.Organisation.OrganisationID);
        string sourceTemplatePath = lettersDir + (useDefaultDocs ? @"Default\" + letter.Site.SiteID + @"\" : letter.Organisation.OrganisationID + @"\") + letter.Docname;

        if (!File.Exists(sourceTemplatePath))
        {
            throw new CustomMessageException("File doesn't exist: " + Path.GetFileName(sourceTemplatePath));
        }

        // get temp directory
        string tmpLettersDirectory = Letter.GetTempLettersDirectory();

        if (!Directory.Exists(tmpLettersDirectory))
        {
            throw new CustomMessageException("Temp letters directory doesn't exist");
        }

        return(new BulkLetterSendingQueueAdditionalLetter(
                   -1,
                   -1,
                   letter.LetterID,
                   keepInHistory && Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["StoreLettersHistoryInDB"]),
                   keepInHistory && Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["StoreLettersHistoryInFlatFile"]),
                   letterPrintHistorySendMethodID,
                   Letter.GetLettersHistoryDirectory(booking.Organisation.OrganisationID),
                   letter.Docname.Replace(".dot", ".doc"),
                   siteID,
                   booking.Organisation.OrganisationID,
                   booking.BookingID,
                   patient.PatientID,
                   -1, // register_referrer_id_to_use_instead_of_patients_reg_ref
                   staffID,
                   healthCardActionID,
                   sourceTemplatePath,
                   tmpLettersDirectory + letter.Docname.Replace(".dot", ".doc"),
                   true,
                   "",
                   ""
                   ));
    }