Search in sources :

Example 6 with Tag

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;
}
Also used : Setter(lombok.Setter) LocationTranslator(org.openmrs.module.fhir2.api.translators.LocationTranslator) Autowired(org.springframework.beans.factory.annotation.Autowired) Reference(org.hl7.fhir.r4.model.Reference) NumberUtils(org.apache.commons.lang.math.NumberUtils) LocationAttribute(org.openmrs.LocationAttribute) LocationTagTranslator(org.openmrs.module.fhir2.api.translators.LocationTagTranslator) FhirGlobalPropertyService(org.openmrs.module.fhir2.api.FhirGlobalPropertyService) AccessLevel(lombok.AccessLevel) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Nonnull(javax.annotation.Nonnull) FhirUtils.getMetadataTranslation(org.openmrs.module.fhir2.api.util.FhirUtils.getMetadataTranslation) Location(org.hl7.fhir.r4.model.Location) FhirLocationDao(org.openmrs.module.fhir2.api.dao.FhirLocationDao) ProvenanceTranslator(org.openmrs.module.fhir2.api.translators.ProvenanceTranslator) LocationAddressTranslator(org.openmrs.module.fhir2.api.translators.LocationAddressTranslator) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) Collectors(java.util.stream.Collectors) LocationTag(org.openmrs.LocationTag) Objects(java.util.Objects) TelecomTranslator(org.openmrs.module.fhir2.api.translators.TelecomTranslator) BaseOpenmrsData(org.openmrs.BaseOpenmrsData) List(java.util.List) Component(org.springframework.stereotype.Component) Coding(org.hl7.fhir.r4.model.Coding) Validate.notNull(org.apache.commons.lang3.Validate.notNull) Coding(org.hl7.fhir.r4.model.Coding) LocationAttribute(org.openmrs.LocationAttribute)

Example 7 with Tag

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()));
}
Also used : LocationTag(org.openmrs.LocationTag) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 8 with Tag

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()));
}
Also used : LocationTag(org.openmrs.LocationTag) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Example 9 with Tag

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();
}
Also used : ASN1Template(org.mozilla.jss.asn1.ASN1Template) UTF8String(org.mozilla.jss.asn1.UTF8String) PrintableString(org.mozilla.jss.asn1.PrintableString) TeletexString(org.mozilla.jss.asn1.TeletexString) ASN1Value(org.mozilla.jss.asn1.ASN1Value) IA5String(org.mozilla.jss.asn1.IA5String) Tag(org.mozilla.jss.asn1.Tag) UniversalString(org.mozilla.jss.asn1.UniversalString) BMPString(org.mozilla.jss.asn1.BMPString)

Example 10 with Tag

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);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) Tag(org.mozilla.jss.asn1.Tag) EXPLICIT(org.mozilla.jss.asn1.EXPLICIT) INTEGER(org.mozilla.jss.asn1.INTEGER)

Aggregations

Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)66 Test (org.junit.Test)26 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)23 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)16 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)16 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)16 Date (java.util.Date)12 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)12 Coding (org.hl7.fhir.r4.model.Coding)10 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)10 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)9 Relation (org.openstreetmap.osmosis.core.domain.v0_6.Relation)9 Test (org.junit.jupiter.api.Test)7 SQLException (java.sql.SQLException)6 UUID (java.util.UUID)6 LocationTag (org.openmrs.LocationTag)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Osmformat (crosby.binary.Osmformat)5