Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Adding coordinates to events.
Browse files Browse the repository at this point in the history
  • Loading branch information
volsch committed Oct 8, 2018
1 parent 7ce5e83 commit 3b56688
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.dhis2.fhir.adapter.prototype.converter.TypedConverter;
import org.dhis2.fhir.adapter.prototype.dhis.model.ValueType;
import org.dhis2.fhir.adapter.prototype.geo.LocationToStringConverter;
import org.dhis2.fhir.adapter.prototype.geo.StringToLocationConverter;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -63,6 +64,7 @@ protected void initConverters()
addConverter( ValueType.DATETIME, new LocalDateToZonedDateTimeConverter() );
addConverter( ValueType.DATETIME, new ObjectToZonedDateTimeConverter() );
addConverter( ValueType.COORDINATE, new LocationToStringConverter() );
addConverter( ValueType.COORDINATE, new StringToLocationConverter() );
addConverter( ValueType.TEXT, new DoubleToTextStringConverter() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.dhis2.fhir.adapter.prototype.dhis.model.DhisResource;
import org.dhis2.fhir.adapter.prototype.dhis.model.DhisResourceType;
import org.dhis2.fhir.adapter.prototype.dhis.model.WritableDataValue;
import org.dhis2.fhir.adapter.prototype.geo.Location;

import javax.annotation.Nonnull;
import java.io.Serializable;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class Event implements DhisResource, Serializable, Comparable<Event>

private ZonedDateTime dueDate;

private Location coordinate;

private List<WritableDataValue> dataValues;

@JsonIgnore
Expand Down Expand Up @@ -213,6 +216,16 @@ public void setDueDate( ZonedDateTime dueDate )
this.dueDate = dueDate;
}

public Location getCoordinate()
{
return coordinate;
}

public void setCoordinate( Location coordinate )
{
this.coordinate = coordinate;
}

public List<? extends DataValue> getDataValues()
{
return dataValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.dhis2.fhir.adapter.prototype.Scriptable;
import org.dhis2.fhir.adapter.prototype.fhir.transform.TransformException;
import org.dhis2.fhir.adapter.prototype.geo.Location;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -75,6 +76,13 @@ public ZonedDateTime getEventDate()
return delegate.getEventDate();
}

@Nullable
@Override
public Location getCoordinate()
{
return delegate.getCoordinate();
}

@Override
public void validate() throws TransformException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.dhis2.fhir.adapter.prototype.Scriptable;
import org.dhis2.fhir.adapter.prototype.fhir.transform.scripted.ScriptedDhisResource;
import org.dhis2.fhir.adapter.prototype.geo.Location;

import javax.annotation.Nullable;
import java.time.ZonedDateTime;
Expand All @@ -45,4 +46,7 @@ public interface ScriptedEvent extends ScriptedDhisResource

@Nullable
ZonedDateTime getEventDate();

@Nullable
Location getCoordinate();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
import org.dhis2.fhir.adapter.prototype.converter.ConversionException;
import org.dhis2.fhir.adapter.prototype.dhis.converter.DhisValueConverter;
import org.dhis2.fhir.adapter.prototype.dhis.model.DataValue;
import org.dhis2.fhir.adapter.prototype.dhis.model.ValueType;
import org.dhis2.fhir.adapter.prototype.dhis.model.WritableDataValue;
import org.dhis2.fhir.adapter.prototype.dhis.tracker.program.Event;
import org.dhis2.fhir.adapter.prototype.dhis.tracker.program.ProgramStage;
import org.dhis2.fhir.adapter.prototype.dhis.tracker.program.ProgramStageDataElement;
import org.dhis2.fhir.adapter.prototype.fhir.transform.TransformException;
import org.dhis2.fhir.adapter.prototype.fhir.transform.TransformMappingException;
import org.dhis2.fhir.adapter.prototype.geo.Location;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -146,6 +148,18 @@ protected void setValue( @Nonnull ProgramStageDataElement dataElement, Object va
}
}

@Nullable
@Override
public Location getCoordinate()
{
return event.getCoordinate();
}

public void setCoordinate(@Nullable Location location) {
event.setCoordinate( location );
event.setModified( true );
}

public boolean isAnyDataValueModified()
{
return (event.getDataValues() != null) && event.getDataValues().stream().anyMatch( DataValue::isModified );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ public class Location implements Geometry, Serializable
{
private static final long serialVersionUID = 7916805545140123930L;

private final double longitude;
private double longitude;

private final double latitude;
private double latitude;

public Location()
{
super();
}

public Location( double longitude, double latitude )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.dhis2.fhir.adapter.prototype.geo;

/*
* Copyright (c) 2004-2018, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import org.dhis2.fhir.adapter.prototype.converter.ConversionException;
import org.dhis2.fhir.adapter.prototype.converter.TypedConverter;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringToLocationConverter extends TypedConverter<String, Location>
{
private final Pattern locationPattern = Pattern.compile( "\\[\\s*([\\d.]+)\\s*,\\s*([\\d.]+)\\s*\\]" );

public StringToLocationConverter()
{
super( String.class, Location.class );
}

@Nullable
@Override
public Location doConvert( @Nonnull String source ) throws ConversionException
{
final Matcher matcher = locationPattern.matcher( source );
if (!matcher.matches()) {
throw new ConversionException( "Not a valid location: " + source );
}
try {
return new Location( Double.valueOf( matcher.group( 1 ) ), Double.valueOf( matcher.group( 2 ) ) );
} catch(NumberFormatException e) {
throw new ConversionException( "Not a valid location: " + source );
}
}
}
18 changes: 11 additions & 7 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ VALUES ('664b61b4-c0ab-4be0-8865-eec266902fac', 0, '73cd99c5-0ca8-42ad-a53b-1891
INSERT INTO FHIR_AUTOMATED_ENROLLMENT VALUES('e48eb514-aa60-4541-841a-16119507e525',1,'var age = dateTimeUtils.getAge( trackedEntityInstance.getValueByName(''Birth date'') ); (age != null) && (age < 1)','output.organizationUnitId = trackedEntityInstance' ||
'.organizationUnitId; output.enrollmentDate = new Date(); output.incidentDate = trackedEntityInstance.getValueByName( ''Birth date'' ); true;');
INSERT INTO FHIR_DHIS_MAP VALUES('13aeb380-0695-4e36-b255-36e18aa8a5c2',1,'IMMUNIZATION','DSTU3','EVENT',TRUE,1,'!input.notGiven && codeUtils.getCode( input.vaccineCode, ''http://example.ph/vaccine-codes'' ) == ''BCG''','output.setValueByName( ''CP - MCH ' ||
'BCG dose'', true ); true;',NULL,NULL,NULL,FALSE);
'BCG dose'', true ); output.coordinate=trackedEntityInstance.coordinates; true;',NULL,NULL,NULL,FALSE);
INSERT INTO FHIR_DHIS_MAP VALUES('5b4bae24-ec73-46fc-89ef-accfcd81e14d',1,'IMMUNIZATION','DSTU3','EVENT',TRUE,1,'!input.notGiven && codeUtils.getCode( input.vaccineCode, ''http://example.ph/vaccine-codes'' ) == ''MMR''','output.setValueByName( ''CP - MCH ' ||
'Measles dose'', true ); true;',NULL,NULL,NULL,FALSE);
'Measles dose'', true ); output.coordinate=trackedEntityInstance.coordinates; true;',NULL,NULL,NULL,FALSE);
INSERT INTO FHIR_DHIS_MAP VALUES('a5623570-446a-4267-944b-025a2c35c18c',1,'PATIENT','DSTU3','TRACKED_ENTITY',TRUE,1,'true','output.organizationUnitId = organizationUtils.getOrganizationUnitId( input.managingOrganization, ''http://example.ph/organizations'' ' ||
'); output.setValueByName( ''National identifier'', identifierUtils.getIdentifier( input, ''http://example.ph/national-patient-id'' ) ); output.setValueByName( ''Last name'', humanNameUtils.getPrimaryName( input.name ).family ); output.setValueByName( ''First name'', humanNameUtils.getSingleGiven( humanNameUtils.getPrimaryName( input.name ) ) ); output.setValueByName( ''Birth date'', dateTimeUtils.getPreciseDate( input.birthDateElement ) ); output.setValueByName( ''Gender'', input.gender ); output.setValueByName( ''Address line'', addressUtils.getSingleLine( addressUtils.getPrimaryAddress( input.address ) ) ); output.setValueByName( ''City'', addressUtils.getPrimaryAddress( input.address ).city ); output.setValueByName( ''State of country'', addressUtils.getPrimaryAddress( input.address ).state ); output.setValueByName( ''Country'', addressUtils.getPrimaryAddress( input.address ).country ); output.coordinates = geoUtils.getLocation( addressUtils.getPrimaryAddress( input.address ) ); true;','National identifier','NAME','http://example.ph/national-patient-id',FALSE);
'); output.setValueByName( ''National identifier'', identifierUtils.getIdentifier( input, ''http://example.ph/national-patient-id'' ) ); output.setValueByName( ''Last name'', humanNameUtils.getPrimaryName( input.name ).family ); output.setValueByName( ' ||
'''First name'', humanNameUtils.getSingleGiven( humanNameUtils.getPrimaryName( input.name ) ) ); output.setValueByName( ''Birth date'', dateTimeUtils.getPreciseDate( input.birthDateElement ) ); output.setValueByName( ''Gender'', input.gender ); output' ||
'.setValueByName( ''Address line'', addressUtils.getSingleLine( addressUtils.getPrimaryAddress( input.address ) ) ); output.setValueByName( ''City'', addressUtils.getPrimaryAddress( input.address ).city ); output.setValueByName( ''State of country'', ' ||
'addressUtils.getPrimaryAddress( input.address ).state ); output.setValueByName( ''Country'', addressUtils.getPrimaryAddress( input.address ).country ); output.coordinates = geoUtils.getLocation( addressUtils.getPrimaryAddress( input.address ) ); true;',
'National identifier','NAME','http://example.ph/national-patient-id',FALSE);
INSERT INTO FHIR_DHIS_MAP VALUES('f4e164a7-ed91-4f76-83b8-eda0daa0b406',1,'IMMUNIZATION','DSTU3','EVENT',TRUE,1,'!input.notGiven && codeUtils.getCode( input.vaccineCode, ''http://example.ph/vaccine-codes'' ) == ''OPV''','output.setValueByName( ''CP - MCH ' ||
'OPV dose'', Math.max(0, Math.min(3, immunizationUtils.getMaxDoseSequence(input)-1)) ); true;',NULL,NULL,NULL,FALSE);
'OPV dose'', Math.max(0, Math.min(3, immunizationUtils.getMaxDoseSequence(input)-1)) ); output.coordinate=trackedEntityInstance.coordinates; true;',NULL,NULL,NULL,FALSE);
INSERT INTO FHIR_DHIS_MAP VALUES('f4e164a7-ed91-4f76-83b8-eda0daa0b408',1,'IMMUNIZATION','DSTU3','EVENT',TRUE,1,'!input.notGiven && codeUtils.getCode( input.vaccineCode, ''http://example.ph/vaccine-codes'' ) == ''DTaP''','output.setValueByName( ''CP - MCH ' ||
'DPT dose'', Math.max(1, Math.min(3, immunizationUtils.getMaxDoseSequence(input))) ); true;',NULL,NULL,NULL,FALSE);
'DPT dose'', Math.max(1, Math.min(3, immunizationUtils.getMaxDoseSequence(input))) ); output.coordinate=trackedEntityInstance.coordinates; true;',NULL,NULL,NULL,FALSE);
INSERT INTO FHIR_TRACKED_ENTITY_MAP VALUES('a5623570-446a-4267-944b-025a2c35c18c','Person');
INSERT INTO FHIR_EVENT_MAP VALUES('13aeb380-0695-4e36-b255-36e18aa8a5c2','Child Programme','Birth',TRUE,'e48eb514-aa60-4541-841a-16119507e525');
INSERT INTO FHIR_EVENT_MAP VALUES('5b4bae24-ec73-46fc-89ef-accfcd81e14d','Child Programme','Baby Postnatal',TRUE,'e48eb514-aa60-4541-841a-16119507e525');
Expand All @@ -72,8 +76,8 @@ INSERT INTO FHIR_AUTOMATED_ENROLLMENT VALUES('2f311cf9-f1a5-4c7d-8c3e-7d92509fc8
'.incidentDate = (observation == null) || !observation.hasValueDateTimeType() ? null : observation.valueDateTimeType; (output.incidentDate != null)');
INSERT INTO FHIR_DHIS_MAP VALUES('f33451e1-ab0b-4bdd-bcd9-8784b3717f2b',1,'OBSERVATION','DSTU3','EVENT',TRUE,1,'codeUtils.containsCode( input.code, ''http://loinc.org'', ''85354-9'' )','output.setValueByName(''RMNCH - WHOMCH Diastolic blood pressure''' ||
', observationUtils.getBackboneElement(input.component, ''http://loinc.org'', ''8462-4'').value); output.setValueByName(''RMNCH - WHOMCH Systolic blood pressure'', observationUtils.getBackboneElement(input.component, ''http://loinc.org'', ''8480-6'')' ||
'.value); true',NULL,NULL,NULL,FALSE);
'.value); output.coordinate=trackedEntityInstance.coordinates; true',NULL,NULL,NULL,FALSE);
INSERT INTO FHIR_EVENT_MAP VALUES('f33451e1-ab0b-4bdd-bcd9-8784b3717f2b','WHO RMNCH Tracker','First antenatal care visit',TRUE,'2f311cf9-f1a5-4c7d-8c3e-7d92509fc850');
INSERT INTO FHIR_DHIS_MAP VALUES('d43c264f-7331-4c64-9af5-46e1da610fe8',1,'OBSERVATION','DSTU3','EVENT',TRUE,1,'codeUtils.containsCode( input.code, ''http://loinc.org'', ''8665-2'' )',
'output.setValueByName(''RMNCH - WHOMCH LMP date'', input.hasValueDateTimeType() ? input.valueDateTimeType : null); true',NULL,NULL,NULL,FALSE);
'output.setValueByName(''RMNCH - WHOMCH LMP date'', input.hasValueDateTimeType() ? input.valueDateTimeType : null); output.coordinate=trackedEntityInstance.coordinates; true',NULL,NULL,NULL,FALSE);
INSERT INTO FHIR_EVENT_MAP VALUES('d43c264f-7331-4c64-9af5-46e1da610fe8','WHO RMNCH Tracker','First antenatal care visit',TRUE,'2f311cf9-f1a5-4c7d-8c3e-7d92509fc850');

0 comments on commit 3b56688

Please sign in to comment.