예제 #1
0
  private void loadArticlesUsedOnSelectedDay() {
    String date =
        dtDate.getYear()
            + String.format("%02d", dtDate.getMonth() + 1)
            + String.format("%02d", dtDate.getDay());

    Query<Konsultation> qbe = new Query<Konsultation>(Konsultation.class);
    qbe.add(Konsultation.FLD_DATE, Query.EQUALS, date);
    List<Konsultation> cons = qbe.execute();

    StringBuilder sb = new StringBuilder();

    for (Konsultation c : cons) {
      List<Verrechnet> leistungen = c.getLeistungen();
      for (Verrechnet v : leistungen) {
        IVerrechenbar vv = v.getVerrechenbar();
        if (vv instanceof Artikel) {
          Artikel art = (Artikel) vv;
          Mandant mandator = ElexisEventDispatcher.getSelectedMandator();
          IStockEntry stockEntry =
              CoreHub.getStockService()
                  .findPreferredStockEntryForArticle(
                      art.storeToString(), (mandator != null) ? mandator.getId() : null);
          if (stockEntry != null) {
            StockEntry se = (StockEntry) stockEntry;
            currOrder.addBestellungEntry(
                se.getArticle(), se.getStock(), se.getProvider(), v.getZahl());
          } else {
            sb.append(art.getLabel() + " ist kein Lagerartikel.\n");
          }
        }
      }
    }
  }
예제 #2
0
 private void doShakeKons(IProgressMonitor monitor, int workUnits) {
   try {
     monitor.subTask("Anonymisiere Konsultationen");
     Query<Konsultation> qbe = new Query<Konsultation>(Konsultation.class);
     List<Konsultation> list = qbe.execute();
     int workPerKons = (Math.round(workUnits * .8f) / list.size());
     Lipsum lipsum = new Lipsum();
     monitor.worked(Math.round(workUnits * .2f));
     for (Konsultation k : list) {
       VersionedResource vr = k.getEintrag();
       StringBuilder par = new StringBuilder();
       int numPars = (int) Math.round(3 * Math.random() + 1);
       while (numPars-- > 0) {
         par.append(lipsum.getParagraph());
       }
       vr.update(par.toString(), "random contents");
       k.setEintrag(vr, true);
       k.purgeEintrag();
       if (monitor.isCanceled()) {
         break;
       }
       monitor.worked(workPerKons);
     }
   } catch (Throwable e) {
     SWTHelper.showError("Fehler", e.getMessage());
   }
 }
예제 #3
0
  public static ch.elexis.data.Patient getElexisPatient(Patient ehcPatient) {
    // try to look up via ids
    List<Identificator> ids = ehcPatient.getIds();
    for (Identificator identificator : ids) {
      String idRoot = identificator.getRoot();
      if (idRoot.equals(CodeSystems.SwissSSNDeprecated.getCodeSystemId())
          || idRoot.equals(CodeSystems.SwissSSN.getCodeSystemId())) {
        IPersistentObject ret = Xid.findObject(Xid.DOMAIN_AHV, identificator.getExtension());
        if (ret instanceof Kontakt) {
          if (((Kontakt) ret).istPatient()) {
            return ch.elexis.data.Patient.load(ret.getId());
          }
        }
        System.out.println("foud ret " + ret);
        if (ret instanceof ch.elexis.data.Patient) {
          return (ch.elexis.data.Patient) ret;
        }
      }
    }

    Query<ch.elexis.data.Patient> qpa =
        new Query<ch.elexis.data.Patient>(ch.elexis.data.Patient.class);
    // initialize data
    Name ehcName = ehcPatient.getName();
    Date ehcBirthdate = ehcPatient.getBirthday();
    String gender =
        ehcPatient.getAdministrativeGenderCode() == AdministrativeGender.FEMALE
            ? Person.FEMALE
            : Person.MALE;
    TimeTool ttBirthdate = new TimeTool();
    // add data to query
    if (ehcName.getFamilyName() != null && !ehcName.getFamilyName().isEmpty()) {
      qpa.add(ch.elexis.data.Patient.FLD_NAME, Query.EQUALS, ehcName.getFamilyName());
    }
    if (ehcName.getGivenNames() != null && !ehcName.getGivenNames().isEmpty()) {
      qpa.add(ch.elexis.data.Patient.FLD_FIRSTNAME, Query.EQUALS, ehcName.getGivenNames());
    }
    if (ehcBirthdate != null) {
      ttBirthdate.setTime(ehcBirthdate);
      qpa.add(Person.BIRTHDATE, Query.EQUALS, ttBirthdate.toString(TimeTool.DATE_COMPACT));
    }
    List<ch.elexis.data.Patient> existing = qpa.execute();
    // create or overwrite Patient
    ch.elexis.data.Patient ret = null;
    if (existing.isEmpty()) {
      ret =
          new ch.elexis.data.Patient(
              ehcName.getFamilyName(),
              ehcName.getGivenNames(),
              ttBirthdate.toString(TimeTool.DATE_COMPACT),
              gender);
    } else {
      ret = existing.get(0);
    }

    return ret;
  }
예제 #4
0
 @Override
 public boolean delete() {
   Query<Note> qbe = new Query<Note>(Note.class);
   qbe.add(FLD_PARENT, Query.EQUALS, getId());
   List<Note> list = qbe.execute();
   for (Note note : list) {
     note.delete();
   }
   return super.delete();
 }
예제 #5
0
  private void doShakeNames(IProgressMonitor monitor, int workUnits) {
    monitor.subTask("Anonymisiere Patienten und Kontakte");
    Query<Kontakt> qbe = new Query<Kontakt>(Kontakt.class);
    List<Kontakt> list = qbe.execute();
    int workPerName = (Math.round(workUnits * .8f) / list.size());
    Namen n = null;
    if (zufallsnamen) {
      n = new Namen();
    }
    monitor.worked(Math.round(workUnits * .2f));
    for (Kontakt k : list) {
      String vorname = "";
      // Mandanten behalten
      // if(k.get(Kontakt.FLD_IS_MANDATOR).equalsIgnoreCase(StringConstants.ONE))
      // continue;

      if (zufallsnamen) {
        k.set("Bezeichnung1", n.getRandomNachname());
      } else {
        k.set("Bezeichnung1", getWord());
      }

      if (zufallsnamen) {
        vorname = n.getRandomVorname();
      } else {
        vorname = getWord();
      }
      k.set("Bezeichnung2", vorname);

      if (k.istPerson()) {
        Person p = Person.load(k.getId());
        p.set(Person.SEX, StringTool.isFemale(vorname) ? Person.FEMALE : Person.MALE);
      }
      k.set(Kontakt.FLD_ANSCHRIFT, "");
      k.set(Kontakt.FLD_PHONE1, getPhone());
      k.set(Kontakt.FLD_PHONE2, Math.random() > 0.6 ? getPhone() : "");
      k.set(Kontakt.FLD_MOBILEPHONE, Math.random() > 0.5 ? getPhone() : "");
      k.set(Kontakt.FLD_E_MAIL, "");
      k.set(Kontakt.FLD_PLACE, "");
      k.set(Kontakt.FLD_STREET, "");
      k.set(Kontakt.FLD_ZIP, "");
      k.set(Kontakt.FLD_FAX, Math.random() > 0.8 ? getPhone() : "");
      if (monitor.isCanceled()) {
        break;
      }
      monitor.worked(workPerName);
    }
  }
예제 #6
0
  private void updateDosierungen() {
    Query<Prescription> q = new Query<Prescription>(Prescription.class);
    List<Prescription> pl = q.execute();
    for (Prescription p : pl) {
      try {
        String[] parts = p.getDosis().split("-");

        if (parts == null || parts.length != 4) {
          // System.out.println("skip");
          continue;
        }
        for (int i = 0; i < 4; i++) {
          String d = parts[i];
          if (d.equals("x")) {
            parts[i] = "X";
            break;
          }

          // Brueche kuerzen
          if (d.matches("[0-9]+/[0-9]+")) {
            String[] dp = d.split("/");
            int z = Integer.parseInt(dp[0]);
            int n = Integer.parseInt(dp[1]);
            if (z > n) {
              int g = z / n;
              z %= n;
              parts[i] = g + " " + z + "/" + n;
            }
          }
        }
        p.setDosis(parts[0] + "-" + parts[1] + "-" + parts[2] + "-" + parts[3]);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
예제 #7
0
 public Object[] getElements(final Object inputElement) {
   Query<Bestellung> qbe = new Query<Bestellung>(Bestellung.class);
   return qbe.execute().toArray();
 }
예제 #8
0
  @Override
  protected IStatus createContent(IProgressMonitor monitor) {
    int total = 10000000;
    Query<AccountTransaction> qbe = new Query<AccountTransaction>(AccountTransaction.class);
    TimeTool ttStart = new TimeTool(this.getStartDate().getTimeInMillis());
    TimeTool ttEnd = new TimeTool(this.getEndDate().getTimeInMillis());
    qbe.add(
        AccountTransaction.FLD_DATE,
        Query.GREATER_OR_EQUAL,
        ttStart.toString(TimeTool.DATE_COMPACT)); // $NON-NLS-1$ //$NON-NLS-2$
    qbe.add(
        AccountTransaction.FLD_DATE,
        Query.LESS_OR_EQUAL,
        ttEnd.toString(TimeTool.DATE_COMPACT)); // $NON-NLS-1$ //$NON-NLS-2$
    monitor.beginTask(NAME, total);
    monitor.subTask(Messages.FakturaJournal_DatabaseQuery);
    List<AccountTransaction> transactions = qbe.execute();
    int sum = transactions.size();
    final ArrayList<Comparable<?>[]> result = new ArrayList<Comparable<?>[]>();
    if (sum == 0) {
      monitor.done();
      this.dataSet.setContent(result);
      return Status.OK_STATUS;
    }
    int step = total / sum;
    monitor.worked(20 * step);
    PatientIdFormatter pif = new PatientIdFormatter(8);
    String actMnId = CoreHub.actMandant.getId();
    for (AccountTransaction at : transactions) {
      Patient pat = at.getPatient();
      if (pat != null) {
        if (bOnlyActiveMandator) {
          Rechnung rn = at.getRechnung();
          if (rn == null) {
            continue;
          }
          Mandant mn = rn.getMandant();
          if (mn != null) {
            if (!mn.getId().equals(actMnId)) {
              continue;
            }
          }
        }
        Comparable<?>[] row = new Comparable<?>[this.dataSet.getHeadings().size()];
        row[0] = pif.format(pat.get(Patient.FLD_PATID));
        row[1] = new DateTool(at.getDate());
        row[2] = at.getAmount();
        row[4] = at.getRemark();
        if (((Money) row[2]).isNegative()) {
          row[3] = Messages.FakturaJournal_FA;
        } else {
          if (((String) row[4]).toLowerCase().contains("storno")) { // $NON-NLS-1$
            row[3] = Messages.FakturaJournal_ST;
          } else {
            row[3] = Messages.FakturaJournal_GU;
          }
        }
        if (monitor.isCanceled()) {
          return Status.CANCEL_STATUS;
        }
        result.add(row);
      }
      monitor.worked(step);
    }

    // Set content.
    this.dataSet.setContent(result);

    // Job finished successfully
    monitor.done();

    return Status.OK_STATUS;
  }
  /**
   * Import a medicament from one row of the BAG-Medi file
   *
   * @param row
   *     <pre>
   * 		row[0] = ID,bzw Name
   * 		row[1] = Generikum
   * 		row[2] = Pharmacode
   * 	 	row[3] = BAG-Dossier
   * 		row[4] = Swissmedic-Nr
   * 		row[5] = Swissmedic-Liste
   * 	 	row[6]
   * 		row[7] = Namen
   * 		row[8] = EK-Preis
   *      row[9] = VK-Preis
   *      row[10]= Limitatio (Y/N)
   *      row[11]= LimitatioPts
   *      row[12]= Gruppe (optional)
   *      row[13]= Substance (optional)
   * </pre>
   *
   * @return
   */
  public static boolean importUpdate(final String[] row) throws ElexisException {
    String pharmacode = "0";
    BAGMedi imp = null;
    // Kein Pharmacode, dann nach Name suchen
    if (StringTool.isNothing(row[2].trim())) {
      String mid = qbe.findSingle(Artikel.FLD_NAME, "=", row[7]);
      if (mid != null) {
        imp = BAGMedi.load(mid);
      }
    } else {
      try {
        // strip leading zeroes
        int pcode = Integer.parseInt(row[2].trim());
        pharmacode = Integer.toString(pcode);

      } catch (Exception ex) {
        ExHandler.handle(ex);
        log.log(Level.WARNING, "Pharmacode falsch: " + row[2]);
      }

      qbe.clear(true);
      qbe.add(Artikel.FLD_SUB_ID, "=", pharmacode);
      qbe.or();
      qbe.add(Artikel.FLD_SUB_ID, Query.EQUALS, row[2].trim());
      List<Artikel> lArt = qbe.execute();
      if (lArt == null) {
        throw new ElexisException(
            BAGMediImporter.class,
            "Article list was null while scanning for " + pharmacode,
            ElexisException.EE_UNEXPECTED_RESPONSE,
            true);
      }
      if (lArt.size() > 1) {
        // Duplikate entfernen, genau einen gültigen und existierenden Artikel behalten
        Iterator<Artikel> it = lArt.iterator();
        boolean hasValid = false;
        Artikel res = null;
        while (it.hasNext()) {
          Artikel ax = it.next();
          if (hasValid || (!ax.isValid())) {
            if (res == null) {
              res = ax;
            }
            it.remove();
          } else {
            hasValid = true;
          }
        }
        if (!hasValid) {
          if (res != null) {
            if (res.isDeleted()) {
              res.undelete();
              lArt.add(res);
            }
          }
        }
      }
      imp = lArt.size() > 0 ? BAGMedi.load(lArt.get(0).getId()) : null;
    }
    if (imp == null || (!imp.isValid())) {
      imp = new BAGMedi(row[7], pharmacode);

      String sql =
          new StringBuilder()
              .append("INSERT INTO ")
              .append(BAGMedi.EXTTABLE)
              .append(" (ID) VALUES (")
              .append(imp.getWrappedId())
              .append(");")
              .toString();
      PersistentObject.getConnection().exec(sql);

    } else {

      String sql =
          new StringBuilder()
              .append("SELECT ID FROM ")
              .append(BAGMedi.EXTTABLE)
              .append(" WHERE ID=")
              .append(imp.getWrappedId())
              .toString();
      String extid = PersistentObject.getConnection().queryString(sql);
      if (extid == null) {
        sql =
            new StringBuilder()
                .append("INSERT INTO ")
                .append(BAGMedi.EXTTABLE)
                .append(" (ID) VALUES (")
                .append(imp.getWrappedId())
                .append(");")
                .toString();
        PersistentObject.getConnection().exec(sql);
      }
    }
    imp.update(row);
    return true;
  }
예제 #10
0
 /**
  * find the children of this note
  *
  * @return a list of all Notes that are children of the current note. The list might me empty but
  *     is never null.
  */
 public List<Note> getChildren() {
   Query<Note> qbe = new Query<Note>(Note.class);
   qbe.add(FLD_PARENT, Query.EQUALS, getId());
   return qbe.execute();
 }