/**
   * @param source
   * @param target
   * @param subjectPersonId
   * @param focalPersonId
   * @param factLists
   * @throws ImproperUsageException
   * @throws DataFormatException
   * @throws InvalidDataException
   */
  public static void pullIn(
      org.opencds.vmr.v1_0.schema.ScheduledProcedure source,
      ScheduledProcedure target,
      String subjectPersonId,
      String focalPersonId,
      FactLists factLists)
      throws ImproperUsageException, DataFormatException, InvalidDataException {

    String _METHODNAME = "pullIn(): ";

    if (source == null) {
      return;
    }

    try {
      ProcedureBaseMapper.pullIn(source, target, subjectPersonId, focalPersonId, factLists);
    } catch (ImproperUsageException u) {
      String errStr = _METHODNAME + "Caught unexpected ImproperUsageException: " + u.getMessage();
      logger.error(errStr, u);
      throw new RuntimeException(errStr);
    }

    if (source.getProcedureTime() != null)
      target.setProcedureTime(MappingUtility.iVLTS2IVLDateInternal(source.getProcedureTime()));

    factLists.internalScheduledProcedureList.add(target);

    // pull in nested RelatedEntities and RelatedClinicalStatements
    NestedObjectsMapper.pullInClinicalStatementNestedObjects(
        source, target.getId(), subjectPersonId, focalPersonId, factLists);

    return;
  }
  /**
   * Populate external vMR object from corresponding internal vMR object; if supplied source
   * parameter is null, simply returns
   *
   * @param source
   * @param target
   * @param organizedResults
   * @return
   * @throws ImproperUsageException
   * @throws DataFormatException
   * @throws InvalidDataException
   */
  public static org.opencds.vmr.v1_0.schema.ScheduledProcedure pushOut(
      ScheduledProcedure source,
      org.opencds.vmr.v1_0.schema.ScheduledProcedure target,
      OrganizedResults organizedResults)
      throws ImproperUsageException, DataFormatException, InvalidDataException {

    String _METHODNAME = "pushOut(): ";

    if (source == null) return null;

    target = new org.opencds.vmr.v1_0.schema.ScheduledProcedure();

    try {
      ProcedureBaseMapper.pushOut(source, target);
    } catch (ImproperUsageException u) {
      String errStr = _METHODNAME + "Caught unexpected ImproperUsageException: " + u.getMessage();
      logger.error(errStr, u);
      throw new RuntimeException(errStr);
    }

    if (source.getProcedureTime() != null)
      target.setProcedureTime(MappingUtility.iVLDateInternal2IVLTS(source.getProcedureTime()));

    // look for and add any nested RelatedClinicalStatements and nested RelatedEntities
    target =
        NestedObjectsMapper.pushOutClinicalStatementNestedObjects(source, target, organizedResults);

    if (organizedResults.getOutput().getScheduledProcedures() == null) {
      organizedResults
          .getOutput()
          .setScheduledProcedures(
              new org.opencds.vmr.v1_0.schema.EvaluatedPerson.ClinicalStatements
                  .ScheduledProcedures());
    }

    return target;
  }