/** Returns a full representation for a given variant. */ @Override public Representation represent(Variant variant) throws ResourceException { String endPoint; if (version == 1) { jsonRequestString = "{getMedicationFacts:{criteria:{queryId:\"20100411011010\",\"senderId\":\"Adapter Assembly Service\",\"interactionId\":\"QUPC_IN043100UV\",\"triggerEventCode\":\"QUPC_TE043100UV0\",\"patientId\":\"" + patientId + "\",\"careProvisionCode\":\"HISTMEDLIST\",\"careRecordStartTimePeriod\":\"" + fromDate + "\",\"careRecordEndTimePeriod\":\"" + toDate + "\"}}}"; endPoint = this.getProperty("JSONPojoFactServiceEndpoint"); } else { jsonRequestString = "{\"getMedicationFacts\":{\"criteria\":{\"queryId\":\"20100411011010\",\"senderId\":\"Adapter Assembly Service\",\"interactionId\":\"QUPC_IN043100UV\",\"triggerEventCode\":\"QUPC_TE043100UV01\"," + "\"careRecordPayload\":{\"patientId\":\"" + patientId + "\",\"careProvisionCode\":\"HISTMEDLIST\",\"careRecordStartTimePeriod\":\"" + fromDate + "\",\"careRecordEndTimePeriod\":\"" + toDate + "\"}}}}"; endPoint = this.getProperty("JSONPojoFactServiceEndpointV2"); } try { Client client = new Client(Protocol.HTTP); client.setConnectTimeout(10); Request request = new Request( Method.POST, new Reference(endPoint), new StringRepresentation(jsonRequestString)); Response response = client.handle(request); if (response.getStatus().isSuccess()) { String rep = response.getEntity().getText(); JSONObject jo = new JSONObject(rep); Object omf = jo.get("medicationFact"); if (!(omf instanceof JSONArray)) { JSONArray joa = new JSONArray(); joa.put(omf); jo.remove("medicationFact"); jo.put("medicationFact", joa); rep = jo.toString(); } Representation representation = new StringRepresentation(rep, MediaType.APPLICATION_JSON); return representation; } else { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "Error during call to JSONPojoFactServiceEndpoint, Status = " + response.getStatus().getDescription()); } } catch (ResourceException e) { throw e; } catch (Exception e) { Logger.getLogger(AllergiesResource.class.getName()).log(Level.SEVERE, null, e); throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "Error calling JSONPojoFactServiceEndpoint", e); } }