Improve formatting of prescriptions.

develop
Daniel Kraus 7 years ago
parent 4479efc196
commit 6ec282ee68
  1. BIN
      gimp/mm.xcf
  2. 20
      zaaReloaded2/Commands.cs
  3. 8
      zaaReloaded2/Formatter/DocumentWriter.cs
  4. BIN
      zaaReloaded2/Icons/mm.png
  5. 131
      zaaReloaded2/Medication/Formatter.cs
  6. 9
      zaaReloaded2/Properties/Settings.Designer.cs
  7. 3
      zaaReloaded2/Properties/Settings.settings
  8. 7
      zaaReloaded2/Ribbon.cs
  9. 13
      zaaReloaded2/Ribbon.xml
  10. 3
      zaaReloaded2/app.config
  11. 5
      zaaReloaded2/zaaReloaded2.csproj

Binary file not shown.

@ -138,8 +138,13 @@ namespace zaaReloaded2
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.
// (NB Technically, there is never _no_ selection in a document.)
Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow;
@ -160,7 +165,18 @@ namespace zaaReloaded2
Medication.Importer importer = new Medication.Importer(activeWindow.Selection.Text);
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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

@ -55,18 +55,38 @@ namespace zaaReloaded2.Medication
/// <param name="document"></param>
public void FormatOneColumn(Document document)
{
if (document == null)
{
throw new ArgumentNullException(
"Cannot format prescriptions because no document was given.");
}
DoFormat("Medikation einspaltig formatieren",
document,
writer =>
{
foreach (Prescription p in Prescriptions)
{
writer.WriteLine(p.ToString());
}
});
}
Helpers.StartUndo("Medikation formatieren");
foreach (Prescription p in Prescriptions)
{
document.ActiveWindow.Selection.TypeText(p.ToString() + "\r");
}
Helpers.EndUndo();
/// <summary>
/// Writes a block of prescriptions with two columns to a
/// Word document.
/// </summary>
/// <param name="document"></param>
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>
@ -77,6 +97,95 @@ namespace zaaReloaded2.Medication
{
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
}

@ -276,5 +276,14 @@ namespace zaaReloaded2.Properties {
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"]));
}
}
}
}

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

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

@ -29,14 +29,19 @@
getEnabled="CanFormat" />
<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." />
<button id="zrlDaniel" label="Daniels Spezial" image="dk.png" onAction="Ribbon_Click" size="large"
getVisible="Daniel_GetVisible"/>
</group>
<group id="zrlGroupDrugs" label="Medikamente">
<button id="zrlFormatDrugs" label="Formatieren" image="m.png" onAction="Ribbon_Click" size="large"
supertip="Formatiert die Medikationsliste"
<button id="zrlFormatDrugsOneCol" label="Einspaltig" image="m.png" onAction="Ribbon_Click" size="large"
supertip="Formatiert die Medikationsliste einspaltig"
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 id="zrlInfoGroup" label="Info">
<button id="zrlDemo" label="Demo" image="d.png" onAction="Ribbon_Click" size="large"
screentip="Demo-Dokument öffnen"

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

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

Loading…
Cancel
Save