Improve formatting of prescriptions.

This commit is contained in:
Daniel Kraus 2015-12-01 17:38:44 +01:00
parent 4479efc196
commit 6ec282ee68
11 changed files with 179 additions and 20 deletions

BIN
gimp/mm.xcf Normal file

Binary file not shown.

View File

@ -138,8 +138,13 @@ namespace zaaReloaded2
Globals.ThisAddIn.Application.Selection); Globals.ThisAddIn.Application.Selection);
} }
public static void FormatDrugs() public static void FormatDrugs(int columns)
{ {
if (columns < 1 || columns > 2)
{
throw new ArgumentOutOfRangeException("Can only format 1 or 2 columns, not " + columns);
}
// If no "real" selection exists, attempt to auto-detect the drugs section. // If no "real" selection exists, attempt to auto-detect the drugs section.
// (NB Technically, there is never _no_ selection in a document.) // (NB Technically, there is never _no_ selection in a document.)
Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow; Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow;
@ -160,7 +165,18 @@ namespace zaaReloaded2
Medication.Importer importer = new Medication.Importer(activeWindow.Selection.Text); Medication.Importer importer = new Medication.Importer(activeWindow.Selection.Text);
Medication.Formatter formatter = new Medication.Formatter(importer.Prescriptions); Medication.Formatter formatter = new Medication.Formatter(importer.Prescriptions);
formatter.FormatOneColumn(activeWindow.Document);
switch (columns)
{
case 1:
formatter.FormatOneColumn(activeWindow.Document);
break;
case 2:
formatter.FormatTwoColumns(activeWindow.Document);
break;
default:
break;
}
} }
#endregion #endregion

View File

@ -171,6 +171,14 @@ namespace zaaReloaded2.Formatter
_buffer.AppendLine(text); _buffer.AppendLine(text);
} }
/// <summary>
/// Appends a newline to the buffer.
/// </summary>
public void WriteLine()
{
_buffer.AppendLine();
}
/// <summary> /// <summary>
/// Inserts text at the start of the buffer. /// Inserts text at the start of the buffer.
/// </summary> /// </summary>

BIN
zaaReloaded2/Icons/mm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

View File

@ -55,18 +55,38 @@ namespace zaaReloaded2.Medication
/// <param name="document"></param> /// <param name="document"></param>
public void FormatOneColumn(Document document) public void FormatOneColumn(Document document)
{ {
if (document == null) DoFormat("Medikation einspaltig formatieren",
{ document,
throw new ArgumentNullException( writer =>
"Cannot format prescriptions because no document was given."); {
} foreach (Prescription p in Prescriptions)
{
writer.WriteLine(p.ToString());
}
});
}
Helpers.StartUndo("Medikation formatieren"); /// <summary>
foreach (Prescription p in Prescriptions) /// Writes a block of prescriptions with two columns to a
{ /// Word document.
document.ActiveWindow.Selection.TypeText(p.ToString() + "\r"); /// </summary>
} /// <param name="document"></param>
Helpers.EndUndo(); public void FormatTwoColumns(Document document)
{
DoFormat("Medikation zweispaltig formatieren",
document,
writer =>
{
for (int i = 0; i < Prescriptions.Count; i += 2)
{
writer.Write(Prescriptions[i].ToString());
if (i + 1 < Prescriptions.Count)
{
writer.Write("\t" + Prescriptions[i+1].ToString());
}
writer.WriteLine();
}
});
} }
/// <summary> /// <summary>
@ -77,6 +97,95 @@ namespace zaaReloaded2.Medication
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion
#region Private methods
void AddDisclaimer(zaaReloaded2.Formatter.DocumentWriter writer)
{
writer.WriteLine("<highlight><b>Bitte Medikation überprüfen!</b></highlight>");
}
/// <summary>
/// Creates a paragraph and character styles in the document.
/// </summary>
void CreateStyles(Document document)
{
if (document != null)
{
Style style;
// Don't see a better way to check for the existence of a particular
// paragraph style than by using a try...catch construction.
try
{
style = document.Styles[Properties.Settings.Default.DrugsParagraph];
}
catch
{
// Add default paragraph style for laboratory
style = document.Styles.Add(Properties.Settings.Default.DrugsParagraph);
style.Font.Size = 10; // pt
style.Font.Bold = 0;
style.Font.Italic = 0;
style.Font.Underline = 0;
style.ParagraphFormat.SpaceAfter = 0;
style.ParagraphFormat.SpaceBefore = 0;
style.ParagraphFormat.LeftIndent = 0; // pt
style.ParagraphFormat.FirstLineIndent = 0; // pt
style.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
style.ParagraphFormat.TabStops.ClearAll();
int tabStop = 108; // 108 pt = 2.5 in = 3.8 cm
int halfWay = 227; // 227 pt = 3.15 in = 8 cm
style.ParagraphFormat.TabStops.Add(tabStop);
style.ParagraphFormat.TabStops.Add(halfWay);
style.ParagraphFormat.TabStops.Add(halfWay + tabStop);
}
// try
// {
// style = document.Styles[Properties.Settings.Default.DrugsHeader];
// }
// catch
// {
// // Add header paragraph style for laboratory
// style = document.Styles.Add(Properties.Settings.Default.DrugsHeader);
// style.Font.Size = 10; // pt
// style.Font.Bold = 1;
// style.Font.Italic = 0;
// style.Font.Underline = WdUnderline.wdUnderlineSingle;
// style.ParagraphFormat.SpaceAfter = 0;
// style.ParagraphFormat.SpaceBefore = 12;
// style.ParagraphFormat.LeftIndent = 36; // pt
// style.ParagraphFormat.FirstLineIndent = -36; // pt
// style.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphJustify;
// style.set_NextParagraphStyle(document.Styles[Properties.Settings.Default.DrugsParagraph]);
// }
}
}
/// <summary>
/// Does the heavy lifting in a DRY way.
/// </summary>
void DoFormat(string description, Document document,
Action<zaaReloaded2.Formatter.DocumentWriter> outputAction)
{
if (document == null)
{
throw new ArgumentNullException(
"Cannot format prescriptions because no document was given.");
}
Helpers.StartUndo(description);
zaaReloaded2.Formatter.DocumentWriter writer = new zaaReloaded2.Formatter.DocumentWriter(document);
CreateStyles(document);
writer.Write(String.Format("<style:{0}>", Properties.Settings.Default.DrugsParagraph));
outputAction(writer);
AddDisclaimer(writer);
// writer.Write("</style>"); // causes COM exceptions, needs fix
writer.Flush();
Helpers.EndUndo();
}
#endregion #endregion
} }

View File

@ -276,5 +276,14 @@ namespace zaaReloaded2.Properties {
this["NeedUpgrade"] = value; this["NeedUpgrade"] = value;
} }
} }
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("zaaReloaded2-Medikamente")]
public string DrugsParagraph {
get {
return ((string)(this["DrugsParagraph"]));
}
}
} }
} }

View File

@ -80,5 +80,8 @@
<Setting Name="NeedUpgrade" Type="System.Boolean" Scope="User"> <Setting Name="NeedUpgrade" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value> <Value Profile="(Default)">True</Value>
</Setting> </Setting>
<Setting Name="DrugsParagraph" Type="System.String" Scope="Application">
<Value Profile="(Default)">zaaReloaded2-Medikamente</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>

View File

@ -105,8 +105,11 @@ namespace zaaReloaded2
case "zrlDemo": case "zrlDemo":
Commands.LoadDemo(); Commands.LoadDemo();
break; break;
case "zrlFormatDrugs": case "zrlFormatDrugsOneCol":
Commands.FormatDrugs(); Commands.FormatDrugs(1);
break;
case "zrlFormatDrugsTwoCol":
Commands.FormatDrugs(2);
break; break;
default: default:
throw new InvalidOperationException("No operation defined for " + control.Id); throw new InvalidOperationException("No operation defined for " + control.Id);

View File

@ -29,13 +29,18 @@
getEnabled="CanFormat" /> getEnabled="CanFormat" />
<button id="zrlSettings" label="Stilauswahl" image="fff.png" onAction="Ribbon_Click" size="large" <button id="zrlSettings" label="Stilauswahl" image="fff.png" onAction="Ribbon_Click" size="large"
supertip="Zeigt eine Liste vorhandener Stile an. Stile können bearbeitet, hinzugefügt, gelöscht werden." /> supertip="Zeigt eine Liste vorhandener Stile an. Stile können bearbeitet, hinzugefügt, gelöscht werden." />
<button id="zrlDaniel" label="Daniels Spezial" image="dk.png" onAction="Ribbon_Click" size="large"
getVisible="Daniel_GetVisible"/>
</group> </group>
<group id="zrlGroupDrugs" label="Medikamente"> <group id="zrlGroupDrugs" label="Medikamente">
<button id="zrlFormatDrugs" label="Formatieren" image="m.png" onAction="Ribbon_Click" size="large" <button id="zrlFormatDrugsOneCol" label="Einspaltig" image="m.png" onAction="Ribbon_Click" size="large"
supertip="Formatiert die Medikationsliste" supertip="Formatiert die Medikationsliste einspaltig"
getEnabled="CanFormatDrugs" /> getEnabled="CanFormatDrugs" />
<button id="zrlFormatDrugsTwoCol" label="Zweispaltig" image="mm.png" onAction="Ribbon_Click" size="large"
supertip="Formatiert die Medikationsliste zweispaltig"
getEnabled="CanFormatDrugs" />
</group>
<group id="zrlSpecial" label="Spezial">
<button id="zrlDaniel" label="Daniels Spezial" image="dk.png" onAction="Ribbon_Click" size="large"
getVisible="Daniel_GetVisible"/>
</group> </group>
<group id="zrlInfoGroup" label="Info"> <group id="zrlInfoGroup" label="Info">
<button id="zrlDemo" label="Demo" image="d.png" onAction="Ribbon_Click" size="large" <button id="zrlDemo" label="Demo" image="d.png" onAction="Ribbon_Click" size="large"

View File

@ -86,6 +86,9 @@
<setting name="Repository" serializeAs="String"> <setting name="Repository" serializeAs="String">
<value>http://git.bovender.de</value> <value>http://git.bovender.de</value>
</setting> </setting>
<setting name="DrugsParagraph" serializeAs="String">
<value>zaaReloaded2-Medikamente</value>
</setting>
</zaaReloaded2.Properties.Settings> </zaaReloaded2.Properties.Settings>
</applicationSettings> </applicationSettings>
<userSettings> <userSettings>

View File

@ -29,6 +29,7 @@
<AssemblyName>zaaReloaded2</AssemblyName> <AssemblyName>zaaReloaded2</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<DefineConstants>VSTO40</DefineConstants> <DefineConstants>VSTO40</DefineConstants>
<IsWebBootstrapper>False</IsWebBootstrapper>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<InstallUrl /> <InstallUrl />
@ -38,7 +39,6 @@
<UpdateEnabled>true</UpdateEnabled> <UpdateEnabled>true</UpdateEnabled>
<UpdateInterval>7</UpdateInterval> <UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>days</UpdateIntervalUnits> <UpdateIntervalUnits>days</UpdateIntervalUnits>
<IsWebBootstrapper>False</IsWebBootstrapper>
<ProductName>zaaReloaded2</ProductName> <ProductName>zaaReloaded2</ProductName>
<PublisherName /> <PublisherName />
<SupportUrl /> <SupportUrl />
@ -453,6 +453,9 @@
<ItemGroup> <ItemGroup>
<Resource Include="Icons\m.png" /> <Resource Include="Icons\m.png" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Resource Include="Icons\mm.png" />
</ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>