Please note that Scripts1 and Scripts2 are the subforms. It checks vYExtent (PageExtentY) by measureonly parameter before printing it.
Ignore RemoveRunEntryOnEvent ( ) is added as I started this command from mainmenu with RunEntryOnEvent() and that has to be broken.
In the begining for about half of a first page, I did not check the overflow as I know it would not overflow at that level. This code works and it is being used to printout 60 to 70 entry everyday and seem to work flawlessly.
var vFont as String = " Arial"
var vFontSize as Int = 17
var vPrinterA as String //= "IBM 4039 LaserPrinter" //Local Printer
var vPrinterB as String //= "\\Reception\IBMPCL5" //Network Printer
var vStr1 as String
var vStr2 as String
var vStr3 as String
//var n as Int
var vLoop as Int
var vPage as Int
var vYExtent as Int
var vChart as String
var vBP as String
var vHC as String
var vGrowthBlock as String
var vBreastBlock as String
var vStopReset as Int = 0
var vServer as String
var vStation as String
var vPhysicalPrintStringPrinterSelect as Int
var vServerDefault as String
var vSignatureOnPhysicalPrintString as Int
var vPrinterList as String
var vSelectedPrinter as String
var vList as String
var vPrintIndicator as String
var vMedicine as String
var vInstruction as String
SubRoutine CompleteTask ( )
PrintString (DN, 550, @PageExtentY ( ) + 10, 0, vFont, vFontSize, 0)
If vPage > 1 then
{
PrintString (UDF_FormatDate (Date1), 0, 1060, 0, vFont, vFontsize, 0, PrintString_Align_Right)
PrintString ("Page " + @str (vPage), 0, 1060, 0, vFont, vFontsize, 0, PrintString_Align_Center)
PrintString (LN + " - " + RecNumber, 0, 1060, 0, vFont, vFontsize, 0, PrintString_Align_Left )
}
vStopReset = 1
FinishPage ( )
//RestoreDefaultPrinter ( )
//Stop //stop is replaced with vStopReset
End Subroutine
SubRoutine PageControlMeasure(vString as String ) //This includes PageControl ( )
If @PageExtentY ( ) > 1050 then
{
If vPage > 1 then
{
PrintString ("Page " + @str (vPage), 0, 1060, 0, vFont, vFontsize, 0, PrintString_Align_Center)
PrintString (LN + " - " + RecNumber, 600, 1060, 0, vFont, vFontsize, 0)
}
FinishPage ( )
NewPage (850, 1100)
PageExtentY (0)
vYExtent = 0
PrintString (vString, 0, vYExtent, 0, vFont, vFontSize, 0)
VPrintIndicator = "Printed" //to avoid printing twice
vPage = vPage + 1
}
End SubRoutine
SubRoutine PageControl( ) //Created just to put at the end otherwise PageControlMeasure ( ) will do
If @PageExtentY ( ) > 1050 then
{
If vPage > 1 then
{
PrintString ("Page " + @str (vPage), 0, 1060, 0, vFont, vFontsize, 0, PrintString_Align_Center)
PrintString (LN + " - " + RecNumber, 600, 1060, 0, vFont, vFontsize, 0)
}
FinishPage ( )
NewPage (850, 1100)
PageExtentY (0)
vPage = vPage + 1
}
End SubRoutine
SubRoutine Printing_Physical ( )
var n as Int
//Functions below is in Global area
//all variables to code below are defined in the begining of code
vChart = @xLookup (@FN, RecNumber, "Index!RecNumber", "Chart")
vChart = vChart + "-" + @Right (Q, 3)
If BP <> "" then
{
vBP = "BP: " + BP
}
If HC <> "" then
{
vHC = "Head Circum: " + HC
}
VGrowthBlock = Tab (1) + W
If H <> "" then
{
vGrowthBlock = vGrowthBlock + @NL ( ) + Tab (1) + H
}
If C <> "" then
{
vGrowthBlock = vGrowthBlock + @NL ( ) + Tab (1) + C
}
If HW <> "" then
{
vGrowthBlock = vGrowthBlock + @NL ( ) + Tab (1) + HW
}
//Parameters: Value, xpos, ypos, column Width, Font, FontSize, measureOnly, Alignment
NewPage (850, 1100)
PrintPagePaper (28)
PrintPageMargin (30, 45, 40, 30)
PrintString ("Name: " + LN, 0, 0, 0, vFont, vFontSize, 0)
PrintString ("Rec#: " + RecNumber, @PageExtentX ( ) + 30, -1, 0, vFont, vFontSize, 0)
PrintString ("Date: " + UDF_FormatDate (Date1), @PageExtentX ( ) + 30, -1, 0, vFont, vFontSize, 0)
PrintString ("Chart# " + vChart, @PageExtentX ( ) + 30, -1, 0, vFont, vFontSize, 0)
PrintString ("VITAL SIGNS", 0, @PageExtentY ( ) + 10, 0, "BArial", vFontSize, 0)
PrintRGBColor (1, 0, 0)
PrintBox (Box_Type_Flat_Box, 0, @PageExtentY ( ), @PageExtentX( ), 1)
PrintString ("Weight: " + WT, 0, @PageExtentY ( ), 200, vFont, vFontSize, 0)
PrintString ("Height: " + HT, -1, -1, 200, vFont, vFontSize, 0)
PrintString ("Temp: " + T, -1, -1, 200, vFont, vFontSize, 0)
PrintString ("BMI: " + BMI, -1, -1, 150, vFont, vFontSize, 0)
PrintString ("Pulse: " + P, 0, @PageExtentY ( ), 200, vFont, vFontSize, 0)
PrintString ("Resp: " + R, -1, -1, 200, vFont, vFontSize, 0)
If vBP <> "" then
{
PrintString (vBP, -1, -1, 200, vFont, vFontSize, 0)
}
Else
{
PrintString (vHC, -1, -1, 200, vFont, vFontSize, 0)
}
If LMP <> "" then
{
PrintString ("LMP: " + UDF_FormatDate (LMP), 0, @PageExtentY ( ), 200, vFont, vFontSize, 0)
}
IF LDP <> "" then
{
If LMP <> "" then
{
PrintString ("LastDepo: " + UDF_FormatDate (LDP), -1, -1, 200, vFont, vFontSize, 0)
}
Else
{
PrintString ("LastDepo: " + UDF_FormatDate (LDP), 0, @PageExtentY (), 200, vFont, vFontSize, 0)
}
}
If FP <> "" then
{
If LMP <> "" or LDP <> "" then
{
PrintString ("FP: " + FP, -1, -1, 0, vFont, vFontSize, 0)
}
Else
{
PrintString ("FP: " + FP, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
}
}
PrintString (vGrowthBlock, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString ("HISTORY OF PRESENT ILLNESS", 0, @PageExtentY ( ) + 5, 0, "BArial", vFontSize, 0)
PrintRGBColor (1, 0, 0)
PrintBox (Box_Type_Flat_Box, 0, @PageExtentY ( ), @PageExtentX( ), 1)
PrintString ("The Patient is " + Age + " old " + Sex + ".", 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (His1 + " " + His2 + " " + His3, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString ("PHYSICAL EXAMINATION", 0, @PageExtentY ( ) + 5, 0, "BArial", vFontSize, 0)
PrintRGBColor (1, 0, 0)
PrintBox (Box_Type_Flat_Box, 0, @PageExtentY ( ), @PageExtentX( ), 1)
PrintString (GRL, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (HN, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Eyes, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Ears, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Lung, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (CVS, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Breast, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (ABD, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Skin, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Joint, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Ext, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Gtal, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (CNS, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Rtal, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (LymphN, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString ("PERTINENT LAB, XRAY AND OTHER DIAGNOSIC WORKUP", 0, @PageExtentY ( ) + 5, 0, "BArial", vFontSize, 0)
PrintRGBColor (1, 0, 0)
PrintBox (Box_Type_Flat_Box, 0, @PageExtentY ( ), @PageExtentX( ), 1)
PrintString (AB_Lab, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
IF Lab <> "" or Xray1 <> "" then
{
PrintString (Lab + " " + Xray1, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
}
If HB <> "" or Tine <> "" or Blood_Glucose <> "" then
{
PrintString (HB + " " + TINE + " " + Blood_Glucose, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
}
PrintString (UD, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Hearing, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (Imm, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString ("DIAGNOSIS AND ASSESSMENT", 0, @PageExtentY ( ) + 5, 0, "BArial", vFontSize, 0)
PrintRGBColor (1, 0, 0)
PrintBox (Box_Type_Flat_Box, 0, @PageExtentY ( ), @PageExtentX( ), 1)
PrintString (@Left (Cond1, (@Len(cond1) -7)), 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (@Left (Cond2, (@Len(cond2) -7)), 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString (@Left (Cond3, (@Len(cond3) -7)), 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString ("CHRONIC ONGOING PROBLEMS", 0, @PageExtentY ( ) + 5, 0, "BArial", vFontSize, 0)
PrintRGBColor (1, 0, 0)
PrintBox (Box_Type_Flat_Box, 0, @PageExtentY ( ), @PageExtentX( ), 1)
PrintString (Chr_Problems, 0, @PageExtentY ( ), 0, vFont, vFontSize, 0)
PrintString ("TREATMENT PLAN", 0, @PageExtentY ( ) + 5, 0, "BArial", vFontSize, 0)
PrintRGBColor (1, 0, 0)
PrintBox (Box_Type_Flat_Box, 0, @PageExtentY ( ), @PageExtentX( ), 1)
For n = 1 to @FormResultSetTotal ("Scripts1")
vMedicine = @FormFieldValue ("Scripts1", "Medicine", n)
vInstruction = @FormFieldValue ("Scripts1", "Medicine", n)
If vMedicine <> "" then
{
vStr3 = vMedicine + " " + vInstruction
vYExtent = @PageExtentY ( )
PrintString (vStr3, 0, @PageExtentY ( ), 0, vFont, vFontSize, 1)
vPrintIndicator = "Not Printed" //Avoid double printing, Reset to printed if printed through pagecontrolMeasure ( )
PageControlMeasure (vStr3)
If vPage = 1 or (vPage = 2 and vPrintIndicator = "Not Printed") then
{
PrintString (vStr3, 0, vYExtent, 0, vFont, vFontSize, 0)
}
}
Next
For n = 1 to @FormResultSetTotal ("Scripts2")
vMedicine = @FormFieldValue ("Scripts2", "Medicine", n)
vInstruction = @FormFieldValue ("Scripts2", "Medicine", n)
If vMedicine <> "" then
{
vStr3 = vMedicine + " " + vInstruction
vYExtent = @PageExtentY ( )
PrintString (vStr3, 0, @PageExtentY ( ), 0, vFont, vFontSize, 1)
vPrintIndicator = "Not Printed" //Avoid double printing, Reset to printed if printed through pagecontrolMeasure ( )
PageControlMeasure (vStr3)
If vPage = 1 or (vPage = 2 and vPrintIndicator = "Not Printed") then
{
PrintString (vStr3, 0, vYExtent, 0, vFont, vFontSize, 0)
}
}
Next
vYExtent = @PageExtentY ( )
PrintString (AD1 + " " + AD2 + " " + AD3 + " " + ADP, 0, vYExtent, 0, vFont, vFontSize, 1)
//writeLN (@PageExtentY ( ) )
If @PageExtentY () <= 1100 then
{
PrintString (AD1 + " " + AD2 + " " + AD3 + " " + ADP, 0, vYExtent, 0, vFont, vFontSize, 0)
}
Else
{
PageExtentY (vYExtent)
PrintString (AD1 + " " + AD2 + " " + AD3, 0, vYExtent, 0, vFont, vFontSize, 1)
//WriteLn (@PageExtentY ( ))
If @PageExtentY () < 1100 and vPage = 1 and vStopReset = 0 then
{
PrintString (AD1 + " " + AD2 + " " + AD3, 0, vYExtent, 0, vFont, vFontSize, 0)
PageControlMeasure (ADP)
CompleteTask ( )
}
PageExtentY (vYExtent)
PrintString (AD1 + " " + AD2, 0, vYExtent, 0, vFont, vFontSize, 1)
//WriteLN (@PageExtentY ( ) )
If @PageExtentY () < 1100 and vPage = 1 and vStopReset = 0 then
{
PrintString (AD1 + " " + AD2, 0, vYExtent, 0, vFont, vFontSize, 0)
PageControlMeasure (AD3 + " " + ADP)
CompleteTask ( )
}
PageExtentY (vYExtent)
PrintString (AD1, 0, vYExtent, 0, vFont, vFontSize, 1)
//WriteLN (@PageExtentY ( ) )
If @PageExtentY () < 1100 and vPage = 1 and vStopReset = 0 then
{
PrintString (AD1, 0, vYExtent, 0, vFont, vFontSize, 0)
PageControlMeasure (AD2 + " " + AD3 + " " + ADP)
CompleteTask ( )
}
}
PrintString (DN, 550, @PageExtentY ( ) + 10, 0, vFont, vFontSize, 0)
if @GlobalValue (vSignatureOnPhysicalPrintString) = "1" then
{
PrintImage ("C:\images\bharat_sig.jpg", 550, @PageExtentY ( ) + 10, -1, -1)
}
If vPage > 1 then
{
PrintString (UDF_FormatDate (Date1), 0, 1060, 0, vFont, vFontsize, 0, PrintString_Align_Right)
PrintString ("Page " + @str (vPage), 0, 1060, 0, vFont, vFontsize, 0, PrintString_Align_Center)
PrintString (LN + " - " + RecNumber, 0, 1060, 0, vFont, vFontsize, 0, PrintString_Align_Left )
}
FinishPage ( )
//RestoreDefaultPrinter ( )
End SubRoutine
vPrinterA = @GlobalValue ("PrinterA")
vPrinterB = @GlobalValue ("PrinterB")
vServerDefault = @GlobalValue ("ServerDefaultPrinter")
vPrinterList = udfGetPrinterList ( )
If @AskUser("Do you want to PRINT PHYSICALS for all " + @Str(@ResultSetTotal()) + " records in the result set?", "", "") then
{
If @UserParameter (1) = @GlobalValue ("ServerComp") and @GlobalValue ("PhysicalPrintStringPrinterSelect") <> "1" then //User Param entered in Sesame.ini file of Main_Server
{
AlternateDefaultPrinter (vPrinterB)
}
Else if @UserParameter (1) = @GlobalValue ("ServerComp") and @GlobalValue ("PhysicalPrintStringPrinterSelect") = "1" then
{
PopupSelectPosition(4, @Xpos(ThisElement), @Ypos(ThisElement))
vSelectedPrinter = @PopupChoiceList(vPrinterList, "Select A Printer")
AlternateDefaultPrinter (VSelectedPrinter)
}
Else if @UserParameter (1) = @GlobalValue ("FrontComp") then //User Param entered in Sesame.ini file of Reception
{
AlternateDefaultPrinter (vPrinterA)
}
Else if @Globalvalue ("PhysicalPrintStringPrinterSelect") = "1" then
{
PopupSelectPosition(4, @Xpos(ThisElement), @Ypos(ThisElement))
vSelectedPrinter = @PopupChoiceList(vPrinterList, "Select A Printer")
AlternateDefaultPrinter (VSelectedPrinter)
}
Else
{
RestoreDefaultPrinter ( )
}
For vLoop = 1 to @ResultSetTotal( )
vPage = 1
vStopReset = 0
ResultSetCurrentPosition (vLoop)
Printing_Physical ( )
next
RestoreDefaultPrinter ( )
RemoveRunEntryOnEvent()
}
Else
{
RemoveRunEntryOnEvent()
ClientLocalValue ("PrintFromMenu", "0") //Reset value
@save //come out of form
@exit
}
RemoveRunEntryOnEvent()
If @ClientLocalValue ("PrintFromMenu") = "1" and @UserParameter (1) = vStation then
{
RemoveRunEntryOnEvent()
ClientLocalValue ("PrintFromMenu", "0") //Reset value
@Save
@Exit //come out of form
}