Esempio n. 1
0
  private ca.uhn.fhir.jpa.dao.IFhirResourceDao<? extends IBaseResource> toDao(
      UrlParts theParts, String theVerb, String theUrl) {
    RuntimeResourceDefinition resType;
    try {
      resType = getContext().getResourceDefinition(theParts.getResourceType());
    } catch (DataFormatException e) {
      String msg =
          getContext()
              .getLocalizer()
              .getMessage(BaseHapiFhirSystemDao.class, "transactionInvalidUrl", theVerb, theUrl);
      throw new InvalidRequestException(msg);
    }
    IFhirResourceDao<? extends IBaseResource> dao = null;
    if (resType != null) {
      dao = getDao(resType.getImplementingClass());
    }
    if (dao == null) {
      String msg =
          getContext()
              .getLocalizer()
              .getMessage(BaseHapiFhirSystemDao.class, "transactionInvalidUrl", theVerb, theUrl);
      throw new InvalidRequestException(msg);
    }

    // if (theParts.getResourceId() == null && theParts.getParams() == null) {
    // String msg = getContext().getLocalizer().getMessage(BaseHapiFhirSystemDao.class,
    // "transactionInvalidUrl", theVerb, theUrl);
    // throw new InvalidRequestException(msg);
    // }

    return dao;
  }
  @Test
  public void testQueryBoundCodeableConcept() {
    RuntimeResourceDefinition patientType = ourCtx.getResourceDefinition(Patient.class);
    String childName = "maritalStatus";
    BaseRuntimeChildDatatypeDefinition genderChild =
        (BaseRuntimeChildDatatypeDefinition) patientType.getChildByName(childName);
    ourLog.trace(genderChild.getClass().getName());

    assertEquals(MaritalStatusCodesEnum.class, genderChild.getBoundEnumType());
  }
  @Test
  public void testQueryBoundCode() {
    RuntimeResourceDefinition patientType = ourCtx.getResourceDefinition(Patient.class);
    String childName = "gender";
    BaseRuntimeChildDatatypeDefinition genderChild =
        (BaseRuntimeChildDatatypeDefinition) patientType.getChildByName(childName);
    ourLog.trace(genderChild.getClass().getName());

    assertEquals(AdministrativeGenderEnum.class, genderChild.getBoundEnumType());
  }
Esempio n. 4
0
  @Override
  public MethodOutcome validate(IResource theResource) {
    BaseHttpClientInvocation invocation =
        ValidateMethodBinding.createValidateInvocation(theResource, null, myContext);
    if (isKeepResponses()) {
      myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
    }

    RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
    final String resourceName = def.getName();

    OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
    MethodOutcome resp = invokeClient(myContext, binding, invocation, myLogRequestAndResponse);
    return resp;
  }
Esempio n. 5
0
  @Override
  public IBaseResource generateProfile(
      RuntimeResourceDefinition theRuntimeResourceDefinition, String theServerBase) {
    StructureDefinition retVal = new StructureDefinition();

    RuntimeResourceDefinition def = theRuntimeResourceDefinition;

    myId = def.getId();
    if (StringUtils.isBlank(myId)) {
      myId = theRuntimeResourceDefinition.getName().toLowerCase();
    }

    retVal.setId(new IdDt(myId));
    return retVal;
  }
Esempio n. 6
0
    @Override
    public MethodOutcome execute() {
      if (myResource == null) {
        myResource = parseResourceBody(myResourceBody);
      }
      myId = getPreferredId(myResource, myId);

      BaseHttpClientInvocation invocation =
          MethodUtil.createCreateInvocation(myResource, myResourceBody, myId, myContext);

      RuntimeResourceDefinition def = myContext.getResourceDefinition(myResource);
      final String resourceName = def.getName();

      OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);

      Map<String, List<String>> params = new HashMap<String, List<String>>();
      return invoke(params, binding, invocation);
    }
Esempio n. 7
0
    @Override
    public MethodOutcome execute() {
      if (myResource == null) {
        myResource = parseResourceBody(myResourceBody);
      }
      if (myId == null) {
        myId = myResource.getId();
      }
      if (myId == null || myId.hasIdPart() == false) {
        throw new InvalidRequestException(
            "No ID supplied for resource to update, can not invoke server");
      }

      BaseHttpClientInvocation invocation =
          MethodUtil.createUpdateInvocation(myResource, myResourceBody, myId, myContext);

      RuntimeResourceDefinition def = myContext.getResourceDefinition(myResource);
      final String resourceName = def.getName();

      OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);

      Map<String, List<String>> params = new HashMap<String, List<String>>();
      return invoke(params, binding, invocation);
    }
Esempio n. 8
0
  private void encodeResourceToXmlStreamWriter(
      IBaseResource theResource,
      XMLStreamWriter theEventWriter,
      boolean theContainedResource,
      String theResourceId)
      throws XMLStreamException {
    if (!theContainedResource) {
      super.containResourcesForEncoding(theResource);
    }

    RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);
    if (resDef == null) {
      throw new ConfigurationException("Unknown resource type: " + theResource.getClass());
    }

    theEventWriter.writeStartElement(resDef.getName());
    theEventWriter.writeDefaultNamespace(FHIR_NS);

    if (theResource instanceof IAnyResource) {

      // HL7.org Structures
      encodeCompositeElementToStreamWriter(
          theResource, theResource, theEventWriter, resDef, theContainedResource);

    } else {

      if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {

        // DSTU2+

        IResource resource = (IResource) theResource;
        writeOptionalTagWithValue(theEventWriter, "id", theResourceId);

        InstantDt updated =
            (InstantDt) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
        IdDt resourceId = resource.getId();
        String versionIdPart = resourceId.getVersionIdPart();
        if (isBlank(versionIdPart)) {
          versionIdPart = ResourceMetadataKeyEnum.VERSION.get(resource);
        }
        List<BaseCodingDt> securityLabels =
            extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS);
        List<IdDt> profiles =
            extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES);
        TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(resource);
        if (ElementUtil.isEmpty(versionIdPart, updated, securityLabels, profiles) == false) {
          theEventWriter.writeStartElement("meta");
          writeOptionalTagWithValue(theEventWriter, "versionId", versionIdPart);
          if (updated != null) {
            writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString());
          }

          for (IdDt profile : profiles) {
            theEventWriter.writeStartElement("profile");
            theEventWriter.writeAttribute("value", profile.getValue());
            theEventWriter.writeEndElement();
          }
          for (BaseCodingDt securityLabel : securityLabels) {
            theEventWriter.writeStartElement("security");
            BaseRuntimeElementCompositeDefinition<?> def =
                (BaseRuntimeElementCompositeDefinition<?>)
                    myContext.getElementDefinition(securityLabel.getClass());
            encodeCompositeElementChildrenToStreamWriter(
                resource, securityLabel, theEventWriter, def.getChildren(), theContainedResource);
            theEventWriter.writeEndElement();
          }
          if (tags != null) {
            for (Tag tag : tags) {
              theEventWriter.writeStartElement("tag");
              writeOptionalTagWithValue(theEventWriter, "system", tag.getScheme());
              writeOptionalTagWithValue(theEventWriter, "code", tag.getTerm());
              writeOptionalTagWithValue(theEventWriter, "display", tag.getLabel());
              theEventWriter.writeEndElement();
            }
          }
          theEventWriter.writeEndElement();
        }

        if (theResource instanceof IBaseBinary) {
          IBaseBinary bin = (IBaseBinary) theResource;
          writeOptionalTagWithValue(theEventWriter, "contentType", bin.getContentType());
          writeOptionalTagWithValue(theEventWriter, "content", bin.getContentAsBase64());
        } else {
          encodeResourceToStreamWriterInDstu2Format(
              resDef, theResource, theResource, theEventWriter, resDef, theContainedResource);
        }

      } else {

        // DSTU1
        if (theResourceId != null && theContainedResource) {
          theEventWriter.writeAttribute("id", theResourceId);
        }

        if (theResource instanceof IBaseBinary) {
          IBaseBinary bin = (IBaseBinary) theResource;
          if (bin.getContentType() != null) {
            theEventWriter.writeAttribute("contentType", bin.getContentType());
          }
          theEventWriter.writeCharacters(bin.getContentAsBase64());
        } else {
          encodeCompositeElementToStreamWriter(
              theResource, theResource, theEventWriter, resDef, theContainedResource);
        }
      }
    }

    theEventWriter.writeEndElement();
  }
Esempio n. 9
0
 private void setType(Class<? extends IResource> theResourceType) {
   myResourceType = theResourceType;
   RuntimeResourceDefinition definition = myContext.getResourceDefinition(theResourceType);
   myResourceName = definition.getName();
 }