use of org.hl7.cql_annotations.r1.Tag in project openmrs-module-fhir2 by openmrs.
the class LocationTranslatorImpl method toOpenmrsType.
/**
* @see org.openmrs.module.fhir2.api.translators.LocationTranslator#toOpenmrsType(org.openmrs.Location,
* org.hl7.fhir.r4.model.Location)
*/
@Override
public org.openmrs.Location toOpenmrsType(@Nonnull org.openmrs.Location openmrsLocation, @Nonnull Location fhirLocation) {
notNull(openmrsLocation, "The existing Openmrs location should not be null");
notNull(fhirLocation, "The Location object should not be null");
openmrsLocation.setUuid(fhirLocation.getIdElement().getIdPart());
openmrsLocation.setName(fhirLocation.getName());
openmrsLocation.setDescription(fhirLocation.getDescription());
if (fhirLocation.getAddress() != null) {
openmrsLocation.setCityVillage(fhirLocation.getAddress().getCity());
openmrsLocation.setStateProvince(fhirLocation.getAddress().getState());
openmrsLocation.setCountry(fhirLocation.getAddress().getCountry());
openmrsLocation.setPostalCode(fhirLocation.getAddress().getPostalCode());
}
if (fhirLocation.getPosition().hasLatitude()) {
openmrsLocation.setLatitude(fhirLocation.getPosition().getLatitude().toString());
}
if (fhirLocation.getPosition().hasLongitude()) {
openmrsLocation.setLongitude(fhirLocation.getPosition().getLongitude().toString());
}
fhirLocation.getTelecom().stream().map(contactPoint -> (LocationAttribute) telecomTranslator.toOpenmrsType(new LocationAttribute(), contactPoint)).distinct().filter(Objects::nonNull).forEach(openmrsLocation::addAttribute);
if (fhirLocation.getMeta().hasTag()) {
for (Coding tag : fhirLocation.getMeta().getTag()) {
openmrsLocation.addTag(locationTagTranslator.toOpenmrsType(tag));
}
}
openmrsLocation.setParentLocation(getOpenmrsParentLocation(fhirLocation.getPartOf()));
return openmrsLocation;
}
use of org.hl7.cql_annotations.r1.Tag in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldCreateNewLocationWithExistingTagAsJson.
@Test
public void shouldCreateNewLocationWithExistingTagAsJson() throws Exception {
// Create Location Tag Before Posting LOcation
LocationTag tag = new LocationTag("mCSD_Location", "mCSD_Location");
locationService.saveLocationTag(tag);
// read JSON record
String jsonLocation;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_LOCATION_DOCUMENT)) {
Objects.requireNonNull(is);
jsonLocation = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create location
MockHttpServletResponse response = post("/Location").accept(FhirMediaTypes.JSON).jsonContent(jsonLocation).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Location location = readResponse(response);
assertThat(location, notNullValue());
assertThat(location.getName(), equalTo("Test location"));
assertThat(location.getAddress().getCity(), equalTo("kampala"));
assertThat(location.getAddress().getCountry(), equalTo("uganda"));
assertThat(location.getAddress().getState(), equalTo("MI"));
assertThat(location.getAddress().getPostalCode(), equalTo("9105 PZ"));
assertThat(location.getMeta().getTagFirstRep().getCode(), equalTo("mCSD_Location"));
assertThat(location.getMeta().getTagFirstRep().getDisplay(), equalTo("mCSD_Location"));
assertThat(location, validResource());
// try to get new location
response = get("/Location/" + location.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Location newLocation = readResponse(response);
assertThat(newLocation.getId(), equalTo(location.getId()));
}
use of org.hl7.cql_annotations.r1.Tag in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldCreateNewLocationWithExistingTagAsJson.
@Test
public void shouldCreateNewLocationWithExistingTagAsJson() throws Exception {
// Create Location Tag Before Posting LOcation
LocationTag tag = new LocationTag("mCSD_Location", "mCSD_Location");
locationService.saveLocationTag(tag);
// read JSON record
String jsonLocation;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_LOCATION_DOCUMENT)) {
Objects.requireNonNull(is);
jsonLocation = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create location
MockHttpServletResponse response = post("/Location").accept(FhirMediaTypes.JSON).jsonContent(jsonLocation).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Location location = readResponse(response);
assertThat(location, notNullValue());
assertThat(location.getName(), equalTo("Test location"));
assertThat(location.getAddress().getCity(), equalTo("kampala"));
assertThat(location.getAddress().getCountry(), equalTo("uganda"));
assertThat(location.getAddress().getState(), equalTo("MI"));
assertThat(location.getAddress().getPostalCode(), equalTo("9105 PZ"));
assertThat(location.getMeta().getTagFirstRep().getCode(), equalTo("mCSD_Location"));
assertThat(location.getMeta().getTagFirstRep().getDisplay(), equalTo("mCSD_Location"));
assertThat(location, validResource());
// try to get new location
response = get("/Location/" + location.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Location newLocation = readResponse(response);
assertThat(newLocation.getId(), equalTo(location.getId()));
}
use of org.hl7.cql_annotations.r1.Tag in project jss by dogtagpki.
the class JSSUtil method decode.
public static String decode(byte tag, byte[] bytes) throws Exception {
ASN1Template template;
switch(tag) {
case DerValue.tag_BMPString:
template = new BMPString.Template();
break;
case DerValue.tag_IA5String:
template = new IA5String.Template();
break;
case DerValue.tag_PrintableString:
template = new PrintableString.Template();
break;
case DerValue.tag_T61String:
template = new TeletexString.Template();
break;
case DerValue.tag_UniversalString:
template = new UniversalString.Template();
break;
case DerValue.tag_UTF8String:
template = new UTF8String.Template();
break;
default:
throw new Exception("Unsupported tag: " + tag);
}
ASN1Value asnValue = ASN1Util.decode(new Tag(Tag.UNIVERSAL, tag), template, bytes);
if (asnValue == null) {
throw new Exception("Cannot decode the given bytes.");
}
return asnValue.toString();
}
use of org.hl7.cql_annotations.r1.Tag in project jss by dogtagpki.
the class CertificateInfo method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
if (version != v1) {
// v1 is the default
seq.addElement(new EXPLICIT(new Tag(0), new INTEGER(version.getNumber())));
}
seq.addElement(serialNumber);
seq.addElement(signatureAlgId);
seq.addElement(issuer);
SEQUENCE validity = new SEQUENCE();
validity.addElement(encodeValidityDate(notBefore));
validity.addElement(encodeValidityDate(notAfter));
seq.addElement(validity);
seq.addElement(subject);
seq.addElement(subjectPublicKeyInfo);
if (issuerUniqueIdentifier != null) {
seq.addElement(new Tag(1), issuerUniqueIdentifier);
}
if (subjectUniqueIdentifier != null) {
seq.addElement(new Tag(2), subjectUniqueIdentifier);
}
if (extensions.size() > 0) {
seq.addElement(new EXPLICIT(new Tag(3), extensions));
}
seq.encode(implicitTag, ostream);
}
Aggregations